Problem with nested properties
by Olivier THIERRY
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
17 years, 3 months
Books on Drools
by Ravi Krishnamurthy
Hello:
Could you suggest some books on Drools.
Thanks,
Ravi
17 years, 3 months
managing rules in brms, fetching directly from DB
by Paul Sentosa
Hi all,
just some further questions regarding Guvnor:
I would like to use Guvnor for managing my rules with an external RDBMS for storing them, and later on fetching the rules directly from DB from my application,
how can I do this?
in which kind of datatypes are the rules actually saved in database?
anyone can share their experience in short?
Appreciating your ASAP response
Regards
17 years, 3 months
Decision table capabilities
by Ravi Krishnamurthy
Hello:
1) Is it possible to write any if then else kind of rule instead of
stating all the possibilities in a decision table.
For example: if a == 25
print (success)
else if a == 10
print (not bad)
else
print (try again)
Thanks,
Ravi
17 years, 3 months
Performance question - eval on a HashMap vs. from on an ArrayList
by steve.vance
Hi, I'm somewhat new to drools and would like some comments on performance.
I'm choosing between doing an eval on a HashMap vs. a from on an ArraryList.
My assumption is the from on an ArrayList is better, is that correct? In my
situation the HashMap and ArrayList do not have many items in them.
thanks!
1. eval on HashMap
when
$item:RulesVatTOA()
eval($item.getMyHashMap().get("Vat_YesNo") != null &&
$item.getMyHashMap().get("Vat_YesNo").equals("Yes"))
then
2. from on ArrayList
when
$item:RulesVatTOA()
$myValue:com.mycode.util.NameValue(name == "Vat_YesNo", value == "Yes")
from $item.getMyArrayList()
then
--
View this message in context: http://www.nabble.com/Performance-question---eval-on-a-HashMap-vs.-from-o...
Sent from the drools - user mailing list archive at Nabble.com.
17 years, 3 months
Finicky eval statements
by Bagwell, Allen F
I'm puzzled over the proper use of in-line evals. I've used them successfully in some places. But it seems that on occasion something doesn't work when I think it should.
First, this is a when clause that works properly using a separate eval statement. The rule activates and fires when expected:
$rt : RuleTimer(uniqueName == "Hardware Status Request", timedOut == true)
$hw : Hardware($activelyMonitored : activelyMonitored, command == null)
AttrBoolean(this == $activelyMonitored, currentValue == true)
eval($hw.getStatusRequested().howOld() > $hw.getStatusPeriod())
However, this re-write changing to an in-line eval never fires.
$rt : RuleTimer(uniqueName == "Hardware Status Request", timedOut == true)
$hw : Hardware($activelyMonitored : activelyMonitored, command == null, eval(statusRequested.howOld() > statusPeriod) )
AttrBoolean(this == $activelyMonitored, currentValue == true)
Likewise, this re-write doesn't fire either where I sought to bind the more complex statusRequested object to a Drools variable before using it in the eval. The field statusPeriod just holds a primitive double.
$rt : RuleTimer(uniqueName == "Hardware Status Request", timedOut == true)
$hw : Hardware($activelyMonitored : activelyMonitored, $sr : statusRequested, command == null,
eval($sr.howOld() > statusPeriod) )
AttrBoolean(this == $activelyMonitored, currentValue == true)
I haven't been able to find anything in the manual that says these other two syntaxes are wrong. Furthermore, the Drools compiler has no issues with them.
Thanks!
Allen F. Bagwell
e-mail: afbagwe(a)sandia.gov
phone: 505/284-4517
fax: 505/ 844-7886
Ask your doctor if medical advice from a TV commercial is right for you.
17 years, 3 months
Error while adding rule package in 5.0.0M2 & 5.0.0M3
by Jagathesh
Hi,
When I pointed the rules from Drools 4.0.7 to Drools 5.0.0M2, I'm getting the following errors at runtime. I also tried Drools 5.0.0M3 (same error). The error occurs while adding a package.
Could someone help me? Do I've to do something differently for 5.0.0M2?
java.lang.NullPointerException
at org.drools.common.AbstractRuleBase.addPackage(AbstractRuleBase.java:420)
at org.drools.reteoo.ReteooRuleBase.addPackage(ReteooRuleBase.java:381)
Thanks,
Jagathesh
17 years, 3 months