View Javadoc
1   package org.kuali.ole.deliver.controller;
2   
3   import org.apache.commons.collections.CollectionUtils;
4   import org.apache.commons.lang3.StringUtils;
5   import org.apache.log4j.Logger;
6   import org.codehaus.jettison.json.JSONArray;
7   import org.codehaus.jettison.json.JSONException;
8   import org.codehaus.jettison.json.JSONObject;
9   import org.kuali.ole.OLEConstants;
10  import org.kuali.ole.OLEParameterConstants;
11  import org.kuali.ole.deliver.OleLoanDocumentsFromSolrBuilder;
12  import org.kuali.ole.deliver.bo.OleLoanDocument;
13  import org.kuali.ole.deliver.calendar.service.DateUtil;
14  import org.kuali.ole.deliver.controller.checkout.CheckoutValidationController;
15  import org.kuali.ole.deliver.controller.checkout.CircUtilController;
16  import org.kuali.ole.deliver.controller.renew.RenewController;
17  import org.kuali.ole.deliver.form.CircForm;
18  import org.kuali.ole.deliver.service.OleLoanDocumentPlatformAwareDao;
19  import org.kuali.ole.deliver.service.ParameterValueResolver;
20  import org.kuali.ole.deliver.util.*;
21  import org.kuali.ole.docstore.common.document.DocstoreDocument;
22  import org.kuali.ole.docstore.common.document.Item;
23  import org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.ItemRecord;
24  import org.kuali.ole.sys.context.SpringContext;
25  import org.kuali.ole.utility.OleStopWatch;
26  import org.kuali.rice.core.api.config.property.ConfigContext;
27  import org.kuali.rice.core.api.datetime.DateTimeService;
28  import org.kuali.rice.krad.service.BusinessObjectService;
29  import org.kuali.rice.krad.web.form.UifFormBase;
30  import org.springframework.stereotype.Controller;
31  import org.springframework.validation.BindingResult;
32  import org.springframework.web.bind.annotation.ModelAttribute;
33  import org.springframework.web.bind.annotation.RequestMapping;
34  import org.springframework.web.servlet.ModelAndView;
35  
36  import javax.servlet.http.HttpServletRequest;
37  import javax.servlet.http.HttpServletResponse;
38  import java.sql.Timestamp;
39  import java.text.ParseException;
40  import java.text.SimpleDateFormat;
41  import java.util.*;
42  
43  /**
44   * Created by pvsubrah on 6/3/15.
45   */
46  
47  @Controller
48  @RequestMapping(value = "/circcontroller")
49  public class CircController extends CheckoutValidationController {
50  
51      private static final Logger LOG = Logger.getLogger(CircController.class);
52      private OleLoanDocumentsFromSolrBuilder oleLoanDocumentsFromSolrBuilder;
53      private OleLoanDocumentPlatformAwareDao oleLoanDocumentPlatformAwareDao;
54      private BulkItemUpdateUtil bulkItemUpdateUtil;
55      private RenewController renewController;
56      private DateTimeService dateTimeService;
57  
58      @Override
59      @RequestMapping(params = "methodToCall=refresh")
60      public ModelAndView refresh(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
61                                  HttpServletRequest request, HttpServletResponse response) throws Exception {
62          CircForm circForm = (CircForm) form;
63  
64          if (!circForm.getPatronBarcode().equals(circForm.getPatronDocument().getBarcode())) {
65              resetUI(circForm, result, request, response);
66          }
67  
68          if (!circForm.isProceedWithCheckout()) {
69              circForm.setPatronDocument(new OlePatronRecordUtil().getPatronRecordByBarcode(circForm.getPatronBarcode()));
70              return searchPatron(form, result, request, response);
71          } else {
72              if(Boolean.valueOf(getParameter(OLEParameterConstants.LOAN_WHILE_FASTADD))){
73                  lookupItemAndSaveLoan(circForm, result, request, response);
74              }
75          }
76          return getUIFModelAndView(circForm);
77      }
78  
79      @RequestMapping(params = "methodToCall=resetErrorMessages")
80      public ModelAndView resetErrorMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
81                                             HttpServletRequest request, HttpServletResponse response) {
82          //OleLoanForm oleLoanForm = resetForm(form);
83          return getUIFModelAndView(form);
84      }
85  
86      @RequestMapping(params = "methodToCall=showExistingLoan")
87      public ModelAndView showExistingLoan(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
88                                           HttpServletRequest request, HttpServletResponse response) {
89          try {
90              CircForm circForm = (CircForm) form;
91              int defaultPageSize = getDefaultPageSize();
92              circForm.setPageSize(String.valueOf(defaultPageSize));
93              circForm.setPageNumber("1");
94              circForm.setShowExistingLoan(true);
95              if (circForm.getPatronDocument().getOleLoanDocuments().size() > 0) {
96                  circForm.setExistingLoanList(getOleLoanDocumentsFromSolrBuilder().getPatronLoanedItemBySolr
97                          (circForm.getPatronDocument().getOlePatronId(), null));
98              }
99              circForm.setLightboxScript("jq('#existingLoanItemTable_length').val(" + defaultPageSize + ").attr('selected', 'selected');enableDataTableForExistingLoanedItem();");
100         } catch (Exception e) {
101             e.printStackTrace();
102         }
103         return getUIFModelAndView(form);
104     }
105 
106     public int getDefaultPageSize() {
107         String defaultPageSizeFromParameter = ParameterValueResolver.getInstance().getParameter(OLEConstants
108                 .APPL_ID_OLE, OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, OLEConstants.DEFAULT_PAGE_SIZE_LOANED_ITEMS);
109         int defaultPageSize = 10;
110         if(StringUtils.isNotBlank(defaultPageSizeFromParameter)){
111             try{
112                 int searchLimit = Integer.parseInt(defaultPageSizeFromParameter);
113                 if(searchLimit > 0){
114                     defaultPageSize = searchLimit;
115                 }else{
116                     LOG.error("Invalid page size from the system parameter. So taking the default page size : " + defaultPageSize);
117                 }
118             }catch(Exception exception){
119                 LOG.error("Invalid page size from the system parameter. So taking the default page size : " + defaultPageSize);
120             }
121         }else{
122             LOG.error("Invalid page size from the system parameter. So taking the default page size : " + defaultPageSize);
123         }
124         return defaultPageSize;
125     }
126 
127     @RequestMapping(params = "methodToCall=hideExistingLoan")
128     public ModelAndView hideExistingLoan(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
129                                          HttpServletRequest request, HttpServletResponse response) {
130         CircForm circForm = (CircForm) form;
131         circForm.setShowExistingLoan(false);
132         circForm.setExistingLoanList(new ArrayList<OleLoanDocument>());
133         return getUIFModelAndView(form);
134     }
135 
136     // CirDesk Sections
137     @RequestMapping(params = "methodToCall=changeCirculationDeskLocation")
138     public ModelAndView changeCirculationDeskLocation(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
139                                                       HttpServletRequest request, HttpServletResponse response) {
140         showDialog("circDeskChangeDialog", form, request, response);
141         String lightBoxScript = form.getLightboxScript();
142         String circDeskLightBoxScript = lightBoxScript + "jq('#btnOkCircDesk').focus();";
143         form.setLightboxScript(circDeskLightBoxScript);
144         return getUIFModelAndView(form);
145     }
146 
147     @RequestMapping(params = "methodToCall=revertCircDeskLocationSelection")
148     public ModelAndView revertCircDeskLocationSelection(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
149                                                         HttpServletRequest request, HttpServletResponse response) {
150         CircForm circForm = (CircForm) form;
151         circForm.setSelectedCirculationDesk(circForm.getPreviouslySelectedCirculationDesk());
152         return getUIFModelAndView(form, "circViewPage");
153     }
154 
155     @RequestMapping(params = "methodToCall=setPreviousCircDeskToCurrentlySelectedValue")
156     public ModelAndView setPreviousCircDeskToCurrentlySelectedValue(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
157                                                                     HttpServletRequest request, HttpServletResponse response) {
158         CircForm circForm = (CircForm) form;
159         circForm.setPreviouslySelectedCirculationDesk(circForm.getSelectedCirculationDesk());
160         clearUI(form, result, request, response);
161         return getUIFModelAndView(form, "circViewPage");
162     }
163 
164     @RequestMapping(params = "methodToCall=openClaimsReturnDialog")
165     public ModelAndView openClaimsReturnDialog(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
166                                                HttpServletRequest request, HttpServletResponse response) {
167         CircForm circForm = (CircForm) form;
168         List<OleLoanDocument> selectedLoanDocumentList = getSelectedLoanDocumentList(circForm);
169         if (CollectionUtils.isNotEmpty(selectedLoanDocumentList)) {
170             showDialog("claimsReturnDialog", circForm, request, response);
171             ItemRecord itemRecord = getCheckoutUIController(circForm.getFormKey()).getItemRecordByBarcode(selectedLoanDocumentList.get(0).getItemId());
172             circForm.setClaimsReturnNote((itemRecord != null) ? itemRecord.getClaimsReturnedNote() : "");
173             circForm.setClaimsReturnFlag((itemRecord != null) ? (itemRecord.getClaimsReturnedFlag() != null) ?
174                     itemRecord.getClaimsReturnedFlag().booleanValue() : false : false);
175 
176         } else {
177             ErrorMessage errorMessage = new ErrorMessage();
178             errorMessage.setErrorMessage("Please select any one of loaned item to claim.");
179             circForm.setErrorMessage(errorMessage);
180             showDialog("generalInfoDialog", circForm, request, response);
181         }
182         return getUIFModelAndView(form);
183     }
184 
185 
186     @RequestMapping(params = "methodToCall=openDamagedItemDialog")
187     public ModelAndView openDamagedItemDialog(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
188                                               HttpServletRequest request, HttpServletResponse response) {
189         CircForm circForm = (CircForm) form;
190         List<OleLoanDocument> selectedLoanDocumentList = getSelectedLoanDocumentList(circForm);
191         if (CollectionUtils.isNotEmpty(selectedLoanDocumentList)) {
192             showDialog("damagedItemDialog", circForm, request, response);
193             ItemRecord itemRecord = getCheckoutUIController(circForm.getFormKey()).getItemRecordByBarcode(selectedLoanDocumentList.get(0).getItemId());
194             circForm.setDamagedItemNote((itemRecord != null) ? itemRecord.getDamagedItemNote() : "");
195             circForm.setDamagedItemFlag((itemRecord != null) ? itemRecord.isItemDamagedStatus() : false);
196         } else {
197             ErrorMessage errorMessage = new ErrorMessage();
198             errorMessage.setErrorMessage("Please select any one of loaned item to damaged.");
199             circForm.setErrorMessage(errorMessage);
200             showDialog("generalInfoDialog", circForm, request, response);
201         }
202         return getUIFModelAndView(form);
203     }
204 
205 
206     @RequestMapping(params = "methodToCall=openMissingPieceItemDialog")
207     public ModelAndView openMissingPieceItemDialog(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
208                                                    HttpServletRequest request, HttpServletResponse response) {
209         CircForm circForm = (CircForm) form;
210         List<OleLoanDocument> selectedLoanDocumentList = getSelectedLoanDocumentList(circForm);
211         if (CollectionUtils.isNotEmpty(selectedLoanDocumentList)) {
212             showDialog("missingPieceDialog", circForm, request, response);
213             ItemRecord itemRecord = getCheckoutUIController(circForm.getFormKey()).getItemRecordByBarcode(selectedLoanDocumentList.get(0).getItemId());
214             circForm.setMissingPieceFlag((itemRecord != null) ? itemRecord.isMissingPieceFlag() : false);
215             circForm.setMissingPieceNote(circForm.isMissingPieceFlag() ? (itemRecord != null) ? itemRecord.getMissingPieceFlagNote() : "" : "");
216             circForm.setMissingPieceCount(circForm.isMissingPieceFlag() ? (itemRecord != null) ? itemRecord.getMissingPiecesCount() : "" : "");
217             circForm.setNumberOfPiece((itemRecord != null) ? itemRecord.getNumberOfPieces() : "");
218         } else {
219             ErrorMessage errorMessage = new ErrorMessage();
220             errorMessage.setErrorMessage("Please select any one of loaned item to apply missing piece.");
221             circForm.setErrorMessage(errorMessage);
222             showDialog("generalInfoDialog", circForm, request, response);
223         }
224         return getUIFModelAndView(form);
225     }
226 
227     @RequestMapping(params = "methodToCall=applyClaimsReturn")
228     public ModelAndView applyClaimsReturn(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
229                                           HttpServletRequest request, HttpServletResponse response) throws Exception {
230         CircForm circForm = (CircForm) form;
231         String claimsDescription = request.getParameter("claimDescription");
232         List<OleLoanDocument> selectedLoanDocumentList = getSelectedLoanDocumentList(circForm);
233         for (Iterator<OleLoanDocument> iterator = selectedLoanDocumentList.iterator(); iterator.hasNext(); ) {
234             OleLoanDocument oleLoanDocument = iterator.next();
235             oleLoanDocument.setClaimsReturnNote(claimsDescription);
236             oleLoanDocument.setClaimsReturnedIndicator(true);
237             oleLoanDocument.setClaimsReturnedDate(new Timestamp(new Date().getTime()));
238         }
239         createClaimsReturnForItem(circForm, selectedLoanDocumentList, circForm.getPatronDocument());
240         return getUIFModelAndView(form);
241     }
242 
243     @RequestMapping(params = "methodToCall=removeClaimsReturn")
244     public ModelAndView removeClaimsReturn(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
245                                            HttpServletRequest request, HttpServletResponse response) throws Exception {
246         CircForm circForm = (CircForm) form;
247         List<OleLoanDocument> selectedLoanDocumentList = getSelectedLoanDocumentList(circForm);
248         deleteClaimsReturnForItem(circForm, selectedLoanDocumentList);
249         return getUIFModelAndView(form);
250     }
251 
252     @RequestMapping(params = "methodToCall=openAlterDueDateDialog")
253     public ModelAndView openAlterDueDateDialog(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
254                                                HttpServletRequest request, HttpServletResponse response) throws JSONException {
255         CircForm circForm = (CircForm) form;
256         circForm.setErrorMessage(new ErrorMessage());
257         List<OleLoanDocument> selectedLoanDocumentList = getSelectedLoanDocumentList(circForm);
258         if (CollectionUtils.isNotEmpty(selectedLoanDocumentList)) {
259             circForm.setLoanDocumentsForAlterDueDate(selectedLoanDocumentList);
260             String jsonStringForAlterDueDate = getJsonStringForAlterDueDate(selectedLoanDocumentList);
261             showDialogAndRunCustomScript("alterDueDateDialog", circForm,"populateDueDateForAlterDueDateDialog(" + jsonStringForAlterDueDate + ")");
262         } else {
263             ErrorMessage errorMessage = new ErrorMessage();
264             errorMessage.setErrorMessage("Please select any one of loaned item to alter due date.");
265             circForm.setErrorMessage(errorMessage);
266             showDialog("generalInfoDialog", circForm, request, response);
267         }
268         return getUIFModelAndView(form);
269     }
270 
271     private String getJsonStringForAlterDueDate(List<OleLoanDocument> selectedLoanDocumentList) throws JSONException {
272         JSONArray finalJsonArray = new JSONArray();
273         for (Iterator<OleLoanDocument> iterator = selectedLoanDocumentList.iterator(); iterator.hasNext(); ) {
274             OleLoanDocument oleLoanDocument = iterator.next();
275             JSONObject valueObject = new JSONObject();
276             valueObject.put("itemBarcode",oleLoanDocument.getItemId());
277             valueObject.put("date", getDateString(oleLoanDocument.getLoanDueDate()));
278             valueObject.put("dateTime", getTimeString(oleLoanDocument.getLoanDueDate()));
279             finalJsonArray.put(valueObject);
280         }
281         return finalJsonArray.toString();
282     }
283 
284     private String getTimeString(Timestamp loanDueDate) {
285         if (null != loanDueDate) {
286             SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
287             return simpleDateFormat.format(loanDueDate);
288         }
289         return "";
290     }
291 
292     private String getDateString(Timestamp loanDueDate) {
293         if (null != loanDueDate) {
294             SimpleDateFormat simpleDateFormat = new SimpleDateFormat(ConfigContext.getCurrentContextConfig().getProperty("DATE_TO_STRING_FORMAT_FOR_USER_INTERFACE"));
295             return simpleDateFormat.format(loanDueDate);
296         }
297         return "";
298     }
299 
300     @RequestMapping(params = "methodToCall=alterDueDate")
301     public ModelAndView alterDueDate(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
302                                      HttpServletRequest request, HttpServletResponse response) {
303         CircForm circForm = (CircForm) form;
304         String jsonString = request.getParameter("alterDueDateObjectValues");
305 
306         AlterDueDateAndRenewResponse alterDueDateAndRenewResponse = processJsonString(jsonString);
307 
308         String failureResponseMessage = prepareFailureResponseForInvalidDueDate(alterDueDateAndRenewResponse.getInvalidItemIdsMap(), "Invalid time format selected.");
309 
310         if(StringUtils.isNotBlank(failureResponseMessage)){
311             circForm.getErrorMessage().setErrorMessage(failureResponseMessage);
312         }
313 
314         try {
315             AlterDueDateAndRenewResponse alterDueDateAndRenewResponseAfterSave = updateDueDate(alterDueDateAndRenewResponse.getValidItemIdsMap(), circForm);
316             String failureResponseForRenew = prepareFailureResponseForInvalidDueDate(alterDueDateAndRenewResponseAfterSave.getInvalidItemIdsMap(), "");
317 
318             if(StringUtils.isNotBlank(failureResponseForRenew)){
319                 circForm.getErrorMessage().setErrorMessage(failureResponseForRenew);
320             }
321 
322             //TODO: process invalid item ids; Set error message on circ message.
323         } catch (Exception e) {
324             //TODO: handle exception
325             circForm.getErrorMessage().setErrorMessage("Alter due date was failed ");
326             e.printStackTrace();
327         }
328 
329         if(null != circForm.getErrorMessage() && StringUtils.isNotBlank(circForm.getErrorMessage().getErrorMessage())){
330             showDialogAndRunCustomScript("generalInfoDialog", circForm, "jq('.loanedItemCBClass').removeAttr('checked');jq('.loaningItemCBClass').removeAttr('checked');");
331         }else{
332             circForm.setLightboxScript("jq('.loanedItemCBClass').removeAttr('checked');jq('.loaningItemCBClass').removeAttr('checked');");
333         }
334         return getUIFModelAndView(circForm);
335     }
336 
337     private String prepareFailureResponseForInvalidDueDate(Map<String, String[]> invalidItemIdsMap, String customMsg) {
338         CircUtilController circUtilController = new CircUtilController();
339         StringBuilder stringBuilder = new StringBuilder();
340         if(invalidItemIdsMap.size() >  0 ){
341             for (Iterator<String> iterator = invalidItemIdsMap.keySet().iterator(); iterator.hasNext(); ) {
342                 String itemBarcode = iterator.next();
343                 circUtilController.addToFormattedContent(stringBuilder, "Alter due date was not successful for item (" + itemBarcode + " )." + customMsg);
344             }
345         }
346         return stringBuilder.toString();
347     }
348 
349     private AlterDueDateAndRenewResponse processJsonString(String jsonString) {
350         HashMap<String, String[]> validItemIdsMap = new HashMap();
351         HashMap<String, String[]> invalidItemIdsMap = new HashMap();
352         CircUtilController circUtilController = new CircUtilController();
353 
354         JSONArray alterDueDateObjectValues = null;
355         try {
356             alterDueDateObjectValues = new JSONArray(jsonString);
357             for (int index = 0; index < alterDueDateObjectValues.length(); index++) {
358                 JSONObject jsonObject = (JSONObject) alterDueDateObjectValues.get(index);
359                 String itemBarcode = getStringValueFromJsonObject(jsonObject, "itemBarcode");
360                 String[] alterDueDateTime = new String[2];
361                 alterDueDateTime[0] = getStringValueFromJsonObject(jsonObject, "date");
362                 alterDueDateTime[1] = getStringValueFromJsonObject(jsonObject, "dateTime");
363                 if (circUtilController.validateTime(alterDueDateTime[1])) {
364                     validItemIdsMap.put(itemBarcode, alterDueDateTime);
365                 } else {
366                     invalidItemIdsMap.put(itemBarcode, alterDueDateTime);
367                 }
368             }
369         } catch (JSONException e) {
370             e.printStackTrace();
371         }
372 
373         AlterDueDateAndRenewResponse alterDueDateAndRenewResponse = new AlterDueDateAndRenewResponse();
374         alterDueDateAndRenewResponse.setValidItemIdsMap(validItemIdsMap);
375         alterDueDateAndRenewResponse.setInvalidItemIdsMap(invalidItemIdsMap);
376         return alterDueDateAndRenewResponse;
377     }
378 
379 
380     public String getStringValueFromJsonObject(JSONObject jsonObject, String key) {
381         String returnValue = null;
382         try {
383             returnValue = jsonObject.getString(key);
384         } catch (JSONException e) {
385             e.printStackTrace();
386         }
387         return returnValue;
388     }
389 
390     private AlterDueDateAndRenewResponse updateDueDate(Map<String, String[]> itemBarcodeMap, CircForm circForm) throws Exception {
391         HashMap<String, String[]> validItemIdsMap = new HashMap();
392         HashMap<String, String[]> invalidItemIdsMap = new HashMap();
393 
394         List<OleLoanDocument> selectedLoanDocumentList = filterListForInvalidDueDateItems(itemBarcodeMap, getSelectedLoanDocumentList(circForm));
395         List<OleLoanDocument> loanDocumentsToBeUpdatedInDb = filterListForInvalidDueDateItems(itemBarcodeMap, getSelectedLoanDocumentList(circForm));
396         CircUtilController circUtilController = new CircUtilController();
397 
398         Map<String, Map> docstoreResultMap = alterDueDateInDocstore(circForm, itemBarcodeMap, selectedLoanDocumentList);
399         for (Iterator<String> iterator = docstoreResultMap.keySet().iterator(); iterator.hasNext(); ) {
400             String itemUuid = iterator.next();
401             Map result = docstoreResultMap.get(itemUuid);
402             DocstoreDocument.ResultType resultType = (DocstoreDocument.ResultType) result.get("result");
403             OleLoanDocument loanDocument = getCheckoutUIController(circForm.getFormKey()).getLoanDocumentFromListBasedOnItemUuid(itemUuid, selectedLoanDocumentList);
404             if (resultType.equals(DocstoreDocument.ResultType.SUCCESS)) {
405                 if (null != loanDocument) {
406                     String[] dueDateAndTime = itemBarcodeMap.get(loanDocument.getItemId());
407                     String dateString = dueDateAndTime[0];
408                     Timestamp newDueDate = null;
409                     if (StringUtils.isNotBlank(dateString)) {
410                         if(StringUtils.isBlank(dueDateAndTime[1])) {
411                             dueDateAndTime[1] =ParameterValueResolver.getInstance().getParameter(OLEConstants
412                                     .APPL_ID_OLE, OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, OLEConstants.DEFAULT_TIME_FOR_DUE_DATE);
413                         }
414                         newDueDate = getCheckoutUIController(circForm.getFormKey()).processDateAndTimeForAlterDueDate(getDateFromString(dateString), dueDateAndTime[1]);
415                     }
416                     loanDocument.setLoanDueDate(newDueDate);
417                     circUtilController.updateNoticesForLoanDocument(loanDocument);
418                     validItemIdsMap.put(loanDocument.getItemId(), dueDateAndTime);
419                 }
420             } else {
421                 loanDocumentsToBeUpdatedInDb.remove(loanDocument);
422                 invalidItemIdsMap.put(loanDocument.getItemId(), null);
423                 LOG.error("Alter due date was not successful for itemUUID : " + itemUuid);
424             }
425         }
426         saveLoanDocumentsToDb(loanDocumentsToBeUpdatedInDb);
427         //alterDueDateForLoanInDB(loanDocumentsToBeUpdatedInDb);
428         //TODO: Handle rollback in doscstore if db update fails.
429         AlterDueDateAndRenewResponse alterDueDateAndRenewResponse = new AlterDueDateAndRenewResponse();
430         alterDueDateAndRenewResponse.setValidItemIdsMap(validItemIdsMap);
431         alterDueDateAndRenewResponse.setInvalidItemIdsMap(invalidItemIdsMap);
432 
433         return alterDueDateAndRenewResponse;
434     }
435 
436     private void saveLoanDocumentsToDb(List<OleLoanDocument> loanDocumentsToBeUpdatedInDb) {
437         BusinessObjectService oleBusinessObjectService = (BusinessObjectService) SpringContext.getService("oleBusinessObjectService");
438         oleBusinessObjectService.save(loanDocumentsToBeUpdatedInDb);
439     }
440 
441     private Date getDateFromString(String dateString) throws ParseException {
442         return getDateTimeService().convertToDate(dateString);
443     }
444 
445 
446     private List<OleLoanDocument> filterListForInvalidDueDateItems(Map<String, String[]> itemBarcodeMap, List<OleLoanDocument> selectedLoanDocumentList) {
447         ArrayList<OleLoanDocument> filteredDocuments = new ArrayList<>();
448         for (Iterator<OleLoanDocument> iterator = selectedLoanDocumentList.iterator(); iterator.hasNext(); ) {
449             OleLoanDocument oleLoanDocument = iterator.next();
450             if (itemBarcodeMap.containsKey(oleLoanDocument.getItemId())) {
451                 filteredDocuments.add(oleLoanDocument);
452             }
453         }
454 
455         return filteredDocuments;
456     }
457 
458     private Map<String, Map> alterDueDateInDocstore(CircForm circForm, Map<String, String[]> itemIdMap, List<OleLoanDocument> selectedLoanDocumentList) throws Exception {
459         List<Item> itemList = new ArrayList<>();
460         for (Iterator<OleLoanDocument> iterator = selectedLoanDocumentList.iterator(); iterator.hasNext(); ) {
461             Map<String, Object> valueMap = new HashMap<>();
462             OleLoanDocument oleLoanDocument = iterator.next();
463             String[] dueDateAndTime = itemIdMap.get(oleLoanDocument.getItemId());
464             String dateString = dueDateAndTime[0];
465             Timestamp newDueDate = null;
466             if (StringUtils.isNotBlank(dateString)) {
467                 if(StringUtils.isBlank(dueDateAndTime[1])) {
468                     dueDateAndTime[1] = ParameterValueResolver.getInstance().getParameter(OLEConstants
469                             .APPL_ID_OLE, OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, OLEConstants.DEFAULT_TIME_FOR_DUE_DATE);
470                 }
471                 newDueDate = getCheckoutUIController(circForm.getFormKey()).processDateAndTimeForAlterDueDate(getDateFromString(dateString), dueDateAndTime[1]);
472             }
473             valueMap.put("loanDueDate", newDueDate);
474             valueMap.put("itemUUID", oleLoanDocument.getItemUuid());
475             Item itemForUpdate = getCheckoutUIController(circForm.getFormKey()).getItemForUpdate(valueMap);
476             if (null != itemForUpdate) {
477                 itemList.add(itemForUpdate);
478             }
479 
480         }
481         OleStopWatch oleStopWatch = new OleStopWatch();
482         oleStopWatch.start();
483         Map<String, Map> docstoreResultMap = getBulkItemUpdateUtil().updateItemsToDocstore(itemList);
484         oleStopWatch.end();
485         System.out.println("Time taken to batch update item loan due dates in solr : " + oleStopWatch.getTotalTime());
486         return docstoreResultMap;
487     }
488 
489     private void alterDueDateForLoanInDB(List<OleLoanDocument> oleLoanDocuments) {
490         List<BulkUpdateDataObject> bulkUpdateDataObjects = new ArrayList<>();
491         for (Iterator<OleLoanDocument> iterator = oleLoanDocuments.iterator(); iterator.hasNext(); ) {
492             OleLoanDocument oleLoanDocument = iterator.next();
493             BulkUpdateDataObject bulkUpdateDataObject = new BulkUpdateDataObject();
494             HashMap setClauseMap = new HashMap();
495             setClauseMap.put("CURR_DUE_DT_TIME", oleLoanDocument.getLoanDueDate());
496             bulkUpdateDataObject.setSetClauseMap(setClauseMap);
497             HashMap whereClauseMap = new HashMap();
498             whereClauseMap.put("ITM_ID", oleLoanDocument.getItemId());
499             bulkUpdateDataObject.setWhereClauseMap(whereClauseMap);
500             bulkUpdateDataObjects.add(bulkUpdateDataObject);
501         }
502 
503         OleStopWatch oleStopWatch = new OleStopWatch();
504         oleStopWatch.start();
505         int[] updatedCount = getOleLoanDocumentPlatformAwareDao().updateLoanDocument(bulkUpdateDataObjects);
506         oleStopWatch.end();
507         System.out.println("Time taken to batch update loan documents in DB : " + oleStopWatch.getTotalTime());
508         System.out.println(Arrays.toString(updatedCount));
509     }
510 
511     public List<OleLoanDocument> getSelectedLoanDocumentList(CircForm circForm) {
512         List<OleLoanDocument> selectedLoanList = new ArrayList<>();
513         List<OleLoanDocument> loanList = new ArrayList<>();
514         if (CollectionUtils.isNotEmpty(circForm.getExistingLoanList()))
515             loanList.addAll(circForm.getExistingLoanList());
516         if (CollectionUtils.isNotEmpty(circForm.getLoanDocumentListForCurrentSession()))
517             loanList.addAll(circForm.getLoanDocumentListForCurrentSession());
518         if (CollectionUtils.isNotEmpty(loanList)) {
519             for (Iterator<OleLoanDocument> iterator = loanList.iterator(); iterator.hasNext(); ) {
520                 OleLoanDocument oleLoanDocument = iterator.next();
521                 if (oleLoanDocument.isCheckNo() && !selectedLoanList.contains(oleLoanDocument)) {
522                     selectedLoanList.add(oleLoanDocument);
523                 }
524             }
525         }
526         return selectedLoanList;
527     }
528 
529     @RequestMapping(params = "methodToCall=applyDamagedItem")
530     public ModelAndView applyDamagedItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
531                                          HttpServletRequest request, HttpServletResponse response) throws Exception {
532         CircForm circForm = (CircForm) form;
533         String damageItemDescription = request.getParameter("damageItemDescription");
534         List<OleLoanDocument> loanDocumentList = getSelectedLoanDocumentList(circForm);
535         if (CollectionUtils.isNotEmpty(loanDocumentList)) {
536             for (Iterator<OleLoanDocument> iterator = loanDocumentList.iterator(); iterator.hasNext(); ) {
537                 OleLoanDocument oleLoanDocument = iterator.next();
538                 oleLoanDocument.setItemDamagedNote(damageItemDescription);
539                 oleLoanDocument.setDamagedItemIndicator(true);
540                 oleLoanDocument.setDamagedItemDate(new Timestamp(new Date().getTime()));
541             }
542             createDamagedItem(circForm, loanDocumentList, circForm.getPatronDocument());
543         }
544         return getUIFModelAndView(form);
545     }
546 
547 
548     @RequestMapping(params = "methodToCall=removeDamagedItem")
549     public ModelAndView removeDamagedItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
550                                           HttpServletRequest request, HttpServletResponse response) throws Exception {
551         CircForm circForm = (CircForm) form;
552         List<OleLoanDocument> selectedLoanDocumentList = getSelectedLoanDocumentList(circForm);
553         deleteDamagedItem(circForm, selectedLoanDocumentList);
554         return getUIFModelAndView(form);
555     }
556 
557     @RequestMapping(params = "methodToCall=removeMissingPieceItem")
558     public ModelAndView removeMissingPieceItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
559                                                HttpServletRequest request, HttpServletResponse response) throws Exception {
560         CircForm circForm = (CircForm) form;
561         List<OleLoanDocument> selectedLoanDocumentList = getSelectedLoanDocumentList(circForm);
562         deleteMissingPieceItem(circForm, selectedLoanDocumentList);
563         return getUIFModelAndView(form);
564     }
565 
566 
567     @RequestMapping(params = "methodToCall=applyMissingPieceItem")
568     public ModelAndView applyMissingPieceItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
569                                               HttpServletRequest request, HttpServletResponse response) throws Exception {
570         CircForm circForm = (CircForm) form;
571         String missingPieceCnt = request.getParameter("missingPieceCnt");
572         String noOfPieces = request.getParameter("noOfPieces");
573         String missingPieceNote = request.getParameter("missingPieceNte");
574         List<OleLoanDocument> loanDocumentList = getSelectedLoanDocumentList(circForm);
575         if (CollectionUtils.isNotEmpty(loanDocumentList)) {
576             for (Iterator<OleLoanDocument> iterator = loanDocumentList.iterator(); iterator.hasNext(); ) {
577                 OleLoanDocument oleLoanDocument = iterator.next();
578                 oleLoanDocument.setMissingPiecesCount(missingPieceCnt);
579                 oleLoanDocument.setMissingPieceFlag(true);
580                 oleLoanDocument.setMissingPieceNote(missingPieceNote);
581                 oleLoanDocument.setNoOfMissingPiece(noOfPieces);
582                 oleLoanDocument.setMissingPieceItemDate(new Timestamp(new Date().getTime()));
583             }
584             createMissingPieceItem(circForm, loanDocumentList, circForm.getPatronDocument());
585         }
586         return getUIFModelAndView(form);
587     }
588 
589     @RequestMapping(params = "methodToCall=renew")
590     public ModelAndView renew(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
591                               HttpServletRequest request, HttpServletResponse response) throws Exception {
592 
593         CircForm circForm = (CircForm) form;
594 
595         if (null != circForm.getLoanDocumentsForRenew()) {
596             circForm.setLoanDocumentsForRenew(new ArrayList<OleLoanDocument>());
597         }
598         circForm.setErrorMessage(new ErrorMessage());
599         List<OleLoanDocument> selectedLoanDocumentList = getSelectedLoanDocumentList(circForm);
600         if (CollectionUtils.isNotEmpty(selectedLoanDocumentList)) {
601             DroolsResponse droolsResponse = getRenewController().renewItems(selectedLoanDocumentList, circForm.getPatronDocument());
602 
603             String messageContentForRenew = getRenewController().analyzeRenewedLoanDocuments(circForm, droolsResponse);
604 
605             ErrorMessage errorMessage = new ErrorMessage();
606             errorMessage.setErrorMessage(messageContentForRenew);
607             circForm.setErrorMessage(errorMessage);
608 
609             if (CollectionUtils.isNotEmpty(circForm.getLoanDocumentsForRenew())) {
610                 showDialogAndRunCustomScript("renewOverrideDialog", circForm, "jq('.renewItemCBClass').removeAttr('checked');jq('.renewItemCBClass').removeAttr('checked');");
611             } else if (StringUtils.isNotBlank(messageContentForRenew)) {
612                 showDialogAndRunCustomScript("generalInfoWithRefreshDialog", circForm, "jq('.loanedItemCBClass').removeAttr('checked');jq('.loaningItemCBClass').removeAttr('checked');");
613                 circForm.setLoanDocumentsForRenew(new ArrayList<OleLoanDocument>());
614             }
615         } else {
616             ErrorMessage errorMessage = new ErrorMessage();
617             errorMessage.setErrorMessage("Please select any one of loaned item to renew.");
618             circForm.setErrorMessage(errorMessage);
619             showDialog("generalInfoDialog", circForm, request, response);
620         }
621 
622         return getUIFModelAndView(form);
623     }
624 
625     private void processJsonStringForRenew(CircForm circForm, String jsonString, List<OleLoanDocument> selectedLoanDocumentForRenewOverride) {
626         JSONArray renewObjectValues = null;
627         try {
628             renewObjectValues = new JSONArray(jsonString);
629             for (int index = 0; index < renewObjectValues.length(); index++) {
630                 JSONObject jsonObject = (JSONObject) renewObjectValues.get(index);
631                 String itemBarcode = getStringValueFromJsonObject(jsonObject, "itemBarcode");
632                 OleLoanDocument loanDocument = getCheckoutUIController(circForm.getFormKey()).getLoanDocumentFromListBasedOnItemBarcode(itemBarcode, selectedLoanDocumentForRenewOverride);
633                 if (null != loanDocument) {
634                     loanDocument.setRenewCheckNo(true);
635                     if (loanDocument.isNonCirculatingItem()) {
636                         String dateString = getStringValueFromJsonObject(jsonObject, "date");
637                         String dateTimeString = getStringValueFromJsonObject(jsonObject, "dateTime");
638                         Timestamp timestamp = null;
639                         try {
640                             timestamp = getCheckoutUIController(circForm.getFormKey()).processDateAndTimeForAlterDueDate(new DateUtil().getDate(dateString), dateTimeString);
641                         } catch (Exception e) {
642                             e.printStackTrace();
643                         }
644                         loanDocument.setLoanDueDate(timestamp);
645                     }
646                 }
647             }
648         } catch (JSONException e) {
649             e.printStackTrace();
650         }
651     }
652 
653 
654     @RequestMapping(params = "methodToCall=overrideRenewItems")
655     public ModelAndView overrideRenewItems(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
656                                            HttpServletRequest request, HttpServletResponse response) throws Exception {
657         CircForm circForm = (CircForm) form;
658 
659         String jsonString = request.getParameter("renewObjectValues");
660         processJsonStringForRenew(circForm, jsonString, circForm.getLoanDocumentsForRenew());
661 
662         List<OleLoanDocument> circulatingLoanDocumentsForRenew = new ArrayList<>();
663         List<OleLoanDocument> nonCirculatingLoanDocumentsForRenew = new ArrayList<>();
664         if (CollectionUtils.isNotEmpty(circForm.getLoanDocumentsForRenew())) {
665             for (Iterator<OleLoanDocument> iterator = circForm.getLoanDocumentsForRenew().iterator(); iterator.hasNext(); ) {
666                 OleLoanDocument oleLoanDocument = iterator.next();
667                 if (oleLoanDocument.isRenewCheckNo()) {
668                     if (oleLoanDocument.isNonCirculatingItem()) {
669                         nonCirculatingLoanDocumentsForRenew.add(oleLoanDocument);
670                     } else {
671                         circulatingLoanDocumentsForRenew.add(oleLoanDocument);
672                     }
673                 }
674             }
675             String responseForNonCirculatingItem = null;
676             if (CollectionUtils.isNotEmpty(nonCirculatingLoanDocumentsForRenew)) {
677                 DroolsResponse droolsResponseForNonCirculatingItem = getRenewController().proceedToSaveLoanDocuments(nonCirculatingLoanDocumentsForRenew);
678                 responseForNonCirculatingItem = getRenewController().prepareResponseForRenewedLoanDocuments(droolsResponseForNonCirculatingItem);
679             }
680 
681             String responseForCirculatingItem = null;
682             if (CollectionUtils.isNotEmpty(circulatingLoanDocumentsForRenew)) {
683                 DroolsResponse droolsResponseForCirculatingItem = getRenewController().proceedToSaveLoanDocuments(circulatingLoanDocumentsForRenew);
684                 responseForCirculatingItem = getRenewController().prepareResponseForRenewedLoanDocuments(droolsResponseForCirculatingItem);
685             }
686 
687             if (StringUtils.isNotBlank(responseForNonCirculatingItem)) {
688                 getRenewController().prepareResponeMessage(circForm, responseForNonCirculatingItem);
689             }
690             if (StringUtils.isNotBlank(responseForCirculatingItem)) {
691                 getRenewController().prepareResponeMessage(circForm, responseForCirculatingItem);
692             }
693         }
694 
695         if (CollectionUtils.isNotEmpty(nonCirculatingLoanDocumentsForRenew) && CollectionUtils.isNotEmpty(circulatingLoanDocumentsForRenew)) {
696             circForm.getLoanDocumentsForRenew().clear();
697         }
698 
699         if (null != circForm.getErrorMessage() && StringUtils.isNotBlank(circForm.getErrorMessage().getErrorMessage())) {
700             showDialog("generalInfoDialog", circForm, request, response);
701         }
702 
703         return getUIFModelAndView(form);
704     }
705 
706 
707     @RequestMapping(params = "methodToCall=doNotRenewalItem")
708     public ModelAndView doNotRenewalItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
709                                          HttpServletRequest request, HttpServletResponse response) throws Exception {
710         CircForm circForm = (CircForm) form;
711         if (null != circForm.getErrorMessage() && StringUtils.isNotBlank(circForm.getErrorMessage().getErrorMessage())) {
712             showDialog("generalInfoDialog", circForm, request, response);
713         } else {
714             executeCustomScriptAfterClosingLightBox(circForm, "jq.fancybox.close(); jq('#checkoutItem_control').focus();");
715         }
716         circForm.getLoanDocumentsForRenew().clear();
717         return getUIFModelAndView(circForm);
718     }
719 
720     @RequestMapping(params = "methodToCall=newPage")
721     public ModelAndView showNewPage(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
722                                     HttpServletRequest request, HttpServletResponse response) {
723         CircForm circForm = (CircForm) form;
724         circForm.setPageNumber(request.getParameter("pageNumber"));
725         return getUIFModelAndView(form);
726     }
727 
728     @RequestMapping(params = "methodToCall=newPageCheckoutDialog")
729     public ModelAndView showNewPageCheckoutDialog(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
730                                     HttpServletRequest request, HttpServletResponse response) {
731         CircForm circForm = (CircForm) form;
732         circForm.setPageNumber(request.getParameter("pageNumber"));
733         String overrideParameters = "{closeBtn:false,autoSize : false}";
734         return showDialogWithOverrideParameters("proxyListCheckoutDialog", circForm,overrideParameters);
735     }
736 
737 
738     @RequestMapping(params = "methodToCall=newSizeCheckoutDialog")
739     public ModelAndView showNewPageSizeCheckoutDialog(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
740                                         HttpServletRequest request, HttpServletResponse response) {
741         CircForm circForm = (CircForm) form;
742         circForm.setPageSize(request.getParameter("pageSize"));
743         String overrideParameters = "{closeBtn:false,autoSize : false}";
744         return showDialogWithOverrideParameters("proxyListCheckoutDialog", circForm, overrideParameters);
745     }
746 
747 
748     @RequestMapping(params = "methodToCall=newSize")
749     public ModelAndView showNewPageSize(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
750                                         HttpServletRequest request, HttpServletResponse response) {
751         CircForm circForm = (CircForm) form;
752         circForm.setPageSize(request.getParameter("pageSize"));
753         return getUIFModelAndView(form);
754     }
755 
756 
757     @RequestMapping(params = "methodToCall=selectAll")
758     public ModelAndView selectAll(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
759                                   HttpServletRequest request, HttpServletResponse response) {
760         CircForm circForm = (CircForm) form;
761         for (OleLoanDocument oleLoanDocument : circForm.getExistingLoanList()) {
762             oleLoanDocument.setCheckNo(true);
763         }
764 
765         return getUIFModelAndView(form);
766     }
767 
768 
769     @RequestMapping(params = "methodToCall=deselectAll")
770     public ModelAndView deselectAll(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
771                                     HttpServletRequest request, HttpServletResponse response) {
772         CircForm circForm = (CircForm) form;
773         for (OleLoanDocument oleLoanDocument : circForm.getExistingLoanList()) {
774             oleLoanDocument.setCheckNo(false);
775         }
776 
777         return getUIFModelAndView(form);
778     }
779 
780     @RequestMapping(params = "methodToCall=proceedForRenew")
781     public ModelAndView proceedForRenew(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
782                                         HttpServletRequest request, HttpServletResponse response) {
783         CircForm circForm = (CircForm) form;
784         if (null != circForm.getLoanDocumentsForRenew()) {
785             circForm.setLoanDocumentsForRenew(new ArrayList<OleLoanDocument>());
786         }
787         circForm.setErrorMessage(new ErrorMessage());
788         OleLoanDocument currentLoanDocument = getCheckoutUIController(circForm.getFormKey()).getCurrentLoanDocument(circForm.getItemBarcode());
789         List<OleLoanDocument> selectedLoanDocumentList = new ArrayList<>();
790         if (null != currentLoanDocument) {
791             selectedLoanDocumentList.add(currentLoanDocument);
792         }
793         if (CollectionUtils.isNotEmpty(selectedLoanDocumentList)) {
794             DroolsResponse droolsResponse = getRenewController().renewItems(selectedLoanDocumentList, circForm.getPatronDocument());
795 
796             String messageContentForRenew = getRenewController().analyzeRenewedLoanDocuments(circForm, droolsResponse);
797 
798             ErrorMessage errorMessage = new ErrorMessage();
799 
800             if (CollectionUtils.isNotEmpty(circForm.getLoanDocumentsForRenew())) {
801                 errorMessage.setErrorMessage(circForm.getLoanDocumentsForRenew().get(0).getErrorMessage());
802                 circForm.setErrorMessage(errorMessage);
803                 showDialog("checkoutRenewCustomDueDateConfirmationDialog", circForm, request, response);
804             } else if (StringUtils.isNotBlank(messageContentForRenew)) {
805                 errorMessage.setErrorMessage(messageContentForRenew);
806                 circForm.setErrorMessage(errorMessage);
807                 showDialog("generalInfoWithRefreshDialog", circForm, request, response);
808                 circForm.setLoanDocumentsForRenew(new ArrayList<OleLoanDocument>());
809             }
810         }
811         return getUIFModelAndView(form);
812     }
813 
814     @RequestMapping(params = "methodToCall=overrideCheckoutRenewItems")
815     public ModelAndView overrideCheckoutRenewItems(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
816                                                    HttpServletRequest request, HttpServletResponse response) throws Exception {
817         CircForm circForm = (CircForm) form;
818         circForm.getErrorMessage().setErrorMessage(null);
819         String customDate = request.getParameter("renewCustomDueDateMap");
820         String customDateTime = request.getParameter("renewCustomDueDateTime");
821         if (StringUtils.isNotBlank(customDate)) {
822             circForm.setCustomDueDateMapForRenew(new DateUtil().getDate(customDate));
823         }
824         circForm.setCustomDueDateTimeForRenew(customDateTime);
825         if (CollectionUtils.isNotEmpty(circForm.getLoanDocumentsForRenew())) {
826             String responseForRenewItem = null;
827             Timestamp timestamp = getCheckoutUIController(circForm.getFormKey
828                     ()).processDateAndTimeForAlterDueDate(circForm.getCustomDueDateMapForRenew(), circForm.getCustomDueDateTimeForRenew());
829             circForm.getLoanDocumentsForRenew().get(0).setLoanDueDate(timestamp);
830             DroolsResponse droolsResponseForRenewItem = getRenewController().proceedToSaveLoanDocuments(circForm.getLoanDocumentsForRenew());
831             responseForRenewItem = getRenewController().prepareResponseForRenewedLoanDocuments(droolsResponseForRenewItem);
832             getRenewController().prepareResponeMessage(circForm, responseForRenewItem);
833         }
834         circForm.getLoanDocumentsForRenew().clear();
835         if (null != circForm.getErrorMessage() && StringUtils.isNotBlank(circForm.getErrorMessage().getErrorMessage())) {
836             showDialog("generalInfoDialog", circForm, request, response);
837         }
838         return getUIFModelAndView(form);
839     }
840 
841     @RequestMapping(params = "methodToCall=cancelOverrideCheckoutRenewItems")
842     public ModelAndView cancelOverrideCheckoutRenewItems(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
843                                                          HttpServletRequest request, HttpServletResponse response) throws Exception {
844         CircForm circForm = (CircForm) form;
845         circForm.getErrorMessage().setErrorMessage(null);
846         circForm.getLoanDocumentsForRenew().clear();
847         circForm.getCustomDueDateMapForRenew();
848         circForm.getCustomDueDateTimeForRenew();
849         circForm.getCustomDueDateTimeMessageForRenew();
850         return getUIFModelAndView(form);
851     }
852 
853     public OleLoanDocumentsFromSolrBuilder getOleLoanDocumentsFromSolrBuilder() {
854         if (null == oleLoanDocumentsFromSolrBuilder) {
855             oleLoanDocumentsFromSolrBuilder = new OleLoanDocumentsFromSolrBuilder();
856 
857         }
858         return oleLoanDocumentsFromSolrBuilder;
859     }
860 
861     public OleLoanDocumentPlatformAwareDao getOleLoanDocumentPlatformAwareDao() {
862         if (null == oleLoanDocumentPlatformAwareDao) {
863             oleLoanDocumentPlatformAwareDao = (OleLoanDocumentPlatformAwareDao) SpringContext.getService("OleLoanDocumentPlatformAwareDao");
864         }
865         return oleLoanDocumentPlatformAwareDao;
866     }
867 
868     public void setOleLoanDocumentPlatformAwareDao(OleLoanDocumentPlatformAwareDao oleLoanDocumentPlatformAwareDao) {
869         this.oleLoanDocumentPlatformAwareDao = oleLoanDocumentPlatformAwareDao;
870     }
871 
872     public BulkItemUpdateUtil getBulkItemUpdateUtil() {
873         if (null == bulkItemUpdateUtil) {
874             bulkItemUpdateUtil = new BulkItemUpdateUtil();
875         }
876         return bulkItemUpdateUtil;
877     }
878 
879     public void setBulkItemUpdateUtil(BulkItemUpdateUtil bulkItemUpdateUtil) {
880         this.bulkItemUpdateUtil = bulkItemUpdateUtil;
881     }
882 
883     public RenewController getRenewController() {
884         if (null == renewController) {
885             renewController = new RenewController();
886         }
887         return renewController;
888     }
889 
890 
891 
892     public DateTimeService getDateTimeService() {
893         if(dateTimeService == null){
894             dateTimeService = (DateTimeService) SpringContext.getService("dateTimeService");
895         }
896         return dateTimeService;
897     }
898 
899     public void setDateTimeService(DateTimeService dateTimeService) {
900         this.dateTimeService = dateTimeService;
901     }
902 
903     public void setRenewController(RenewController renewController) {
904         this.renewController = renewController;
905     }
906 
907     private String getParameter(String parameterName) {
908         String parameter = ParameterValueResolver.getInstance().getParameter(OLEConstants.APPL_ID_OLE, OLEConstants.DLVR_NMSPC, OLEConstants
909                 .DLVR_CMPNT, parameterName);
910         return parameter;
911     }
912 }