On 10 August 2011 17:14, Sumeet Karawal <span dir="ltr"><<a href="mailto:sumeet.karawal@tcs.com">sumeet.karawal@tcs.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
<br>
package rules.person<br>
<br>
import com.person.Age<br>
Import com.person.Classification<br>
<br>
rule "Check_person.option1"<br>
<br>
when<br>
<br>
$age : com.person.Age()<br>
$classification : com.person.Classification()<br></blockquote><div><br>If you import, you can use just "Age" and "Classification".<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
eval ($age.getClassification("16"))<br></blockquote><div><br>This is not correct since the return value of Age.getClassification is not a boolean.<br><br>As you present this code, it doesn't make any sense. The condition is a join of an Age object and a Classification object and the argument of getClassification("16") is a literal.<br>
<br>Providing an object to collect results is one reasonable way of doing it.<br><br>-W<br><br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
then<br>
<br>
modify ($classification) {$classification.setResult('"Teenager"; }<br>
<br>
end<br>
<br>
rule "Check_person.option2"<br>
<br>
when<br>
<br>
$age : com.person.Age()<br>
$classification : com.person.Classification()<br>
<br>
eval ($age.getClassification("40"))<br>
<br>
then<br>
<br>
modify ($classification) {$classification.setResult('"Adult"; }<br>
<br>
end<br>
<br>
<br>
Application Class :<br>
<br>
public class Age<br>
{<br>
public string getClassification(String name) {<br>
<Logic of the application><br>
return str;<br>
}<br>
}<br>
<br>
public class Classification<br>
{<br>
public void setResult(String name) {<br>
<Logic of the application><br>
<br>
}<br>
}<br>
<br>
<br>
<br>
Queries :<br>
<br>
Please let me know if I am using the 'when' part correctly.<br>
And please check for the use of the object 'classification' in my<br>
application (as return value to the application)<br>
<div class="im"><br>
<br>
<br>
<br>
Thanks & Regards,<br>
Sumeet Karawal<br>
Mailto: <a href="mailto:sumeet.karawal@tcs.com">sumeet.karawal@tcs.com</a><br>
<br>
<br>
<br>
</div> From: Wolfgang Laun <<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>><br>
<br>
To: Rules Users List <<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>><br>
<br>
Date: 08/10/2011 03:03 PM<br>
<br>
Subject: Re: [rules-users] Calling a method in when part<br>
<br>
Sent by: <a href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org</a><br>
<div><div></div><div class="h5"><br>
<br>
<br>
<br>
<br>
<br>
If you don't show your code we can't tell you what is wrong with it. So I<br>
think what you may have to do is<br>
<br>
when<br>
$someObj: SomeClass() # matches each WME of SomeClass<br>
eval( $someObj.getValueBoolean("abc"))<br>
then<br>
<br>
There is not much to be gained by using a DRL function; it would have to be<br>
called like<br>
eval( someFunction( $someObj, "abc" ) )<br>
<br>
-W<br>
<br>
<br>
On 10 August 2011 11:05, Sumeet Karawal <<a href="mailto:sumeet.karawal@tcs.com">sumeet.karawal@tcs.com</a>> wrote:<br>
<br>
Hi,<br>
<br>
I have a requirement where there is a customized Java class having a<br>
method<br>
that returns some value.<br>
like:<br>
<br>
getValueBoolean("Some String")<br>
<br>
{ //some calculation<br>
// returns a boolean value<br>
}<br>
<br>
The default getters and setters are not being used in the Application.<br>
The<br>
value that is being returned by the method needs to be checked in<br>
the .drl<br>
file.<br>
There are different Java classes with these kind of methods. Where the<br>
string and integer value is also returned. I have gone through the<br>
documentation for Drools-Expert but have only found the implementation<br>
for<br>
the method in the consequence part, i.e., the then part.<br>
<br>
This is how I tried:<br>
<br>
importing the class<br>
<br>
in when<br>
binding the a variable to the Class name suppose $c<br>
eval ($c.getValueBoolean("abc"))<br>
then<br>
System.out.println("the value is true")<br>
<br>
<br>
It didn't work this way.<br>
I tried by another way like :<br>
<br>
creating a function in the .drl itself that calls the method of that<br>
class<br>
and returns a value<br>
then calling this drl function in the when part and carrying on.<br>
<br>
It would be very helpful if some body could let me know how to do this in<br>
the .drl.<br>
<br>
<br>
Thanks & Regards,<br>
Sumeet Karawal<br>
Mailto: <a href="mailto:sumeet.karawal@tcs.com">sumeet.karawal@tcs.com</a><br>
<br>
=====-----=====-----=====<br>
Notice: The information contained in this e-mail<br>
message and/or attachments to it may contain<br>
confidential or privileged information. If you are<br>
not the intended recipient, any dissemination, use,<br>
review, distribution, printing or copying of the<br>
information contained in this e-mail message<br>
and/or attachments to it are strictly prohibited. If<br>
you have received this communication in error,<br>
please notify us by reply e-mail or telephone and<br>
immediately and permanently delete the message<br>
and any attachments. Thank you<br>
<br>
<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br>