There is a way, provided the required information is available at the time the rule is created.<br><br>There is a detailed section in the Expert manual explaining how to call template expansion with either a Collection of Map objects or a Collection of JavaBean objects. Taking beans, you would have<br>
<br>ServiceBean( String name, String value )<br>String getName<br>String getValue<br>String getType(){<br> if( "AAA".equals( value ) ) return "Type1";<br> if( "XYZ".equals( value ) ) return "Type2";<br>
...<br>}<br><br>You create a collection of such Objects, and call the expander for a template like this:<br><br>rule "DC_@{row.rowNumber}"
<br>when <br> $service: Service(name == "@{service}", value ==
"@{value}") <br> $riskType: RiskType() <br>then <br>
$riskType.setName("@{type}"); <br><div>
$riskType.setAtt(0,"@{value}"); <br>end </div><br>-W<br><br><br><br><div class="gmail_quote">2011/6/1 ChrisMu <span dir="ltr"><<a href="mailto:christopher.mullard@credit-suisse.com">christopher.mullard@credit-suisse.com</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div dir="ltr" align="left"><span><font face="Arial" size="2" color="#0000ff">So in essence, there's no way to use a function to insert a
string literal into a rule from a template?</font></span></div><br>
<div dir="ltr" lang="en-us" align="left">
<hr>
<font face="Tahoma" size="2"><b>From:</b> FrankVhh [via Drools]
[mailto:<a href="http://user/SendEmail.jtp?type=node&node=3009838&i=0" rel="nofollow" link="external" target="_blank">[hidden email]</a>] <br><b>Sent:</b> 31 May
2011 17:20<br><b>To:</b> Mullard, Christopher<br><b>Subject:</b> RE: Smart
Templates<br></font><br></div>
<div></div>But then that would call the service.getType() method when the rule
is <br>run wouldn't it? <br>-> Yes <br> <br>I'm trying create explicit,
simple rules to avoid doing extra work when <br>running data through them.
<br>-> OK, in essence, I like that :-) <br> <br>How would you use a
rule to set the value within another rule? <br>-> I am not sure that I follow
you here... <br>If you want to avoid to execute the getType()-service at rule
execution, then you would need to add an attribute name to your object, and call
getType() before creating the rules. <br><br>Alternatively, you can insert an
intermediate value whose value will be set by another rule and then use this
intermediate value in your DC rules. <br><br>When <br>Service(value = "AAA")
<br>Then <br>String name = "Type1"; <br>insert(name); <br><br>Something like
this... but make sure not to create a loop :-) <br><br>Regards, <br>Frank
<br><br>
<blockquote style="border-left: 2px solid rgb(204, 204, 204); padding: 0px 1em;">
<div>
<div style="font-weight: bold;">ChrisMu wrote:</div>
<div>But then that would call the
service.getType() method when the rule is <br>run wouldn't it? <br>
<br>I'm trying create explicit, simple rules to avoid doing extra work when
<br>running data through them. <br> <br>How would you use a rule to set
the value within another rule? <br> <br>Thanks <br>Chris
<br><br>________________________________ <br><br>From: FrankVhh [via Drools]
<br>[mailto:<a href="http://user/SendEmail.jtp?type=node&node=3006773&i=0" rel="nofollow" link="external" target="_blank">[hidden email]</a>] <br>Sent: 31 May
2011 16:48 <br>To: Mullard, Christopher <br>Subject: Re: Smart Templates
<br><br><br>Hi, <br><br>The way I see it, this is the way your template should
look like. I do <br>not see the need to use eval() at all. <br><br>rule "DC_0"
<br>when <br> $service: Service(name == "@{service}", value ==
"@{value}") <br> $riskType: RiskType() <br>then <br>
$riskType.setName($service.getType("@{value}")); <br>
$riskType.setAtt(0,"@{value}"); <br>end <br><br>I am assuming that RiskType is
already inserted in WM, but you could <br>just as well create a new object in
the then-part of the rule. <br><br>In stead of using the java-function to
determine the name, you might <br>actually just as well create an other rule
that sets the name according <br>to the value, thus putting the entire
decision logic in rules. <br><br>Hope this helps. <br><br>Regards, <br>Frank
<br><br><br><br> ChrisMu wrote: <br>
Hi, <br> <br>
I'm trying to get a template (.drt) to generate 2 rules (.drl)
<br>from 2 datasets but by doing a little bit more work than direct
<br>substitution. <br> <br>
Data (service,value): <br> DC, AAA
<br> DC, XYZ <br>
<br> Idea for the template - if value is of type1
then create Type <br>object with 'Type1' as name. If value is of type2, use
'Type2' as name: <br> <br>
rule "DC_@{row.rowNumber}" <br> when
<br> Service(name == "DC")
<br> then <br>
Type.setName(eval(Service.getType(@{value}))) <br>
Type.setAtt(0,@{value}) <br>
end template <br> <br>
eval(Service.getType(@{arg0})) should take 'AAA' or 'XYZ' etc as
<br>arg and return a string Type1/Type2 etc. <br>
<br> This would then generate 2 rules that look
like: <br> <br> rule
"DC_0" <br> when <br>
Service(name == "DC", value == "AAA") <br>
then <br>
RiskType.setName("Type1") <br>
RiskType.setAtt(0,"AAA") <br> <br>
rule "DC_1" <br> when <br>
Service(name == "DC", value == "XYZ")
<br> then <br>
RiskType.setName("Type2") <br>
RiskType.setAtt(0,"XYZ") <br>
<br> ...is this possible at all? I'm trying to
avoid the eval step <br>being done in the actual rule (.drl) . <br>
<br> Thanks <br>
<br> Chris
<br><br><br><br>________________________________ <br><br>If you reply to this
email, your message will be added to the discussion <br>below: <br><a href="http://drools.46999.n3.nabble.com/Smart-Templates-tp3006479p3006589.html" rel="nofollow" link="external" target="_blank">http://drools.46999.n3.nabble.com/Smart-Templates-tp3006479p3006589.html</a><br>
<br>To
unsubscribe from Smart Templates, click here <br><<a href="http://drools.46999.n3.nabble.com/template/NamlServlet.jtp?macro=unsubs" rel="nofollow" link="external" target="_blank">http://drools.46999.n3.nabble.com/template/NamlServlet.jtp?macro=unsubs</a><br>
cribe_by_code&node=3006479&code=Y2hyaXN0b3BoZXIubXVsbGFyZEBjcmVkaXQtc3Vp
<br>c3NlLmNvbXwzMDA2NDc5fDE5NzczMDY1MzE=> .
<br><br>===============================================================================
<br>Please access the attached hyperlink for an important electronic
communications disclaimer: <br><a href="http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html" rel="nofollow" link="external" target="_blank">http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html</a>
<br>===============================================================================
</div></div></blockquote><br><br>
<hr noshade size="1" color="#cccccc">
<div style="font-family: tahoma,geneva,helvetica,arial,sans-serif; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; font-size-adjust: none; font-stretch: normal; color: rgb(68, 68, 68);">
<div style="font-weight: bold;">If you reply to this email, your message will be
added to the discussion below:</div><a href="http://drools.46999.n3.nabble.com/Smart-Templates-tp3006479p3006773.html" rel="nofollow" link="external" target="_blank">http://drools.46999.n3.nabble.com/Smart-Templates-tp3006479p3006773.html</a>
</div>
<div style="margin-top: 0.4em; font-family: tahoma,geneva,helvetica,arial,sans-serif; font-style: normal; font-variant: normal; font-weight: normal; font-size: 11px; line-height: normal; font-size-adjust: none; font-stretch: normal; color: rgb(102, 102, 102);">
To
unsubscribe from Smart Templates, <a rel="nofollow" link="external">click
here</a>. </div> <br><p class="MsoNormal"><span style="font-size: 8pt; font-family: Courier;" lang="EN-US">==============================================================================<br>Please access the attached hyperlink for an important electronic communications disclaimer:<br>
<a href="http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html" rel="nofollow" link="external" target="_blank">http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html</a><br>==============================================================================</span></p>
<br>
        
<br><hr width="300" align="left">
View this message in context: <a href="http://drools.46999.n3.nabble.com/Smart-Templates-tp3006479p3009838.html" target="_blank">RE: Smart Templates</a><br>
Sent from the <a href="http://drools.46999.n3.nabble.com/Drools-User-forum-f47000.html" target="_blank">Drools: User forum mailing list archive</a> at Nabble.com.<br><br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>