Decision Table Support in the Rules Engine

EN | ES

Available from version 3.0.0

It has been possible for a long time to create business rules on the platform thanks to the Rules Engine module.

In this Q1 we have made several significant improvements in this module, such as the support of Decision Tables, a new wrapper to be able to execute queries on ontologies in a very simple way within the rule and the possibility of loading a JSON from a file in the part rules testing.

Decision Table Support

Until now it was only possible to create rules defined in DRL (Drools Rule Language), from this version of the Platform it is also possible to define rules based on DDT (Drools Decision Tables).

Decision Tables in Drools have to be defined in Excel format (XLS, XLSX), where each row is a rule and each column in that row is a condition or action for that rule. Ideally, the rules are created without regard to the order of the rows, making them easy to maintain.

How to create a rule based on DDT

It is recommended to read the documentation regarding the semantics of Decision Tables in Drools. You can check it here.

Access the menu option Development> My Rules and you will access your domain, within your domain is where you can find your rules. By default it will be started, if you stop it your rules defined on ontologies will not be executed automatically.

Selecting the eye icon, access the list of your rules where if we select the Create button we will access the form for creating the rules:

A Load Decision Table check has been added and when selecting it, the option to select the Excel file of our team that we want to use as a Decision Table will appear.

In the event that there are problems with the syntax within the table, an error will appear when creating the rule.

For the rule to work, the following considerations must be taken:

  • RuleSet: has to be com.minsait.onesait.platform.rulesengine

  • Import: the com.minsait.onesait.platform.rulesengine.model.OntologyJsonWrapper class always has to be imported

  • Variables: the global output variable must always be defined, which will be of the OntologyJsonWrapper type since it will be the output object of the rule.

  • Condition: the input object must always be defined in the conditions, which will be of the OntologyJsonWrapper type since it will be our input JSON to the rule.

As for the rules defined in DRL, we have the following methods available for the OntologyJsonWrapper class:

  • getProperty("property_name") to get the value of a property

  • setProperty("property_name", value) to set a value to a property

  • setRootNode("root_node") root element of the target ontology, necessary for the Ontology type rules to work correctly

  • removeProperty("property_name") to remove a property

  • updateProperty("property_name", value) to update a property

  • copyInputToOutput() to copy the input object to the output object

  • printValues() to paint in the logs of the RulesEngine the value of the object

  • toJson() to convert the object to Json format

These functions can be used both in conditions and in actions, let's analyze an example table:

In this case, when the currentSalary property of the input object is less than 1000, then the output object would look like this:

1 2 3 4 5 6 { "roles": { "name": "Junior Role", "role": "junior" } }

Whereas when currentSalary is less than 2000 we would have the following output:

1 2 3 4 5 6 { "roles": { "name": "Consultant Role", "role": "consultant" } }

Rules management

Once the rule defined on a DDT is created, we can manage it as a rule defined in DRL. If we access the list of our rules:

When selecting a rule defined on a Decision Table, different options will appear:

  • Test: it will give us the possibility to test the rule, given an input JSON it will give us the output JSON resulting from executing the rule.

  • Edit: to edit the rule it will be necessary to load a new Decision Table using the Load Decision Table button

  • Download: allows you to download the Excel file of the associated rule.

In addition, if we click with the right mouse button on the rule in the list, the options will appear:

  • Disable: disables the rule, it does not run

  • Edit: will send you to the edit screen of the rule

  • Remove: removes the rule.