yoon wai
yoon wai

Reputation: 31

Drools facts filtering with eval does not work for boolean with quotes ""

I have guided decision tables with a boolean condition column with predicate as follows

"$param" == "NA" ? true : "$param" == boolFlag

The decision table source translates as follows for different condition values (true,false,NA)

For true

when
   f : Foo(..., eval( "true" == "NA"  ? true :  "true" == boolFlag )) 

For false

when
   f : Foo(..., eval( "false" == "NA"  ? true :  "false" == boolFlag )) 

For NA

when
   f : Foo(..., eval( "NA" == "NA"  ? true :  "NA" == boolFlag )) 

These filters works on other environments (RHDM 7.52.0.Final-redhat-00008) but when i try in my local, which is "RHDM 7.59.0.Final-redhat-00009" it does not work anymore.

In my local, I transform the decision table to a drl file and I have to remove the quote "" from expression to work

when
   f : Foo(..., eval( "true" == "NA"  ? true :  true == boolFlag )) 

It is only happening if eval() is used for fact filtering. If i remove the eval it also works with quotes like below

when
   f : Foo(..., "true" == boolFlag) 

And if i use eval() outside of fact filtering, it works also

when
   eval("true" == boolFlag) 

It does not work only if eval() is used for the fact filtering.
I am not sure it is due to the version difference or i need to change some config to make it work or not.

I am new to the drools and appreciate for any guide to finding the root cause.


My sample codes from local are as follows

package com.myspace.test;

rule "init"
    salience 100
    dialect "mvel"
    
    when
         eval(true)
    then
       drools.setFocus("AG1");
end

rule "test"
    salience 99
    agenda-group "AG1"
    activation-group "AVG1"
    dialect "mvel"
    
    when
        //      f : Foo(eval("true" == "NA" ? true :  "true" == copy))   // does not work in local  
        //      f : Foo(eval("true" == "NA" ? true :  true == copy))     // works in local
    //  f : Foo("true" == copy)                                  // works in local 
        eval("true" == true)          // works in local
        f : Foo()                               
    
       then
       System.out.println("Name = " + f.Name);
       
       //copy name to Bar
       Bar b = new Bar();
       b.setName(f.Name);
       insert(b);
end

Objects

package com.myspace.test;

/**
 * This class was automatically generated by the data modeler tool.
 */

public class Foo implements java.io.Serializable {

    static final long serialVersionUID = 1L;

    @org.kie.api.definition.type.Label("Name")
    private java.lang.String name;
    @org.kie.api.definition.type.Label(value = "Copy")
    private boolean copy;

    public Foo() {
    }

    public java.lang.String getName() {
        return this.name;
    }

    public void setName(java.lang.String name) {
        this.name = name;
    }

    public boolean isCopy() {
        return this.copy;
    }

    public void setCopy(boolean copy) {
        this.copy = copy;
    }

    public Foo(java.lang.String name, boolean copy) {
        this.name = name;
        this.copy = copy;
    }

}
package com.myspace.test;

/**
 * This class was automatically generated by the data modeler tool.
 */

public class Bar implements java.io.Serializable {

    static final long serialVersionUID = 1L;

    private java.lang.String name;

    public Bar() {
    }

    public java.lang.String getName() {
        return this.name;
    }

    public void setName(java.lang.String name) {
        this.name = name;
    }

    public Bar(java.lang.String name) {
        this.name = name;
    }
}

Upvotes: 1

Views: 119

Answers (0)

Related Questions