[rules-users] How check if all the values in a collection match a criteria

Edson Tirelli tirelli at post.com
Sun May 18 15:30:34 EDT 2008


   Hmm, now that you mentioned, I see that our parser is limiting the
forall() CE, not allowing nested "from" CEs. This is something we should
fix, since the limitation is purely a parser limitation.

   Anyway, for your case, the workaround is simply to use the "raw"
forall-equivalence: not( A() and not( B() ) ). So try this:

rule "Do Not Process TAX"                        when
               $report: ExpenseReport($expenseDetails: expenseDetails)
               not ( $ed : ExpenseDetails() from $expenseDetails and
                     not ( ExpenseDetails( this == $ed, expenseType ==
ExpenseType.TAX ) from $expenseDetails )
               )
 then
               System.out.println("################ It works
##################");
               insertLogical("Bypass Process");
end

   This is just more verbose than the forall, but it is exactly the same.
Once the parser is fixed, you will be able to simply write:

rule "Do Not Process TAX"                        when
               $report: ExpenseReport($expenseDetails: expenseDetails)
               forall ( ExpenseDetails( expenseType == ExpenseType.TAX )
from $expenseDetails )
 then
               System.out.println("################ It works
##################");
               insertLogical("Bypass Process");
end

    BTW, may I ask you please to open a JIRA so we don't forget to fix this
for 5.0?

    Thanks,
         Edson



2008/5/18 Alessandro Di Bella <aldibella at gmail.com>:

> Hi,
>
> I have these two classes:
>
> ExpenseReport{
>  Collection<ExpenseDetails> expenseDetails
> }
> ExpenseDetails{    ExpenseReport document
>  ExpenseType expenseType
> }
>
> I am trying to create a rule that fires when all the ExpenseDetails in a
> ExpenseReport  are of the same type:
>
> rule "Do Not Process TAX"                        when
>                $report: ExpenseReport($expenseDetails: expenseDetails)
>                forall (
>                        ExpenseDetails(document==$report, expenseType ==
> ExpenseType.TAX)
>                )          then
>                System.out.println("################ It works
> ##################");
>                insertLogical("Bypass Process");
> end
>
> For some reasons, it fires regardless that value of
> ExpenseDetails.expenseType.
>
> I just started with drools and any help i more than welcome.
>
> Thanks
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



-- 
Edson Tirelli
JBoss Drools Core Development
Office: +55 11 3529-6000
Mobile: +55 11 9287-5646
JBoss, a division of Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20080518/70581e09/attachment.html 


More information about the rules-users mailing list