Hi,
I am using Drools version 5.0 . I am facing an issue in my LHS that I haven’t been able to figure out how to resolve :-
The rule looks like this :-
when
$customerCart : CustomerGrid($c_holdings : cartHoldings, $c_productTypes: productTypes, $c_details : customerDetails)
$productType : java.lang.String() from $c_productTypes
$productType_total : Double()
from accumulate (
CustomerHolding(productType == $productType, $value : percent) from $c_holdings,
sum ($value)
)
$ch : CustomerHolding (productType == $productType, $group : productGroup) from $c_holdings
$productType_reference : CustomerDetail(identifier (== $productType || == $group) , $productType_limit : purchaseLimit)
from $c_details
eval ($productType_limit < Math.abs($productType_total.doubleValue()))
then
System.out.println(“XYZ”);
End
The issue is with this line of code
$ch : CustomerHolding (productType == $productType, $group : productGroup) from $c_holdings
This will get executed as many times as there are number of CustomerHolding objects for the given $productType in the $c_holdings collection.
All I need to do is simply get the Associated $group with the $productType and thus should only get executed once.
Any idea how to go about writing this rule ?
Also is there a better way to write this rule ?
Regards,
Akash