I just gave a "name" to your anonymous objects... :)
"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."
So, replace this Day object for whatever you have in your business domain
model. Also, I added "status == Day.WORKED" to represent whatever constraint
you use do differentiate working days from non-working days... so, in other
words, that was just me guessing a scenario similar to yours but probably
coming up with something completely different... ;)
[]s
Edson
2008/11/4 Bryan Hansen <bryankhansen(a)gmail.com>
Thank you Edson, this helps me get going in the right direction.
In this logic:
Period( $sd : startDate, $ed : endDate )
Number( intValue > 10 ) from accumulate(
Day( date >= $sd && <= $ed, status == Day.WORKED ),
count( 1 ) )
Where is date coming from? As I read the statements, I am getting startDate
and endDate from a Period object that I pass in. The Number() statement just
says to take the result and parse it as a number right? What about Day and
date though? Is Day a java object from my Java code? I searched the docs
looking for a Day object in the drools docs and didn't come up with
anything. I am assuming it is because of the Day.WORKED status, would date
just be a member of that object?
Thanks,
Bryan
On Mon, Nov 3, 2008 at 7:51 PM, Edson Tirelli <tirelli(a)post.com> wrote:
>
> 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(a)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(a)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
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
>
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
Edson Tirelli
JBoss Drools Core Development
JBoss, a division of Red Hat @