java - can we access working memory fact of drools rule engine in jbpm6 script task? -
is there way access working memory fact of drools rule engine in jbpm6 script task?
i have model class : application.java rule : check if salary > 10000 (part of rule group : salarycheck )
jbpm flow : start -> salarycheck(rule task, associated rule group : salarycheck) -> updatescore(script task) -> end
updatescore - script rask code:
system.out.println(system.out.println((application)(kcontext.getkieruntime().getfacthandles().toarray()[0]));
error:
java.lang.classcastexception: org.drools.core.common.defaultfacthandle cannot cast org.model.application
updated script task:
import org.model.application import org.drools.runtime.rule.queryresults import org.drools.runtime.rule.queryresultsrow queryresults results = kcontext.getkieruntime().getqueryresults( "getobjectsofapplication" ); ( queryresultsrow row : results ) { application applicantion = ( application ) row.get( "$result" ); application.setscore(700); system.out.println("application object :: "+ application); }
added query rule drl file
query "getobjectsofapplication" $result: application() end
getfacthandles()
not method looking for. method think looking getobjects()
. either way, getting first element of returned collection without validation seems dangerous me. can't guarantee order of elements in returned collection remain same between different invocations.
a better approach use version of getobjects()
accepts objectfilter
parameter. better , more 'declarative' approach define query in returns exact object looking for. can execute query using kcontext.getkieruntime().getqueryresults()
.
you can better understanding on of these 2 approaches (using objectfilter
or query) in thread: retrieving facts of specific type working memory
edit:
the post suggested using query or objectfilter
drools 5 code. in drools 6, api classes moved different package. these imports should use if want invoke query in code:
org.kie.api.runtime.rule.queryresults
org.kie.api.runtime.rule.queryresultsrow
these classes both part of kie-api
project.
Comments
Post a Comment