Thanks Edson! But I still can't find a complete workaround for current biz need: Here Student is a complicate POJO, and there is a one-to-many mapping between Student and exam ( we use hibernate as the data access layer).
The complete biz requirement for the question is: we want to filter out such students, who has started the training in last 7 days, and if he still hasn't submitted all detail index information. So I hope there is such a rule: $s : (Student($startDate : startDate ->(utilService.dateWithin($startDate,(new Date()),7, utilService.UNIT_DAY))) && ( Student($examDate :examDate == null) || Student($reExamTimes: reExamTimes == null) || Student($dailyHours : dailyHours == null) )); which will tell us these students, whose startDate is in last 7 days. and at least one of the index,examDate, reExamTimes and dailyHours, is null. Could you give more suggestions for it? Thanks! BTW, is there such rule sample which is closer real biz world? Best Regards Weily On 11/24/06, Edson Tirelli <[EMAIL PROTECTED]> wrote:
Weily, When you use AND between patterns, you are saying the engine: find one fact that match the first pattern and find another fact that matches the second pattern. If you want the same fact to match more than one "constraint", simply write all constraints inside the same pattern. I guess this is what you are looking for: when $student: Student(examDate == null, $startDate : startDate ->(utilService.dateWithin($startDate,(new Date()),7, utilService.UNIT_DAY ))) then println("...") end The above will match each single fact that complies to both constraints. BTW, if you indeed want to match more than one fact using AND between patterns, you don't need to explicit writing the AND as it is already implicit: when $s1 : Student(examDate == null) $s2 : Student($startDate : startDate ->(utilService.dateWithin($startDate,(new Date()),7, utilService.UNIT_DAY)))) then println("...") end Above example will match all possible combinations of 2 facts, as long as the first fact matches the first pattern (and it will be bound to variable $s1) and the second fact matches second pattern (and it will be bound to variable $s2). The above is exactly the same of: when $s1 : Student(examDate == null) AND $s2 : Student($startDate : startDate ->(utilService.dateWithin($startDate,(new Date()),7, utilService.UNIT_DAY)))) then println("...") end Regarding syntax, we are working on parser improvements just to avoid any confusion like the one you reported in the first e-mail, but the semantics of conditional elements (and, or, not, exists, etc) will not change and it is important you understand them. Hope it helps. []s Edson weily li wrote: > Hi ALL, > > Here is several test cases: > > facts feeded: 5 Students. > > 1. > When > Student(examDate == null); > Then > println(".."); > <expected>: one line printed out > <result>: one line printed out > > 2. > When > Student($startDate : startDate > ->(utilService.dateWithin($startDate,(new Date()),7, > utilService.UNIT_DAY))) > Then > println("...") > <expected>: three lines printed out > <result>: three lines printed out > > 3. > when > (Student(examDate == null) and Student($startDate : startDate > ->(utilService.dateWithin($startDate,(new Date()),7, > utilService.UNIT_DAY)))) > then > println("...") > <expected>: one line printed out > <result>: three lines printed out(same as scenario 2) > > 4. > when > $s : (Student(examDate == null) and Student($startDate : startDate > ->(utilService.dateWithin($startDate,(new Date()),7, > utilService.UNIT_DAY)))) > then > println($s.get....) > > At scenario 4, it should assign the Student which meet all columns to > $s. right? > > Could anyone help explain how to make 'AND' work as expected? > > Thanks > Best Regards > Weily > > > -- --- Edson Tirelli Software Engineer - JBoss Rules Core Developer Office: +55 11 3124-6000 Mobile: +55 11 9218-4151 JBoss, a division of Red Hat @ www.jboss.com IT executives: Red Hat still #1 for value http://www.redhat.com/promo/vendor/ --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email