1 package org.kuali.ole.deliver.controller.checkout;
2
3 import org.apache.commons.lang3.StringUtils;
4 import org.apache.log4j.Logger;
5 import org.kuali.ole.OLEConstants;
6 import org.kuali.ole.deliver.bo.*;
7 import org.kuali.ole.deliver.drools.DroolsConstants;
8 import org.kuali.ole.deliver.drools.DroolsExchange;
9 import org.kuali.ole.deliver.form.CircForm;
10 import org.kuali.ole.deliver.form.OLEForm;
11 import org.kuali.ole.deliver.util.OleItemRecordForCirc;
12 import org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.ItemRecord;
13 import org.kuali.rice.krad.util.GlobalVariables;
14
15 import java.sql.Timestamp;
16 import java.text.SimpleDateFormat;
17 import java.util.*;
18 import java.util.regex.Matcher;
19 import java.util.regex.Pattern;
20
21
22
23
24 public class CheckoutUIController extends CheckoutBaseController {
25 private static final Logger LOG = Logger.getLogger(CheckoutUIController.class);
26
27 @Override
28 protected void setDataElements(OLEForm oleForm, OleItemRecordForCirc oleItemRecordForCirc) {
29 CircForm circForm = getCircForm(oleForm);
30 circForm.getDroolsExchange().addToContext("oleItemRecordForCirc", oleItemRecordForCirc);
31 circForm.getDroolsExchange().addToContext("circForm", circForm);
32 }
33
34 @Override
35 public CircForm getCircForm(OLEForm oleForm){
36 return (CircForm) oleForm;
37 }
38
39 @Override
40 public ItemRecord getItemRecord(OLEForm oleForm) {
41 return getCircForm(oleForm).getItemRecord();
42 }
43
44 @Override
45 public String getOperatorId(OLEForm oleForm) {
46 return getLoginUserId();
47 }
48
49 @Override
50 public void setItemRecord(OLEForm oleForm, ItemRecord itemRecord) {
51 getCircForm(oleForm).setItemRecord(itemRecord);
52 }
53
54 @Override
55 public String getItemBarcode(OLEForm oleForm) {
56 return getCircForm(oleForm).getItemBarcode();
57 }
58
59 @Override
60 public void setItemBarcode(OLEForm oleForm, String itemBarcode) {
61 getCircForm(oleForm).setItemBarcode(itemBarcode);
62 }
63
64 @Override
65 public OlePatronDocument getCurrentBorrower(OLEForm oleForm) {
66 return getCircForm(oleForm).getPatronDocument();
67 }
68
69 @Override
70 public void setItemValidationDone(boolean result, OLEForm oleForm) {
71 getCircForm(oleForm).setItemValidationDone(result);
72 }
73
74 @Override
75 public OleCirculationDesk getSelectedCirculationDesk(OLEForm oleForm) {
76 OleCirculationDesk oleCirculationDesk = getCircDeskLocationResolver().getCircDeskForOpertorId
77 (GlobalVariables.getUserSession().getPrincipalId());
78 return oleCirculationDesk;
79 }
80
81 @Override
82 public void addLoanDocumentToCurrentSession(OleLoanDocument oleLoanDocument, OLEForm oleForm) {
83 getCircForm(oleForm).getLoanDocumentListForCurrentSession().add(0,oleLoanDocument);
84 }
85
86 @Override
87 public boolean processCustomDueDateIfSet(OLEForm oleForm, OleLoanDocument oleLoanDocument) {
88 if (null != getCircForm(oleForm).getCustomDueDateMap()) {
89 try {
90 processCustomDueDate(oleForm, oleLoanDocument);
91 } catch (Exception e) {
92 return true;
93 }
94 }
95 return false;
96 }
97
98 private void processCustomDueDate(OLEForm oleForm, OleLoanDocument oleLoanDocument) throws Exception {
99 boolean timeFlag = false;
100 Timestamp timestamp;
101 Pattern pattern;
102 Matcher matcher;
103 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OlePatron.PATRON_MAINTENANCE_DATE_FORMAT);
104
105 String customDueDateTime = getCircForm(oleForm).getCustomDueDateTime();
106 Date customDueDateMap = getCircForm(oleForm).getCustomDueDateMap();
107
108 if (StringUtils.isNotBlank(customDueDateTime)) {
109 String[] str = customDueDateTime.split(":");
110 pattern = Pattern.compile(OLEConstants.TIME_24_HR_PATTERN);
111 matcher = pattern.matcher(customDueDateTime);
112 timeFlag = matcher.matches();
113 if (timeFlag) {
114 if (str != null && str.length <= 2) {
115 getCircForm(oleForm).setCustomDueDateTime(customDueDateTime + OLEConstants.CHECK_OUT_DUE_TIME_MS);
116 }
117 timestamp = Timestamp.valueOf(new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT).format(customDueDateMap).concat(" ").concat(getCircForm(oleForm).getCustomDueDateTime()));
118 } else {
119 getCircForm(oleForm).setCustomDueDateTimeMessage(OLEConstants.DUE_DATE_TIME_FORMAT_MESSAGE);
120 throw new Exception();
121 }
122 } else if (fmt.format(customDueDateMap).compareTo(fmt.format(new Date())) == 0) {
123 timestamp = new Timestamp(new Date().getTime());
124 } else {
125 timestamp = Timestamp.valueOf(new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT).format(customDueDateMap).concat(" ").concat(new SimpleDateFormat("HH:mm:ss").format(new Date())));
126 }
127 oleLoanDocument.setLoanDueDate(timestamp);
128 oleLoanDocument.setCirculationPolicyId(OLEConstants.NO_CIRC_POLICY_FOUND);
129 }
130
131 @Override
132 public void setDueDateTimeForItemRecord(OLEForm oleForm, Timestamp loanDueDate) {
133 getItemRecord(oleForm).setDueDateTime(loanDueDate);
134 }
135
136 @Override
137 public void addCurrentLoandDocumentToListofLoandedToPatron(OLEForm oleForm, OleLoanDocument oleLoanDocument) {
138 getCircForm(oleForm).getPatronDocument().getOleLoanDocuments().add(oleLoanDocument);
139 }
140
141 @Override
142 public void removeCurrentLoanDocumentFromCurrentSession(OLEForm oleForm, OleLoanDocument oleLoanDocument) {
143 getCircForm(oleForm).getLoanDocumentListForCurrentSession().remove(oleLoanDocument);
144 }
145
146 @Override
147 public void clearCurrentSessionList(OLEForm oleForm) {
148 getCircForm(oleForm).getLoanDocumentListForCurrentSession().clear();
149 }
150
151 @Override
152 public String getCirculationLocationId(OLEForm oleForm) {
153 return getCircForm(oleForm).getSelectedCirculationDesk();
154 }
155
156 @Override
157 public boolean isRecordNoteForDamagedItem(OLEForm oleForm) {
158 return getCircForm(oleForm).isRecordNoteForDamagedItem();
159 }
160
161 @Override
162 public boolean isRecordNoteForClaimsReturn(OLEForm oleForm) {
163 return getCircForm(oleForm).isRecordNoteForClaimsReturn();
164 }
165
166 @Override
167 public boolean isRecordNoteForMissingPiece(OLEForm oleForm) {
168 return getCircForm(oleForm).isRecordNoteForMissingPiece();
169 }
170
171 }