|Home | Downloads | Project Information | Discussion Groups | Tutorials | Team|
An Intro to OpenEmcee Microflow Validators
By Scott Schenkein, Edited By Michael Roane
Welcome to the OpenEmcee Microflow Validator introduction. In my career as a systems programmer, I have often found myself looking for an elegant and repeatable way to validate the data flowing through systems. While input validation is an essential part of any stable system, it has a tendency to hinder the readability (and thus understandability) of code.
In our first installment, "An Intro Tutorial to OpenEmcee Microflows", we showed how we can use the OpenEmcee Microflow Engine to separate business logic from core program flow. In this article, we will demonstrate how we can use the framework to separate data validation from business logic, and program flow.
Data Permissions Revisited
Recall from the first tutorial that we register permissions for data that we wish to flow through our Microflow. We have removed all but one data permission from the other example here for sake of clarity.
In this example, we use what is called "un-validated, typed data". In other words, the data is guaranteed to be of a certain type (here java.lang.String), but the content of that data is not guaranteed.
The problem we are solving
Let's say that our system is having issues because the system, which is generating our "account_id", sometimes returns garbage instead of an actual order number. For example, "COBOL EXC 9432, UNABLE TO DO PHYSICAL ORDER FETCH OF DATA" rather than "A348933434".
In order to maintain the integrity of our system, we are going to create a data validation routine. If we encounter an invalid "account_id", the system needs to cease processing to avoid any downstream impact.
Here are the requirements for our validation:
How we solve the problem
The OpenEmcee Microflow framework provides a validation interface. In order to use this interface, one must create a class which implements the "org.openemcee.microflow.usercore.PermissionedDataValidator" interface. This interface contains two methods:
public boolean setParameters(MicroflowParameters
The "setParameters" method is called once when the Validator is created to expose any configuration parameters that are exposed in the XML. We'll talk about the syntax for those later.
The "validate" method is called AFTER a task that accesses or modifies the "validated" data completes.
The Java implementation for the Validator
As we discussed before, we are going to implement the "PermissionedDataValidator" interface to create our validator. Please see the following code, and its embedded comments to understand how this works.
As you see in the above example, we implement the two methods, returning "true" for a success, and "false" for a failure.
Configuring and Installing your Validator
Now that we have created a validator, we are going to install it into our flow. Please see the following XML and inline comments.
Save your XML, (re)start your client, and you're on your way.
The Microflow Validator lifecycle is defined as follows:
1) A validator is created using the default constructor. If no public
default constructor is available, the workflow terminates with a CreationException.
What we've learned
You have now seen how Validators can be used to ensure the integrity of data in an OpenEmcee Microflow, without impacting your business logic or program flow. Note that different Validators can be used in different "contexts" (Microflow Jobs) with the same data, making your core application tasks more reusable.
In a future release of OpenEmcee, we plan to provide some basic canned validators like "String Length", "Number Range", "Regular Expression Matches", etc… If you have an idea for a canned validator you'd like to see, please don't hesitate to send me your ideas, either directly or to the "openemcee-users" list.
Please let us know what you think about the product and this tutorial.
Any software or content on this or affiliated project site are released for your use under MPL 1.1 License. Please see source code modules for complete license.