Question

I have a quite simple problem: for a rule I want to specifie an array of values which are valid values. How can I do so? I already had a look on the "in" keyword, but if I use the keyword I get a very strange exception from the Drools Compiler.

Working example with "in"

This image shows the working rule with the "in" keyword. But I also want the user to be able to mark the rule as "ignorable" if needed, for example using a special character..

If I use the following rule with the "ignore rule"-Extra (which I also use in other rules with success), I get a very strange error message from the Drools Compiler:

Not working rule

Error message from the compiler:

Unable to Analyse Expression plant == "91" || plant == "83" || plant == "63" || plant == "28" || "91":
[Error: Right side of logical operation is not of type boolean. Found class java.lang.String]
[Near : {... lant == "83" || plant == "63" || plant == "28" || "91" ....}]
                                                           ^
[Line: 9, Column: 2] : [Rule name='CAS_11']

Predicate '"83"' must be a Boolean expression
[Line: 9, Column: 2] : [Rule name='CAS_11']

Predicate '"63"' must be a Boolean expression
[Line: 9, Column: 2] : [Rule name='CAS_11']

I hope you guys can help me.. I am very new to Drools which might be the problem ;)...

C YA

Was it helpful?

Solution

Maybe the easiest way to accomplish what you want is to change you your condition like

plant in ($param) && "-" not in ($param)

With this "91","28","63" fires the rule, but "93","28","-" does not. Plain "-" ignores the rule as well.

If you want a fancier solution you could and another fact to your domain, such as Ignore with one boolean attribute, and have another condition for that. Details of this solutions requires a bit more info on your actual use case, but I hope you get the idea.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top