Drools Runtime does not recognize Custom Operator Parameter

254 Views Asked by At

Problem Statement:

We have few custom operators for Date and Strings, which are implemented looking at Str operator like shown here: https://github.com/kiegroup/drools/blob/f7ab4ee3c88d767a8cbb372c2db1afa84b20a51d/drools-core/src/main/java/org/drools/core/base/evaluators/StrEvaluatorDefinition.java

with below configuration in kie.properties.conf:

drools.evaluator.str = com.company.drools.operators.StrEvaluatorDefinition

For Custom Str operator we created, Drools runtime is not able to make distinction between Str[begins] and Str[ends].

What this means is when we are running below tests, we expect Rule-1 to fail and Rule-2 to get activated. But what we noticed is, Rule-2 will not be activated.

// Facts input into drools :
//     str1 = drools
//     str2 = dr 

rule "Rule-1"
   when message : Customer( str1 str[endsWith] str2 )
   then System.out.println("Rule - Str 1 -  fired");
end


rule "Rule-2"
   when message : Customer( str1 str[startsWith] str2 )
   then System.out.println("Rule - Str 2 - fired");
end

Other Observations:

If we change RHS to a a string literal like shown below, then Rule-2 will be Activated.

// Facts input into drools :
//     str1 = drools
//     str2 = dr 

rule "Rule-1"
   when message : Customer( str1 str[endsWith] "abc" )
   then System.out.println("Rule - Str 1 -  fired");
end


rule "Rule-2"
   when message : Customer( str1 str[startsWith] str2 )
   then System.out.println("Rule - Str 2 - fired");
end

Finally

We removed Str custom operator, and then used the out of the box Str operator provided by drools. We ran below mentioned tests again, this time Rule-2 gets activated.

// Facts input into drools :
//     str1 = drools
//     str2 = dr 

rule "Rule-1"
   when message : Customer( str1 str[endsWith] str2 )
   then System.out.println("Rule - Str 1 -  fired");
end


rule "Rule-2"
   when message : Customer( str1 str[startsWith] str2 )
   then System.out.println("Rule - Str 2 - fired");
end

Need help on :

Is there an issue with the way we are registering custom operator? because we literally copied entire code from Drools Repo and created our own operator. But notice different behavior in executions.

We have other operators like date[before/after/equals] we are noticing same behavior for them too. We are using latest version of the drools JARs.

0

There are 0 best solutions below