[rules-users] Rule Templates and Array Handling

Wolfgang Laun wolfgang.laun at gmail.com
Fri Jun 14 14:33:20 EDT 2013


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 at 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_@{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


More information about the rules-users mailing list