Drools: How to use enumeration in rules?

I'm having difficulty writing a rule that matches the enum value in its lhs.

For example, if I have the following enumeration:

public enum EStatus {
  OK,
  NOT_OK
}

I would like to use it 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 possible in Drools? I am using version 5.1.1.

+5
source share
3 answers

This works for me:

rule "my rule"
when
    Ticket(status == EStatus.OK)
then
    ...
end

so that it works too:

rule "my rule"
when
    EStatus(this == EStatus.OK)
then
    ...
end

Make sure it is still encountered in Drools 5.3 and writes an error if it is in jira

+6
source

I tried to use Enum on LHS [Ticket (status == EStatus.OK)], I get a compile time error:

BuildError: == EStatus.OK : :....

:

LHS Constant... : user: User ( > 60) - 60.

, Enum, Ticket (status == EStatus.OK)... EStatus.OK, . Enum.

, LHS : Ticket (status == EStatus.getEStatus(1))

EStatus :

public enum EStatus {

// you can use values other than int also
OK(1),
ERROR(2);

private int value;

EStatus (int number)   {       this.value = number;   }

public int valueOf()
{
    return this.value;
}

public static EStatus getEStatus(int value){
    EStatus eStatus = null;

    for(EStatus e : EStatus.values()){
        if(e.valueOf() == value){
            eStatus = d;
            break;
        }
    }

    return eStatus;
}

}

jdk 1.6 Linux Windows.

!

0

. enum estatus, .

public enum EStatus  {
OK,
NOT_OK;

public EStatus getValue(){
    return this;
}

}

:

rule "my rule"
when
    EStatus(value == EStatus.OK)
then
    ...
end
0

All Articles