If I understood it correctly and have not missed a comma or parenthesis:<br><br>rule "level three"<br>when<br> $l0: Level0()<br> $list1: List( size > 0 ) <br> from accumulate (Level1( $level1List: level1List) from $l0.level1List,<br>
init( List l = new ArrayList(); )<br> action( l.addAll($level1List); )<br> return( l ) )<br> $date: PartialDate()<br> from accumulate (Level2((name in ("name1", "name2"),$occurrence: occurrence) from $list1, <br>
maxDate($occurence) )<br>then<br><br>-W<br><br><br>2011/10/5 Claes, Kenny [JRDBE - Non J&J] <<a href="mailto:kclaes@its.jnj.com">kclaes@its.jnj.com</a>><br>><br>> I have a question regarding creating a list of items that are all in nested collections of my main object.<br>
><br>> A high level overview of the model is like this:<br>><br>> <br>><br>> public Level0 { <br>> private List<Level1> level1List; <br>> } <br>><br>> <br>><br>> public Level1 { <br>
> private List<Level2> level1List; <br>> } <br>><br>> <br>><br>> public Level2 { <br>> private Date occurence; <br>> } <br>><br>> <br>><br>> 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.<br>
><br>> <br>><br>> If there’s only 2 levels and I want to find the latest occurrence of Level2’s with a certain name, I can write:<br>><br>> <br>><br>> rule "latest level 1"<br>><br>> when<br>
><br>> $l0: Level0()<br>><br>> $date: Date() from accumulate (Level1(name in ("name1", "name2"), $occurence: occurence) from $l0.level1List, maxDate($occurence))<br>><br>> then<br>
><br>> // register fact that latest occurrence of name1/name2 level1 was on $date<br>><br>> end<br>><br>> <br>><br>> 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.<br>
><br>> <br>><br>> What I currently have is this:<br>><br>> <br>><br>> rule "latest level 2"<br>><br>> when<br>><br>> $l0: Level0()<br>><br>> $l1: Level1() from $l1.level1List<br>
><br>> $l2List: List(size > 0) from collect( Level2(name in (("name1", "name2")) from $l1.level2List )<br>><br>> $date: PartialDate() from accumulate (Level2( $occurence: occurence) from $l2List, maxDate($occurence))<br>
><br>> then<br>><br>> // register fact that latest occurrence of name1/name2 level2 was on $date<br>><br>> end<br>><br>> <br>><br>> 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.<br>
><br>> <br>><br>> Any suggestions?<br>><br>> _______________________________________________<br>> rules-users mailing list<br>> <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
> <a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>><br><br>