[rules-users] Drools templates header arguments
Alexander Wolf
mail at alexander-wolf.net
Mon Nov 25 06:11:35 EST 2013
afaik that's not possible.
Basically the templates replace the value for @{param} with param.toString() (that's why your approach is not working).
Regarding your concerns about performance: the templates are translated into rules once -> afterwards there is no connection between the variables and the rules in KnowledgeBase.
You could instead write a module that replaces the @{param} fields with values from your arrayList within your rules (e.g. loading the rules from a file into string, then use regex or whatever suits you best).
Then just insert the rules somewhat like this:
String myRules = "rule "test" when @{arr[1]}>x... then ... ";
String parameterizedRules =MyTemplateBuilder.build(myRules, yourParams);
Reader rdr = new StringReader(parameterizedRules);
kbuilder.add(ResourceFactory.newReaderResource(rdr), ResourceType.DRL);
- Alex
On 25 Nov 2013, at 11:43, petert <peter.j.troelsen at gmail.com> wrote:
> I am working on a project, using templates to generate all my rules. I have
> one problem though, I wanna parse my arguments to the template as a
> ArrayList, and do somthing like this:
>
> template header
>
> ruleId
> args
>
> package dk.prks
> import com.poc.entity.Bill;
> import com.poc.entity.BillLine;
> import com.poc.entity.Description;
> import java.util.ArrayList;
>
> template "01"
>
>
> rule "@{ruleId}_@{row.rowNumber}"
> dialect "mvel"
> when
> $bill : Bill ($line : lines) and
> BillLine( service == @{args.get(0)}, $lineNr : lineNr) from $line and
> BillLine( service == @{args.get(1)}, lineNr < $lineNr) from $line
> then
> $bill.setColor(1);
>
> end
>
> end template
> However, this is not possible. Furthermore I want to stretch that
> performance is an issue, and i want the generated file to only contain the
> values from the list, and not make any look ups in the array when running my
> rules
>
>
>
> --
> View this message in context: http://drools.46999.n3.nabble.com/Drools-templates-header-arguments-tp4026908.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 841 bytes
Desc: Message signed with OpenPGP using GPGMail
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20131125/32c221e4/attachment.bin
More information about the rules-users
mailing list