Search code examples
javadrools

Ignore an attribute value dynamically in drools rules


I have a situation Where I need to ignore any attribute value at run time.

$applicant : Applicant ($age : age, $gender : gender, $income : income)
$person : Person( age == $age, gender == $gender, income == $income )

Say in income attribute, I am saying ANY value; it means if der is any value specified in application income attribute then it is ok otherwise also it should execute the rule because ANY value is acceptable.

Please help to implement this.

Thanks


Solution

  • For a dynamic switch you need another object, PersonControl with boolean attributes:

    $applicant : Applicant ($age : age, $gender : gender, $income : income)
    PersonControl( $igAge: igAge, $igGender: ifGender, $igIncome: igIncome)
    $person : Person( age == $age || $igAge,
                      gender == $gender || $igGender,
                      income == $income || $igIncome )
    

    You may have to insert/retract (or modify) PersonControl for each Applicant evaluation if these evaluations need to be done individually.

    If you want to state a value as any, you'll have to think about a value you can use for that, e.g. -1 for numeric values:

    $applicant : Applicant ($age : age, $gender : gender, $income : income)
    $person : Person( age == $age ,
                      gender == $gender,
                      income == $income || == -1 )