How would one go about loading rules from a database table at startup and updating them from the same table in Drools 6.2.0? I\'ve found an example using Drools 5 that I cou
drools-templates has ResultSetGenerator.java which has method compile(resultSet, template) to do the job.
I had data coming over HTTP to be converted to rule. I found a way to do this using ObjectDataCompiler. May be some people might find this useful.
ObjectDataCompiler compiler = new ObjectDataCompiler();
String generatedDRL = compiler.compile(ruleAttributes, new FileInputStream(REGULATION_TEMPLATE_FILE));
where ruleAttributes is
List
KieBase can then be created like this:
KieServices kieServices = KieServices.Factory.get();
KieHelper kieHelper = new KieHelper();
//multiple such resoures/rules can be added
byte[] b1 = generatedDRL.getBytes();
Resource resource1 = kieServices.getResources().newByteArrayResource(b1);
kieHelper.addResource(resource1, ResourceType.DRL);
KieBase kieBase = kieHelper.build();
Rules can be applied like this:
KieSession kieSession = kieBase.newKieSession();
kieSession.setGlobal("myGlobal", myGlobal);
kieSession.insert(abc);
int numberOfRulesFired = kieSession.fireAllRules();
kieSession.dispose();
Template file looks like this:
template header
ruleid
ifcondition
thencondition
import fk.sp.seldon.msku.MSKU
global com.something.blah.MyGlobal myGlobal
template "tmp1"
rule "@{ruleid}"
dialect "mvel"
when
@{ifcondition}
then
@{thencondition};
end
end template