Today let me talk about user input validation in Oracle Policy Automation. We can validate the user input data in two ways, either by creating error and warning events in the Oracle Policy Automation rule document or via the Oracle Policy Modeling tool. This post is about doing through OPA rule document. Validation can be achieved by writing error and warning events in the rule doc. You can keep a separate rule document for this purpose or you can just write along with the rule whose input to which we need to do the input validation. Anyway the oracle determination engine will take care the execution order by prioritizing the rules.
Input validation will either warn or prevent the user from entering the data which is not allowed or expected. The error and warning events won’t conduct inferencing on the attributes instead it will just trigger the command/message specified on the rule if the attribute involved is known. This events requires the conclusion to be known as it won’t conduct inferencing. Now, don’t get confused on that line let’s move on to some real live example.
Input Validation in OPA using Error and Warning Events
Start by creating a new project in Oracle Policy Modeling tool and name it as Error_Warning_Test. (any name is fine).
Now create a new rule document. Locate the rules folder in the left project explorer pane. Right click on rules –> Add New Word Document. Double click on the word doc and it will open the Microsoft Word window. In there write down the following rules;
Error(“You can only be married to one person.”) if
the applicant’s number of spouses > 1
warning(“The date of birth you have entered is in the future.”) if
the person’s date of birth > the current date
the application will be processed if
the applicant’s number of spouses is known and
the person’s date of birth is known
It will look like this in the screen;
Now, add the attributes using the Add Attribute button on the top. Here ‘the applicant’s number of spouses’ and ‘the person’s date of birth’ are the number and date attributes respectively.
PS: The Error, Warning events are declared as conclusion.
Once you have done that you can just compile the rule doc and if everything is rite your rules will get compiled successfully. Go back to the OPM window and select build and run the project.
You will get the following screens on the browser;
Click on that link to start inferencing the rule. It will first display the question about the number of spouses. If you look here we cannot continue the execution if we enter more than 1 spouse. We have declared this as a error event so the message will appear in red colors and the submit button won’t continue unless and until you solve that error.
Once you enter 1 as the number of spouse the application will continue executing and it will show the screen for entering the date of birth. Now we have added a warning message here if the user enters future date. See the screen below;
The warning message will shown in black color and it will pop up on the first submit attempt. Here as it is a warning event you can ignore it and continue.
The final conclusion screen;
Error events won’t allow user to continue with the application execution unless and until the expected input is entered. Whereas, the Warning Event will show only a message and the user can continue by ignoring it.
So that’s all about the input validation in OPA by creating error and warning events in the rule document. There is another type of input validation in OPA that can be implemented in the OPM tool. See my post on How To Do Input Validation in OPM Using Regular Expressions, Max-Min Values for detailed step by step guide.
Hope you liked the post. Connect with me on LinkedIn by following the link below. Subscribe for free email newsletters and like us on Facebook to get instant updates. Thank you for reading.