drools - How to get output result from guvnor rule in java code -
i uploaded patient model jar on guvnor, class has name , result field.
i created rule in guvnor insert result "pass" whenever name has particular value: code of rule below:
rule "isjohn" dialect "mvel" when patient( name == "john") patient fact0 = new patient(); fact0.setresultstring( "pass" ); fact0.setname( "patient: john" ); insert( fact0 ); end
below java code call rule.
knowledgebase knowledgebase = readknowledgebase(); statefulknowledgesession session = knowledgebase.newstatefulknowledgesession(); patient patient = new patient(); patient.setname("john"); system.out.println("patient.name "+patient.getname()); session.insert(patient); session.fireallrules(); system.out.println("************patient.name "+patient.getname()); system.out.println("patient result string "+patient.getresultstring());
but when run code same name , result string null. mistake doing here.
basically need way through can call simple rule , display result using java. there example demonstrating it.
the problem that, in rule, creating new instance of patient instead of modifying existing one. need bind matching patient , use in rhs:
rule "isjohn" dialect "mvel" when fact0: patient( name == "john") fact0.setresultstring( "pass" ); fact0.setname( "patient: john" ); update( fact0 ); // 'update' if want other rules aware of change. // better, if want other rules notice these changes use 'modify' // construct insted of 'update'. java perspective, don't need // step: invoking setresultstring() , setname() // on real java object. end
hope helps,
Comments
Post a Comment