[rules-users] How to Access Rule RHS (THEN Part) from JAVA?

Ravikiran ravikiran.kakarla at gmail.com
Fri Jul 13 03:31:43 EDT 2012


Hi Drools Gurus,

One more newbie here for Drools Guvnor. I have chosen
"guvnor-distribution-5.3.0.Final" (I could see version as SNAPSHOT 5.4.0
within Guvnor-->Administration-->About) to start with. After reading through
the complete user manual, I was able to setup and deploy Drools Guvnor war
in JBoss AS 7.

My intension is to access all the rules that i have created using Guvnor
web. I have written a java test case to access my Rules which are resided in
a drools Package using REST API. I was successful to access them using
standard Authentication mechanism with charset*.xml. Even though i was able
to call fireAllRules with specific rule using "AgendaFilter" provided. But i
was not able to access the values at RHS after a specific rule got fired.
For Example, i want to access "percent value as 2.5" after the below sample
rule is successfully executed,
I have uploaded my model jar to Guvnor containing Person & LoanFormula
classes.

---Rule 1 (please do not see the syntax errors)
WHEN
 Person age > 25
 ----
THEN
 LoanFormula percent = 2.5
 ....
 ....

JAVA Code follows
---------------------
KnowledgeBase kbase = ...
FactType personType = kbase.getFactType( "org.drools.examples","Person" );
Object bob = personType.newInstance();
personType.set( bob, "name","Bob" );
personType.set( bob,"age",42 );
StatefulKnowledgeSession ksession = ...
ksession.insert( bob );
AgendaFilter filter = new ......("Rule1");
int count = ksession.fireAllRules(filter);
String name = personType.get( bob, "name" );
int age = personType.get( bob, "age" );

It would be great help if some one can show me the sample code for accessing
RHS part of the Rule. Please let me know if you need more details.

thanks
Kiru

--
View this message in context: http://drools.46999.n3.nabble.com/How-to-Access-Rule-RHS-THEN-Part-from-JAVA-tp4018651.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list