I am having difficulties in writing a rule which match with an enum value in its lhs.
For example, if I have the following enum:
public enum EStatus {
OK,
NOT_OK
}
I would like to use it in something like this:
rule "my rule"
dialect "java"
when
status : EStatus() // --> this works, but I want to be more specific
// status : EStatus(this == EStatus.OK) // --> doesn't work. How can I make it work?
then
// ...
end
Is this even possible in Drools? I use version 5.1.1.
You should always use enums when a variable (especially a method parameter) can only take one out of a small set of possible values. Examples would be things like type constants (contract status: “permanent”, “temp”, “apprentice”), or flags (“execute now”, “defer execution”).
If you just create a list of the enum values (instead of strings) via parsing, then sort that list using Collections. sort , it should sort the way you want. If you need a list of strings again, you can just convert back by calling name() on each element.
This works for me:
rule "my rule"
when
Ticket(status == EStatus.OK)
then
...
end
so that should work too:
rule "my rule"
when
EStatus(this == EStatus.OK)
then
...
end
Verify if it still occurs in Drools 5.3 and file a bug if it does in jira
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With