Open Your Business Rules!
Rules-based
Operational Decision Services
Release Notes 6.4.2 (May-2017)
OpenRules® Release 6.4.2 adds new decision modeling capabilities listed below:
- DecisionTableAssign
- DecisionTableIterate
- DecisionTableSort
- New Decision Methods for Array Iteration and Sorting
- Custom Reporting of Executed Rules
- New Decision Projects
New "DecisionTableAssign" for Multiple Assignments
We added a special type "DecisionTableAssign" that simplifies assignments of values to decision variables. Here is an example of this new type of decision tables:
The first column contains decision variable, to which the values from the second column will be assigned. The values may be calculated using DMN FEEL formulas (like in this example) or OpenRules Java snippets. This table is equivalent to the regular decision table:
You can see the entire decision model that uses this decision table in the standard project "DecisionLoanPreQualification".
New "DecisionTableIterate" for Iteration Over Arrays
We added a special type "DecisionTableIterate" that allows you to iterate over arrays like in the following example:
This table iterates over arrays of objects, defined in the first column, applying the rules, defined in the second column, to every element of these arrays. This example is borrowed from the sample project "DecisionUserv", which glossary consists of 3 business concepts: Driver, Car, and Client. Client defines decision variables Drivers and Cars that actually are arrays of objects which have types Driver and Car correspondingly.
Previously to iterate over arrays our customers used regular decision tables with a special action of the type "ActionRulesOnArray" like in this example:
Whle for bacl-compatibility this action remains intact, now you may replace this action with a more simple type "ActionIterate" that does not require the column "Array Type":
This new table type "DecisionTableIterate" allows a user to avoid DMN FEEL explicit loops expressed using for..return expressions.
New "DecisionTableSort" for Array Sorting
We added a special type "DecisionTableSort" that allows you to sort arrays using regular decision tables that compare any two elements of such arrays. Consider the following example provided in the standard project "DecisionSortPassengers":
This table sorts the arrays "Passengers", which elements have type "Passenger". During the sorting process, every two elements of this array are compared using the following rules:
This table assigns scores to each pair of passengers (Passenger 1 and Passenger 2) - a passenger with higher credentials is supposed to receive a higher score. The name of this table "ComparePassengers" is composed by the word "Compare" and the name of the array "Passengers" (with omitting spaces if any). If you prefer to explicitly define the comparison rules, you can do it using the following decision table format:
It's assumed that the elements of the array "Passengers" are instances of a Java class "Passenger" that extends the standard OpenRules class ComparableDecisionVariable.
The proper Glossary is defined as follows:
Thus, the array itself is a decision variable defined by the business concept "Problem". The glossary must include two business concepts "Passenger1" and "Passenger2", which names are formed by adding "1" and "2" to the type of the array elements. These business concepts should at a minimum include all decision variables that are being used by the comparison rules "ComparePassengers". You may find more complex example in the sample project "DecisionFlightRebooking".
This new table of the type "DecisionTableSort" allows a user to avoid text expression "sort" introduced by the DMN FEEL.
The sample project "DecisionSortProducts" demonstrates how to sort arrays of objects not inherited from ComparableDecisionVariable.
New Decision Methods for Array Iteration and Sorting
The above decision tables utilize the following new methods added to the standard class Decision:
-
iterate(String arrayName, String rules) - Iterates over the array "arrayName" applying rules from the decision table "rules" to each element of the array
-
iterate(String arrayName, String arrayType, String rules) - an additional second parameter specifies the type of each element of the array
-
sort(String arrayName) - sorts the array "arrayName". The name of a decision table to compare any two elements of the array is defined automatically as "Compare"+arrayName. For example, if your glossary specifies an array "Passengers" of the type "Passenger" you may sort this array by calling sort("Passengers") and using the decision table "ComparePassengers" that compares objects specified in the glossary as "Passenger1" and "Passenger2".
-
sort(String arrayName, String rules) - sorts the array "arrayName" using the comparison "rules"
-
sort(ComparableDecisionVariable[] array) - sorts this "array". The name of a decision table to compare any two elements of this array is defined automatically as "Compare<Type>" where <Type> is a type of the array elements.
-
sort(ComparableDecisionVariable[] array, String rules - sorts this "array" using the "rules" to compare the array elements.
Custom Reporting of Executed Rules
To generate HTML reports that contain actually executed rules OpenRules customers may simply specify decision.put("report", "On") before executing a decision. This feature was available only in design time as it did not support production environments with concurrent users. Now it can be used in production environment as well with concurrent users.
More than that, we opened the internal API that is used by the Why-Analyzer to show the actually generated rules. Now a user has an ability to show the executed rules in its own format, e.g. to display them in a custom GUI. Here is an example of the code to display the executed rules after the execution of the decision:
ReportInMemory report = decision.getReport().getReportInMemory();ArrayList<RuleInMemory> rules = report.getRulesInMemory();
for (int i = 0; i < rules.size(); i++) {
RuleInMemory rule = rules.get(i);
decision.log("RuleText: " + rule.getRule() + " DecisionTable: " + rule.getTable() + " Rule#: " + rule.getNumber());
}
We added several sample projects to the workspace "openrules.dmn":
- DecisionLoanApproval - this is a solution for the DMCommunity Challenge "Loan Approval"
- DecisionAggregatedValues - demonstrates how to calculate different attributes of a collection of business objects
- DecisionSortProducts - demonstrates how to create arrays of products which can be recommended to different customers and how to soft these arrays based on the best-fit criteria
- DecisionSortPassengers - demonstrates how to create arrays of passengers using their frequent flyer status and miles
- DecisionFlightRebooking - demonstrates how to sort and array of passengers and then how to iterate over all elements of this array applying different rules
- DecisionUserv - this project has been modified to demonstrate the use of DecisionTableIterate.
Download the latest complete OpenRules® release 6.4.2 from here.
If you have any questions, comments or suggestions, please post them at the Google Discussion Group or send them directly to support@openrules.com.