[rules-users] Dynamic generated list

Giovanni Motta mottagio at gmail.com
Wed May 19 06:49:52 EDT 2010


I would like to generate a template that can output rules, as explained in
Drools expert user guide at chapter 5.2 (
http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/drools-expert/html_single/index.html#d0e6212
).
My parameters are 2 lists of strings. In some case the list is to be
outputted as a "multi restriction", and that is no problem.
But, from one of this lists, i need also to generate a collection of strings
to then reason over.
As an example, suppose the list1 contains 3 productIds, "A","B","C", and the
list2 contains "X" and "Y".
In the generated rule, i need to check, for example, that:

   - if a product with id 'X' or 'Y' exists (this part is easy),

and

   - a tuple composed of products from the other list(one "A", one "B", one
   "C") that individually satisfy some condition exists (this is tough for me)

then i will execute my code.

I think the generated rule should be something like:

when
    $target: Product (id in ("X","Y"))
    $list: ArrayList() from ????  #arrayList should contain the parameter
values "A","B","C"
    forall ( $id: String() from $list
             Product (id == $id, ....here some condition...)
    )
then
   .....

The difficult part is to generate the ArrayList dynamically, i don't know
how to accomplish that...
Any ideas? Is there a better approach than templates, to generate a rule
like this?
Do you have a suggestion on how the rule could be rewritten to avoid the use
of the ArrayList?
Thank you in advance
Giovanni
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100519/d17414ea/attachment.html 


More information about the rules-users mailing list