1

While running Drools DRT with some empty values gives an error .

This is the rule which we have used....

rule "Rule1_@{row.rowNumber}"

when
      variable:Fact(("All"=="@{Column1}" || ("Gold"=="@{Column1}" && @{Column2} == 
      GoldId) || ("Silver"=="@{Column1}" && @{Column2} == SilverId)) && 
      ("All"=="@{Column3}" || ("Diamond"=="@{Column3}" && @{Column4}== DiamondId) || 
      ("Platinum"=="@{Column3}" && @{Column4}== PlatinumId)) && ("@{Column5}" == 
      Column5) && ("@{Column6}" == Column6))
then
      list.add(@{Column7}+"@{Column8}");
end

When the parameter is not empty the rule we get is this and its the rule which we want.

rule "Rule1_1"

when
      variable:Fact(("All"=="Gold" || ("Gold"=="Gold" && 10 == GoldId) || 
      ("Silver"=="Gold" && 10 == SilverId)) && ("All"=="Platinum" || 
      ("Diamond"=="Platinum" && 15== DiamondId) || ("Platinum"=="Platinum" && 15== 
      PlatinumId)) && ("GoldPlatinum" == Column5) && ("Discount" == Column6))
then
      list.add(2+"Customer");
end

but when the parameter is null or Empty String, for example:Column1=All;Column2=empty or Empty String("");Column3=Diamond;Column4=9.

the rule generated is this...

rule "Rule1_2"

when
      //Here it shows nothing
      //only for this part it is full empty because of empty value in excel cell
then
      list.add(1+"Customer");
end

the condition part gets disappeared when the value for specific parameters gets empty or Empty String. Just like in this case the the value in Column3 was empty as well as for Empty String.

Is there any solution where we can run DRT file with an empty String in Parameters.

Radovan Synek
  • 954
  • 6
  • 11
Samyak
  • 81
  • 8
  • `"All"=="Gold"`? `"Gold"=="Gold"` ? `"Platinum"=="Platinum"`? I'm not sure you're using templates correctly. – Roddy of the Frozen Peas Sep 07 '22 at 18:10
  • The template is right. The only problem is when we pass null in parameter, the when parts gets disappear. Even when we pass an Empty String it gives the same problem, I think that its considering null for an empty string. And its works fine when we pass some values. @RoddyoftheFrozenPeas – Samyak Sep 08 '22 at 05:48
  • I'm telling you your "good" rule doesn't make sense. You're not using the templates correctly to create sensible rules. – Roddy of the Frozen Peas Sep 08 '22 at 14:20
  • rule "Rule1_@{row.rowNumber}" salience @{salience} dialect "java" when variable:NewFact("Sam"=="@{FirstName}" && "Jain"=="@{LastName}") then list.add("@{name}"); end Now lets take this simple template file, in this when "@FirstName" is null or an Empty String, while executing the when part gets disappear or it shows empty and by default it will add in the list which we don't want. The issue is with when we pass null or an empty string to parameters – Samyak Sep 09 '22 at 05:26
  • I understand your problem. Your generated rule is still terrible and inefficient. That is all I've been saying repeatedly. You're not using templates to generate good rules. – Roddy of the Frozen Peas Sep 09 '22 at 05:47
  • Can you please help me to solve this problem by suggesting some example for the template with the requirement I am needed. I will be so much helpful for me. @RoddyoftheFrozenPeas – Samyak Sep 13 '22 at 12:11

2 Answers2

1

The issue was we were giving @parameter instead of @ there should be $. And when we use $ it works absolutely fine.

Samyak
  • 81
  • 8
1

Try like this ${parameter} instead of @{parameter} it should work

Harsha
  • 86
  • 5