I have a drools question which has been troubling me for some time. I want to find out the min and max price from a list of Item objects (contains price) using accumulate. A Member object (which contails list of Item objects) is inserted which contains the list of Items.
groovy/java source pseudo code
-------------------------------
class Item {
BigDecimal price
}
class Member {
List<Item>> items
}
...
droolsStatefulSession.insert(member)
session.fireAllRules()
...
rule.drl
---------
rule "rule1"
when
member : Member ($itemList : items)
/*
*/
then
System.out.println("condition met...")
end
Now the questions is in the above rule is it possible to if so how do I find out the item with the minimum Price and maximum price using drools accumulate feature. I do not want to use an java/groovy utility functions.
I see the "collect" feature allows to use "from" and then a datasource. I wonder if "accumulate" is similar to collect.
No need to use accumulate
, just do something like
Item($lowestPrice : price, $id : id)
not Item(price > $lowestPrice, id < $id)
That's if your Items are inserted into the working memory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With