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: