I am iterating a list in the DRL file. I need to call the new Agenda after completion of the loop. But the following code calls the Agenda "B to C" for all iterations
rule "Difference in offsets"
dialect "java"
lock-on-active
when
$notification : NotificationVO()
wtOffset:Integer() from $notification.getWeightOffset();
then
System.out.println("Hello loop1");
$notification.getOffsetChngesInterval().
add((wtOffset-$notification.getInitialOffset()));
update($notification);
drools.setFocus("B to C");
rule "Last activity"
dialect "java"
salience 2
no-loop true
auto-focus false
agenda-group "B to C"
when
$notification:NotificationVO
($notification.getOffsetChngesInterval()!=null)
then
System.out.println("Rule2---"+
$notification.getOffsetChngesInterval().size());
end
In the above code i want to focus the agenda-group "B to C" only after completing the iteration of $notification.getWeightOffset();.
Two comments. (1) The abundant usage of rule attributes is something to be avoided. (2) Rule "Difference in offsets" implements a procedural paradigm: map elements of one list to create another list.
That said, I'd do the calculation of the "changes intervals" on the right hand side of a rule that triggers when there are more "weight offsets" that "changes intervals". (I'm guessing that this is a good condition.)
rule "Difference in offsets"
dialect "java"
when
$ntf: NotificationVO( weightOffset.size() > offsetChngesInterval.size(),
$initOff: initialOffset )
then
for( Integer ioff: $ntf.getWeightOffset ){
$ntf.getOffsetChngesInterval().add(ioff - $initOff );
}
update( $ntf );
System.out.println( $ntf.getOffsetChngesInterval().size());
end