Don't do anything with a side-effect on LHS. Condition evaluation
is something the Engine does, and it decides when what is
evaluated.
All fact modifications should be done in LHS code (or Java code
called from there), and the E must be notified.
Drools is not really different from Jess in that respect.
Another hint: your fact objects should initialize lists to the
empty list - don't leave them null. It greatly simplifies rules.
-W
On 04/09/2012, Phani Saripalli <saripalli.phani(a)gmail.com> wrote:
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-tp4019512p401...
Sent from the Drools: User forum mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users