If I understood it correctly and have not missed a comma or parenthesis:
rule "level three"
when
$l0: Level0()
$list1: List( size > 0 )
from accumulate (Level1( $level1List: level1List) from $l0.level1List,
init( List l = new ArrayList(); )
action( l.addAll($level1List); )
return( l ) )
$date: PartialDate()
from accumulate (Level2((name in ("name1", "name2"),$occurrence: occurrence) from $list1,
maxDate($occurence) )
then
-W
2011/10/5 Claes, Kenny [JRDBE - Non J&J] <kclaes@its.jnj.com>
>
> I have a question regarding creating a list of items that are all in nested collections of my main object.
>
> A high level overview of the model is like this:
>
>
>
> public Level0 {
> private List<Level1> level1List;
> }
>
>
>
> public Level1 {
> private List<Level2> level1List;
> }
>
>
>
> public Level2 {
> private Date occurence;
> }
>
>
>
> Now, I add objects of type 0 in the working memory and for each of those objects, I want to find the latest occurrence of a certain Level2, regardless of which level1 they belong to.
>
>
>
> If there’s only 2 levels and I want to find the latest occurrence of Level2’s with a certain name, I can write:
>
>
>
> rule "latest level 1"
>
> when
>
> $l0: Level0()
>
> $date: Date() from accumulate (Level1(name in ("name1", "name2"), $occurence: occurence) from $l0.level1List, maxDate($occurence))
>
> then
>
> // register fact that latest occurrence of name1/name2 level1 was on $date
>
> end
>
>
>
> Now, with 3 levels, since I obviously can’t replace $l0.level1List with $l0.level1List.level2List, is there a way to create an intermediate list that will contain all Level2 objects? No filtering needs to take place on Level1, but if there’s a way to do that too, that would be nice.
>
>
>
> What I currently have is this:
>
>
>
> rule "latest level 2"
>
> when
>
> $l0: Level0()
>
> $l1: Level1() from $l1.level1List
>
> $l2List: List(size > 0) from collect( Level2(name in (("name1", "name2")) from $l1.level2List )
>
> $date: PartialDate() from accumulate (Level2( $occurence: occurence) from $l2List, maxDate($occurence))
>
> then
>
> // register fact that latest occurrence of name1/name2 level2 was on $date
>
> end
>
>
>
> But this does not work as it treats each Level1 seperately: it creates a “latest occurrence” for all accumulated level2 facts within a level1, instead of one for the entire set of level 2’s ‘owned’ by the level0 object.
>
>
>
> Any suggestions?
>
> _______________________________________________
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>