Search code examples
droolsrule-enginemvel

EqualsIgnoreCase on Drools


I am trying to rewrite my drl from using regex to equalsIgnoreCase as I think its faster. I am not sure its faster though. However, drools doesn't like it for some reason and I get unknown error.

The one on top works, but the one using equalsIgnoreCase doesn't

rule "name"
salience 0
activation-group "flow"
dialect "mvel"
no-loop true
when
    $vurderinger: Vurderinger(vurdering1909 != null &&
                              vurdering1909.verdi matches "(?i)^FOO$")
then
    modify( $vurderinger ) { setVurdering1913(new DroolsType("SHOW")) }
end


rule "name"
salience 0
activation-group "flow"
dialect "mvel"
no-loop true
when
    $vurderinger: Vurderinger(vurdering1909 != null &&
                 eval("FOO".equalsIgnoreCase(vurdering1909.verdi)))
then
    modify( $vurderinger ) { setVurdering1913(new DroolsType("SHOW")) }
end

Can anyone spot the mistake?


Solution

  • Within eval, stick to Java: refer to bound variables, use getter.

    when
    $vurderinger: Vurderinger($v: vurdering1909 != null &&
                 eval("FOO".equalsIgnoreCase($v.getVerdi())))
    then
    

    Edit Not knowing the class definition, the error and the version, I advise using eval/Java, to be on the safe side, no matter what the Drools version is. For 6.3.0, you can omit eval, and it works.

    when
    $vurderinger: Vurderinger(vurdering1909 != null &&
                  "FOO".equalsIgnoreCase(vurdering1909.verdi))
    then