drools - How to remove Rules which are having errors -
i having list of rules created dynamically. after created check whether there errors. cannot find way remove rules having errors dynamically.
public void validaterule(list<string> rules, collection<abstractfact> facts) { kieservices kieservices = kieservices.factory.get(); kiefilesystem kiefilesystem = kieservices.newkiefilesystem(); int ruleindex = 0; (string rule : rules) { stringbuilder rulename = new stringbuilder("src/main/resources/rule"); rulename.append(ruleindex).append(".drl"); kiefilesystem.write(rulename.tostring(), rule); ruleindex ++; } kiebuilder kiebuilder = kieservices.newkiebuilder(kiefilesystem).buildall(); if (kiebuilder.getresults().hasmessages(message.level.error)) { //remove rules failing } kiecontainer container = kieservices.newkiecontainer(kieservices.getrepository().getdefaultreleaseid()); kiesession ksession = container.newkiesession(); (abstractfact fact : facts) { // insert facts ksession.insert(fact); } ksession.fireallrules(); }
drools file validation
template header name package test; template "test template" rule "test rule" when $fact : fact(code != ) // expression wrong intentionally $fact.setok(false); end end template
write each rule kiefilesystem file try.drl
, call buildall. keep track of filing rules.
delete try.drl.
in second pass, write now, skipping rules failed in first pass.
Comments
Post a Comment