rules:
rule "accounting_11" dialect "mvel" //for value of l except given in accounting_12 salience 1 activation-group "group l" auto-focus true lock-on-active no-loop true when $iv:invoice(x in ("d20","d21","d22", "d23", "d24","d25"),y =="e20",z =="f20",a =="g20") modify($iv) { sg.seta("all l"), sg.setb("c20")} end rule "accounting_12" dialect "mvel" //exceptions of l salience 2 activation-group "group l" auto-focus true lock-on-active no-loop true //pattern similar accounting_11 additional constraint "l in (....)" when $iv:invoice(l in ("c20","c21","c22", "c23", "c24","c25") , x in ("d20","d21","d22", "d23", "d24","d25"),y =="e20",z =="f20",a =="g20") modify($iv) { sg.seta("sepcific l"), sg.setb("c20")} end
inserted 2 facts in working memory in loop.
- invoice(l="c20", x="d20", y= "e20", z="f20",", a="g20")
- invoice(x="d20", y= "e20", z="f20", a="g20")
call fireallrules().3 activations created, expected.
==>[activationcreatedevent: getactivation()=[[ accounting_11 active=false ] [ [fact 0:2:4445234:4445234:2:default:non_trait:org.cpg.poc.drools.keloy.domain.invoice@43d432] ] ], getknowledgeruntime()=org.drools.core.impl.statefulknowledgesessionimpl@1743ccd] ==>[activationcreatedevent: getactivation()=[[ accounting_11 active=false ] [ [fact 0:1:2489285:2489285:1:default:non_trait:org.cpg.poc.drools.keloy.domain.invoice@25fbc5] ] ], getknowledgeruntime()=org.drools.core.impl.statefulknowledgesessionimpl@1743ccd] ==>[activationcreatedevent: getactivation()=[[ accounting_12 active=false ] [ [fact 0:2:4445234:4445234:2:default:non_trait:org.cpg.poc.drools.keloy.domain.invoice@43d432] ] ], getknowledgeruntime()=org.drools.core.impl.statefulknowledgesessionimpl@1743ccd]
one of expected activation gets fired
==>[beforeactivationfiredevent: getactivation()=[[ accounting_12 active=false ] [ [fact 0:2:4445234:4445234:2:default:non_trait:org.cpg.poc.drools.keloy.domain.invoice@43d432] ] ], getknowledgeruntime()=org.drools.core.impl.statefulknowledgesessionimpl@1743ccd]
but cancels out other activations.
==>[activationcancelledevent: getcause()=clear, getactivation()=[[ accounting_11 active=false ] [ [fact 0:2:4445234:4445234:2:default:non_trait:org.cpg.poc.drools.keloy.domain.invoice@43d432] ] ], getknowledgeruntime()=org.drools.core.impl.statefulknowledgesessionimpl@1743ccd] ==>[activationcancelledevent: getcause()=clear, getactivation()=[[ accounting_11 active=false ] [ [fact 0:1:2489285:2489285:1:default:non_trait:org.cpg.poc.drools.keloy.domain.invoice@25fbc5] ] ], getknowledgeruntime()=org.drools.core.impl.statefulknowledgesessionimpl@1743ccd]
should not cancel activation created same fact-handle (invoice@43d432) , 1 l=c20 ?
why cancels activation created invoice@25fbc5 , second 1 null value 'l'?
note: when fire rules after each fact insertion, expected result.
using rule attributes no-loop , lock-on-active advertised simplifying rule authoring, true in percentage of use cases. is, however, always way avoid stringent application of logic, fundament of rule conditions. although adding full logic rule conditions may require more work, it'll create logic robust, resulting in rule executions desire.
that said, don't see should happen due inserted rules. clearly, constraints of accounting_11 , accounting_12 overlapping, accounting_12 being more restrictive. dubious situation: want both consequences happen or one? accounting_12 has higher alience, it'll preferred (irrespective of value of field l
). without rule attributes i'd expect other activation remain active, lock-on-active
, activations cancelled.
as said: describing required logic in elementary constraints preferable.
if, instance, rule should not activated l
values being in range defined set `("c20", "c21", "c22", "c23", "c24", "c25"), add constraint:
$iv:invoice(l not in ("c20", "c21", "c22", "c23", "c24", "c25"),...)
Comments
Post a Comment