[rules-users] Problem with nested properties

Michael Neale michael.neale at gmail.com
Thu Dec 11 04:03:42 EST 2008


I don't recall drools 4 being able to do nested fields like that.  
Drools 5 can if you want to check it out.

Sent from my iPhone

On 11/12/2008, at 19:52, "Olivier THIERRY" <olivier.thierry at gmail.com>  
wrote:

> Hi,
>
> We plan to use rules engine on a project because business rules will
> often change and need to be written by business experts. We are
> testing Drools 4.0.7 and are very interested with it, in particular
> because of the ability to write DSL.
>
> In our tests we wrote a rule that needs nested properties to compare
> year part of two dates. But it doesn't work, it can't resolve nested
> properties while we created the needed getter methods.
>
> The rule is as following :
>
> rule "CALCUL_RELICAT_CP"
>    salience 8
>    dialect "java"
>    no-loop
>    when
>            not VOCounter( code == "RELICAT_CP" )
>        $beginDate : RuleDate( name == "startDate")
>        $relicat : VOCounter (code == "SOLDE_CP_CUM", startDate.year ==
> ($beginDate.year + 1))
>    then
>               ....
> end
>
> And the stack trace is as following :
>
> org.drools.RuntimeDroolsException: Exception executing predicate eval(
> startDate.year == ( $beginDate.year + 1 ) )
>    at org.drools.rule.PredicateConstraint.isAllowedCachedLeft 
> (PredicateConstraint.java:239)
>    at org.drools.common.SingleBetaConstraints.isAllowedCachedLeft 
> (SingleBetaConstraints.java:122)
>    at org.drools.reteoo.JoinNode.assertTuple(JoinNode.java:108)
>    at org.drools.reteoo.SingleTupleSinkAdapter.propagateAssertTuple 
> (SingleTupleSinkAdapter.java:20)
>    at org.drools.reteoo.JoinNode.assertObject(JoinNode.java:156)
>    at org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject 
> (SingleObjectSinkAdapter.java:22)
>    at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:145)
>    at org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject 
> (SingleObjectSinkAdapter.java:22)
>    at org.drools.reteoo.ObjectTypeNode.assertObject 
> (ObjectTypeNode.java:162)
>    at org.drools.reteoo.Rete.assertObject(Rete.java:175)
>    at org.drools.reteoo.ReteooRuleBase.assertObject 
> (ReteooRuleBase.java:192)
>    at org.drools.reteoo.ReteooWorkingMemory.doInsert 
> (ReteooWorkingMemory.java:71)
>    at org.drools.common.AbstractWorkingMemory.insert 
> (AbstractWorkingMemory.java:911)
>    at org.drools.common.AbstractWorkingMemory.insert 
> (AbstractWorkingMemory.java:883)
>    at org.drools.common.AbstractWorkingMemory.insert 
> (AbstractWorkingMemory.java:684)
>    at t4.test.drools.TestRuleBase.loadLines(TestRuleBase.java:89)
>    at t4.test.drools.TestRuleBase.executeRuleWithDsl 
> (TestRuleBase.java:116)
>    at t4.test.drools.Test1.testDsl(Test1.java:39)
> Caused by: org.mvel.CompileException: unable to resolve property: year
>    at  
> org. 
> mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain 
> (ReflectiveAccessorOptimizer.java:289)
>    at  
> org. 
> mvel. 
> optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor 
> (ReflectiveAccessorOptimizer.java:110)
>    at  
> org.mvel.ast.VariableDeepPropertyNode.getReducedValueAccelerated 
> (VariableDeepPropertyNode.java:26)
>    at org.mvel.ast.PropertyASTNode.initializePropertyNode 
> (PropertyASTNode.java:70)
>    at org.mvel.ast.PropertyASTNode.getReducedValueAccelerated 
> (PropertyASTNode.java:24)
>    at org.mvel.ast.BinaryOperation.getReducedValueAccelerated 
> (BinaryOperation.java:21)
>    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.MVELPredicateExpression.evaluate 
> (MVELPredicateExpression.java:45)
>    at org.drools.rule.PredicateConstraint.isAllowedCachedLeft 
> (PredicateConstraint.java:232)
>    ... 46 more
> Caused by: org.mvel.PropertyAccessException: unable to resolve  
> property: year
>    at  
> org. 
> mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.getBeanProperty 
> (ReflectiveAccessorOptimizer.java:383)
>    at  
> org. 
> mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain 
> (ReflectiveAccessorOptimizer.java:258)
>    ... 56 more
>
> We could make it work this way :
>
>        $relicat : VOCounter (code == "SOLDE_CP_CUM", $debut :  
> startDate )
>        $startDate : RuleDate( name == "startDate" )
>        eval ($startDate.getYear() == $debut.getYear() + 1)
>
> But we find this very complex for non business experts that are not
> developers. And we find it too complex to write DSL for this.
> It would be great if we could make it work using nested properties.
>
> Are nested properties supported (I found in mailing list archives that
> it was planned for 3.1 :
> http://www.mail-archive.com/user@drools.codehaus.org/msg01331.html ) ?
> Note I am a newbie with Drools and rules engine, so maybe there is a
> better way to write it ?
>
> Thanks in advance ;)
>
> Olivier
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users



More information about the rules-users mailing list