<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><DIV>Hi Wolfgang,</DIV>
<DIV> </DIV>
<DIV>thanks for your reply.</DIV>
<DIV>I did have the idea about having the concepts of first, last,predecessor, successor etc. in TimeEntry. Unfortunately, it really isn't possible because this class (i.e TimeEntry) is a main part of a huge application model, which has been existing since long, has many dependencies to other classes, and shouldn't be changed ("only" for fulfilling the requirement of rules-engine) . So unfortunately I can only use those which are available to me. That's why I was hoping if there's really pure rule-based solution to this.</DIV>
<DIV> </DIV>
<DIV>Regards</DIV>
<DIV style="FONT-FAMILY: times new roman, new york, times, serif; FONT-SIZE: 12pt"><BR>
<DIV style="FONT-FAMILY: arial, helvetica, sans-serif; FONT-SIZE: 13px"><FONT size=2 face=Tahoma>
<HR SIZE=1>
<B><SPAN style="FONT-WEIGHT: bold">From:</SPAN></B> Wolfgang Laun <wolfgang.laun@gmail.com><BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> Rules Users List <rules-users@lists.jboss.org><BR><B><SPAN style="FONT-WEIGHT: bold">Sent:</SPAN></B> Wed, November 11, 2009 11:29:29 AM<BR><B><SPAN style="FONT-WEIGHT: bold">Subject:</SPAN></B> Re: [rules-users] Need help in formulating rule (using list)<BR></FONT><BR>Implied by the List representation are concepts such as "first",<BR>"last", "predecessor"<BR>and "successor". All of these may or may not be represented by the fields in<BR>TimeEntry. This would be so if it is *guaranteed* that one TimeEntry's<BR>start time is another one's end time; (and then you wouldn't even need them<BR>being sorted). Failing this, an explicit representation by adding an ordinal<BR>number or (as I prefer doing) a reference to the previous and next TimeEntry<BR>might be considered.<BR><BR>But, either way, reasoning
over pairs of TimeEntry objects (of one<BR>Schedule) requires that they are all (at least temporarily) present as facts in<BR>WM. Then, to be identified as TimeEntrys of a specific Schedule, they also<BR>could have a reference to that.<BR><BR>It's a simple task to write a rule that fires for a new Schedule and creates<BR>the extended TimeEntryPlus facts from its List<TimeEntry>. To avoid NPEs,<BR>I'd add a dummy TimeEntryPlus object (type=="OFF") before and after. Then, you<BR>could write rules<BR><BR>rule checkValidBreak1<BR>when<BR> $break : TimeEntryPlus( type == "BREAK" )<BR> TimeEntryPlus( type == "WORK", succ == $break || pred == $break,<BR>length <= 10 )<BR>then<BR> System.out.println( "Short work b/a break " + ... $break ...,<BR>$break.getSchedule() ... )<BR>end<BR><BR>rule checkValidBreak2<BR>when<BR> $break : TimeEntryPlus( type == "BREAK" )<BR> TimeEntryPlus( type == "WORK",
succ == $break )<BR>then<BR> System.out.println( "Can't start with a break " + ... $break ...,<BR>$break.getSchedule() ... )<BR>end<BR><BR>-W<BR><BR><BR>On Wed, Nov 11, 2009 at 10:46 AM, psentosa <<A href="mailto:psentosa@yahoo.com" ymailto="mailto:psentosa@yahoo.com">psentosa@yahoo.com</A>> wrote:<BR>><BR>> Hi Brody,<BR>><BR>> I have had similar situation several times, and each time I had to modify my<BR>> objects to avoid this, and it was really tedious.<BR>> I'd also would like to know whether it is possible to have a "real solution"<BR>> in this case without needing to change the base objects, but rather use the<BR>> rule language to formulate this kind of business rule<BR>><BR>> *why didn't I receive this mail through the mailing list? maybe you haven't<BR>> subscribed yet?*<BR>><BR>><BR>><BR>><BR>> Brody bach wrote:<BR>>><BR>>> Hi all,<BR>>><BR>>> I have an object
which I use as main fact object, let's say "Schedule",<BR>>> which has a list of objects called "TimeEntry" ---><BR>>><BR>>> class Schedule(){<BR>>> List<TimeEntry> entries;<BR>>> }<BR>>><BR>>> class TimeEntry(){<BR>>> String type;<BR>>> Date start;<BR>>> Date end;<BR>>> Integer length;<BR>>> }<BR>>><BR>>><BR>>> Now, if I insert Schedule into the WM, and would like to iterate over the<BR>>> list of TimeEntry, due to the following business rule :<BR>>><BR>>> For all time entries, if it is of type BREAK:<BR>>> check whether a time entry of type WORK exist,<BR>>> before and/or after this BREAK, which has only length of 10 minutes<BR>>><BR>>> The content of the time entry list has been sorted before so they are
all<BR>>> in correct time order, e.g<BR>>><BR>>> 09:00 - 09:10 WORK (10 min)<BR>>> 09:10 - 09:30 BREAK (20 min)<BR>>> 09:30 - 10:30 WORK (60 min)<BR>>> --> in this case, the rule should fire<BR>>><BR>>> How can I define this rule? Some questions which I have:<BR>>> - how do I check previous and next element of the current element?<BR>>> - the length of the list isn't fix; it may contain 1, 2, or more entries.<BR>>> So somehow in an attempt to access next element, it should take care of<BR>>> the bound of the list. But should this be really part of the rule<BR>>> definition?<BR>>><BR>>> Many thanks in advance!<BR>>><BR>>> Regards<BR>>><BR>>><BR>>><BR>>><BR>><BR>> --<BR>> View this message in context:
http://old.nabble.com/Need-help-in-formulating-rule-%28using-list%29-tp26284362p26298480.html<BR>> Sent from the drools - user mailing list archive at <A href="http://nabble.com/" target=_blank>Nabble.com</A>.<BR>><BR>> _______________________________________________<BR>> rules-users mailing list<BR>> <A href="mailto:rules-users@lists.jboss.org" ymailto="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</A><BR>> <A href="https://lists.jboss.org/mailman/listinfo/rules-users" target=_blank>https://lists.jboss.org/mailman/listinfo/rules-users</A><BR>><BR><BR>_______________________________________________<BR>rules-users mailing list<BR><A href="mailto:rules-users@lists.jboss.org" ymailto="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</A><BR><A href="https://lists.jboss.org/mailman/listinfo/rules-users" target=_blank>https://lists.jboss.org/mailman/listinfo/rules-users</A><BR></DIV></DIV><!--
cg8.c4.mail.gq1.yahoo.com compressed/chunked Tue Nov 10 06:41:49 PST 2009 --></div><br>
</body></html>