Decision Model “Vacation Days”

Building Decision Model in Excel
Testing Decision Model
Integrating Decision Model

Business Logic

This decision model specifies decision logic for assigning vacation days to an employee based on his/her age and years of service. Here are the business rules:

Every employee receives at least 22 vacation days. Additional days are provided depending on age and years of service:

    • Only employees younger than 18 or at least 60 years, or employees with at least 30 years of service will receive an extra 5 days;
    • Employees with at least 30 years of service and also employees of age 60 or more receive an extra 3 days, on top of possible additional days already given;
    • If an employee has at least 15 but less than 30 years of service, an extra 2 days are given. These 2 days are also provided for employees of age 45 or more. These extra 2 days cannot be combined with an extra 5 days.

Building Decision Model in Excel

Our decision model represents business logic that determines the following goals:

    1. The ultimate goal “Vacation Days” can be presented in the decision table “CalculateVacationDays”:

As usual, all columns in the first row of any OpenRules table should be merged. This table has type “DecisionTableMultiHit” that force it to execute all satisfied rules. It allowed us to accumulate assigned vacation days by adding extra days when an employee is eligible for them. This table already takes care of the rule “An extra 2 days cannot be combined with an extra 5 days.” Now we need to specify sub-goals for different extra days.

2. To specify the sub-goal “Eligible for Extra 5 Days” we can use the following decision table:

This is a regular, single-hit decision table that stops working when at one rule is satisfied.

3. To specify the sub-goal “Eligible for Extra 3 Days” we can use the following decision table:

4. To specify the sub-goal “Eligible for Extra 2 Days” we can use the following decision table:

To complete our decision model we need to put all decision variables (goals and input variables used in the above tables) in one Glossary:

Thus, our complete decision model consists of the glossary surrounded by decision tables for all goals:

We placed all these 4 decision tables in the file “rules/Rules.xls”.

Testing Decision Model

To test this model,  we create test-cases in Excel using the following tables:

    1. Datatype table that specifies our business concept Customer:
    2. Data table that specifies test-customers:
    3. Test cases with expected results defined in this table:

We placed all these 3 tables in the file “rules/Test.xls”. We also created the file “rules/DecisionModel.xls” that contains only one table that tells OpenRules where all related files are located:

To execute these test-cases, we should adjust the standard file “settings.bat“:

To execute these test-cases, we may simply double-click on the standard bat-files:

    • build.bat that will automatically determine all dependencies within the decision model and transforms the model in the executable code
    • run.bat that will execute the model producing the following results for the test-case D:

You can also look at the generated HTML report that explains which rules were actually executed and why:

Integrating Decision Model with a Java Application

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 to incorporate this model into a Java application or deploy as a containerized decision service. Here is an example of a Java launcher that can be used to execute the above model “Vacation Days” from a Java application:

Thus, every decision model, built with OpenRules DM, includes a Java class such as DecisionModelVacationDays. 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 Employee (that is another Java class generated based on the Datatype “Employee”) should be passed to the goal using goal.use(“Employee”,employee); and then the goal maybe simply executed using goal.execute(); 

This program will print the following results:

*** Decision DecisionModelVacationDays initialized ***
Execute Vacation Days
Execute SetEligibleForExtra5Days
Assign: Eligible for Extra 5 Days = false
Execute SetEligibleForExtra3Days
Assign: Eligible for Extra 3 Days = false
Execute SetEligibleForExtra2Days
Assign: Eligible for Extra 2 Days = true
Execute CalculateVacationDays
Conclusion: Vacation Days = 22
Conclusion: Vacation Days += 24
*** Decision DecisionModelVacationDays finalized ***
Vacation Days = 24