0

I have to check a condition on date whether a date field of a entity is in range of another two sets of date from other entity

First Entity :

1. id
2. name
3. date

Second Entity ;

1. id
.
.
.
.
17 : Start Date
18 : End Date

I have to check whether the date field of first entity is in range of Start Date and End Date of second entity.

e.g.

(t1.date>= t2.Start Date and t1.date <= t2.End Date)

Problem is that, there are some row where t2 is null.. if it is null, then second condition return true.

My Attempt

PriorAuthorizationLogVO( cardid == $paidClaimVO.cardholderId, ruleType == 'INCL' , $paidClaimVO.time>=etime , (ttime==null || (ttime!=null && $paidClaimVO.time<=ttime))

But, i am not able to confirm whether it is working....

Please help.

4

1 回答 1

2

You could add that check for date between the range of dates in either a static helper method or within one of your entities. In my opinion this will make your rules more readable and you can easily write unit tests for the date check method.

Option 1 - Static helper method

Create a class for having static helper methods, something like this

public class DateUtils {
  private DateUtils() {}  // Cannot be initialized

  public static boolean dateInRange( Date toCheck, Date min, Date max ) {
    // Add null checks here
    // Use Date#before(Date) and Date#after(Date) for checking
    return true|false
  }
}

Your rule would then be like

import static DateUtils.*

rule "date in range"
when:
   dateInRange( e1.date, e2.start, e2.end )
then:
   // logic
end

Option 2 - Method within fact/entity

Create the check method inside one of your facts. In which entity to put this depends on your use case, the information you've given does not specify this yet. I think you can figure out the best place by yourself. Anyway, the code would be something like this

public class Entity1 {
  Date date
}

public class Entity2 {
  Date start
  Date end

 public boolean entity1InRange( Entity1 e ) {
  // null checks
  // Use the Date#before() and Date#after() as above
 }

}

And the rule

rule "date in range"
when:
  e2.entity1InRange( e1 )
then:
  // Logic
end
于 2013-09-30T07:41:20.530 回答