Search code examples
javadrools

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


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.


Solution

  • 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