1 package org.kuali.ole.deliver.controller.checkout;
2
3 import org.apache.commons.collections.CollectionUtils;
4 import org.apache.commons.lang3.StringUtils;
5 import org.apache.log4j.Logger;
6 import org.kuali.ole.DocumentUniqueIDPrefix;
7 import org.kuali.ole.OLEConstants;
8 import org.kuali.ole.deliver.bo.OleLoanDocument;
9 import org.kuali.ole.deliver.bo.OlePatronDocument;
10 import org.kuali.ole.deliver.calendar.service.DateUtil;
11 import org.kuali.ole.deliver.drools.DroolsConstants;
12 import org.kuali.ole.deliver.form.CircForm;
13 import org.kuali.ole.deliver.form.OleLoanForm;
14 import org.kuali.ole.deliver.service.OleDeliverRequestDocumentHelperServiceImpl;
15 import org.kuali.ole.deliver.util.DroolsResponse;
16 import org.kuali.ole.deliver.util.ErrorMessage;
17 import org.kuali.ole.deliver.util.OleItemRecordForCirc;
18 import org.kuali.ole.docstore.common.document.content.instance.ItemClaimsReturnedRecord;
19 import org.kuali.ole.docstore.common.document.content.instance.ItemDamagedRecord;
20 import org.kuali.ole.docstore.common.document.content.instance.MissingPieceItemRecord;
21 import org.kuali.rice.core.api.config.property.ConfigContext;
22 import org.kuali.rice.krad.util.GlobalVariables;
23 import org.kuali.rice.krad.web.form.UifFormBase;
24 import org.springframework.validation.BindingResult;
25 import org.springframework.web.bind.annotation.ModelAttribute;
26 import org.springframework.web.bind.annotation.RequestMapping;
27 import org.springframework.web.servlet.ModelAndView;
28
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
31 import java.sql.Timestamp;
32 import java.text.SimpleDateFormat;
33 import java.util.*;
34
35
36
37
38 public class CheckoutItemController extends CircFastAddItemController {
39
40 private static final Logger LOG = Logger.getLogger(CheckoutItemController.class);
41
42
43 @RequestMapping(params = "methodToCall=lookupItemAndSaveLoan")
44 public ModelAndView lookupItemAndSaveLoan(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
45 HttpServletRequest request, HttpServletResponse response) {
46 CircForm circForm = (CircForm) form;
47 DroolsResponse droolsResponse = getCheckoutUIController(circForm.getFormKey()).lookupItemAndSaveLoan(circForm);
48 if (null != droolsResponse &&
49 StringUtils.isNotBlank(droolsResponse.retrieveErrorMessage())) {
50 if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.ERROR_CODES.CUSTOM_LOAN_DUE_DATE_REQUIRED.getName())) {
51 circForm.setErrorMessage(droolsResponse.getErrorMessage());
52 showDialog("customDueDateDialog", circForm, request, response);
53 } else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.GENERAL_MESSAGE_FLAG)) {
54 circForm.setErrorMessage(droolsResponse.getErrorMessage());
55 showDialog("generalInfoDialog", circForm, request, response);
56 } else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.REQUEST_EXITS_FOR_AVAIL_ITEM)) {
57 circForm.setErrorMessage(droolsResponse.getErrorMessage());
58 circForm.setRequestExistOrLoanedCheck(true);
59 showDialog("overrideMessageDialog", circForm, request, response);
60 }else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.REQUEST_EXITS_FOR_LOANED_ITEM)) {
61 circForm.setErrorMessage(droolsResponse.getErrorMessage());
62 showDialog("checkoutRenewOptionDialog", circForm, request, response);
63 }else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.CHECKED_OUT_BY_SAME_PATRON)) {
64 circForm.setErrorMessage(droolsResponse.getErrorMessage());
65 showDialog("checkoutRenewOptionDialog", circForm, request, response);
66 }else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.LOANED_BY_DIFFERENT_PATRON)) {
67 circForm.setErrorMessage(droolsResponse.getErrorMessage());
68 resetItemInfoForNextTrans(circForm);
69 showDialog("generalInfoDialog", circForm, request, response);
70 } else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.GENERAL_INFO)){
71 circForm.setErrorMessage(droolsResponse.getErrorMessage());
72 showDialog("generalInfoDialog",circForm,request,response);
73 }else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.ITEM_CLAIMS_RETURNED)){
74 handleClaimsReturnedProcess(request, response, circForm, droolsResponse);
75 }else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.ITEM_DAMAGED)){
76 handleDamagedItemProcess(request, response, circForm, droolsResponse);
77 }else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.ITEM_MISSING_PIECE)){
78 handleMissingPieceProcess(request, response, circForm, droolsResponse);
79 }else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.DUE_DATE_TRUNCATED)){
80 circForm.setErrorMessage(droolsResponse.getErrorMessage());
81 showDialog("dueDateTruncated",circForm,request,response);
82 }else {
83 circForm.setErrorMessage(droolsResponse.getErrorMessage());
84 circForm.setItemOverride(true);
85 showErrorMessageDialog(circForm, request, response);
86 }
87 } else {
88 resetItemInfoForNextTrans(circForm);
89 }
90
91 if(StringUtils.isBlank(circForm.getLightboxScript())){
92 circForm.setLightboxScript("jq('#checkoutItem_control').focus();");
93 } else {
94 String lightBoxScript = circForm.getLightboxScript();
95 String itemLightBoxScript = lightBoxScript + "jq('#checkoutItem_control').blur();";
96 circForm.setLightboxScript(itemLightBoxScript);
97 }
98
99 return getUIFModelAndView(circForm);
100 }
101
102 @RequestMapping(params = "methodToCall=processDamagedItem")
103 public ModelAndView processDamagedItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
104 HttpServletRequest request, HttpServletResponse response) {
105 CircForm circForm = (CircForm) form;
106 processItemInformationIfAvailable(request, circForm);
107 OleItemRecordForCirc oleItemRecordForCirc = (OleItemRecordForCirc) circForm.getDroolsExchange().getContext().get("oleItemRecordForCirc");
108 DroolsResponse droolsResponse = getCheckoutUIController(circForm.getFormKey()).
109 preValidationForDamagedItem(oleItemRecordForCirc.getItemRecord(), circForm);
110 if (null != droolsResponse && StringUtils.isNotBlank(droolsResponse.retrieveErrorMessage())) {
111 if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.ERROR_CODES.CUSTOM_LOAN_DUE_DATE_REQUIRED.getName())) {
112 circForm.setErrorMessage(droolsResponse.getErrorMessage());
113 showDialog("customDueDateDialog", circForm, request, response);
114 } else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.REQUEST_EXITS_FOR_AVAIL_ITEM)) {
115 circForm.setErrorMessage(droolsResponse.getErrorMessage());
116 circForm.setRequestExistOrLoanedCheck(true);
117 showDialog("overrideMessageDialog", circForm, request, response);
118 }else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.REQUEST_EXITS_FOR_LOANED_ITEM)) {
119 circForm.setErrorMessage(droolsResponse.getErrorMessage());
120 showDialog("checkoutRenewOptionDialog", circForm, request, response);
121 }else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.CHECKED_OUT_BY_SAME_PATRON)) {
122 circForm.setErrorMessage(droolsResponse.getErrorMessage());
123 showDialog("checkoutRenewOptionDialog", circForm, request, response);
124 }else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.LOANED_BY_DIFFERENT_PATRON)) {
125 circForm.setErrorMessage(droolsResponse.getErrorMessage());
126 resetItemInfoForNextTrans(circForm);
127 showDialog("generalInfoDialog", circForm, request, response);
128 } else if(null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equalsIgnoreCase(DroolsConstants.ITEM_MISSING_PIECE)) {
129 handleMissingPieceProcess(request, response, circForm, droolsResponse);
130 } else if (null!= droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equalsIgnoreCase(DroolsConstants.ITEM_DAMAGED)) {
131 handleDamagedItemProcess(request, response, circForm, droolsResponse);
132 }else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.DUE_DATE_TRUNCATED)){
133 circForm.setErrorMessage(droolsResponse.getErrorMessage());
134 showDialog("dueDateTruncated",circForm,request,response);
135 } else {
136 circForm.setErrorMessage(droolsResponse.getErrorMessage());
137 circForm.setItemOverride(true);
138 showErrorMessageDialog(circForm, request, response);
139 }
140 } else {
141 resetItemInfoForNextTrans(circForm);
142 }
143 if(StringUtils.isBlank(circForm.getLightboxScript())){
144 circForm.setLightboxScript("jq('#checkoutItem_control').focus();");
145 } else {
146 String lightBoxScript = circForm.getLightboxScript();
147 String itemLightBoxScript = lightBoxScript + "jq('#checkoutItem_control').blur();";
148 circForm.setLightboxScript(itemLightBoxScript);
149 }
150 return getUIFModelAndView(circForm);
151 }
152
153 @RequestMapping(params = "methodToCall=processMissingPieceItem")
154 public ModelAndView processMissingPieceItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
155 HttpServletRequest request, HttpServletResponse response) {
156 CircForm circForm = (CircForm) form;
157 processItemInformationIfAvailable(request, circForm);
158 OleItemRecordForCirc oleItemRecordForCirc = (OleItemRecordForCirc) circForm.getDroolsExchange().getContext().get("oleItemRecordForCirc");
159 DroolsResponse droolsResponse = getCheckoutUIController(circForm.getFormKey()).preValidationForMissingPiece(oleItemRecordForCirc.getItemRecord(), circForm);
160 if (null != droolsResponse && StringUtils.isNotBlank(droolsResponse.retrieveErrorMessage())) {
161 if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.ERROR_CODES.CUSTOM_LOAN_DUE_DATE_REQUIRED.getName())) {
162 circForm.setErrorMessage(droolsResponse.getErrorMessage());
163 showDialog("customDueDateDialog", circForm, request, response);
164 } else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.REQUEST_EXITS_FOR_AVAIL_ITEM)) {
165 circForm.setErrorMessage(droolsResponse.getErrorMessage());
166 circForm.setRequestExistOrLoanedCheck(true);
167 showDialog("overrideMessageDialog", circForm, request, response);
168 }else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.REQUEST_EXITS_FOR_LOANED_ITEM)) {
169 circForm.setErrorMessage(droolsResponse.getErrorMessage());
170 showDialog("checkoutRenewOptionDialog", circForm, request, response);
171 }else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.CHECKED_OUT_BY_SAME_PATRON)) {
172 circForm.setErrorMessage(droolsResponse.getErrorMessage());
173 showDialog("checkoutRenewOptionDialog", circForm, request, response);
174 }else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.LOANED_BY_DIFFERENT_PATRON)) {
175 circForm.setErrorMessage(droolsResponse.getErrorMessage());
176 resetItemInfoForNextTrans(circForm);
177 showDialog("generalInfoDialog", circForm, request, response);
178 } else if(null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equalsIgnoreCase(DroolsConstants.ITEM_MISSING_PIECE)) {
179 handleMissingPieceProcess(request, response, circForm, droolsResponse);
180 } else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.DUE_DATE_TRUNCATED)){
181 circForm.setErrorMessage(droolsResponse.getErrorMessage());
182 showDialog("dueDateTruncated",circForm,request,response);
183 } else {
184 circForm.setErrorMessage(droolsResponse.getErrorMessage());
185 circForm.setItemOverride(true);
186 showErrorMessageDialog(circForm, request, response);
187 }
188 } else {
189 resetItemInfoForNextTrans(circForm);
190 }
191 if(StringUtils.isBlank(circForm.getLightboxScript())){
192 circForm.setLightboxScript("jq('#checkoutItem_control').focus();");
193 } else {
194 String lightBoxScript = circForm.getLightboxScript();
195 String itemLightBoxScript = lightBoxScript + "jq('#checkoutItem_control').blur();";
196 circForm.setLightboxScript(itemLightBoxScript);
197 }
198 return getUIFModelAndView(circForm);
199 }
200
201 @RequestMapping(params = "methodToCall=processCheckoutAfterPreValidations")
202 public ModelAndView processCheckoutAfterPreValidations(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
203 HttpServletRequest request, HttpServletResponse response) {
204 CircForm circForm = (CircForm) form;
205 processItemInformationIfAvailable(request, circForm);
206 OleItemRecordForCirc oleItemRecordForCirc = (OleItemRecordForCirc) circForm.getDroolsExchange().getContext().get("oleItemRecordForCirc");
207 DroolsResponse droolsResponse = getCheckoutUIController(circForm.getFormKey()).processCheckoutAfterPreValidations(circForm, oleItemRecordForCirc);
208 if (null != droolsResponse && StringUtils.isNotBlank(droolsResponse.retrieveErrorMessage())) {
209 if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.ERROR_CODES.CUSTOM_LOAN_DUE_DATE_REQUIRED.getName())) {
210 circForm.setErrorMessage(droolsResponse.getErrorMessage());
211 showDialog("customDueDateDialog", circForm, request, response);
212 } else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.REQUEST_EXITS_FOR_AVAIL_ITEM)) {
213 circForm.setErrorMessage(droolsResponse.getErrorMessage());
214 circForm.setRequestExistOrLoanedCheck(true);
215 showDialog("overrideMessageDialog", circForm, request, response);
216 }else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.REQUEST_EXITS_FOR_LOANED_ITEM)) {
217 circForm.setErrorMessage(droolsResponse.getErrorMessage());
218 showDialog("checkoutRenewOptionDialog", circForm, request, response);
219 }else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.CHECKED_OUT_BY_SAME_PATRON)) {
220 circForm.setErrorMessage(droolsResponse.getErrorMessage());
221 showDialog("checkoutRenewOptionDialog", circForm, request, response);
222 }else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.LOANED_BY_DIFFERENT_PATRON)) {
223 circForm.setErrorMessage(droolsResponse.getErrorMessage());
224 resetItemInfoForNextTrans(circForm);
225 showDialog("generalInfoDialog", circForm, request, response);
226 } else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.DUE_DATE_TRUNCATED)){
227 circForm.setErrorMessage(droolsResponse.getErrorMessage());
228 showDialog("dueDateTruncated",circForm,request,response);
229 } else {
230 circForm.setErrorMessage(droolsResponse.getErrorMessage());
231 circForm.setItemOverride(true);
232 showErrorMessageDialog(circForm, request, response);
233 }
234 } else {
235 resetItemInfoForNextTrans(circForm);
236 }
237 if(StringUtils.isBlank(circForm.getLightboxScript())){
238 circForm.setLightboxScript("jq('#checkoutItem_control').focus();");
239 } else {
240 String lightBoxScript = circForm.getLightboxScript();
241 String itemLightBoxScript = lightBoxScript + "jq('#checkoutItem_control').blur();";
242 circForm.setLightboxScript(itemLightBoxScript);
243 }
244 return getUIFModelAndView(circForm);
245 }
246
247 private void handleMissingPieceProcess(HttpServletRequest request, HttpServletResponse response, CircForm circForm, DroolsResponse droolsResponse) {
248 circForm.setRecordNoteForMissingPiece(true);
249 circForm.setErrorMessage(droolsResponse.getErrorMessage());
250 showDialog("checkoutMissingPieceDialog",circForm,request,response);
251 }
252
253 private void handleDamagedItemProcess(HttpServletRequest request, HttpServletResponse response, CircForm circForm, DroolsResponse droolsResponse) {
254 circForm.setRecordNoteForDamagedItem(true);
255 circForm.setErrorMessage(droolsResponse.getErrorMessage());
256 showDialog("checkoutDamagedItemDialog",circForm,request,response);
257 }
258
259 private void handleClaimsReturnedProcess(HttpServletRequest request, HttpServletResponse response, CircForm circForm, DroolsResponse droolsResponse) {
260 circForm.setRecordNoteForClaimsReturn(true);
261 circForm.setErrorMessage(droolsResponse.getErrorMessage());
262 showDialog("checkoutClaimsReturnDialog",circForm,request,response);
263 }
264
265 private void processItemInformationIfAvailable(HttpServletRequest request, CircForm circForm) {
266
267 claimsReturnedCheck(request, circForm);
268
269 damagedItemCheck(request, circForm);
270
271 missingPieceCheck(request, circForm);
272
273 }
274
275 private void missingPieceCheck(HttpServletRequest request, CircForm circForm) {
276 String recordNoteForMissingPieceChecked = request.getParameter("recordNoteForMissingPieceChecked");
277 if(StringUtils.isNotBlank(recordNoteForMissingPieceChecked)) {
278 circForm.setRecordNoteForMissingPiece(Boolean.valueOf(recordNoteForMissingPieceChecked));
279 }
280 }
281
282 private void damagedItemCheck(HttpServletRequest request, CircForm circForm) {
283 String recordNoteForDamageChecked = request.getParameter("recordNoteForDamageChecked");
284 if(StringUtils.isNotBlank(recordNoteForDamageChecked)) {
285 circForm.setRecordNoteForDamagedItem(Boolean.valueOf(recordNoteForDamageChecked));
286 }
287 }
288
289 private void claimsReturnedCheck(HttpServletRequest request, CircForm circForm) {
290 String recordNoteForClaimChecked = request.getParameter("recordNoteForClaimChecked");
291 if(StringUtils.isNotBlank(recordNoteForClaimChecked)) {
292 circForm.setRecordNoteForClaimsReturn(Boolean.valueOf(recordNoteForClaimChecked));
293 }
294 }
295
296 @RequestMapping(params = "methodToCall=proceedToValidateItemAndSaveLoan")
297 public ModelAndView proceedToValidateItemAndSaveLoan(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
298 HttpServletRequest request, HttpServletResponse response) {
299 CircForm circForm = (CircForm) form;
300 circForm.setErrorMessage(new ErrorMessage());
301 DroolsResponse droolsResponse = getCheckoutUIController(circForm.getFormKey()).proceedWithItemValidation(circForm);
302 circForm.setDroolsExchange(droolsResponse.getDroolsExchange());
303 circForm.setErrorMessage(droolsResponse.getErrorMessage());
304 if (null != droolsResponse &&
305 StringUtils.isNotBlank(droolsResponse.retrieveErrorMessage())) {
306 if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.ERROR_CODES.CUSTOM_LOAN_DUE_DATE_REQUIRED.getName())) {
307 showDialog("customDueDateDialog", circForm, request, response);
308 } else if (null != droolsResponse.retriveErrorCode() && droolsResponse.retriveErrorCode().equals(DroolsConstants.GENERAL_MESSAGE_FLAG)) {
309 showDialog("generalMessageAndResetUIDialog", circForm, request, response);
310 } else {
311 circForm.setItemOverride(true);
312 showErrorMessageDialog(circForm, request, response);
313 }
314 } else {
315 resetItemInfoForNextTrans(circForm);
316 }
317 if(StringUtils.isBlank(circForm.getLightboxScript())){
318 circForm.setLightboxScript("jq('#checkoutItem_control').focus();");
319 } else {
320 String lightBoxScript = circForm.getLightboxScript();
321 String itemLightBoxScript = lightBoxScript + "jq('#checkoutItem_control').blur();";
322 circForm.setLightboxScript(itemLightBoxScript);
323 }
324 return getUIFModelAndView(circForm);
325 }
326
327 @RequestMapping(params = "methodToCall=proceedToSaveLoan")
328 public ModelAndView proceedToSaveLoan(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
329 HttpServletRequest request, HttpServletResponse response) {
330 CircForm circForm = (CircForm) form;
331 String customDate = request.getParameter("customDueDateMap");
332 if (StringUtils.isNotBlank(customDate)) {
333 circForm.setCustomDueDateMap(new DateUtil().getDate(customDate));
334 }
335 getCheckoutUIController(circForm.getFormKey()).proceedToSaveLoan(circForm);
336 resetItemInfoForNextTrans(circForm);
337 return getUIFModelAndView(circForm, "circViewPage");
338 }
339
340
341 @RequestMapping(params = "methodToCall=setItemBarcode")
342 public ModelAndView setItemBarcode(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
343 HttpServletRequest request, HttpServletResponse response) throws Exception {
344 OleLoanForm oleLoanForm = (OleLoanForm) form;
345 oleLoanForm.setItem(fastAddBarcode);
346 return getUIFModelAndView(oleLoanForm, "circViewPage");
347 }
348
349 @RequestMapping(params = "methodToCall=openFastAdd")
350 public ModelAndView openFastAdd(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
351 HttpServletRequest request, HttpServletResponse response) {
352 LOG.debug("Inside the openFastAdd method");
353 OleLoanForm oleLoanForm = (OleLoanForm) form;
354 oleLoanForm.setFastAddItemIndicator(true);
355 String url = ConfigContext.getCurrentContextConfig().getProperty("ole.fs.url.base") + OLEConstants.FAST_ADD_LINK;
356 oleLoanForm.setFastAddUrl(url);
357 return getUIFModelAndView(oleLoanForm, "circViewPage");
358 }
359
360 public void createClaimsReturnForItem(CircForm circForm, List<OleLoanDocument> loanDocumentList, OlePatronDocument olePatronDocument) throws Exception {
361 if (CollectionUtils.isNotEmpty(loanDocumentList)) {
362 for (Iterator<OleLoanDocument> iterator = loanDocumentList.iterator(); iterator.hasNext(); ) {
363 OleLoanDocument oleLoanDocument = iterator.next();
364 List<ItemClaimsReturnedRecord> itemClaimsReturnedRecords = updateClaimsReturnedHistory(oleLoanDocument, olePatronDocument.getBarcode());
365 Map parameterMap = new HashMap();
366 parameterMap.put("claimsReturnNote", oleLoanDocument.getClaimsReturnNote());
367 parameterMap.put("ClaimsReturnedDate", convertToString(oleLoanDocument.getClaimsReturnedDate()));
368 parameterMap.put("itemClaimsReturnedRecords", itemClaimsReturnedRecords);
369 parameterMap.put("itemClaimsReturnedFlag", oleLoanDocument.isClaimsReturnedIndicator());
370 parameterMap.put("patronId", olePatronDocument.getOlePatronId());
371 parameterMap.put("proxyPatronId", oleLoanDocument.getProxyPatronId());
372 getCheckoutUIController(circForm.getFormKey()).updateItemInfoInSolr(parameterMap, oleLoanDocument.getItemUuid(), false);
373 new OleDeliverRequestDocumentHelperServiceImpl().cancelPendingRequestForClaimsReturnedItem(oleLoanDocument.getItemUuid());
374 }
375 }
376 }
377
378 public void deleteClaimsReturnForItem(CircForm circForm, List<OleLoanDocument> loanDocumentList) throws Exception {
379 if (CollectionUtils.isNotEmpty(loanDocumentList)) {
380 for (Iterator<OleLoanDocument> iterator = loanDocumentList.iterator(); iterator.hasNext(); ) {
381 OleLoanDocument oleLoanDocument = iterator.next();
382 Map parameterMap = new HashMap();
383 parameterMap.put("deleteClaimsReturn", null);
384 Boolean itemUpdate = getCheckoutUIController(circForm.getFormKey()).deleteItemInfoInSolr(parameterMap, oleLoanDocument.getItemUuid());
385 if(itemUpdate!=null && itemUpdate.booleanValue()) {
386 oleLoanDocument.setClaimsReturnNote(null);
387 oleLoanDocument.setClaimsReturnedDate(null);
388 }
389 }
390 }
391 }
392
393 private List<ItemClaimsReturnedRecord> updateClaimsReturnedHistory(OleLoanDocument existingLoanDocument, String patronBarcode) {
394 SimpleDateFormat dateFormatForClaimsReturn = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
395 Map<String, String> map = new HashMap<>();
396 map.put("itemId", DocumentUniqueIDPrefix.getDocumentId(existingLoanDocument.getItemUuid()));
397 List<org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.ItemClaimsReturnedRecord> claimsReturnedRecordList = (List<org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.ItemClaimsReturnedRecord>) getBusinessObjectService().findMatchingOrderBy(org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.ItemClaimsReturnedRecord.class, map, "claimsReturnedId", true);
398 List<ItemClaimsReturnedRecord> itemClaimsReturnedRecordList = new ArrayList<>();
399 for (Iterator<org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.ItemClaimsReturnedRecord> iterator = claimsReturnedRecordList.iterator(); iterator.hasNext(); ) {
400 org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.ItemClaimsReturnedRecord itemClaimsReturnedRecord = iterator.next();
401 ItemClaimsReturnedRecord claimsReturnedRecord = new ItemClaimsReturnedRecord();
402 if (itemClaimsReturnedRecord.getClaimsReturnedFlagCreateDate() != null && !itemClaimsReturnedRecord.getClaimsReturnedFlagCreateDate().toString().isEmpty()) {
403 String formatedDateStringForClaimsReturn = convertToString(itemClaimsReturnedRecord.getClaimsReturnedFlagCreateDate());
404 claimsReturnedRecord.setClaimsReturnedFlagCreateDate(formatedDateStringForClaimsReturn);
405 }
406 claimsReturnedRecord.setClaimsReturnedNote(itemClaimsReturnedRecord.getClaimsReturnedNote());
407 claimsReturnedRecord.setClaimsReturnedPatronBarcode(itemClaimsReturnedRecord.getClaimsReturnedPatronBarcode());
408 claimsReturnedRecord.setClaimsReturnedOperatorId(itemClaimsReturnedRecord.getClaimsReturnedOperatorId());
409 claimsReturnedRecord.setItemId(itemClaimsReturnedRecord.getItemId());
410 itemClaimsReturnedRecordList.add(claimsReturnedRecord);
411 }
412 ItemClaimsReturnedRecord claimsReturnedRecord = new ItemClaimsReturnedRecord();
413 claimsReturnedRecord.setClaimsReturnedNote(existingLoanDocument.getClaimsReturnNote());
414 claimsReturnedRecord.setClaimsReturnedPatronBarcode(patronBarcode);
415 claimsReturnedRecord.setClaimsReturnedOperatorId(GlobalVariables.getUserSession().getPrincipalId());
416 claimsReturnedRecord.setItemId(DocumentUniqueIDPrefix.getDocumentId(existingLoanDocument.getItemUuid()));
417 claimsReturnedRecord.setClaimsReturnedFlagCreateDate(dateFormatForClaimsReturn.format(existingLoanDocument.getClaimsReturnedDate()));
418 itemClaimsReturnedRecordList.add(claimsReturnedRecord);
419 return itemClaimsReturnedRecordList;
420 }
421
422
423 public void createMissingPieceItem(CircForm circForm, List<OleLoanDocument> loanDocumentList, OlePatronDocument olePatronDocument) throws Exception {
424 if (CollectionUtils.isNotEmpty(loanDocumentList)) {
425 for (Iterator<OleLoanDocument> iterator = loanDocumentList.iterator(); iterator.hasNext(); ) {
426 OleLoanDocument oleLoanDocument = iterator.next();
427 List<MissingPieceItemRecord> itemMissingPieceItemRecords = updateMissingPieceItemHistory(oleLoanDocument, olePatronDocument.getBarcode());
428 Map parameterMap = new HashMap();
429 parameterMap.put("missingPieceItemFlag", oleLoanDocument.isMissingPieceFlag());
430 parameterMap.put("missingPieceItemNote", oleLoanDocument.getMissingPieceNote());
431 parameterMap.put("noOfmissingPiece", oleLoanDocument.getNoOfMissingPiece());
432 parameterMap.put("missingPieceItemCount", oleLoanDocument.getMissingPiecesCount());
433 parameterMap.put("missingPieceItemDate", convertToString(oleLoanDocument.getMissingPieceItemDate()));
434 parameterMap.put("itemMissingPieceItemRecords", itemMissingPieceItemRecords);
435 parameterMap.put("patronId", olePatronDocument.getOlePatronId());
436 parameterMap.put("proxyPatronId", oleLoanDocument.getProxyPatronId());
437 getCheckoutUIController(circForm.getFormKey()).updateItemInfoInSolr(parameterMap, oleLoanDocument.getItemUuid(), false);
438 new OleDeliverRequestDocumentHelperServiceImpl().cancelPendingRequestForMissingPieceItem(oleLoanDocument.getItemUuid());
439 }
440 }
441 }
442
443
444 private List<MissingPieceItemRecord> updateMissingPieceItemHistory(OleLoanDocument existingLoanDocument, String patronBarcode) {
445 SimpleDateFormat dateFormatForMissingItem = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
446 Map<String, String> map = new HashMap<>();
447 map.put("itemId", DocumentUniqueIDPrefix.getDocumentId(existingLoanDocument.getItemUuid()));
448 List<org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.MissingPieceItemRecord> missingPieceItemRecordList = (List<org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.MissingPieceItemRecord>) getBusinessObjectService().findMatchingOrderBy(org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.MissingPieceItemRecord.class, map, "missingPieceItemId", true);
449 List<MissingPieceItemRecord> itemMissingPieceRecordList = new ArrayList<>();
450 for (Iterator<org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.MissingPieceItemRecord> iterator = missingPieceItemRecordList.iterator(); iterator.hasNext(); ) {
451 org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.MissingPieceItemRecord itemMissingPieceItemRecord = iterator.next();
452 MissingPieceItemRecord missingPieceItemRecord = new MissingPieceItemRecord();
453 if (itemMissingPieceItemRecord.getMissingPieceDate() != null && !itemMissingPieceItemRecord.getMissingPieceDate().toString().isEmpty()) {
454 Timestamp formatedDateStringForDamagedItem = itemMissingPieceItemRecord.getMissingPieceDate();
455 missingPieceItemRecord.setMissingPieceDate(dateFormatForMissingItem.format(formatedDateStringForDamagedItem));
456 }
457 missingPieceItemRecord.setMissingPieceFlagNote(itemMissingPieceItemRecord.getMissingPieceFlagNote());
458 missingPieceItemRecord.setMissingPieceCount(itemMissingPieceItemRecord.getMissingPieceCount());
459 missingPieceItemRecord.setPatronBarcode(itemMissingPieceItemRecord.getPatronBarcode());
460 missingPieceItemRecord.setOperatorId(itemMissingPieceItemRecord.getOperatorId());
461 missingPieceItemRecord.setItemId(itemMissingPieceItemRecord.getItemId());
462 itemMissingPieceRecordList.add(missingPieceItemRecord);
463 }
464 MissingPieceItemRecord missingPieceItemRecord = new MissingPieceItemRecord();
465 missingPieceItemRecord.setMissingPieceFlagNote(existingLoanDocument.getMissingPieceNote());
466 missingPieceItemRecord.setMissingPieceCount(existingLoanDocument.getMissingPiecesCount());
467 missingPieceItemRecord.setPatronBarcode(patronBarcode);
468 missingPieceItemRecord.setOperatorId(GlobalVariables.getUserSession().getPrincipalId());
469 missingPieceItemRecord.setItemId(DocumentUniqueIDPrefix.getDocumentId(existingLoanDocument.getItemUuid()));
470 missingPieceItemRecord.setMissingPieceDate(dateFormatForMissingItem.format(existingLoanDocument.getMissingPieceItemDate()));
471 itemMissingPieceRecordList.add(missingPieceItemRecord);
472 return itemMissingPieceRecordList;
473 }
474
475 public void deleteMissingPieceItem(CircForm circForm, List<OleLoanDocument> loanDocumentList) throws Exception {
476 if (CollectionUtils.isNotEmpty(loanDocumentList)) {
477 for (Iterator<OleLoanDocument> iterator = loanDocumentList.iterator(); iterator.hasNext(); ) {
478 OleLoanDocument oleLoanDocument = iterator.next();
479 Map parameterMap = new HashMap();
480 parameterMap.put("deleteMissingPieceItem", null);
481 Boolean itemUpdate = getCheckoutUIController(circForm.getFormKey()).deleteItemInfoInSolr(parameterMap, oleLoanDocument.getItemUuid());
482 if(itemUpdate!=null && itemUpdate.booleanValue()) {
483 oleLoanDocument.setMissingPieceNote(null);
484 }
485 }
486 }
487 }
488
489
490 public void createDamagedItem(CircForm circForm, List<OleLoanDocument> loanDocumentList, OlePatronDocument olePatronDocument) throws Exception {
491 if (CollectionUtils.isNotEmpty(loanDocumentList)) {
492 for (Iterator<OleLoanDocument> iterator = loanDocumentList.iterator(); iterator.hasNext(); ) {
493 OleLoanDocument oleLoanDocument = iterator.next();
494 List<ItemDamagedRecord> itemDamagedItemRecords = updateDamagedItemHistory(oleLoanDocument, olePatronDocument.getBarcode());
495 Map parameterMap = new HashMap();
496 parameterMap.put("damagedItemNote", oleLoanDocument.getItemDamagedNote());
497 parameterMap.put("damagedItemDate", convertToString(oleLoanDocument.getDamagedItemDate()));
498 parameterMap.put("itemDamagedRecords", itemDamagedItemRecords);
499 parameterMap.put("patronId", olePatronDocument.getOlePatronId());
500 parameterMap.put("proxyPatronId", oleLoanDocument.getProxyPatronId());
501 getCheckoutUIController(circForm.getFormKey()).updateItemInfoInSolr(parameterMap, oleLoanDocument.getItemUuid(), false);
502 new OleDeliverRequestDocumentHelperServiceImpl().cancelPendingRequestForDamagedItem(oleLoanDocument.getItemUuid());
503 }
504 }
505 }
506
507 private List<ItemDamagedRecord> updateDamagedItemHistory(OleLoanDocument existingLoanDocument, String patronBarcode) {
508 SimpleDateFormat dateFormatForDamagedItem = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
509 Map<String, String> map = new HashMap<>();
510 map.put("itemId", DocumentUniqueIDPrefix.getDocumentId(existingLoanDocument.getItemUuid()));
511 List<org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.ItemDamagedRecord> damagedItemRecordList = (List<org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.ItemDamagedRecord>) getBusinessObjectService().findMatchingOrderBy(org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.ItemDamagedRecord.class, map, "itemDamagedId", true);
512 List<ItemDamagedRecord> itemDamagedRecordList = new ArrayList<>();
513 for (Iterator<org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.ItemDamagedRecord> iterator = damagedItemRecordList.iterator(); iterator.hasNext(); ) {
514 org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.ItemDamagedRecord itemDamagedItemRecord = iterator.next();
515 ItemDamagedRecord damagedItemRecord = new ItemDamagedRecord();
516 if (itemDamagedItemRecord.getDamagedItemDate() != null && !itemDamagedItemRecord.getDamagedItemDate().toString().isEmpty()) {
517 Timestamp formatedDateStringForDamagedItem = itemDamagedItemRecord.getDamagedItemDate();
518 damagedItemRecord.setDamagedItemDate(dateFormatForDamagedItem.format(formatedDateStringForDamagedItem));
519 }
520 damagedItemRecord.setDamagedItemNote(itemDamagedItemRecord.getDamagedItemNote());
521 damagedItemRecord.setPatronBarcode(itemDamagedItemRecord.getPatronBarcode());
522 damagedItemRecord.setOperatorId(itemDamagedItemRecord.getOperatorId());
523 damagedItemRecord.setItemId(itemDamagedItemRecord.getItemId());
524 itemDamagedRecordList.add(damagedItemRecord);
525 }
526 ItemDamagedRecord damagedItemRecord = new ItemDamagedRecord();
527 damagedItemRecord.setDamagedItemNote(existingLoanDocument.getItemDamagedNote());
528 damagedItemRecord.setPatronBarcode(patronBarcode);
529 damagedItemRecord.setOperatorId(GlobalVariables.getUserSession().getPrincipalId());
530 damagedItemRecord.setItemId(DocumentUniqueIDPrefix.getDocumentId(existingLoanDocument.getItemUuid()));
531 damagedItemRecord.setDamagedItemDate(dateFormatForDamagedItem.format(existingLoanDocument.getDamagedItemDate()));
532 itemDamagedRecordList.add(damagedItemRecord);
533 return itemDamagedRecordList;
534 }
535
536 public void deleteDamagedItem(CircForm circForm, List<OleLoanDocument> loanDocumentList) throws Exception {
537 if (CollectionUtils.isNotEmpty(loanDocumentList)) {
538 for (Iterator<OleLoanDocument> iterator = loanDocumentList.iterator(); iterator.hasNext(); ) {
539 OleLoanDocument oleLoanDocument = iterator.next();
540 Map parameterMap = new HashMap();
541 parameterMap.put("deleteDamagedItem", null);
542 Boolean itemUpdate = getCheckoutUIController(circForm.getFormKey()).deleteItemInfoInSolr(parameterMap, oleLoanDocument.getItemUuid());
543 if(itemUpdate!=null && itemUpdate.booleanValue()) {
544 oleLoanDocument.setItemDamagedNote(null);
545 }
546 }
547 }
548 }
549
550
551 public String convertToString(Timestamp date) {
552 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
553 String stringFormatOfDate = "";
554 stringFormatOfDate = simpleDateFormat.format(date).toString();
555 return stringFormatOfDate;
556 }
557
558
559 }