You'll have to establish individual String objects to select type. There's two ways to do that.

1. You know all possible type values and insert them as facts. This is the most efficient way. (Perhaps wrap
the string into a fact type ItemType{ String type; }.)

rule  "StoreABC"

                when

                                #conditions

                                $type: String()

                                Number( $TotalSalesAmount : intValue, intValue > 100)

                                from accumulate ( Sale(type == $type, $amount : amount, $quantity : quantity)

                                from entry-point StoreABC,sum($amount * $quantity))

                then

                                System.out.println("StoreABC sale exceeds 100…");

End


2. You can, e.g. by using some attribute order, select one Sale for each type from a store.

rule  "StoreABC"

                when

                                #conditions

                               Sale( $pos: pos, $type: type )

                               not Sale( pos < pos, type == $type ) 

                               // same as before


HTH

-W



2011/1/3 Kiran Ananthpur Bacche (kbacche) <kbacche@cisco.com>

Hi,

 

I have a event processing rule as follows

 

declare Sale

                @role(event)

end

 

rule "StoreABC"

 

                when

                                #conditions

                                Number( $TotalSalesAmount : intValue, intValue > 100)

                                from accumulate ( Sale($amount : amount, $quantity : quantity)

                                from entry-point StoreABC,sum($amount * $quantity))

                then

                                System.out.println("StoreABC sale exceeds 100…");

End

 

The POJO Sale has a attribute “String type;”. The above rule actually ignores the type, and does the accumulation for all types put together. Now I want the rule to fire successfully only when the TotalSalesAmount for _any_ given type exceeds 100.

 

And is it possible to access the “type” of Sale whose sales exceeded 100, in the “Then” clause ?

 

Example:

 

Lets say the input events are  as below (Triplets – Type, Quantity and Amount)

 

1.       Apple , 10, 5

2.       Orange, 10, 6

3.       Banana,  20, 4

4.       Orange, 10, 5

5.       Apple, 2, 5

 

Now in the above rule, the event fires after Event 2 since the total sales is > 100. However I want the rule to fire after Event 4 since at that point the sale of one particular item, viz. “Orange” exceeds 100 in this store. In the “THEN” clause of the rules, I also want access to a variable that indicates that it was “Orange” whose sale exceeded 100 in this store.

 

Is this possible in Drools Fusion ? If yes, can you please let me know the changes to be made to the above rule ?

 

 

Thanks

  Kiran

 

 


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