javadroolsdrools-guvnordrools-fusion

Drools : drl file variables


Below is my class :

    public class NumberDetails {

        private String a ; 
        private String b;
        private String c;
        private String status;

        private String result;

         // getters and setters
        }

Initilize values status : 302, a = "A", b="2"

I have to apply logic :

if(status=302){
    result = a+b; 

}

How to write this in .drl file ?

rule "302 case"
when 
    numberObject: NumberDetails(status==302)
then

    numberObject.setResult(numberObject(a)+numberObject(b)); // I know this is wrong but how to write it ?
end

Solution

  • You can use the getter and setter methods to get the value in your drl file. For example, you can write your rule as:

    rule "302 case"
    when 
        numberObject: NumberDetails(status==302)
    then
    
        numberObject.setResult(numberObject.getA()+numberObject.getB());
    end