Improvements to the Rules Engine
In Onesait Platform version 3.0.0-Jailbreak, we have incorporated some significant improvements to the Rules Engine – a rules engine that allows you to create business rules.
Next we offer you a brief description of these improvements, and we leave you with an explanatory video.
Support for decision tables
Up until now, you could only to create rules defined in DRL (Drools Rule Language), but from this version on, you can also define rules based on DDT (Drools Decision Tables).
Drools Decision Tables must be defined in Excel format (*.XLS or *.XLSX), where each row is a rule and each column in that row is a condition or action for that rule. Ideally, rules are created without regard to the order of the rows, which makes them easier to maintain.
Next you can see an example of a decision table:
You can find more information about this in this article in our Developer Portal.
Query support
Until now, if you wanted to query an ontology from a rule, you had to program a REST call to the Platform’s IoTBroker in DRL. To improve this functionality, we have added a new Wrapper (QueryWrapper) that will allow to execute queries in a simple and totally transparent way for the user, which is a significant improvement.
Next you can see an example of a rule defined in DRL that makes use of the new QueryWrapper:
package com.minsait.onesait.platform.rulesengine;
import com.minsait.onesait.platform.rulesengine.model.OntologyJsonWrapper;
import com.minsait.onesait.platform.rulesengine.model.QueryWrapper;
global com.minsait.onesait.platform.rulesengine.model.OntologyJsonWrapper output;
dialect "mvel"
function Boolean existEmployee(Object id){
QueryWrapper queryWrapper = new QueryWrapper("employee", "select * from employee as c where c.employee.id = " + Integer.parseInt(id.toString()), "client", "917069adcdf94d96832e711acc9c6631", "http://localhost:19000");
queryWrapper.run();
return !queryWrapper.getQueryResult().isEmpty();
}
rule "Create new employee"
when
input: OntologyJsonWrapper()
eval( !existEmployee(input.getProperty("id")))
then
output.setRootNode("employee")
output.setProperty("id", input.getProperty("id"));
output.setProperty("rol", "Consultant");
end
If you want to know more about this part, we recommend this other article from the Developer Portal.
Improvements in tests
Lastly, we have enabled a new functionality in the testing part of the rules, where, from now on, it will be possible to load a JSON file from your local machine.
All this is explained in detail in this article.
YouTube | Release 3.0.0 Feature – Enhancements in the Rules Engine (in Spanish)