This decision model specifies how to greet a customer based on the time of the day, gender, and marital status. For example, if a customer Robinson is a married woman and current time is 14:25, we want our decision model to produce a hello statement like “Good Afternoon, Mrs. Robinson!”
Our decision model represents business logic that determines the following goals:
- Goal “Greeting” with possible values “Good Morning”, “Good Afternoon”, etc. that can be defined by the following decision table:
- Goal “Salutation” with possible values “Mr.”, “Ms.” And “Mrs.” that can be defined by the following decision table:
- The ultimate goal “Hello Statement” that combines Greeting, Salutation and Customer’s Name in one hello-statement that can be define as follows:
To complete our decision model we need to put all decision variables (goals and input variables used in the above tables) in one Glossary by defining their business names, business concepts they belong to, technical names (attributes fro future integration), and type :
Thus, our complete decision model consists of the glossary surrounded by decision tables for all goals.
Please note the following convention for all OpenRules tables:
- All columns in the first row of any OpenRules table are merged. The merged cells define the start and end columns of OpenRules tables.
- The start of any OpenRules table is recognized by a keyword such as “DecisionTable” or “Glossary”. The bottom of any table is recognized by the last non-empty row. To to be on the safe side, always surround OpenRules tables by empty rows and columns.
To test this model, we create test-cases in Excel using the following tables:
- Data table that specifies test-customers:
- Test cases with expected results defined in this table:
To execute these test-cases, we may simply double-click on the provided bat-file:
- run.bat that will automatically determine all dependencies within the decision model, transforms the model in the executable code, and will execute the model against all test cases producing the following results for the 1st test-case:
You can also look at the generated HTML report that explains which rules were actually executed and why:
After decision models have been tested, their authors usually passed them to Java developers. Any decision model built with OpenRules Decision Manager will include its Java representation that is usually out of interest for business people. But developers would use the generate Java code (in the folder “target”) to incorporate this model into a Java application. Here is an example of a Java launcher that can be used to execute the above model “Hello Customer” from a Java application:
Thus, every decision model, built with OpenRules Decision Manager, includes a Java class similar to DecisionModelHello. A developer may ask this model to create an object of the type Goal for any available business goal. Then the actual object of the type Customer (that is another Java class generated based on the Datatype) should be passed to the goal using goal.use(“Customer”,customer); and then the goal maybe simply executed using goal.execute();
This code will print these results:
Customer [name=Robert Smith, gender=Male, maritalStatus=Single, currentHour=15, helloStatement=Good Afternoon, Mr. Robert Smith!]