While running Drools DRT with some empty values gives an error.
This is the template which we have used....
rule "Rule1_@{row.rowNumber}"
salience @{salience}
dialect "java"
when
variable:Fact(Context == "@{context}")
then
list.add("@{name}");
end
When the parameter is not empty i.e for example @{context}=="PROCESSING" the rule we get is this and its the rule which we want.
rule "Rule1_0"
salience 1
dialect "java"
when
variable:Fact(Context == "PROCESSING")
then
list.add("Task");
end
But when the parameter is empty, for example when we provide @{context}=="" empty string or null then the rule which we get is
rule "Rule1_0"
salience 1
dialect "java"
when
then
list.add("Task");
end
But while refering to the document it says that == or != works same as java's java.util.Objects.equals but when we use this operator and provide null or empty values,in condition part its not working.
This is what they have written in the document:- https://docs.jboss.org/drools/release/latest/drools-docs/html_single/#_patterns_and_constraints
The == operator uses null-safe equals() semantics instead of the usual same semantics. For example, the pattern Person( firstName == "John" ) is similar to java.util.Objects.equals(person.getFirstName(), "John"), and because "John" is not null, the pattern is also similar to "John".equals(person.getFirstName()).
The != operator uses null-safe !equals() semantics instead of the usual not same semantics. For example, the pattern Person( firstName != "John" ) is similar to !java.util.Objects.equals(person.getFirstName(), "John").
I have tried all the possibilities but the answer is same for all.
Is there any solution where we can run DRT file for the parameters with empty string or null values or is there any other method to write the template, if yes then what is it.
The issue was we were giving @Context instead of @ there should be $. And when we use $ it works absolutely fine.