View Javadoc

1   package org.kuali.ole.ingest.function;
2   
3   import org.apache.log4j.Logger;
4   import org.kuali.rice.krms.framework.engine.Function;
5   
6   import java.text.DateFormat;
7   import java.text.ParseException;
8   import java.text.SimpleDateFormat;
9   import java.util.ArrayList;
10  import java.util.Date;
11  
12  /**
13   * PatronMembershipExpiration is used for validating checkMembershipExpirationDate
14   */
15  public class OleCurrentDateComparison implements Function {
16      private static final Logger LOG = Logger.getLogger(OleCurrentDateComparison.class);
17      /**
18       * This method takes the request and invoke the methods to checkMembershipExpirationDate.
19       * @param arguments
20       * @return  Object
21       */
22      @Override
23      public Object invoke(Object... arguments) {
24          LOG.info(" --------- Inside OleCurrentDateComparison ------------");
25          Object argument = arguments[0];
26          Object object = ((ArrayList) argument).get(0);
27          Date expirationDate = null;
28          if(object instanceof String){
29              DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
30              try {
31                  expirationDate= (Date)formatter.parse((String)object);
32              } catch (ParseException e) {
33                  e.printStackTrace();
34              }
35  
36          }else{
37              expirationDate =(Date)((ArrayList) argument).get(0);
38          }
39  
40          return checkMembershipExpirationDate(expirationDate);
41      }
42  
43      /**
44       *  This method check the membership ExpiryDate with current date.
45       * @param expDate
46       * @return  boolean
47       */
48      private boolean checkMembershipExpirationDate(Date expDate){
49          Date curDat = new Date();
50          if(expDate!=null && curDat.compareTo(expDate)>=0){
51              return  true;
52          }
53          return false;
54      }
55  }