This looks as if you inserted some object ServiceBean extends HashMap as a fact? Whatever for? Originally, this was class Service.
Make sure to distinguish template expansion from rule execution. The former should result in a DRL file containing several rules (all with different names!). -W 2011/6/1 ChrisMu <christopher.mull...@credit-suisse.com> > I get this exception: > Exception in thread "main" org.drools.runtime.rule.ConsequenceException: > rule: RFI1 > > at > org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39) > at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:927) > at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:856) > at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1071) > at > org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:785) > at > org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:751) > at > org.drools.template.parser.TemplateDataListener.finishSheet(TemplateDataListener.java:121) > at > org.drools.template.DataProviderCompiler.finishData(DataProviderCompiler.java:100) > at > org.drools.template.DataProviderCompiler.processData(DataProviderCompiler.java:95) > at > org.drools.template.DataProviderCompiler.compile(DataProviderCompiler.java:73) > at > org.drools.template.ObjectDataCompiler.compile(ObjectDataCompiler.java:44) > at > org.drools.examples.decisiontable.TemplateParser.<init>(TemplateParser.java:33) > at > org.drools.examples.decisiontable.TemplateParser.main(TemplateParser.java:18) > Caused by: java.lang.RuntimeException: [Error: unable to resolve method: > java.util.HashMap.value() [arglength=0]] > [Near : {... Unknown ....}] > ^ > [Line: 1, Column: 0] > at > org.drools.template.parser.DefaultGenerator.generate(DefaultGenerator.java:73) > at > org.drools.template.parser.Rule_RFI1_0.defaultConsequence(Rule_RFI1_0.java:7) > at > org.drools.template.parser.Rule_RFI1_0DefaultConsequenceInvoker.evaluate(Rule_RFI1_0DefaultConsequenceInvoker.java:30) > at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:917) > ... 11 more > Caused by: [Error: unable to resolve method: java.util.HashMap.value() > [arglength=0]] > [Near : {... Unknown ....}] > ^ > [Line: 1, Column: 0] > at > org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:932) > at > org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getBeanProperty(ReflectiveAccessorOptimizer.java:592) > at > org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:311) > at > org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:137) > > My rule template is virtually the same (name is a literal): > rule "[hidden email]<http://user/SendEmail.jtp?type=node&node=3010031&i=0> > }" > when > $service:ServiceBean(name == "DiscountCurve", value == "@{value}") > > $riskType:RiskType() > then > $riskType.setName("@{type}"); > $riskType.setValue("@{value}"); > end template > ------------------------------ > *From:* Wolfgang Laun-2 [via Drools] [mailto:[hidden > email]<http://user/SendEmail.jtp?type=node&node=3010031&i=1>] > > *Sent:* 01 June 2011 10:33 > *To:* Mullard, Christopher > *Subject:* Re: [rules-users] Smart Templates > > There is a way, provided the required information is available at the time > the rule is created. > > 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 > > ServiceBean( String name, String value ) > String getName > String getValue > String getType(){ >   if( "AAA".equals( value ) ) return "Type1"; >   if( "XYZ".equals( value ) ) return "Type2"; >   ... > > } > > You create a collection of such Objects, and call the expander for a > template like this: > > rule "DC_@{row.rowNumber}" > when >   $service: Service(name == "@{service}", value == "@{value}") >   $riskType: RiskType() > then >   $riskType.setName("@{type}"); >   $riskType.setAtt(0,"@{value}"); > end > > -W > > > > 2011/6/1 ChrisMu <[hidden > email]<http://user/SendEmail.jtp?type=node&node=3009984&i=0> > > > >> So in essence, there's no way to use a function to insert a string literal >> into a rule from a template? >> >> ------------------------------ >> *From:* FrankVhh [via Drools] [mailto:[hidden >> email]<http://user/SendEmail.jtp?type=node&node=3009838&i=0>] >> >> *Sent:* 31 May 2011 17:20 >> *To:* Mullard, Christopher >> *Subject:* RE: Smart Templates >> >> But then that would call the service.getType() method when the rule is >> run wouldn't it? >> -> Yes >>  >> I'm trying create explicit, simple rules to avoid doing extra work when >> running data through them. >> -> OK, in essence, I like that :-) >>  >> How would you use a rule to set the value within another rule? >> -> I am not sure that I follow you here... >> 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. >> >> 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. >> >> When >> Service(value = "AAA") >> Then >> String name = "Type1"; >> insert(name); >> >> Something like this... but make sure not to create a loop :-) >> >> Regards, >> Frank >> >> ChrisMu wrote: >> 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:[hidden email]<http://user/SendEmail.jtp?type=node&node=3006773&i=0>] >> >> 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 >> =============================================================================== >> >> >> >> >> ------------------------------ >> If you reply to this email, your message will be added to the discussion >> below: >> http://drools.46999.n3.nabble.com/Smart-Templates-tp3006479p3006773.html >> To unsubscribe from Smart Templates, click here. >> >> >> ============================================================================== >> 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: RE: Smart >> Templates<http://drools.46999.n3.nabble.com/Smart-Templates-tp3006479p3009838.html> >> Sent from the Drools: User forum mailing list >> archive<http://drools.46999.n3.nabble.com/Drools-User-forum-f47000.html>at >> Nabble.com. >> >> _______________________________________________ >> rules-users mailing list >> [hidden email] <http://user/SendEmail.jtp?type=node&node=3009984&i=1> >> >> https://lists.jboss.org/mailman/listinfo/rules-users >> >> > > _______________________________________________ > rules-users mailing list > [hidden email] <http://user/SendEmail.jtp?type=node&node=3009984&i=2> > https://lists.jboss.org/mailman/listinfo/rules-users > > > ------------------------------ > If you reply to this email, your message will be added to the discussion > below: > http://drools.46999.n3.nabble.com/Smart-Templates-tp3006479p3009984.html > To unsubscribe from Smart Templates, click here. > > > ============================================================================== > 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: RE: [rules-users] Smart > Templates<http://drools.46999.n3.nabble.com/Smart-Templates-tp3006479p3010031.html> > > Sent from the Drools: User forum mailing list > archive<http://drools.46999.n3.nabble.com/Drools-User-forum-f47000.html>at > Nabble.com. > > _______________________________________________ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > >
_______________________________________________ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users