[rules-users] Complex rule
Edson Tirelli
tirelli at post.com
Mon Nov 3 21:51:12 EST 2008
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 at 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 at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20081103/f0d1e649/attachment.html
More information about the rules-users
mailing list