Rules are not functions, they cannot be called, they execute in response to changes in the working memory.

Mark
Raja.Bobbala@sanofi-aventis.com wrote:
How do i Load & Execute specific rules in my drl file

How do i load & execute specific rules in my drl file? For ex.,
I have 5 rules defined in rules.drl
rule "1"
        when
                cond #1
        then
                System.out.println("Applying Rule 1");
end

rule "2"
        when
                cond #2
        then
                System.out.println("Applying Rule 2");
end

rule "3"
        when
                cond #3
        then
                System.out.println("Applying Rule 3");
end

rule "4"
        when
                cond #4
        then
                System.out.println("Applying Rule 4");
end

rule "5"
        when
                cond #5
        then
                System.out.println("Applying Rule 5");
end

From my Java class, based on some conditions, i should call the respective rules.

public void CheckRules(){
       
        if (some Condition){
                // Execute rule1, rule2
        }else if  (some Condition){
                // Execute rule1, rule3
        }else if (some Condition){
                // Execute rule3, rule5
        }else if (some Condition){
                // Execute rule1,rule2,rule3,rule5
        }
}

PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl(new InputStreamReader(FieldValidation.class.getResourceAsStream("/BizRules.drl")));
RuleBase rulebase = RuleBaseFactory.newRuleBase();
rulebase.addPackage(builder.getPackage());
WorkingMemory workingMemory = rulebase.newWorkingMemory();     
workingMemory.assertObject(object1);
workingMemory.assertObject(object2);
workingMemory.fireAllRules(new RuleNameEqualsAgendaFilter("1"));
               
workingMemory.clearAgenda();
WorkingMemory workingMemory1 = rulebase.newWorkingMemory();
workingMemory1.assertObject(object1);
workingMemory1.assertObject(object2);
workingMemory1.fireAllRules(new RuleNameEqualsAgendaFilter("2"));

Is there any way by which we can add specific rules to the Agendafilter and call fireAllRules() with the rulelist as parameter.


_______________________________________________ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users