[rules-users] Unable to resolve token on function call with mvel dialect

Olivier THIERRY olivier.thierry at gmail.com
Mon Dec 15 09:37:22 EST 2008


Thanks Edson. Here it is :

rule "CALCUL_RELICAT_CP"
	salience 8
	no-loop
	when
		not $RELICAT_CP : VOCounter (code=="RELICAT_CP")
	        $startDate : RuleDate(name=="startDate")
	        $endDate : RuleDate(name=="endDate")
	        $SOLDE_CP_CUM : VOCounter ( code=="SOLDE_CP_CUM",
startDate.year == ($startDate.year - 1) )
	then
		VOCounter $relicat = createCounter(drools,"RELICAT_CP",$SOLDE_CP_CUM.value);
		insert($relicat);
	        insert(createCounter(drools,"SOLDE_RELICAT_CP",$SOLDE_CP_CUM.value));
end

I thought about trying with a newer version of mvel, but it doesn't
look so easy to upgrade it :(

2008/12/15 Edson Tirelli <tirelli at post.com>:
>
>      Can you plz show us the DRL instead of the DSLR for your rule? use the
> DRLViewer tab for that...
>
> 2008/12/15 Olivier THIERRY <olivier.thierry at gmail.com>
>>
>> Hi,
>>
>> I use drools 4.0.7 and I encounter a problem calling a function from a
>> rule written for mvel dialect.
>>
>> The function I need to call has this signature :
>>
>> function VOCounter createCounter(org.drools.spi.KnowledgeHelper
>> drools, String code, Number number)
>>
>> When I call this function, I want to assign result to a variable, for
>> example to insert it to working memory later, or just to use it in
>> another function call.
>> So I wrote something like that (I am writing a DSL so part of the code is
>> DSL ):
>>
>> rule "CALCUL_RELICAT_CP"
>>        salience 8
>>        no-loop
>>        when
>>                not There is a counter called "RELICAT_CP"
>>                There is a date called "startDate"
>>                There is a date called "endDate"
>>                There is a counter called "SOLDE_CP_CUM" with
>>                        - start date is last year
>>        then
>> >               VOCounter $relicat =
>> > createCounter(drools,"RELICAT_CP",$SOLDE_CP_CUM.value);
>> >               insert($relicat);
>>                Copy counter $SOLDE_CP_CUM to SOLDE_RELICAT_CP
>> end
>>
>> But I have the following stack trace :
>>
>> org.drools.spi.ConsequenceException:
>> org.mvel.UnresolveablePropertyException: unable to resolve token:
>> createCounter(drools,"RELICAT_CP",$SOLDE_CP_CUM.value)
>>        at
>> org.drools.base.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:13)
>>        at
>> org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:558)
>>        at
>> org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:518)
>>        at
>> org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:475)
>>        at
>> org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:439)
>>        at
>> fr.horoquartz.t4.test.drools.TestRuleBase.executeRuleWithDsl(TestRuleBase.java:120)
>>        at fr.horoquartz.t4.test.drools.Test1.testDsl(Test1.java:39)
>> Caused by: org.mvel.UnresolveablePropertyException: unable to resolve
>> token: createCounter(drools,"RELICAT_CP",$SOLDE_CP_CUM.value)
>>        at
>> org.mvel.ast.PropertyASTNode.initializePropertyNode(PropertyASTNode.java:129)
>>        at
>> org.mvel.ast.PropertyASTNode.getReducedValueAccelerated(PropertyASTNode.java:24)
>>        at org.mvel.ExecutableAccessor.getValue(ExecutableAccessor.java:45)
>>        at
>> org.mvel.ast.TypedVarNode.getReducedValueAccelerated(TypedVarNode.java:43)
>>        at org.mvel.MVELRuntime.execute(MVELRuntime.java:90)
>>        at
>> org.mvel.CompiledExpression.getValue(CompiledExpression.java:111)
>>        at org.mvel.MVEL.executeExpression(MVEL.java:235)
>>        at
>> org.drools.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:48)
>>        at
>> org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:554)
>>        ... 34 more
>>
>> What is strange is that it works if I don't assign function call
>> result to a variable. For example the following works  :
>>
>> insert (createCounter(drools,"RELICAT_CP",$SOLDE_CP_CUM.value));
>>
>> It also works if I assign $SOLDE_CP_CUM.value to a temporary variable
>> and use it for function call :
>>
>> Number $val = $SOLDE_CP_CUM.value;
>> VOCounter $relicat = createCounter(drools,"RELICAT_CP",$val);
>> insert($relicat);
>>
>> I had not this problem using java dialect. I understand nothing in
>> what happens ... Anyone has an idea what the problem is ?
>>
>> Thanks in advance,
>>
>> Olivier
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
> --
>  Edson Tirelli
>  JBoss Drools Core Development
>  JBoss, a division of Red Hat @ www.jboss.com
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>



-- 
Seules 2 choses sont infinies : l'univers et la bêtise humaine ; et
encore pour l'univers, je ne suis pas sûr … (Einstein)




More information about the rules-users mailing list