[rules-users] Can drools comtinue testing even if one of theconditions fail ?

Anstis, Michael (M.) manstis1 at ford.com
Fri Aug 15 04:12:06 EDT 2008


Please don't cross post: http://www.jboss.org/drools/lists.html 

IMO, Drools can do what you want but you need to change the way you are
thinking about the problem.

The behaviour you consider undesirable is by design as all patterns
(i.e. conditions) need to be matched for the consequence to activate.

The way that came immediately to mind was to place individual conditions
into separate rules and have the consequences record the match. 

Very simplistically (a mash-up of code and pseudo code):-

Rule "setup"
	when
	then
		ConditionHolder h = new ConditionHolder();
		h.add(condition1, false); //false indicates the
condition was not matched, true that it was
		h.add(condition2, false);
		insert(new ConditionsHolder());
End

Rule "condition1"
	when
		condition1
		$h : ConditionHolder()
	then
		$h.set(condition1, true);
End

Rule "condition2"
	when
		condition2
		$h : ConditionHolder()
	then
		$h.set(condition2, true);
End

You can then retrieve ConditionHolder and lookup which conditions were
matched or unmatched.

Good luck.

Mike		

-----Original Message-----
From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of DroolUser
Sent: 15 August 2008 08:59
To: rules-users at lists.jboss.org
Subject: [rules-users] Can drools comtinue testing even if one of
theconditions fail ?


Hi, 
I'm using drools for testing if the few attributes of my MO are not
null. 

I construct the rule in the .drl file in following way : 

rule "name" 
when 
        condition1 
        condition2 
        condition3 
        condition4 
then 
        consequence 
end 

I have observed that the drool engine verifies the conditions line by
line
(in the sequence they have written). The moment condition fails, control
comes back to the calling method. 

I don't want this. I want the control to execute each and every
condition
whether true or false and maintain a record of passed/failed conditions.

Something like this  : 
rule "name" 
when 
        condition1 
                log the test result  --- This statement should get
executed
even if condition 1 fails and      control should go to condition 2 
        condition2 
                log the test result 
        condition3 
                log the test result 
        condition4 
                log the test result 
then 
        consequence 
end 

Is this possible in Drools ?

-- 
View this message in context:
http://www.nabble.com/Can-drools-comtinue-testing-even-if-one-of-the-con
ditions-fail---tp18995160p18995160.html
Sent from the drools - user mailing list archive at Nabble.com.

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




More information about the rules-users mailing list