<br> Felipe, <br><br> I think you were very close to doing it right. What about this:<br><br><div style="margin: 0px;"><font color="#960000" face="Monaco" size="3"><span style="font-size: 11px;">rule</span></font><font face="Monaco" size="3">
<span style="font-size: 11px;"> </span></font><font color="#008000" face="Monaco" size="3"><span style="font-size: 11px;">"remove used vacation days"</span></font></div><div style="margin: 0px;"><span style="white-space: pre;">
        </span><font color="#960000" face="Monaco" size="3"><span style="font-size: 11px;">no-loop</span></font></div><div style="margin: 0px;"><span style="white-space: pre;">        </span><font color="#960000" face="Monaco" size="3">
<span style="font-size: 11px;">when</span></font></div><div style="margin: 0px;"><span style="white-space: pre;">        </span><span style="white-space: pre;">        </span><font face="Monaco" size="3"><span style="font-size: 11px;">
vr: VacationRequestVO($days: availableDays , $iniDate: initDate )</span></font></div><div style="margin: 0px;"><span style="white-space: pre;">        </span><span style="white-space: pre;">        </span><font face="Monaco" size="3"><span style="font-size: 11px;">
$u: UserVO( $vacReqList: vacationRequestList )</span></font></div><div style="margin: 0px;"><span style="white-space: pre;">        </span><span style="white-space: pre;">        </span><font face="Monaco" size="3"><span style="font-size: 11px;">
Number (</span></font><span style="white-space: pre;"></span><font face="Monaco" size="3"><span style="font-size: 11px;">$usedDays
: </span></font><font face="Monaco" size="3"><span style="font-size: 11px;">intValue > 1) from accumulate ( VacationRequestVO(
isAproved == true, endDate < $iniDate, $uDays: usedDays)</span></font></div><div style="margin: 0px;"><font face="Monaco" size="3"><span style="font-size: 11px;"><span style="white-space: pre;">                                                                                                                </span>from $vacReqList, sum($uDays))
</span></font></div><div style="margin: 0px;"><span style="white-space: pre;">        </span><font color="#960000" face="Monaco" size="3"><span style="font-size: 11px;">then</span></font></div><div style="margin: 0px;"><span style="white-space: pre;">
        </span><span style="white-space: pre;">        </span><font face="Monaco" size="3"><span style="font-size: 11px;">vr.setAvailableDays($days - $usedDays);</span></font></div><div style="margin: 0px;"><font color="#960000" face="Monaco" size="3">
<span style="font-size: 11px;">end</span></font></div><div><br></div> So, basically, what we are trying to do from a language perspective is to allow users to optionally provide a source for each pattern. So, if you simply write a pattern without a source, it comes from the working memory:
<br><br>MyClass( ... ) <br><br> If you want him to come from another source, you use the "from" CE. As you did, it is possible to nest the "from CE" inside the "accumulate CE".<br><br>Number(...) from accumulate( VacationRequestVO(...) from $vacRequeList ... )
<br><br> The other change you needed in your rule is that as you are adding up quantities, you want to use the "sum" function instead of "count" function that is used to count occurrences.<br><br> Try out and let us know... this is a nice rule to show language expressiveness.
<br><br> []s<br> Edson<br><br><div><span class="gmail_quote">2007/8/2, Felipe Piccolini <<a href="mailto:felipe.piccolini@bluesoft.cl">felipe.piccolini@bluesoft.cl</a>>:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div style="">Hi,<div><br></div><div> this is just a dumb question for drools-languaje gurus... like Edson :)</div><div><br></div><div>How ca I write a rule (CE in LHS) for accumulate atributes inside an object, but this objects are not facts,
</div><div>they are inside a collection which is an attribute from a fact... pretty messy right?...lol..</div><div><br></div><div>well, the business problem is this.</div><div><br></div><div>I need to count (accumulate) vacation days used on previous vacation requests.
</div><div>I have an User (which is one fact) having a collection of oldVacationRequests</div><div>and an actual VacationRequest (the another fact).</div><div>So the rules is like this: discount to the available days for vacation those used in previous
</div><div>vacation request, and those days are the days between initDate and endDate in each</div><div>old vacation request with isAproved seted true and having endDate before the actual</div><div>vacation request initDate.
</div><div><br></div><div>did I explain myself?... </div><div><br></div><div><br></div><div><br></div><div>so I need to know if this is possible I was trying to do something like this...but is obviously wrong...:)</div><div style="margin: 0px;">
<font color="#960000" face="Monaco" size="3"><span style="font-size: 11px;">rule</span></font><font face="Monaco" size="3"><span style="font-size: 11px;"> </span></font><font color="#008000" face="Monaco" size="3"><span style="font-size: 11px;">
"remove used vacation days"</span></font></div><div style="margin: 0px;"><span style="white-space: pre;">        </span><font color="#960000" face="Monaco" size="3"><span style="font-size: 11px;">no-loop</span></font></div>
<div style="margin: 0px;"><span style="white-space: pre;">        </span><font color="#960000" face="Monaco" size="3"><span style="font-size: 11px;">when</span></font></div><div style="margin: 0px;"><span style="white-space: pre;">
        </span><span style="white-space: pre;">        </span><font face="Monaco" size="3"><span style="font-size: 11px;">vr: VacationRequestVO($days: availableDays , $iniDate: initDate )</span></font></div><div style="margin: 0px;"><span style="white-space: pre;">
        </span><span style="white-space: pre;">        </span><font face="Monaco" size="3"><span style="font-size: 11px;">$u: UserVO( $vacReqList: vacationRequestList )</span></font></div><div style="margin: 0px;"><span style="white-space: pre;">
        </span><span style="white-space: pre;">        </span><font face="Monaco" size="3"><span style="font-size: 11px;">$usedDays : Number (intValue > 1) from accumulate ( $ovr: VacationRequestVO( isAproved == true, endDate < $iniDate, $uDays: usedDays),
</span></font></div><div style="margin: 0px;"><font face="Monaco" size="3"><span style="font-size: 11px;"><span style="white-space: pre;">                                                                                                                </span>from $vacReqList, count($uDays))</span></font></div><div style="margin: 0px;">
<span style="white-space: pre;">        </span><font color="#960000" face="Monaco" size="3"><span style="font-size: 11px;">then</span></font></div><div style="margin: 0px;"><span style="white-space: pre;">        </span><span style="white-space: pre;">
        </span><font face="Monaco" size="3"><span style="font-size: 11px;">vr.setAvailableDays($days - $usedDays);</span></font></div><div style="margin: 0px;"><font color="#960000" face="Monaco" size="3"><span style="font-size: 11px;">
end</span></font></div><div><br></div><div>Thanks... <br><div> <span style="border-collapse: separate; border-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
<div><span style="text-decoration: underline;"><span> </span></span><div><font size="3"><span style="font-size: 13px;"><b style="font-size: 13px; font-weight: bold;">
<span style="font-size: 13px; font-weight: bold;">Felipe Piccolini M.</span></b></span></font></div><div><a href="mailto:felipe.piccolini@bluesoft.cl" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
<span style="color: rgb(0, 0, 238);">felipe.piccolini@bluesoft.cl</span></a></div><br></div><div><br></div><br></span> </div><br></div></div><br>_______________________________________________<br>rules-users mailing list<br>
<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">
https://lists.jboss.org/mailman/listinfo/rules-users</a><br><br></blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> Software Engineer - JBoss Rules Core Developer<br> Office: +55 11 3529-6000<br> Mobile: +55 11 9287-5646
<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a>