[rules-users] Reg. Iterating over a list

Phani Saripalli saripalli.phani at gmail.com
Mon Sep 3 20:41:41 EDT 2012


Another issue I am stuck up is again a container operation (:( ). 

I have my rule something like this: 

//I have a global List defined as 
global java.util.ArrayList cList

// Function isDefined as :
function boolean isDefined(Object o) { 
	return o != null;		
}

//size as 

function int size(List list) {
    return list.size();
}

//and finally append as

function List append(List list, Number num) {
    list.add(num);
    return list;
}



rule "94"
agenda-group "Group 2"
dialect "mvel"
no-loop true
 when

P : Project()
Project( isDefined(seq_A) && !(size(append(seq_A , 99 )) > 4))

then

System.out.println("Rule not satisfied # " + 94 + setStatics() );
cList.add(94);
end

           ......................................... 

I declared a type called "Project" which basically holds the variables
seq_A, seq_B and everything else.
I configured the value of seq_A using a rule - with agenda group as "Config
rule". 

The problem with the rule is that, it is firing and activating a similar
rule in a different agenda group. However, I am setting focus for each group
separately and firing rules like the following:

            ksession.getAgenda().getAgendaGroup("Group Config").setFocus();
            ksession.fireAllRules();
            ksession.getAgenda().getAgendaGroup("Group 0").setFocus();
            ksession.fireAllRules();
            ksession.getAgenda().getAgendaGroup("Group 1").setFocus();
            ksession.fireAllRules();
            ksession.getAgenda().getAgendaGroup("Group 2").setFocus();
            ksession.fireAllRules();

After the rules are fired, I am getting the value for P_seqA as [1, 2, 3, 4,
5, 199, 199], where as my intention was to to get [1, 2, 3, 4, 5, 199]. In
essence, the append function is being called two times. This is the same
case for any of the append (and prepend) operations, I am doing.

This seems to be very confusing to me and I have already spend hours on
this. I just do not want to activate rules outside the current agenda group. 

Many many thanks in advance :)



--
View this message in context: http://drools.46999.n3.nabble.com/Reg-Iterating-over-a-list-tp4019512p4019563.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list