[rules-users] Smart Templates

ChrisMu christopher.mullard at credit-suisse.com
Tue May 31 11:53:16 EDT 2011


But then that would call the service.getType() method when the rule is
run wouldn't it?
 
I'm trying create explicit, simple rules to avoid doing extra work when
running data through them.
 
How would you use a rule to set the value within another rule?
 
Thanks
Chris

________________________________

From: FrankVhh [via Drools]
[mailto:ml-node+3006589-784869490-404175 at n3.nabble.com] 
Sent: 31 May 2011 16:48
To: Mullard, Christopher
Subject: Re: Smart Templates


Hi, 

The way I see it, this is the way your template should look like. I do
not see the need to use eval() at all. 

rule "DC_0" 
when 
    $service: Service(name == "@{service}", value == "@{value}") 
    $riskType: RiskType() 
then 
    $riskType.setName($service.getType("@{value}")); 
    $riskType.setAtt(0,"@{value}"); 
end 

I am assuming that RiskType is already inserted in WM, but you could
just as well create a new object in the then-part of the rule. 

In stead of using the java-function to determine the name, you might
actually just as well create an other rule that sets the name according
to the value, thus putting the entire decision logic in rules. 

Hope this helps. 

Regards, 
Frank 



	ChrisMu wrote:
	Hi, 
	
	 I'm trying to get a template (.drt) to generate 2 rules (.drl)
from 2 datasets but by doing a little bit more work than direct
substitution. 
	
	Data (service,value): 
	DC, AAA 
	DC, XYZ 
	
	Idea for the template - if value is of type1 then create Type
object with 'Type1' as name. If value is of type2, use 'Type2' as name: 
	
	rule "DC_@{row.rowNumber}" 
	when 
	    Service(name == "DC")     
	then 
	    Type.setName(eval(Service.getType(@{value}))) 
	    Type.setAtt(0,@{value}) 
	end template 
	
	eval(Service.getType(@{arg0})) should take 'AAA' or 'XYZ' etc as
arg and return a string Type1/Type2 etc. 
	
	This would then generate 2 rules that look like: 
	
	rule "DC_0" 
	when 
	    Service(name == "DC", value == "AAA")     
	then 
	    RiskType.setName("Type1") 
	    RiskType.setAtt(0,"AAA") 
	
	rule "DC_1" 
	when 
	    Service(name == "DC", value == "XYZ")     
	then 
	    RiskType.setName("Type2") 
	    RiskType.setAtt(0,"XYZ") 
	
	...is this possible at all? I'm trying to avoid the eval step
being done in the actual rule (.drl) . 
	
	Thanks 
	
	Chris 



________________________________

If you reply to this email, your message will be added to the discussion
below:
http://drools.46999.n3.nabble.com/Smart-Templates-tp3006479p3006589.html

To unsubscribe from Smart Templates, click here
<http://drools.46999.n3.nabble.com/template/NamlServlet.jtp?macro=unsubs
cribe_by_code&node=3006479&code=Y2hyaXN0b3BoZXIubXVsbGFyZEBjcmVkaXQtc3Vp
c3NlLmNvbXwzMDA2NDc5fDE5NzczMDY1MzE=> . 

=============================================================================== 
Please access the attached hyperlink for an important electronic communications disclaimer: 
http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html 
=============================================================================== 



--
View this message in context: http://drools.46999.n3.nabble.com/Smart-Templates-tp3006479p3006618.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110531/7b8f4c65/attachment.html 


More information about the rules-users mailing list