1 package org.kuali.ole.ingest.function;
2
3 import org.apache.log4j.Logger;
4 import org.kuali.ole.DataCarrierService;
5 import org.kuali.ole.OLEConstants;
6 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
7 import org.kuali.rice.krms.framework.engine.Function;
8
9 import java.sql.Timestamp;
10 import java.text.DateFormat;
11 import java.text.ParseException;
12 import java.text.SimpleDateFormat;
13 import java.util.Date;
14
15
16
17
18 public class OleRenewalDateComparison implements Function {
19 private static final Logger LOG = Logger.getLogger(OleRenewalDateComparison.class);
20
21
22
23
24
25 @Override
26 public Object invoke(Object... arguments) {
27 LOG.info(" --------- Inside OleRenewalDateComparison ------------");
28 DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
29 boolean comparison = false;
30 if(arguments!=null && arguments.length==1){
31 Object object = arguments[0];
32 if(object==null)
33 return false;
34 Date orginalDueDate = null;
35 if(object instanceof String){
36 DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
37 try {
38 orginalDueDate= (Date)formatter.parse((String)object);
39 } catch (ParseException e) {
40 e.printStackTrace();
41 }
42
43 }else{
44 orginalDueDate =(Date)object;
45 }
46 if(dataCarrierService.getData(OLEConstants.DUE_DATE)!=null){
47 Timestamp newDueDate = (Timestamp) dataCarrierService.getData(OLEConstants.DUE_DATE);
48 comparison =checkRenewalDate(orginalDueDate,newDueDate);
49 }
50 }
51
52 return comparison;
53 }
54
55
56
57
58
59
60
61 private boolean checkRenewalDate(Date orginalDueDate,Date newDueDate){
62 if(orginalDueDate!=null && newDueDate.compareTo(orginalDueDate)>=0){
63 return true;
64 }
65 return false;
66 }
67 }