0

My requirement is that i need to count the order requests from the same customer without hardcoding the customerid in the rule. The reason being In case if I have 1000 customers then I need to write 1000 rules for the same. To avoid this I need generic way to handle all the customer objects.

for example there are four order resquest objects from customerA and customerB.My rule should able to figure out the number of requests from indivdual customer and also i need to store those objects.

Basically i need sql's group by equvalent method in drools .

Please provide pointers

user1668653
  • 237
  • 2
  • 3
  • 9

1 Answers1

0

Have you tried something like this?:

rule 'Count Order Requests'
when
    $c: Customer()
    $n: Number() from accumulate( 
        $o: OrderRequest(customer == $c),
        count($o)
    )
then
    //use $n
end

This rule will fire even for Customers without any OrderRequest. If that is not what you are looking for, then you must add a constraint on the intValue of $n:

$n: Number(intValue > 0) from accumulate (....)

Hope it helps,

Esteban Aliverti
  • 6,259
  • 2
  • 19
  • 31
  • I need customer specific orders. – user1668653 Feb 20 '13 at 10:28
  • Instead of the number you need the orders? Then you can change the count($o) with a collectSet($o) and change Number() to Set(). In the RHS of your rule you will have the set of all the orders belonging to a customer. You can then save this in a Map>, or do whatever you need. – Esteban Aliverti Feb 20 '13 at 11:01