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

2012-07-13 Thread Ravikiran
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.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


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

2012-07-13 Thread Wolfgang Laun
You cannot access any variable declared between 'then' and 'end'.
These are local in the same sense as a variable declared in a Java
method.

For passing anything computed in a rule consequence to the embedding
Java program you might

* insert a Fact of some suitable type and retrieve this from the
ksession using API methods, e.g., by running a query, or by calling
CollectionObject getObjects(ObjectFilter filter) )

* define a global and simply assign to it in the consequence, and
retrieve it using ksession API Object getGlobal( String identifier )

-W


On 13/07/2012, Ravikiran ravikiran.kaka...@gmail.com wrote:
 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.
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


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

2012-07-13 Thread Ravikiran
Thanks Lane.

Since i am new to this Area, could you please help me with some sample code
how to query the objects that are involved in a rule. Please consider above
my example, on successful execution of Rule 1, i want to access the value of
Percent from Class LoanFormula.

Thanks a lot.

--
View this message in context: 
http://drools.46999.n3.nabble.com/How-to-Access-Rule-RHS-THEN-Part-from-JAVA-tp4018651p4018654.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


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

2012-07-13 Thread Wolfgang Laun
DRL:
LoanFormula percent;

then
percent = ...;

=
Java:
ksession.fireAllRules();
LoanFormula percent = ksession.getGlobal( percent );

I suspect that your knowledge of Java is flawed since you can't have a
class of your own and then assign a double to it:
   LoanFormula percent = 2.5

-W

On 13/07/2012, Ravikiran ravikiran.kaka...@gmail.com wrote:
 Thanks Lane.

 Since i am new to this Area, could you please help me with some sample code
 how to query the objects that are involved in a rule. Please consider above
 my example, on successful execution of Rule 1, i want to access the value
 of
 Percent from Class LoanFormula.

 Thanks a lot.

 --
 View this message in context:
 http://drools.46999.n3.nabble.com/How-to-Access-Rule-RHS-THEN-Part-from-JAVA-tp4018651p4018654.html
 Sent from the Drools: User forum mailing list archive at Nabble.com.
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


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

2012-07-13 Thread Wolfgang Laun
If you change a fact and want to inspect it after firing all rules, use a query.

There is an example in the Drools Expert manual.

-W


On 13/07/2012, Ravikiran ravikiran.kaka...@gmail.com wrote:
 Hi Laune,

 As i mentioned before, I have given some sample code only before. But i
 actually meant that percent is an instance variable of type double from
 class LoanFormula, sorry for creating the confusion. Both Person  Loan
 formula classes are like this,
 declare Person
   age: Integer
   ---
 end
 declare LoanFormula
   percent: Double
 end
 If the above two classes are part of my Model and if my Rule 1 like below

 rule Rule 1
 salience 10
 dialect mvel
 when
   a : LoanFormula( )
   exists (Person( age  25 ))
 then
   a.setPercent(2.5 );
 end

 From the above Rule, When i fire Rule 1 from my Java client and i pass
 age
 of a Person greater than 25, then i should be able to retrieve the percent
 value as 2.5. I hope this would have been much clearer for you now.
 Thanks in advance...

 --
 View this message in context:
 http://drools.46999.n3.nabble.com/How-to-Access-Rule-RHS-THEN-Part-from-JAVA-tp4018651p4018657.html
 Sent from the Drools: User forum mailing list archive at Nabble.com.
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users