Drools: How to use an enum in the lhs of a rule?

Calin picture Calin · Nov 21, 2011 · Viewed 10k times · Source

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.

Answer

Geoffrey De Smet picture Geoffrey De Smet · Nov 21, 2011

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