Bryan,
The main decision here is how to do Date arithmetic, since java does not provide easy to use APIs for that. So, the simplest way IMO, from a rule authoring perspective, is to have a "constraint object" that contain both boundary dates of your rule. Lets call it "Period".
So, if you want to write your rule saying:
"Take a break if you worked more than 10 days in the given period."
Just do:
rule "take a break"
when
Period( $sd : startDate, $ed : endDate )
Number( intValue > 10 ) from accumulate(
Day( date >= $sd && <= $ed, status == Day.WORKED ),
count( 1 ) )
then
// take a break
end
If your Day object is some kind of container object, use a chained from to iterate over them:
rule "take a break"
when
Period( $sd : startDate, $ed : endDate )
DailyReport( $days : days )
Number( intValue > 10 ) from accumulate(
Day( date >= $sd && <= $ed, status == Day.WORKED ) from $days,
count( 1 ) )
then
// take a break
end
Hope it helps.
Edson
2008/11/3 Bryan Hansen
<bryankhansen@gmail.com>
Not really sure how to go about writing this in a rule or whether or not the logic belongs in a rule (I think it does, but if you don't please comment as to why).
I have a list of objects that contain date objects. If the list contains 10 objects that date are before mine then I want them to take a break.
The business case is similar to that of an HR system. If they have worked too many days out of the last 12 then they need to take a break.
I am guessing it would have to use the "collect" attribute, but how would you do the date logic in a LHS clause?
Thanks for any guidance on this.
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
Edson Tirelli
JBoss Drools Core Development
JBoss, a division of Red Hat @ www.jboss.com