[rules-users] eval call from java code

Wolfgang Laun wolfgang.laun at gmail.com
Tue Jul 3 02:30:59 EDT 2012


I suppose this is a case for java.util.Objects.equals(). Mind, this is
Java 1.7 but you can use the source (in another pacakge) with older
versions.

Also, com.google.common.base.Objects has a similar equal() method.

-W

On 03/07/2012, rogelio_sevilla1 <rogelio.sevilla1 at gmail.com> wrote:
> Good day everyone:
>
> Sorry if this is a too basic question.
>
> I'm having a recurrent problem on my rules and I still don't know how to
> really solve it, I searched here at the forum but I'm not so sure that the
> solutions proposed would work for my use case.
>
> I have to call many different methods on the LHS of some of my rules so I
> insert a global 'utils' object and I make my calls within eval() blocks,
> like this:
>
> $myObj1: ClassX (eval(globalUtil.reSupplyNeeded(amount)  ))
>
>
>  Everything works fine for now.  I wrapped all my util methods within try
> catch blocks to avoid screwing up my stateful session (in my use case, is
> CRITICAL to keep the session alive). So, if an exception is thrown, I
> return
> false or true depending on the method.
>
>
> My main problem is with evals where I do comparisons like this one:
>
> eval($myObj1.doSomething()==$myObj2.doSomething())
>
> I have many of these and some times I get an annoying NPE. I know I could
> add   !=null  comparisons but my rules would grow considerably. eval is
> extremely useful so I was wondering if I can call it from my utility class,
> something like this:
>
>
> On my Drl file:
>
> rule "eval called from here and utility class"
> when
> $someObj1 : ClassX()
> $someObj2 : ClassY()
> $myObj : Class1( eval(
> globalUtil.doEval($someObj1.doSomething()==$someObj2.doSomething()  ) ) )
> then
> ...bla bla bla
> end
>
>
> On my Utility Class
>
> public boolean doEval(ClassIDontKnow argument){
>
> try{
> //I don't know if this even exists, just asking if it's possible
> return Drools.eval(argument);
> }
> catch(Exception e){
> logger.error("Something bad happened!!");
> return false;
> }
>
> }
>
>
>
> Is something like this even possible?? , if not, other approach that you
> would recommend me??
>
>
> Thanks a lot in advance :-)
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/eval-call-from-java-code-tp4018398.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>


More information about the rules-users mailing list