I have a POJO implementation as:
public class Product{
String name;
String brand;
String company;
}
My problem::
Need to fetch intended Product from worldOfProductList based on name and company(both fields are known so that filter can be applied). After getting one specific Product from that list then need to store "brand" value into some variable(can be global) for future use.
NOTE:: As of now, getting only a unique Product using that filter.
My approach is something like:
[condition][]Get intended Product from list = $productList: java.util.LinkedList() from collect(Products(name="abc",company="com") from worldOfProductList)
This statement is working properly and able to get my value in sysout statement as:
System.out.println("Brand is "+((Product)($productList.get(0)).getBrand());
But I need to use this brand value in DSL and store into variable. I tried below combinations but not succeed.
1.[condition][] Store Brand into variable=$brandVar: $productList[0].brand
2.[condition][] Store Brand into variable=Product($brandVar: $productList[0].brand)
3.[condition][] Store Brand into variable=$brandVar: ((Product)$productList.get(0)).getBrand()
If you want to have this as 2 separate entries in your DSL, then you can do something like this:
[condition][] Store Brand into variable= Product($brandVar: brand) from $productList
This will cause an activation of the rule for each different Product you have in $productList
. In the RHS of the rule you will have access to $brandVar
.
If you are only interested in the brands and not in the products themselves, then you can also try something like this:
[condition][]Get Brands from intended Product from list = $productList: java.util.Set() from accumulate(Products(name="abc",company="com", $brandVar: brand) from worldOfProductList, collectSet($brand))
Hope it help,