Thanks for the reply Wolfgang.
I chose to use the template because I liked the idea of separating the rule definition
from the rule data. Just seemed intuitive to me. Overall, I'm new to Drools, so not
sure if that is the best choice or not.
I think your approach works if my spreadsheet has all the items separated with commas and
double quotes. Because then it's just referring to the field as a simple string
field, not an array of values.
When the field is in the spreadsheet as: Austria, Germany, Switzerland it needs to be
handled as an array, otherwise it will build the generated rule as: Country(name in
(Austria, Germany, Switzerland)) and fail compile because it's missing the quotes. If
you use "@{country}) it will put ("Austria, Germany, Switzerland"), when
you really need ("Austria", "Germany", "Switzerland")
Maybe I'll just embed the double quotes in the spreadsheet and call it a day, instead
of fighting the field as an array of values.
If you have any other thoughts, let me know!
Thanks,
Jason.
On Jun 14, 2013, at 1:33 PM, Wolfgang Laun <wolfgang.laun(a)gmail.com> wrote:
In the spreadsheet (with class Country) you would have a column such
as:
CONDITION
Country
name in ( $param )
Test whether name is one from a given set
"Austria", "Germany", "Switzerland"
"France", "Canada", "Belgium"
This is the generated rule:
rule "InTest_18"
when
$country: Country(name in (
"Austria","Germany","Switzerland" ))
then
System.out.println( "German is spoken" );
end
You should be able to retrofit the template from this. (Why do you
need a template when you have a spreadsheet?)
-W
On 14/06/2013, Jason Allen <jason.allen(a)data-sign.com> wrote:
> Hi All,
>
> I'm trying to determine if it's possible to process arrays of data using
> Rule Templates. An example of what I'm trying to accomplish.
>
> Spreadsheet of rules, with one of the columns being valid colors. Valid
> colors contains comma separated data and is variable length.
>
> For example
>
> It might contain: "Blue, Green, Red" or "Blue", or "Red,
Green, Purple,
> Silver" Any number of entries.
>
> I then need to process incoming fact values against this list of colors,
> using either CONTAINS or IN.
>
> For example:
>
> template header
> desc
> valid_colors[]
>
> package org.drools.examples.templates
>
> global com.sample.Product product;
>
> template "ColorTestTemplate"
>
> rule "ColorRule_(a){row.rowNumber}"
> when
> product1 : Product (Color in @{valid_colors});
> then
> product1.setDesc("@{desc}");
> end
> end template
>
> I know the following doesn't work: product1 : Product (Color in
> @{valid_colors});
>
> However, I wanted to depict what I'm trying to accomplish.
>
> The challenge is with valid_colors being a variable length array, I can't
> refer to the individual values using constants i.e. valid_colors0,
> valid_colors1, valid_colors3, etc to build my array list.
>
> ie Color in ("@{valid_colors0}", "@{valid_colors1}",
"@{valid_colors2}")
>
> Is there a way to iterate through a variable length array in a template?
>
> Any thoughts on how I could build an array list i.e. ("Blue",
"Green",
> "Red") when the column contains a variable length array?
>
> Thanks in advance,
> Jason
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users