[rules-users] Drools Guvnor: Rule fires multiple times when using eval and OR

Wolfgang Laun wolfgang.laun at gmail.com
Fri Aug 27 03:32:47 EDT 2010


My advice is: Try to avoid the Conditional Element "or". From the
"Expert" manual: "The engine actually has no understanding of the
Conditional Element 'or',..." So, if the engine doesn't "understand"
it, how can we? ;-)

More seriously now, there is general consent that a CE "or" should
ultimately result in two (or more) disjunct (sub-)rules, firing
independently. But this clear strategy is apparently countered (you
could even say marred) by some Rete-level refactoring or optimization.

Anyway, in your case, a "healthy" solution is to write

rule "any blank"
when
    Asset( eval( StringUtil.isBlank(name) || StringUtil.isBlank(tag) ))
then
   //...
end

-W


2010/8/27 Patricia Bogoevici <patriciabogoevici at yahoo.com>
>
> Hi all,
>
> I am using Drools Guvnor 5.1. I created a rule that uses eval, and OR for conditions. When I tested the rule, I noticed in the log, that actually the rule fired twice.
> The error seemed to be caused by eval and or combination. When I re-wrote the rule to not use eval, it fired only once. Also, I re-wrote the rule to use eval, but AND for conditions, again, the rule fired once as expected.
> I wonder if there is any other rule attribute besides no-loop, and lock-on-active that I can use to not have the rule firing twice. Or if there is any way to make the rule not firing twice.The main problem for me, is that after the rule is executed, there are 2 objects created.
>
> Below is the rule test scenario, and audit log:
>
>
> Rule with eval and OR, rule fires twice
>     rule "test_rule_1"
>         lock-on-active true
>         no-loop true
>         dialect "mvel"
>         when
>             Asset(eval(StringUtils.isBlank(name)))
>              or
>             Asset(eval(StringUtils.isBlank(tag)))
>         then
>             Assetfact0 = new Asset();
>             fact0.setStatus( "INVALID" );
>             insert(fact0 );
>     end
>
> Audit log:
> OBJECT ASSERTED value:Asset( model=MODEL, status=null, tag=null, classification=null, name=null, serial=null ) factId: 1
> FIRING rule: [test_rule_1] activationId:test_rule_1 [1] declarations:
> OBJECT ASSERTED value:Asset( model=null, status=INVALID, tag=null, classification=null, name=null, serial=null ) factId: 2
> FIRING rule: [test_rule_1] activationId:test_rule_1 [1] declarations:
> OBJECT ASSERTED value:Asset( model=null, status=INVALID, tag=null, classification=null, name=null, serial=null ) factId: 3
>
> Rule with eval and AND, rule fires only once:
>     rule "test_rule_2"
>         lock-on-active true
>         no-loop true
>         dialect "mvel"
>         when
>             Asset(eval(StringUtils.isBlank(name)))
>             Asset(eval(StringUtils.isBlank(tag)))
>         then
>             Assetfact0 = new Asset();
>             fact0.setStatus( "INVALID" );
>             insert(fact0 );
>     end
>
> Audit log:
> OBJECT ASSERTED value:Asset( model=MODEL, status=null, tag=null, classification=null, name=null, serial=null ) factId: 1
> FIRING rule: [test_rule_2] activationId:test_rule_2 [1] declarations:
> OBJECT ASSERTED value:Asset( model=null, status=INVALID, tag=null, classification=null, name=null, serial=null ) factId: 2
>
> Rule with simple string validation instead of eval. The rule fires only once.
>
>     rule "test_rule_3"
>         lock-on-active true
>         no-loop true
>         dialect "mvel"
>         when
>             Asset(name=="''")
>              or
>             Asset(tag=="'''")
>         then
>             Assetfact0 = new Asset();
>             fact0.setStatus( "INVALID" );
>             insert(fact0 );
>     end
>
>
> Audit log:
> OBJECT ASSERTED value:Asset( model=MODEL, status=null, tag=null, classification=null, name='', serial=null ) factId: 1
> FIRING rule: [test_rule_3] activationId: test_rule_3 [1] declarations:
> OBJECT ASSERTED value:Asset( model=null, status=INVALID, tag=null, classification=null, name=null, serial=null ) factId: 2
>
>
> Thanks,
> Patricia
>
>
> _______________________________________________
> 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