001package org.kuali.ole.ingest.function; 002 003import org.apache.log4j.Logger; 004import org.kuali.rice.krms.framework.engine.Function; 005 006import java.text.DateFormat; 007import java.text.ParseException; 008import java.text.SimpleDateFormat; 009import java.util.ArrayList; 010import java.util.Date; 011 012/** 013 * PatronMembershipExpiration is used for validating checkMembershipExpirationDate 014 */ 015public class OleCurrentDateComparison implements Function { 016 private static final Logger LOG = Logger.getLogger(OleCurrentDateComparison.class); 017 /** 018 * This method takes the request and invoke the methods to checkMembershipExpirationDate. 019 * @param arguments 020 * @return Object 021 */ 022 @Override 023 public Object invoke(Object... arguments) { 024 LOG.info(" --------- Inside OleCurrentDateComparison ------------"); 025 boolean comparison = false; 026 if(arguments!=null && arguments.length==1){ 027 Object object = arguments[0]; 028 if(object==null) 029 return false; 030 Date expirationDate = null; 031 if(object instanceof String){ 032 DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss"); 033 try { 034 expirationDate= (Date)formatter.parse((String)object); 035 } catch (ParseException e) { 036 e.printStackTrace(); 037 } 038 039 }else{ 040 expirationDate =(Date)object; 041 } 042 comparison =checkMembershipExpirationDate(expirationDate); 043 } 044 045 return comparison; 046 } 047 048 /** 049 * This method check the membership ExpiryDate with current date. 050 * @param expDate 051 * @return boolean 052 */ 053 private boolean checkMembershipExpirationDate(Date expDate){ 054 Date curDat = new Date(); 055 if(expDate!=null && curDat.compareTo(expDate)>=0){ 056 return true; 057 } 058 return false; 059 } 060}