1 package org.kuali.ole.deliver.drools;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.OLEParameterConstants;
5 import org.kuali.ole.deliver.bo.OleFixedDateTimeSpan;
6 import org.kuali.ole.deliver.bo.OleFixedDueDate;
7 import org.kuali.ole.deliver.calendar.service.OleCalendarService;
8 import org.kuali.ole.deliver.calendar.service.impl.OleCalendarServiceImpl;
9 import org.kuali.rice.coreservice.api.CoreServiceApiServiceLocator;
10 import org.kuali.rice.coreservice.api.parameter.Parameter;
11 import org.kuali.rice.coreservice.api.parameter.ParameterKey;
12 import org.kuali.rice.krad.service.KRADServiceLocator;
13
14 import java.sql.Timestamp;
15 import java.text.SimpleDateFormat;
16 import java.util.Date;
17 import java.util.HashMap;
18 import java.util.List;
19 import java.util.Map;
20
21
22
23
24 public class FixedDateUtil {
25 public Timestamp getFixedDateByPolicyId(String ruleName){
26 Timestamp dueDate = null;
27 java.sql.Date date = new java.sql.Date(System.currentTimeMillis());
28 List<OleFixedDueDate> oleFixedDueDates = getFixedDueDateBasedOnPolicySet(ruleName);
29 if(oleFixedDueDates!=null && oleFixedDueDates.size()>0){
30 for(OleFixedDueDate oleFixedDueDate : oleFixedDueDates){
31 List<OleFixedDateTimeSpan> oleFixedDateTimeSpans = oleFixedDueDate.getOleFixedDateTimeSpanList();
32 for(OleFixedDateTimeSpan oleFixedDateTimeSpan : oleFixedDateTimeSpans){
33 if(dateComparison(date,oleFixedDateTimeSpan.getFromDueDate(),oleFixedDateTimeSpan.getToDueDate())){
34 String defaultCloseTime = getParameter(OLEParameterConstants.DEF_CLOSE_TIME);
35 dueDate = Timestamp.valueOf(new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT).
36 format(oleFixedDateTimeSpan.getFixedDueDate()).concat(" ").concat(defaultCloseTime));
37 break;
38 }
39 }
40 }
41 }
42 return dueDate;
43 }
44
45 private List<OleFixedDueDate> getFixedDueDateBasedOnPolicySet(String ruleName){
46 Map<String,String> policySet = new HashMap<>();
47 policySet.put("circulationPolicySetId",ruleName);
48 List<OleFixedDueDate> oleFixedDueDates = (List<OleFixedDueDate>) KRADServiceLocator.getBusinessObjectService().findMatching(OleFixedDueDate.class,policySet);
49 return oleFixedDueDates;
50 }
51
52 private boolean dateComparison(Date date1,Date date2,Date date3){
53 if(date1!=null && date2!=null && date3!=null){
54 SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
55 String dateString1 = dateFormat.format(date1);
56 String dateString2 = dateFormat.format(date2);
57 String dateString3 = dateFormat.format(date3);
58 if((date1.after(date2) && date1.before(date3)) || dateString1.equals(dateString2) || dateString1.equals(dateString3)){
59 return true;
60 }
61 }
62 return false;
63 }
64
65 public String getParameter(String name) {
66 ParameterKey parameterKey = ParameterKey.create(OLEConstants.APPL_ID, OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT,name);
67 Parameter parameter = CoreServiceApiServiceLocator.getParameterRepositoryService().getParameter(parameterKey);
68 if(parameter==null){
69 parameterKey = ParameterKey.create(OLEConstants.APPL_ID_OLE, OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT,name);
70 parameter = CoreServiceApiServiceLocator.getParameterRepositoryService().getParameter(parameterKey);
71 }
72 return parameter!=null?parameter.getValue():null;
73 }
74 }
75