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

Patricia Bogoevici patriciabogoevici at yahoo.com
Thu Aug 26 23:35:29 EDT 2010


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



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100826/7a58bd07/attachment.html 


More information about the rules-users mailing list