Felipe,
I think you were very close to doing it right. What about this:
rule "remove used vacation days"
no-loop
when
vr: VacationRequestVO($days: availableDays , $iniDate: initDate )
$u: UserVO( $vacReqList: vacationRequestList )
Number ($usedDays : intValue > 1) from accumulate ( VacationRequestVO(
isAproved == true, endDate < $iniDate, $uDays: usedDays)
from $vacReqList, sum($uDays))
then
vr.setAvailableDays($days - $usedDays);
end
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:
MyClass( ... )
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".
Number(...) from accumulate( VacationRequestVO(...) from $vacRequeList ... )
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.
Try out and let us know... this is a nice rule to show language
expressiveness.
[]s
Edson
2007/8/2, Felipe Piccolini <felipe.piccolini(a)bluesoft.cl>:
Hi,
this is just a dumb question for drools-languaje gurus... like Edson :)
How ca I write a rule (CE in LHS) for accumulate atributes inside an
object, but this objects are not facts,
they are inside a collection which is an attribute from a fact... pretty
messy right?...lol..
well, the business problem is this.
I need to count (accumulate) vacation days used on previous vacation
requests.
I have an User (which is one fact) having a collection of
oldVacationRequests
and an actual VacationRequest (the another fact).
So the rules is like this: discount to the available days for vacation
those used in previous
vacation request, and those days are the days between initDate and endDate
in each
old vacation request with isAproved seted true and having endDate before
the actual
vacation request initDate.
did I explain myself?...
so I need to know if this is possible I was trying to do something like
this...but is obviously wrong...:)
rule "remove used vacation days"
no-loop
when
vr: VacationRequestVO($days: availableDays , $iniDate: initDate )
$u: UserVO( $vacReqList: vacationRequestList )
$usedDays : Number (intValue > 1) from accumulate ( $ovr:
VacationRequestVO( isAproved == true, endDate < $iniDate, $uDays: usedDays),
from $vacReqList, count($uDays))
then
vr.setAvailableDays($days - $usedDays);
end
Thanks...
*Felipe
Piccolini M.*
felipe.piccolini(a)bluesoft.cl
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
Edson Tirelli
Software Engineer - JBoss Rules Core Developer
Office: +55 11 3529-6000
Mobile: +55 11 9287-5646
JBoss, a division of Red Hat @
www.jboss.com