View Javadoc
1   package org.kuali.ole.deliver.controller;
2   
3   import org.apache.commons.collections.CollectionUtils;
4   import org.apache.commons.lang.StringUtils;
5   import org.apache.log4j.Logger;
6   import org.kuali.ole.DocumentUniqueIDPrefix;
7   import org.kuali.ole.OLEConstants;
8   import org.kuali.ole.OLEParameterConstants;
9   import org.kuali.ole.OLEPropertyConstants;
10  import org.kuali.ole.deliver.OleLoanDocumentsFromSolrBuilder;
11  import org.kuali.ole.deliver.batch.OleDeliverBatchServiceImpl;
12  import org.kuali.ole.deliver.batch.OleMailer;
13  import org.kuali.ole.deliver.batch.OleNoticeBo;
14  import org.kuali.ole.deliver.bo.*;
15  import org.kuali.ole.deliver.form.OleLoanForm;
16  import org.kuali.ole.deliver.printSlip.OlePrintSlip;
17  import org.kuali.ole.deliver.processor.LoanProcessor;
18  import org.kuali.ole.deliver.service.CircDeskLocationResolver;
19  import org.kuali.ole.describe.bo.OleItemAvailableStatus;
20  import org.kuali.ole.describe.bo.OleLocation;
21  import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
22  import org.kuali.ole.docstore.common.document.ItemOleml;
23  import org.kuali.ole.docstore.common.document.content.enums.DocType;
24  import org.kuali.ole.docstore.common.document.content.instance.Item;
25  import org.kuali.ole.docstore.common.document.content.instance.MissingPieceItemRecord;
26  import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
27  import org.kuali.ole.sys.context.SpringContext;
28  import org.kuali.ole.sys.exception.ParseException;
29  import org.kuali.rice.core.api.config.property.ConfigContext;
30  import org.kuali.rice.core.api.mail.EmailBody;
31  import org.kuali.rice.core.api.mail.EmailFrom;
32  import org.kuali.rice.core.api.mail.EmailSubject;
33  import org.kuali.rice.core.api.mail.EmailTo;
34  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
35  import org.kuali.rice.kim.api.identity.Person;
36  import org.kuali.rice.kim.api.identity.PersonService;
37  import org.kuali.rice.kim.api.permission.PermissionService;
38  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
39  import org.kuali.rice.krad.service.KRADServiceLocator;
40  import org.kuali.rice.krad.uif.UifConstants;
41  import org.kuali.rice.krad.uif.UifParameters;
42  import org.kuali.rice.krad.util.GlobalVariables;
43  import org.kuali.rice.krad.util.KRADConstants;
44  import org.kuali.rice.krad.util.ObjectUtils;
45  import org.kuali.rice.krad.web.controller.UifControllerBase;
46  import org.kuali.rice.krad.web.form.UifFormBase;
47  import org.springframework.stereotype.Controller;
48  import org.springframework.validation.BindingResult;
49  import org.springframework.web.bind.annotation.ModelAttribute;
50  import org.springframework.web.bind.annotation.RequestMapping;
51  import org.springframework.web.servlet.ModelAndView;
52  
53  import javax.servlet.http.HttpServletRequest;
54  import javax.servlet.http.HttpServletResponse;
55  import java.io.IOException;
56  import java.net.InetAddress;
57  import java.sql.Timestamp;
58  import java.text.DateFormat;
59  import java.text.SimpleDateFormat;
60  import java.util.*;
61  import java.util.regex.Matcher;
62  import java.util.regex.Pattern;
63  
64  /**
65   * The LoanController is the controller class for processing all the actions that corresponds to the Loan functionality in OLE.
66   * The request mapping tag takes care of mapping the individual action to the corresponding functions.
67   */
68  @Controller
69  @RequestMapping(value = "/loancontroller")
70  public class LoanController extends UifControllerBase {
71  
72      private static final Logger LOG = Logger.getLogger(LoanController.class);
73  
74      private List<OleLoanDocument> printDueDateSlipList = new ArrayList<OleLoanDocument>();
75  
76      private List<OleLoanDocument> printHoldSlipList = new ArrayList<OleLoanDocument>();
77  
78      private LoanProcessor loanProcessor;
79  
80      private OleDeliverBatchServiceImpl oleDeliverBatchService;
81  
82      public static String fastAddBarcode = "";
83  
84      private List<String> loginUserList;
85      private DocstoreClientLocator docstoreClientLocator;
86      private CircDeskLocationResolver circDeskLocationResolver;
87      private OleLoanDocumentsFromSolrBuilder oleLoanDocumentsFromSolrBuilder;
88  
89      public DocstoreClientLocator getDocstoreClientLocator() {
90  
91          if (docstoreClientLocator == null) {
92              docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
93  
94          }
95          return docstoreClientLocator;
96      }
97  
98      public OleDeliverBatchServiceImpl getOleDeliverBatchService() {
99          if (oleDeliverBatchService == null) {
100             oleDeliverBatchService = SpringContext.getBean(OleDeliverBatchServiceImpl.class);
101         }
102         return oleDeliverBatchService;
103     }
104 
105     private CircDeskLocationResolver getCircDeskLocationResolver() {
106         if (circDeskLocationResolver == null) {
107             circDeskLocationResolver = new CircDeskLocationResolver();
108         }
109         return circDeskLocationResolver;
110     }
111 
112     public void setCircDeskLocationResolver(CircDeskLocationResolver circDeskLocationResolver) {
113         this.circDeskLocationResolver = circDeskLocationResolver;
114     }
115 
116     public void setLoanProcessor(LoanProcessor loanProcessor) {
117         this.loanProcessor = loanProcessor;
118     }
119 
120     public void setOleDeliverBatchService(OleDeliverBatchServiceImpl oleDeliverBatchService) {
121         this.oleDeliverBatchService = oleDeliverBatchService;
122     }
123 
124     public void setDocstoreClientLocator(DocstoreClientLocator docstoreClientLocator) {
125         this.docstoreClientLocator = docstoreClientLocator;
126     }
127 
128     /**
129      * This method creates new OleLoan form
130      *
131      * @param request
132      * @return OleLoanForm
133      */
134     @Override
135     protected OleLoanForm createInitialForm(HttpServletRequest request) {
136         return new OleLoanForm();
137     }
138 
139     /**
140      * This method converts UifFormBase to OleLoanForm
141      *
142      * @param form
143      * @param result
144      * @param request
145      * @param response
146      * @return ModelAndView
147      */
148     @Override
149     @RequestMapping(params = "methodToCall=start")
150     public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
151                               HttpServletRequest request, HttpServletResponse response) {
152         LOG.debug("Inside the loan start method");
153         fastAddBarcode = "";
154         OleLoanForm oleLoanForm = null;
155         if (form.getViewId().equalsIgnoreCase("PatronItemView")) {
156             String formKey = request.getParameter("formKey");
157             if (formKey == null) {
158                 if (loginUserList != null) {
159                     loginUserList.clear();
160                 }
161                 oleLoanForm = (OleLoanForm) form;
162                 oleLoanForm.setReturnCheck(false);
163                 if (oleLoanForm.getOldPrincipalId() == null || "".equals(oleLoanForm.getOldPrincipalId()))
164                     oleLoanForm.setOldPrincipalId(GlobalVariables.getUserSession().getPrincipalId());
165                 Integer maxTimeForCheckInDate = 0;
166                 String parameter = getLoanProcessor().getParameter(OLEConstants.MAX_TIME_CHECK_IN);
167                 if (LOG.isInfoEnabled()) {
168                     LOG.info("session timeout parameter:" + parameter);
169                 }
170                 String loanParameter = getLoanProcessor().getParameter(OLEConstants.MAX_TIME_LOAN);
171                 String audioOption = getLoanProcessor().getParameter(OLEConstants.AUDIO_OPTION);
172                 String maxSessionTime = loanParameter;
173                 if (LOG.isInfoEnabled()) {
174                     LOG.info("session timeout:" + maxSessionTime);
175                 }
176                 if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
177                     oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));
178                 // Modified as per comments in Jira OLE-4901
179                 if (!getLoanProcessor().isValidCirculationDesk()) {
180                     oleLoanForm.setLoanLoginUserInfo(GlobalVariables.getUserSession().getPrincipalName() + " " + OLEConstants.OleCirculationDesk.OLE_CIRCULATION_DESK_VALIDATIONS);
181                     return super.start(oleLoanForm, result, request, response);
182                 }
183                 //To set circulation desk value initially
184                 oleLoanForm.setCirculationDesk(getLoanProcessor().getCircDeskId());
185                 oleLoanForm.setAudioForPastDate(audioOption != null && !audioOption.isEmpty() && audioOption.equalsIgnoreCase(OLEConstants.TRUE));
186                 if (parameter != null) {
187                     maxTimeForCheckInDate = Integer.parseInt(parameter);
188                 }
189                 oleLoanForm.setMaxTimeForCheckOutConstant(loanParameter);
190                 LOG.info("session timeout maxTimeForCheckInDate:" + maxTimeForCheckInDate);
191                 oleLoanForm.setMaxTimeForCheckInDate(maxTimeForCheckInDate);
192                 oleLoanForm.setCheckInDateMaxTime(maxTimeForCheckInDate);
193                 oleLoanForm.setDateAlertMessage(OLEConstants.CHECK_IN_DATE);
194                 oleLoanForm.setCurrentDate(new Date());
195                 oleLoanForm.setPatronFocus(true);
196                 if (oleLoanForm.getCheckInDate() == null) {
197                     oleLoanForm.setCheckInDate(new Date());
198                 }
199             } else {
200                 oleLoanForm = (OleLoanForm) GlobalVariables.getUifFormManager().getSessionForm(formKey);
201                 if (oleLoanForm.getOldPrincipalId() == null || "".equals(oleLoanForm.getOldPrincipalId()))
202                     oleLoanForm.setOldPrincipalId(GlobalVariables.getUserSession().getPrincipalId());
203                 oleLoanForm.setReturnCheck(false);
204                 oleLoanForm.setAjaxRequest(false);
205                 oleLoanForm.setAjaxReturnType("update-view");
206                 oleLoanForm = (OleLoanForm) form;
207                 oleLoanForm.setPageId(null);
208                 Integer maxTimeForCheckInDate = 0;
209                 String parameter = getLoanProcessor().getParameter(OLEConstants.MAX_TIME_CHECK_IN);
210                 LOG.info("session timeout parameter:" + parameter);
211                 String loanParameter = getLoanProcessor().getParameter(OLEConstants.MAX_TIME_LOAN);
212                 String audioOption = getLoanProcessor().getParameter(OLEConstants.AUDIO_OPTION);
213 
214                 String maxSessionTime = loanParameter;
215                 if (LOG.isInfoEnabled()) {
216                     LOG.info("session timeout:" + maxSessionTime);
217                 }
218                 if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
219                     oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));
220 
221                 oleLoanForm.setRemoveMissingPieceFlag(false);
222                 oleLoanForm.setRecordDamagedItemNote(false);
223                 oleLoanForm.setRecordMissingPieceNote(false);
224                 oleLoanForm.setRecordCheckoutMissingPieceNote(false);
225                 oleLoanForm.setDisplayRecordNotePopup(false);
226                 oleLoanForm.setCheckoutRecordFlag(false);
227                 oleLoanForm.setSkipMissingPieceRecordPopup(false);
228                 oleLoanForm.setSkipDamagedRecordPopup(false);
229                 oleLoanForm.setDisplayMissingPieceNotePopup(false);
230                 oleLoanForm.setCheckoutMissingPieceRecordFlag(false);
231                 oleLoanForm.setDisplayDamagedRecordNotePopup(false);
232                 oleLoanForm.setCheckoutDamagedRecordFlag(false);
233                 // Modified as per comments in Jira OLE-4901
234                 if (!getLoanProcessor().isValidCirculationDesk()) {
235                     oleLoanForm.setLoanLoginUserInfo(GlobalVariables.getUserSession().getPrincipalName() + " " + OLEConstants.OleCirculationDesk.OLE_CIRCULATION_DESK_VALIDATIONS);
236                     return super.start(oleLoanForm, result, request, response);
237                 }
238                 oleLoanForm.setAudioForPastDate(audioOption != null && !audioOption.isEmpty() && audioOption.equalsIgnoreCase(OLEConstants.TRUE));
239                 if (parameter != null) {
240                     maxTimeForCheckInDate = Integer.parseInt(parameter);
241                 }
242                 oleLoanForm.setMaxTimeForCheckOutConstant(loanParameter);
243                 LOG.info("session timeout maxTimeForCheckInDate:" + maxTimeForCheckInDate);
244                 oleLoanForm.setMaxTimeForCheckInDate(maxTimeForCheckInDate);
245                 oleLoanForm.setCheckInDateMaxTime(maxTimeForCheckInDate);
246                 oleLoanForm.setDateAlertMessage(OLEConstants.CHECK_IN_DATE);
247                 oleLoanForm.setCurrentDate(new Date());
248                 oleLoanForm.setPatronFocus(true);
249                 if (oleLoanForm.getCheckInDate() == null) {
250                     oleLoanForm.setCheckInDate(new Date());
251                 }
252             }
253 
254 
255         } else {
256             oleLoanForm = (OleLoanForm) form;
257             //To set circulation desk value initially
258             String formKey = request.getParameter("formKey");
259             if (formKey == null) {
260                 oleLoanForm.setCirculationDesk(getLoanProcessor().getCircDesk());
261             }
262             if (oleLoanForm.getOldPrincipalId() == null || "".equals(oleLoanForm.getOldPrincipalId()))
263                 oleLoanForm.setOldPrincipalId(GlobalVariables.getUserSession().getPrincipalId());
264             oleLoanForm.setPageId(null);
265             oleLoanForm.setReturnCheck(true);
266             Integer maxTimeForCheckInDate = 0;
267             String parameter = getLoanProcessor().getParameter(OLEConstants.MAX_TIME_CHECK_IN);
268             LOG.info("session timeout parameter:" + parameter);
269             String loanParameter = getLoanProcessor().getParameter(OLEConstants.MAX_TIME_LOAN);
270             String audioOption = getLoanProcessor().getParameter(OLEConstants.AUDIO_OPTION);
271 
272             String maxSessionTime = loanParameter;
273             if (LOG.isInfoEnabled()) {
274                 LOG.info("session timeout:" + maxSessionTime);
275             }
276             if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
277                 oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));
278 
279             /*if (!loanProcessor.isValidCirculationDesk()) {
280                 oleLoanForm.setLoanLoginMessage(true);
281                 String loginInfo = loanProcessor.getErrorMessage();
282                 oleLoanForm.setLoanLoginUserInfo(loginInfo);
283                 return super.start(oleLoanForm, result, request, response);
284                 //throw new DocumentAuthorizationException(GlobalVariables.getUserSession().getPrincipalId(), "not Authorized", form.getViewId());
285                 //return new OLEKRADAuthorizationResolver().resolveException(request,response,null,new Exception("is not authorized"));
286             }*/
287             // Modified as per comments in Jira OLE-4901
288             if (!getLoanProcessor().isValidCirculationDesk()) {
289                 oleLoanForm.setLoanLoginUserInfo(GlobalVariables.getUserSession().getPrincipalName() + " " + OLEConstants.OleCirculationDesk.OLE_CIRCULATION_DESK_VALIDATIONS);
290                 return super.start(oleLoanForm, result, request, response);
291             }
292             oleLoanForm.setAudioForPastDate(audioOption != null && !audioOption.isEmpty() && audioOption.equalsIgnoreCase(OLEConstants.TRUE));
293             if (parameter != null) {
294                 maxTimeForCheckInDate = Integer.parseInt(parameter);
295             }
296             oleLoanForm.setMaxTimeForCheckOutConstant(loanParameter);
297             LOG.info("session timeout maxTimeForCheckInDate:" + maxTimeForCheckInDate);
298             oleLoanForm.setMaxTimeForCheckInDate(maxTimeForCheckInDate);
299             oleLoanForm.setCheckInDateMaxTime(maxTimeForCheckInDate);
300             oleLoanForm.setDateAlertMessage(OLEConstants.CHECK_IN_DATE);
301             oleLoanForm.setCurrentDate(new Date());
302             oleLoanForm.setPatronFocus(true);
303             if (oleLoanForm.getCheckInDate() == null) {
304                 oleLoanForm.setCheckInDate(new Date());
305             }
306             OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
307             if (oleLoanDocument != null) {
308                 List<OleLoanDocument> documentList = oleLoanForm.getItemReturnList();
309                 if (documentList != null && documentList.size() > 0) {
310                     OleCirculationDesk oleCirculationDesk = null;
311                     OleLocation oleLocation = null;
312                     if (oleLoanDocument.getCirculationLocationId() != null) {
313                         //oleCirculationDesk = loanProcessor.getOleCirculationDesk(oleLoanDocument.getCirculationLocationId());
314                         try{
315                             oleLocation = getCircDeskLocationResolver().getLocationByLocationCode(oleLoanDocument.getItemLocation());
316                         }
317                         catch (Exception e){
318                             LOG.error("Exception while fetching OleLocation based on item location" +e);
319                         }
320                         String routeTo = oleLoanForm.getRouteToLocation() != null ? oleLoanForm.getRouteToLocation() :
321                                 (oleLoanDocument.getRouteToLocation() != null ? oleLoanDocument.getRouteToLocation() :
322                                         (oleLocation != null ? oleLocation.getLocationCode() : null));
323                         documentList.get(0).setRouteToLocation(routeTo);
324                     }
325                 }
326             }
327             oleLoanForm.setBackGroundCheckIn(false);
328         }
329         return super.start(oleLoanForm, result, request, response);
330     }
331 
332     /**
333      * To refresh patron record.
334      *
335      * @param form
336      * @param result
337      * @param request
338      * @param response
339      * @return
340      * @throws Exception
341      */
342     @Override
343     @RequestMapping(params = "methodToCall=refresh")
344     public ModelAndView refresh(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
345                                 HttpServletRequest request, HttpServletResponse response) throws Exception {
346         OleLoanForm oleLoanForm = (OleLoanForm) form;
347         if (oleLoanForm.getPatronFirstName() != null) {
348             oleLoanForm.setReturnCheck(false);
349             oleLoanForm.setPatronFirstName(null);
350             super.refresh(oleLoanForm, result, request, response);
351             return searchPatron(oleLoanForm, result, request, response);
352         }
353         if (oleLoanForm.getItemUuid() != null && oleLoanForm.getInstanceUuid() != null) {
354             oleLoanForm.setReturnCheck(false);
355             super.refresh(oleLoanForm, result, request, response);
356             ModelAndView modelAndView = addItem(oleLoanForm, result, request, response);
357             oleLoanForm.setItemUuid(null);
358             oleLoanForm.setInstanceUuid(null);
359             return modelAndView;
360         }
361         if (oleLoanForm.getReturnItemUuid() != null && oleLoanForm.getReturnInstanceUuid() != null) {
362             oleLoanForm.setReturnCheck(true);
363             super.refresh(oleLoanForm, result, request, response);
364             ModelAndView modelAndView = validateItem(oleLoanForm, result, request, response);
365             oleLoanForm.setReturnItemUuid(null);
366             oleLoanForm.setReturnInstanceUuid(null);
367             return modelAndView;
368         }
369         return super.refresh(oleLoanForm, result, request, response);
370     }
371 
372     /**
373      * This method displays information about a patron in UI.
374      *
375      * @param form
376      * @param result
377      * @param request
378      * @param response
379      * @return ModelAndView
380      */
381     @RequestMapping(params = "methodToCall=searchPatron")
382     public ModelAndView searchPatron(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
383                                      HttpServletRequest request, HttpServletResponse response) {
384         LOG.debug("Inside the search patron method");
385         Long b1 = System.currentTimeMillis();
386         fastAddBarcode = "";
387         OleLoanForm oleLoanForm = (OleLoanForm) form;
388         oleLoanForm.setLoanList(new ArrayList<OleLoanDocument>(0));
389         oleLoanForm.setBlockPatron(false);
390         oleLoanForm.setExistingLoanList(new ArrayList<OleLoanDocument>(0));
391         oleLoanForm.setInformation("");
392         oleLoanForm.setSuccessInfo("");
393         oleLoanForm.setReturnInformation("");
394         oleLoanForm.getErrorsAndPermission().clear();
395         oleLoanForm.setPatronbill(false);
396         oleLoanForm.setShowExistingLoan(false);
397         try {
398             String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
399             if (LOG.isInfoEnabled()) {
400                 LOG.info("session timeout:" + maxSessionTime);
401             }
402             if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase("")){
403                 oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));
404             }
405             // Modified as per comments in Jira OLE-4901
406             if (!getLoanProcessor().isValidCirculationDesk()) {
407                 oleLoanForm.setLoanLoginUserInfo(GlobalVariables.getUserSession().getPrincipalName() + " " + OLEConstants.OleCirculationDesk.OLE_CIRCULATION_DESK_VALIDATIONS);
408                 return super.start(oleLoanForm, result, request, response);
409             }
410             getLoanProcessor().validateCalanderForCirculationDesk(oleLoanForm.getCirculationDesk());
411             OleLoanDocument oleProxyLoanDocument = null;
412             List<OlePatronDocument> oleRealPatron = oleLoanForm.getRealPatronList();
413             List<OlePatronDocument> oleCurrentPatronDocumentList = oleLoanForm.getCurrentPatronList();
414             OlePatronDocument oleCurrentPatronDocument = new OlePatronDocument();
415             if (oleCurrentPatronDocumentList != null && oleCurrentPatronDocumentList.size() > 0) {
416                 oleCurrentPatronDocument = oleCurrentPatronDocumentList.get(0);
417                 String barcode = oleLoanForm.getPatronBarcode();
418                 if (oleLoanForm.isProxyDisplay() && barcode != null && !barcode.equalsIgnoreCase("") && oleCurrentPatronDocument.getBarcode() != null && !barcode.equalsIgnoreCase(oleCurrentPatronDocument.getBarcode())) {
419                     oleLoanForm.getCurrentPatronList().clear();
420                     oleLoanForm.setRealPatronBarcode(null);
421                     oleLoanForm.setPatronBarcode(barcode);
422                     oleLoanForm.setRealPatronList(null);
423                     oleLoanForm.setProxyDisplay(false);
424                     oleLoanForm.setBackUpDummyLoan(null);
425                     oleRealPatron.clear();
426                 }
427             }
428             if (oleRealPatron != null && oleRealPatron.size() > 0 && !oleCurrentPatronDocument.isSelfCheckOut()) {
429                 for (int realPatron = 0; realPatron < oleRealPatron.size(); realPatron++) {
430                     OlePatronDocument olePatronDocument = oleRealPatron.get(realPatron);
431                     if (olePatronDocument.isRealPatronCheck()) {
432                         oleLoanForm.setRealPatronBarcode(olePatronDocument.getBarcode());
433                         oleLoanForm.setRealPatronFlag(false);
434                         oleProxyLoanDocument = getLoanProcessor().getLoanDocument(olePatronDocument.getBarcode(), null, oleLoanForm.isSelfCheckOut(), false);
435                         break;
436                     }
437                 }
438             }
439             boolean isSelfCheckout = oleCurrentPatronDocument.isSelfCheckOut();
440             if (oleCurrentPatronDocument.isSelfCheckOut()) {
441                 oleLoanForm.setSelfCheckOut(false);
442                 oleLoanForm.setRealPatronFlag(false);
443             }
444             Long b2 = System.currentTimeMillis();
445             Long b3 = b2-b1;
446             LOG.info("The time taken for pre-loaning patron"+b3);
447             OleLoanDocument oleLoanDocument = getLoanProcessor().getLoanDocument(oleLoanForm.getPatronBarcode(), oleLoanForm.getRealPatronBarcode(), isSelfCheckout, false);
448             Long b4 = System.currentTimeMillis();
449             if (oleLoanDocument.isLostPatron()) {
450                 oleLoanForm.setBlockUser(true);
451             }else {
452                 oleLoanForm.setBlockUser(false);
453             }
454             if (oleLoanDocument.getPatronUserNotes() != null) {
455                 oleLoanForm.setPatronNoteFlag(true);
456                 oleLoanForm.setPatronUserNote(oleLoanDocument.getPatronUserNotes());
457                 oleLoanForm.setPatronNoteTypeId(oleLoanDocument.getPatronNoteTypeId());
458             }
459             boolean activeProxyValue = true;
460             int proxyPatronCount = 0;
461             int proxyDisplayCount = 0;
462             if (oleLoanDocument.getRealPatron() != null && oleLoanDocument.getRealPatron().size() > 0) {
463                 List<OlePatronDocument> realPatronActiveListOld = new ArrayList<OlePatronDocument>();
464                 for (OlePatronDocument oleRealPatronDocument : oleLoanDocument.getRealPatron()) {
465                     if (!realPatronActiveListOld.contains(oleRealPatronDocument)) {
466                         realPatronActiveListOld.add(oleRealPatronDocument);
467                     }
468                 }
469                 List<OlePatronDocument> realPatronActiveList = new ArrayList<OlePatronDocument>();
470                 for (OlePatronDocument oleRealPatronDocument : realPatronActiveListOld) {
471                     List<OleProxyPatronDocument> proxyPatronActiveList = new ArrayList<OleProxyPatronDocument>();
472                     for (OleProxyPatronDocument oleProxyPatronDocument : oleRealPatronDocument.getOleProxyPatronDocuments()) {
473                         if (oleProxyPatronDocument.getProxyPatronId().equalsIgnoreCase(oleLoanDocument.getPatronId())) {
474                             proxyPatronCount++;
475                             if (oleProxyPatronDocument.getProxyPatronExpirationDate() == null || !oleProxyPatronDocument.getProxyPatronExpirationDate().before(new Timestamp(System.currentTimeMillis()))) {
476                                 proxyPatronActiveList.add(oleProxyPatronDocument);
477                                 proxyDisplayCount++;
478                             }
479                         }
480                     }
481                     if (proxyPatronActiveList.size() > 0) {
482                         oleLoanForm.setProxyDisplay(true);
483                         oleRealPatronDocument.setOleProxyPatronDocuments(proxyPatronActiveList);
484                         oleRealPatronDocument.setOleProxyPatronDocumentList(proxyPatronActiveList);
485                         realPatronActiveList.add(oleRealPatronDocument);
486                     } else {
487                         activeProxyValue = false;
488                     }
489                 }
490                 if (realPatronActiveList.size() > 0) {
491                     oleLoanForm.setRealPatronList(realPatronActiveList);
492                     List<OlePatronDocument> currentPatronList = new ArrayList<>();
493                     currentPatronList.add(oleLoanDocument.getOlePatron());
494                     oleLoanForm.setCurrentPatronList(currentPatronList);
495                     oleLoanForm.setRealPatronFlag(true);
496                 }
497             }
498             if (!activeProxyValue && proxyPatronCount != 0 && proxyDisplayCount != proxyPatronCount) {
499                 oleLoanDocument = getLoanProcessor().getLoanDocument(oleLoanForm.getPatronBarcode(), oleLoanForm.getRealPatronBarcode(), false, true);
500             }
501             oleLoanForm.setBorrowerCode(oleLoanDocument.getBorrowerTypeCode());
502             oleLoanForm.setPatronId(oleLoanDocument.getPatronId());
503             String patronNameURL = getLoanProcessor().patronNameURL(oleLoanForm.getOldPrincipalId(), oleLoanForm.getPatronId());
504             oleLoanForm.setPatronNameURL(patronNameURL);
505             oleLoanForm.setProxyPatronId(oleLoanDocument.getProxyPatronId());
506             //oleLoanForm.setRealPatronName(oleLoanDocument.getRealPatronName());
507             oleLoanForm.setRealPatronType(oleLoanDocument.getRealPatronType());
508             oleLoanForm.setAddressVerified(oleLoanDocument.isAddressVerified());
509             oleLoanForm.setBlockLoan(oleLoanDocument.isBlockLoan());
510             oleLoanForm.setBorrowerTypeId(oleLoanDocument.getBorrowerTypeId());
511             oleLoanForm.setInformation("");
512             if (oleLoanDocument.getRealPatronBarcode() != null) {
513                 for (OlePatronDocument olePatronDocument : oleLoanForm.getRealPatronList()) {
514                     if (olePatronDocument.isRealPatronCheck()) {
515                         oleLoanForm.setRealPatronId(olePatronDocument.getOlePatronId());
516                     }
517                 }
518                 if (oleLoanForm.getRealPatronId() != null && (oleLoanForm.getRealPatronId() != null && !oleLoanForm.getRealPatronId().equalsIgnoreCase(""))) {
519                  //   oleLoanForm.setExistingLoanList(getLoanProcessor().getPatronLoanedItemBySolr(oleLoanForm.getRealPatronId()));
520                     oleLoanDocument.setRealPatronName(oleLoanForm.getRealPatronName());
521                 }
522 
523             }// else {
524               //  oleLoanForm.setExistingLoanList(getLoanProcessor().getPatronLoanedItemBySolr(oleLoanDocument.getPatronId()));
525           //  }
526             oleLoanForm.setDummyLoan(oleLoanDocument);
527             oleLoanForm.setBlockItem(false);
528             oleLoanForm.setBlockPatron(false);
529             oleLoanForm.setNonCirculatingFlag(false);
530             oleLoanForm.setItem(null);
531             oleLoanForm.setOleItem(null);
532             oleLoanForm.getErrorsAndPermission().putAll(oleLoanDocument.getErrorsAndPermission());
533             if (oleLoanDocument.getErrorMessage() != null) {
534                 oleLoanForm.setSuccess(false);
535                 oleLoanForm.setInformation("");
536                 oleLoanForm.setMessage(oleLoanDocument.getErrorMessage());
537                 getLoanProcessor().setErrorFlagForPatron(oleLoanDocument, oleLoanForm);
538                 oleLoanForm.setPatronName(null);
539                 String audioOption = getLoanProcessor().getParameter(OLEConstants.AUDIO_OPTION);
540                 oleLoanForm.setAudioEnable(audioOption != null && !audioOption.isEmpty() && audioOption.equalsIgnoreCase(OLEConstants.TRUE));
541             }
542             if (oleProxyLoanDocument != null) {
543                 oleLoanForm.setRealPatronName(oleLoanDocument.getPatronName());
544                 oleLoanDocument = oleProxyLoanDocument;
545                 patronNameURL = getLoanProcessor().patronNameURL(oleLoanForm.getOldPrincipalId(), oleLoanForm.getProxyPatronId());
546                 oleLoanForm.setPatronNameURL(patronNameURL);
547             } else {
548                 oleLoanForm.setRealPatronName(null);
549             }
550             oleLoanForm.setPatronName(oleLoanDocument.getPatronName());
551             oleLoanForm.setBorrowerType(oleLoanDocument.getBorrowerTypeName());
552             oleLoanForm.setPreferredAddress(oleLoanDocument.getPreferredAddress());
553             oleLoanForm.setEmail(oleLoanDocument.getEmail());
554             oleLoanForm.setPhoneNumber(oleLoanDocument.getPhoneNumber());
555             oleLoanForm.setItemFocus(true);
556             oleLoanForm.setPatronFocus(false);
557            /* oleLoanForm.setExistingLoanList(oleLoanForm.getDummyLoan().getOlePatron().getOleLoanDocuments());*/
558             Long b5 = System.currentTimeMillis();
559             Long total = b5 - b4;
560             LOG.info("The time taken for post patron search:"+total);
561         } catch (Exception e) {
562             oleLoanForm.setInformation(e.getMessage());
563             LOG.error("Exception while search patron time", e);
564         }
565 
566         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
567     }
568 
569     /**
570      * This method creates new loan for a patron and also renew the existing item.
571      *
572      * @param form
573      * @param result
574      * @param request
575      * @param response
576      * @return ModelAndView
577      */
578     @RequestMapping(params = "methodToCall=addItem")
579     public ModelAndView addItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
580                                 HttpServletRequest request, HttpServletResponse response) {
581         LOG.debug("Inside the add item method");
582         Long begin = System.currentTimeMillis();
583         OleLoanForm oleLoanForm = (OleLoanForm) form;
584         oleLoanForm.setBlockItem(false);
585         if(oleLoanForm.getItem().equals("")){
586             GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.EMPTY_ITEM_BARCODE);
587             return getUIFModelAndView(oleLoanForm);
588         }
589         try {
590             oleLoanForm.setOleFormKey(oleLoanForm.getFormKey());
591             oleLoanForm.setInformation("");
592             oleLoanForm.setSuccessInfo("");
593             oleLoanForm.setReturnInformation("");
594             // Modified as per comments in Jira OLE-4901
595             if (!getLoanProcessor().isValidCirculationDesk()) {
596                 oleLoanForm.setLoanLoginUserInfo(GlobalVariables.getUserSession().getPrincipalName() + " " + OLEConstants.OleCirculationDesk.OLE_CIRCULATION_DESK_VALIDATIONS);
597                 return super.start(oleLoanForm, result, request, response);
598             }
599             boolean renewalFlag = false;
600             List<OleLoanDocument> existItemList = new ArrayList<OleLoanDocument>();
601             if (oleLoanForm.getExistingLoanList() != null && !oleLoanForm.getExistingLoanList().isEmpty())
602                 existItemList.addAll(oleLoanForm.getExistingLoanList());
603             if (oleLoanForm.getLoanList() != null && !oleLoanForm.getLoanList().isEmpty())
604                 existItemList.addAll(oleLoanForm.getLoanList());
605             String item = oleLoanForm.getItem();
606           /*  Long trail = System.currentTimeMillis();*/
607               for (OleLoanDocument oleLoanDocument : existItemList) {
608                // OleLoanDocument oleLoanDocument = existItemList.get(i);
609                 if (oleLoanDocument.getItemId() != null && oleLoanDocument.getItemId().equals(item)) {
610                     oleLoanForm.setRenewalFlag(true);
611                     oleLoanForm.setBlockItem(true);
612                     oleLoanForm.setBlockPatron(true);
613                     oleLoanForm.setSuccess(false);
614                     oleLoanForm.setMessage(OLEConstants.RENEWAL_ITM_POPUP);
615                     renewalFlag = true;
616                     break;
617                 }
618               }
619            /* Long trailEnd = System.currentTimeMillis();
620             Long timeTakenTrail = trailEnd - trail;
621             LOG.info("------------Trail Check---------------"+timeTakenTrail);*/
622             if(!renewalFlag){
623                 OleLoanDocument loanDocument = getLoanProcessor().retrieveByPatronAndItem(oleLoanForm.getPatronId(),item);
624                 if (loanDocument!=null && loanDocument.getItemId() != null && loanDocument.getItemId().equals(item)) {
625                     oleLoanForm.setRenewalLoan(loanDocument);
626                     oleLoanForm.setRenewalFlag(true);
627                     oleLoanForm.setBlockItem(true);
628                     oleLoanForm.setBlockPatron(true);
629                     oleLoanForm.setSuccess(false);
630                     oleLoanForm.setMessage(OLEConstants.RENEWAL_ITM_POPUP);
631                     renewalFlag = true;
632                 }
633             }
634 
635             if (!renewalFlag) {
636                 try {
637                     OleLoanDocument oleLoanDocument = new OleLoanDocument();
638 
639                     String ipAddress = request.getHeader("X-FORWARDED-FOR");
640                     if (ipAddress == null) {
641                         ipAddress = request.getRemoteAddr();
642                     }
643                     oleLoanDocument.setMachineId(ipAddress);
644                     oleLoanDocument.setItemUuid(oleLoanForm.getItemUuid());
645                     oleLoanForm.setAddressVerified(false);
646                     oleLoanForm.getErrorsAndPermission().clear();
647                     if (!getLoanProcessor().isClaimsReturnedItem(oleLoanForm.getItem(), oleLoanDocument)) {
648                         oleLoanForm = getLoanProcessor().processLoan(oleLoanForm, oleLoanDocument);
649                         oleLoanForm.setClaimsFlag(false);
650                     } else {
651                         oleLoanForm.setMessage("claims Returned Item");
652                         oleLoanForm.setSuccess(false);
653                         oleLoanForm.setClaimsFlag(true);
654                         oleLoanForm.setRecordNote(false);
655                     }
656                 } catch (Exception e) {
657                     LOG.error("Exception", e);
658                     oleLoanForm.setInformation(e.getMessage());
659                 }
660             }
661             //oleLoanForm.setPatronbill(false);
662             oleLoanForm.setPatronbill(getLoanProcessor().checkPatronBill(oleLoanForm.getPatronId()));
663             Long end = System.currentTimeMillis();
664             Long timeTaken = end - begin;
665             LOG.info("-----------TimeTaken to complete one loan-----------"+timeTaken);
666         } catch (Exception e) {
667             LOG.error("Exception while adding an item", e);
668         }
669         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
670     }
671 
672     /**
673      * This method  creates loan for a patron who is not able to borrow.
674      *
675      * @param form
676      * @param result
677      * @param request
678      * @param response
679      * @return ModelAndView
680      */
681     @RequestMapping(params = "methodToCall=loan")
682     public ModelAndView loanPatron(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
683                                    HttpServletRequest request, HttpServletResponse response) {
684         Long begin = System.currentTimeMillis();
685         DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
686         LOG.debug("Inside the loan patron method");
687         if (loginUserList == null) {
688             loginUserList = new ArrayList<>();
689         }
690         StringBuffer buffer = new StringBuffer();
691         OleLoanForm oleLoanForm = (OleLoanForm) form;
692         String newPrincipalId = oleLoanForm.getNewPrincipalId();
693         oleLoanForm.setInformation("");
694         oleLoanForm.setSuccessInfo("");
695         oleLoanForm.setReturnInformation("");
696         OleLoanDocument oleLoanDocumentChk = null;
697         ModelAndView overrideModelView = null;
698         if (StringUtils.isBlank(oleLoanForm.getItem())) {
699             try {
700                 String principalId = GlobalVariables.getUserSession().getPrincipalId();
701                 Boolean overRideFlag = getLoanProcessor().checkOverRidePermission(principalId, oleLoanForm);
702                 if (!overRideFlag) {
703                     oleLoanDocumentChk = getLoanProcessor().getLoanDocument(oleLoanForm.getPatronBarcode(), oleLoanForm.getRealPatronBarcode(), oleLoanForm.isSelfCheckOut(), false);
704                     if (oleLoanDocumentChk.getErrorMessage() != null) {
705                         if (!oleLoanForm.getLoanLoginName().equalsIgnoreCase("") || !oleLoanForm.getLoanLoginName().isEmpty()) {
706                             buffer.append(oleLoanForm.getLoanLoginName() + "," + oleLoanForm.getCirculationDesk());
707                             getLoanProcessor().getLoanUserList(loginUserList, buffer);
708                         } else {
709                             if (!oleLoanForm.getOldPrincipalId().equalsIgnoreCase("") || !oleLoanForm.getOldPrincipalId().isEmpty()) {
710                                 buffer.append(oleLoanForm.getOldPrincipalId() + "," + oleLoanForm.getCirculationDesk());
711                                 getLoanProcessor().getLoanUserList(loginUserList, buffer);
712                             }
713                         }
714                         overrideModelView = this.overRide(form, result, request, response);
715                     }
716                 }
717             } catch (Exception e) {
718                 LOG.error("Check for Address Verified and Block Failed." + e.getMessage(), e);
719             }
720         } else {
721             if (!oleLoanForm.getLoanLoginName().equalsIgnoreCase("") || !oleLoanForm.getLoanLoginName().isEmpty()) {
722                 buffer.append(oleLoanForm.getLoanLoginName() + "," + oleLoanForm.getCirculationDesk());
723                 getLoanProcessor().getLoanUserList(loginUserList, buffer);
724             } else {
725                 if (!oleLoanForm.getOldPrincipalId().equalsIgnoreCase("") || !oleLoanForm.getOldPrincipalId().isEmpty()) {
726                     buffer.append(oleLoanForm.getOldPrincipalId() + "," + oleLoanForm.getCirculationDesk());
727                     getLoanProcessor().getLoanUserList(loginUserList, buffer);
728                 }
729             }
730             overrideModelView = this.overRide(form, result, request, response);
731         }
732         if (overrideModelView == null) {
733             try {
734                 List<OleLoanDocument> existingItemList = new ArrayList<OleLoanDocument>();
735                 OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
736                 Timestamp checkinDate = new Timestamp(System.currentTimeMillis());
737                 if (oleLoanDocument != null) {
738                     if (oleLoanDocument.getItemLoanStatus() != null && oleLoanDocument.getItemLoanStatus().equalsIgnoreCase(OLEConstants.ITEM_STATUS_CHECKEDOUT)) {
739                         oleLoanForm.setCheckInItem(oleLoanForm.getItem());
740                         oleLoanForm.setBackGroundCheckIn(true);
741                         //   validateItem(oleLoanForm,result,request,response);
742                         oleLoanForm.setBackUpDummyLoan(oleLoanDocument);
743                         oleLoanDocument = getLoanProcessor().getOleLoanDocumentUsingItemBarcode(oleLoanForm.getCheckInItem());
744                         oleLoanDocument.setCheckInDate(checkinDate);
745                         oleLoanForm.getErrorsAndPermission().clear();
746                         oleLoanDocument = getLoanProcessor().returnLoan(oleLoanForm.getCheckInItem(), oleLoanDocument);
747                         oleLoanForm.setDummyLoan(oleLoanDocument);
748                         if (oleLoanDocument.getErrorMessage() != null) {
749                             oleLoanForm.setSuccess(true);
750                             oleLoanForm.setMessage(null);
751                             oleLoanForm.setReturnSuccess(false);
752                             oleLoanForm.setReturnMessage(oleLoanDocument.getErrorMessage());
753                             return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
754                         }
755                         if (oleLoanDocument.isCopyRequest()) {
756                             oleLoanForm.setSuccess(true);
757                             oleLoanForm.setMessage(null);
758                             oleLoanForm.setCopyRequest(true);
759                             oleLoanForm.setReturnSuccess(false);
760                             oleLoanForm.setReturnMessage(OLEConstants.COPY_REQUEST_FULFILL);
761                             return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
762                         }
763                         if (oleLoanDocument.isNumberOfPieces() || (oleLoanDocument.getOleItem() != null && oleLoanDocument.getOleItem().getNumberOfPieces() != null && !oleLoanDocument.getOleItem().getNumberOfPieces().equalsIgnoreCase(""))) {
764                             oleLoanForm.setSuccess(true);
765                             oleLoanForm.setMessage(null);
766                             oleLoanForm.setNumberOfPieces(true);
767                             oleLoanForm.setReturnSuccess(false);
768                             oleLoanDocument.setContinueCheckIn(true);
769                             oleLoanDocument.setBackgroundCheckInMissingPiece(true);
770                             if (oleLoanDocument.getOleItem() != null && oleLoanDocument.getOleItem().getNumberOfPieces() != null) {
771                                 if (oleLoanDocument.getOleItem().getMissingPieceFlagNote() != null) {
772                                     oleLoanDocument.setDescription(oleLoanDocument.getOleItem().getMissingPieceFlagNote());
773                                 } else {
774                                     oleLoanDocument.setDescription("");
775                                 }
776                             }
777                             if (oleLoanDocument.getItemNumberOfPieces() != null) {
778                                 oleLoanForm.setReturnMessage(OLEConstants.VERIFY_PIECES + oleLoanDocument.getItemNumberOfPieces() + OLEConstants.PIECES_RETURNED
779                                         + OLEConstants.BREAK + "Total No of Pieces :      " + oleLoanDocument.getItemNumberOfPieces() + OLEConstants.BREAK + "No of missing Pieces : " + (oleLoanDocument.getOleItem().getMissingPiecesCount() != null ? oleLoanDocument.getOleItem().getMissingPiecesCount() : "0"));
780                             } else if (oleLoanDocument.getOleItem() != null && oleLoanDocument.getOleItem().getNumberOfPieces() != null) {
781                                 oleLoanForm.setReturnMessage(OLEConstants.VERIFY_PIECES + oleLoanDocument.getOleItem().getNumberOfPieces() + OLEConstants.PIECES_RETURNED
782                                         + OLEConstants.BREAK + "Total No of Pieces :      " + oleLoanDocument.getOleItem().getNumberOfPieces() + OLEConstants.BREAK + "No of missing Pieces : " + (oleLoanDocument.getOleItem().getMissingPiecesCount() != null ? oleLoanDocument.getOleItem().getMissingPiecesCount() : "0"));
783                             }
784                             return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
785                         }
786                         OleLoanForm oleReturnLoanForm = (OleLoanForm) oleLoanForm;
787                         if (oleReturnLoanForm.getDummyLoan() != null) {
788                             oleLoanDocument.setItemLoanStatus(oleReturnLoanForm.getDummyLoan().getItemStatus());
789                             oleLoanForm.getDummyLoan().setItemLoanStatus(oleReturnLoanForm.getDummyLoan().getItemStatus());
790                         }
791                     } else if (oleLoanForm.getBackUpDummyLoan() != null) {
792                         oleLoanDocument = oleLoanForm.getBackUpDummyLoan();
793                         oleLoanDocument.setBackgroundCheckInMissingPiece(oleLoanForm.getDummyLoan().isBackgroundCheckInMissingPiece());
794                         if (oleLoanForm.getDummyLoan() != null) {
795                             oleLoanDocument.setItemLoanStatus(oleLoanForm.getDummyLoan().getItemStatus());
796                             oleLoanDocument.setItemDamagedStatus(oleLoanForm.getDummyLoan().isItemDamagedStatus());
797                             oleLoanDocument.setItemDamagedNote(oleLoanForm.getDummyLoan().getItemDamagedNote());
798                             oleLoanDocument.getOleItem().setMissingPieceFlagNote(oleLoanForm.getMissingPieceMessage());
799                             if (oleLoanDocument.getOleItem() != null) {
800                                 oleLoanDocument.getOleItem().setMissingPiecesCount(oleLoanForm.getDummyLoan().getMissingPiecesCount());
801                                 oleLoanDocument.getOleItem().setMissingPieceFlag(oleLoanForm.getDummyLoan().isMissingPieceFlag());
802                             }
803                         }
804                         oleLoanForm.setBackUpDummyLoan(null);
805                     }
806                     boolean indefinite = false;
807                     if (oleLoanForm.getItem() != null && !oleLoanForm.getItem().isEmpty() && oleLoanForm.getDueDateMap() == null && oleLoanDocument.getExpirationDate() == null) {
808                         indefinite = true;
809                     }
810                     if ((oleLoanForm.getItem() != null && !oleLoanForm.getItem().isEmpty()) || (oleLoanForm.getOleItem() != null && !oleLoanForm.getOleItem().getItemIdentifier().isEmpty()) || indefinite) {
811                         if (oleLoanForm.getDueDateMap() != null) {
812                             Timestamp timestamp;
813                             Pattern pattern;
814                             Matcher matcher;
815                             SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OlePatron.PATRON_MAINTENANCE_DATE_FORMAT);
816                             boolean timeFlag = false;
817                             if (oleLoanForm.getPopDateTime() != null && !oleLoanForm.getPopDateTime().isEmpty()) {
818                                 String[] str = oleLoanForm.getPopDateTime().split(":");
819                                 pattern = Pattern.compile(OLEConstants.TIME_24_HR_PATTERN);
820                                 matcher = pattern.matcher(oleLoanForm.getPopDateTime());
821                                 timeFlag = matcher.matches();
822                                 if (timeFlag) {
823                                     if (str != null && str.length <= 2) {
824                                         oleLoanForm.setPopDateTime(oleLoanForm.getPopDateTime() + OLEConstants.CHECK_IN_TIME_MS);
825                                     }
826                                     timestamp = Timestamp.valueOf(new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT).format(oleLoanForm.getDueDateMap()).concat(" ").concat(oleLoanForm.getPopDateTime()));
827                                 } else {
828                                     oleLoanForm.setPopDateTimeInfo(OLEConstants.DUE_DATE_TIME_FORMAT_MESSAGE);
829                                      /*return getUIFModelAndView(oleLoanForm,"PatronItemViewPage");*/
830                                     return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
831                                 }
832                             } else if (fmt.format(oleLoanForm.getDueDateMap()).compareTo(fmt.format(new Date())) == 0) {
833                                 timestamp = new Timestamp(new Date().getTime());
834                             } else {
835                                 timestamp = Timestamp.valueOf(new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT).format(oleLoanForm.getDueDateMap()).concat(" ").concat(new SimpleDateFormat("HH:mm:ss").format(new Date())));
836                             }
837                             oleLoanDocument.setLoanDueDate(timestamp);
838                         }
839                         if (oleLoanDocument.getItemLoanStatus() != null && !oleLoanDocument.getItemLoanStatus().equalsIgnoreCase(OLEConstants.ITEM_STATUS_CHECKEDOUT) || oleLoanDocument.isBackgroundCheckInMissingPiece()) {
840                             getLoanProcessor().saveLoan(oleLoanForm.getBackUpDummyLoan() != null ? oleLoanForm.getBackUpDummyLoan() : oleLoanDocument);
841                             if (oleLoanForm.getBackUpDummyLoan() != null) {
842                                 oleLoanDocument = oleLoanForm.getBackUpDummyLoan();
843                                 oleLoanDocument.setBackgroundCheckInMissingPiece(oleLoanForm.getDummyLoan().isBackgroundCheckInMissingPiece());
844                                 if (oleLoanForm.getDummyLoan() != null) {
845                                     oleLoanDocument.setItemLoanStatus(oleLoanForm.getDummyLoan().getItemStatus());
846                                     oleLoanDocument.setItemDamagedStatus(oleLoanForm.getDummyLoan().isItemDamagedStatus());
847                                     oleLoanDocument.setItemDamagedNote(oleLoanForm.getDummyLoan().getItemDamagedNote());
848                                     oleLoanDocument.getOleItem().setMissingPieceFlagNote(oleLoanForm.getMissingPieceMessage());
849                                     if (oleLoanDocument.getOleItem() != null) {
850                                         oleLoanDocument.getOleItem().setMissingPiecesCount(oleLoanForm.getDummyLoan().getMissingPiecesCount());
851                                         oleLoanDocument.getOleItem().setMissingPieceFlag(oleLoanForm.getDummyLoan().isMissingPieceFlag());
852                                     }
853                                 }
854                                 oleLoanForm.setBackUpDummyLoan(null);
855                             }
856                             oleLoanForm.setSuccessMessage(oleLoanDocument.getSuccessMessage());
857                             if (!oleLoanForm.isCheckOut())
858                                 existingItemList.add(oleLoanDocument);
859                             oleLoanDocument.setBackgroundCheckInMissingPiece(false);
860                         }
861 
862                         if (oleLoanForm.getLoanList() != null && !oleLoanForm.getLoanList().isEmpty()) {
863                             existingItemList.addAll(oleLoanForm.getLoanList());
864                         }
865                         oleLoanForm.setLoanList(existingItemList);
866                     }
867                     if (StringUtils.isNotEmpty(oleLoanDocument.getItemUuid())) {
868                         org.kuali.ole.docstore.common.document.Item item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(oleLoanDocument.getItemUuid());
869                         String itemXmlContent = item.getContent();
870                         // String itemXmlContent = getLoanProcessor().getItemXML(oleLoanDocument.getItemUuid());
871                         Item oleItem = getLoanProcessor().getItemPojo(itemXmlContent);
872                         if(StringUtils.isBlank(oleLoanDocument.getLocation())){
873                            getLoanProcessor().getLocation(oleItem, oleLoanDocument, item);
874                         }
875                         if (oleLoanDocument.getLocation() == null || oleLoanDocument.getLocation().isEmpty()) {
876                             getLoanProcessor().getDefaultHoldingLocation(oleLoanDocument);
877                         }
878                         if (oleLoanDocument.getCheckInDate() == null) {
879                             oleLoanDocument.setCheckInDate(checkinDate);
880                         }
881                         if (oleLoanDocument.getOleCirculationDesk() == null) {
882                             oleLoanDocument.setCirculationLocationId(oleLoanForm.getCirculationDesk());
883                         }
884                         if (oleItem.isMissingPieceFlag()) {
885                             oleLoanDocument.setMissingPieceNote(oleItem.getMissingPieceFlagNote());
886                             oleLoanDocument.setMissingPieceFlag(oleItem.isMissingPieceFlag());
887                         }
888                         if (oleItem.isItemDamagedStatus()) {
889                             oleLoanDocument.setItemDamagedNote(oleItem.getDamagedItemNote());
890                         }
891                         if (oleLoanForm.getPatronName() == null) {
892                             oleLoanForm.setPatronName(oleLoanDocument.getPatronName());
893                         }
894                         if (oleItem.isClaimsReturnedFlag()) {
895                             if (oleItem.getClaimsReturnedFlagCreateDate() != null)
896                                 oleLoanDocument.setClaimsReturnedDate(new Timestamp(df.parse(oleItem.getClaimsReturnedFlagCreateDate()).getTime()));
897                             oleLoanDocument.setClaimsReturnedIndicator(true);
898                             oleLoanDocument.setClaimsReturnNote(oleItem.getClaimsReturnedNote());
899                         }
900                         if (oleLoanForm.getPatronName() == null) {
901                             oleLoanForm.setPatronName(oleLoanDocument.getPatronName());
902                         }
903                         if (oleLoanForm.isCheckOut()) {
904                             if (!oleLoanDocument.getItemLoanStatus().equalsIgnoreCase(OLEConstants.ITEM_STATUS_CHECKEDOUT))
905                                 getLoanProcessor().saveLoan(oleLoanForm.getBackUpDummyLoan() != null ? oleLoanForm.getBackUpDummyLoan() : oleLoanDocument);
906                             oleLoanForm.setSuccessMessage(oleLoanDocument.getSuccessMessage());
907                             List<OleLoanDocument> oleLoanDocuments = new ArrayList<OleLoanDocument>();
908                             if (oleLoanDocument.getOleItem().getItemStatus() != null) {
909                                 oleLoanDocument.setItemStatusCode(oleLoanDocument.getOleItem().getItemStatus().getCodeValue());
910                             } else {
911                                 oleLoanDocument.setItemStatusCode(oleLoanDocument.getItemLoanStatus());
912                             }
913                             OleItemAvailableStatus oleItemAvailableStatus = getLoanProcessor().validateAndGetItemStatus(oleLoanDocument.getItemStatusCode());
914                             oleLoanDocument.setItemStatus(oleItemAvailableStatus != null ? oleItemAvailableStatus.getItemAvailableStatusName() : null);
915                             oleLoanDocument.setDescription(oleLoanForm.getDescription());
916                             oleLoanDocuments.add(oleLoanDocument);
917                             if (oleLoanForm.getItemReturnList() != null) {
918                                 oleLoanDocuments.addAll(oleLoanForm.getItemReturnList());
919                             }
920                             oleLoanForm.setItemReturnList(oleLoanDocuments);
921                             if (oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isPrintSlip()) {
922                                 if (oleLoanDocument.getOleItem().isMissingPieceFlag()) {
923                                     OleNoticeBo oleNoticeBo = getLoanProcessor().getNotice(oleLoanDocument);
924                                     // SimpleDateFormat simpleDateFormat = new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT);
925                                     SimpleDateFormat dateFormat = new SimpleDateFormat(OLEConstants.DATEFORMAT);
926                                     Date date = new Date(oleLoanDocument.getCheckInDate().getTime());
927                                     if (oleNoticeBo != null) {
928                                         oleNoticeBo.setCheckInDate(dateFormat.format(date));
929                                         String missingNoticeDetails = getOleDeliverBatchService().sendMissingNotice(oleNoticeBo);
930                                         OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
931                                         String replyToEmail = getCircDeskLocationResolver().getReplyToEmail(oleNoticeBo.getItemShelvingLocation());
932                                         if (replyToEmail!=null){
933                                             oleMailer.sendEmail(new EmailFrom(replyToEmail), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
934                                         }else {
935                                             String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
936                                             if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
937                                                 fromAddress = OLEConstants.KUALI_MAIL;
938                                             }
939                                             oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
940                                         }
941                                         if (LOG.isInfoEnabled()) {
942                                             LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
943                                         }
944                                     }
945                                 } else {
946                                     if (oleLoanDocument.getItemStatusCode() != null && oleLoanDocument.getItemStatusCode().equals(OLEConstants.ITEM_STATUS_ON_HOLD) && oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isHoldQueue()) {
947                                         oleLoanForm.setBillAvailability(false);
948                                     } else {
949                                         oleLoanForm.setBillAvailability(true);
950                                     }
951                                 }
952                             }
953                             if (oleLoanDocument.isCheckOut()) {
954                                 oleLoanForm.setDueDateSlip(true);
955                                 oleLoanForm.setBillAvailability(false);
956                             }
957                             oleLoanForm.setReturnSuccess(true);
958                             oleLoanForm.setCheckOut(false);
959                         }
960                         oleLoanForm.setSuccess(true);
961                         oleLoanForm.setMessage(null);
962                         oleLoanForm.setItem("");
963                         oleLoanForm.setInformation("");
964                         oleLoanForm.setPopDateTimeInfo("");
965                         oleLoanForm.setAddressVerified(false);
966                         if (oleLoanDocument.isClaimsReturnedIndicator()) {
967                             saveGeneralNoteForFlaggedItem(OLEConstants.CLAIMS_CHECKED_OUT_FLAG, true, oleLoanDocument, true, false, oleLoanForm.isBackGroundCheckIn(), oleLoanForm.getPatronBarcode());
968                         }
969                     }
970                     if (oleLoanDocument.isMissingPieceFlag() || oleLoanDocument.isItemDamagedStatus()) {
971                         flaggedNoteSave(form, result, request, response);
972                     }
973                 }
974             } catch (Exception e) {
975                 oleLoanForm.setInformation(e.getMessage());
976                 LOG.error("Exception", e);
977             }
978         }
979         /*if (StringUtils.isNotEmpty(newPrincipalId)) {
980             if (getLoanProcessor().isValidCirculationDesk()) {
981                 if (getLoanProcessor().getCircDeskId() != null) {
982                     //oleLoanForm.setCirculationDesk(getLoanProcessor().getCircDeskId());
983                 }
984             }
985         }*/
986         oleLoanForm.setOleFormKey(oleLoanForm.getFormKey());
987         String audioOption = getLoanProcessor().getParameter(OLEConstants.AUDIO_OPTION);
988         oleLoanForm.setAudioEnable(audioOption != null && !audioOption.isEmpty() && audioOption.equalsIgnoreCase(OLEConstants.TRUE));
989         oleLoanForm.setItemUuid(null);
990         oleLoanForm.setInstanceUuid(null);
991         if (oleLoanForm.getDummyLoan() != null && oleLoanForm.getDummyLoan().getOlePatron() != null && oleLoanForm.getDummyLoan().getErrorMessage() != null) {
992             oleLoanForm.setMessage(null);
993             oleLoanForm.setBlockPatron(false);
994             oleLoanForm.setBlockItem(false);
995             oleLoanForm.setSuccess(true);
996         }
997         Long end = System.currentTimeMillis();
998         Long timeTaken = end - begin;
999         LOG.info("-----------TimeTaken to complete override loan-----------"+timeTaken);
1000         return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
1001     }
1002 
1003     /**
1004      * This method doesn't allow a patron to be loaned.
1005      *
1006      * @param form
1007      * @param result
1008      * @param request
1009      * @param response
1010      * @return ModelAndView
1011      */
1012     @RequestMapping(params = "methodToCall=noLoan")
1013     public ModelAndView doNotLoanPatron(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1014                                         HttpServletRequest request, HttpServletResponse response) {
1015         LOG.debug("Inside the do not loan patron method");
1016         OleLoanForm oleLoanForm = (OleLoanForm) form;
1017         OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
1018         if (oleLoanForm.isCheckOut()) {
1019             List<OleLoanDocument> oleLoanDocuments = new ArrayList<OleLoanDocument>();
1020             if (oleLoanDocument.getOleItem().getItemStatus() != null) {
1021                 oleLoanDocument.setItemStatusCode(oleLoanDocument.getOleItem().getItemStatus().getCodeValue());
1022             } else {
1023                 oleLoanDocument.setItemStatusCode(oleLoanDocument.getItemLoanStatus());
1024             }
1025             OleItemAvailableStatus oleItemAvailableStatus = getLoanProcessor().validateAndGetItemStatus(oleLoanDocument.getItemStatusCode());
1026             oleLoanDocument.setItemStatus(oleItemAvailableStatus != null ? oleItemAvailableStatus.getItemAvailableStatusName() : null);
1027             oleLoanDocuments.add(oleLoanDocument);
1028             if (oleLoanForm.getItemReturnList() != null) {
1029                 oleLoanDocuments.addAll(oleLoanForm.getItemReturnList());
1030             }
1031             if (oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isPrintSlip()) {
1032                 if (oleLoanDocument.getOleItem().isMissingPieceFlag()) {
1033                     OleNoticeBo oleNoticeBo = getLoanProcessor().getNotice(oleLoanDocument);
1034                     //SimpleDateFormat simpleDateFormat=new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT);
1035                     SimpleDateFormat dateFormat = new SimpleDateFormat(OLEConstants.DATEFORMAT);
1036                     Date date = new Date(oleLoanDocument.getCheckInDate().getTime());
1037                     if (oleNoticeBo != null) {
1038                         oleNoticeBo.setCheckInDate(dateFormat.format(date));
1039                         String missingNoticeDetails = getOleDeliverBatchService().sendMissingNotice(oleNoticeBo);
1040                         OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
1041                         String replyToEmail = getCircDeskLocationResolver().getReplyToEmail(oleNoticeBo.getItemShelvingLocation());
1042                         if (replyToEmail != null) {
1043                             oleMailer.sendEmail(new EmailFrom(replyToEmail), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
1044                         } else {
1045                             String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
1046                             if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
1047                                 fromAddress = OLEConstants.KUALI_MAIL;
1048                             }
1049                             oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
1050                         }
1051                         if (LOG.isInfoEnabled()) {
1052                             LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
1053                         }
1054                     }
1055                 } else {
1056                     if (oleLoanDocument.getItemStatusCode() != null && oleLoanDocument.getItemStatusCode().equals(OLEConstants.ITEM_STATUS_ON_HOLD) && oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isHoldQueue()) {
1057                         oleLoanForm.setBillAvailability(false);
1058                     } else {
1059                         oleLoanForm.setBillAvailability(true);
1060                     }
1061                 }
1062             }
1063             oleLoanForm.setItemReturnList(oleLoanDocuments);
1064             oleLoanForm.setReturnSuccess(true);
1065             oleLoanForm.setCheckOut(false);
1066             String audioOption = getLoanProcessor().getParameter(OLEConstants.AUDIO_OPTION);
1067             oleLoanForm.setAudioEnable(audioOption != null && !audioOption.isEmpty() && audioOption.equalsIgnoreCase(OLEConstants.TRUE));
1068         }
1069         if (oleLoanForm.getItem() == null || "".equals(oleLoanForm.getItem())) {
1070             clearPatronScreen(oleLoanForm, result, request, response);
1071         }
1072         oleLoanForm.setAddressVerified(false);
1073         oleLoanForm.setItem("");
1074         oleLoanForm.setInformation("");
1075         oleLoanForm.setReturnInformation("");
1076         oleLoanForm.setDueDateSlip(false);
1077         oleLoanForm.setMessage(null);
1078         oleLoanForm.setSuccess(true);
1079         oleLoanForm.setItemUuid(null);
1080         oleLoanForm.setInstanceUuid(null);
1081         return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
1082     }
1083 
1084     /**
1085      * Display the Fast-Add item dialog.
1086      *
1087      * @param form
1088      * @param result
1089      * @param request
1090      * @param response
1091      * @return
1092      */
1093     @RequestMapping(params = "methodToCall=openFastAdd")
1094     public ModelAndView openFastAdd(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1095                                     HttpServletRequest request, HttpServletResponse response) {
1096         LOG.debug("Inside the openFastAdd method");
1097         OleLoanForm oleLoanForm = (OleLoanForm) form;
1098         oleLoanForm.setFastAddItemIndicator(true);
1099         String url = ConfigContext.getCurrentContextConfig().getProperty("ole.fs.url.base") + "/ole-kr-krad/fastAddController?viewId=FastAddItemView&methodToCall=start";
1100         oleLoanForm.setFastAddUrl(url);
1101         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1102     }
1103 
1104 
1105     /**
1106      * Delete the patron user note.
1107      *
1108      * @param form
1109      * @param result
1110      * @param request
1111      * @param response
1112      * @return
1113      */
1114     @RequestMapping(params = "methodToCall=deletePatronUserNote")
1115     public ModelAndView deletePatronUserNote(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1116                                              HttpServletRequest request, HttpServletResponse response) {
1117         LOG.debug("Inside the delete patron user note method");
1118         OleLoanForm oleLoanForm = (OleLoanForm) form;
1119         oleLoanForm.setPatronNoteFlag(false);
1120         try {
1121             getLoanProcessor().deletePatronUserNote(oleLoanForm.getPatronId(), oleLoanForm.getPatronNoteTypeId());
1122         } catch (Exception e) {
1123             oleLoanForm.setInformation(e.getMessage());
1124             LOG.error("Exception while deleting patron user note", e);
1125         }
1126         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1127     }
1128 
1129     /**
1130      * Display the Alter due date dialog.
1131      *
1132      * @param form
1133      * @param result
1134      * @param request
1135      * @param response
1136      * @return
1137      */
1138     @RequestMapping(params = "methodToCall=editDueDate")
1139     public ModelAndView editDueDate(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1140                                     HttpServletRequest request, HttpServletResponse response) {
1141         LOG.debug("Inside the edit due date method");
1142         if (loginUserList == null) {
1143             loginUserList = new ArrayList<>();
1144         }
1145         StringBuffer buffer = new StringBuffer();
1146         OleLoanForm oleLoanForm = (OleLoanForm) form;
1147         oleLoanForm.setInformation("");
1148         oleLoanForm.setSuccessInfo("");
1149         oleLoanForm.setReturnInformation("");
1150         List<OleLoanDocument> alterDueDateList = new ArrayList<OleLoanDocument>();
1151         alterDueDateList = getLoanProcessor().setListValues(oleLoanForm.getLoanList(), oleLoanForm.getExistingLoanList(), false, null, false);
1152 
1153         if (alterDueDateList.size() != 0) {
1154             oleLoanForm.setAlterDueDateList(alterDueDateList);
1155             oleLoanForm.setInformation("");
1156             if (!oleLoanForm.getLoanLoginName().equalsIgnoreCase("") || !oleLoanForm.getLoanLoginName().isEmpty()) {
1157                 buffer.append(oleLoanForm.getLoanLoginName() + "," + oleLoanForm.getCirculationDesk());
1158                 getLoanProcessor().getLoanUserList(loginUserList, buffer);
1159             } else {
1160                 if (!oleLoanForm.getOldPrincipalId().equalsIgnoreCase("") || !oleLoanForm.getOldPrincipalId().isEmpty()) {
1161                     buffer.append(oleLoanForm.getOldPrincipalId() + "," + oleLoanForm.getCirculationDesk());
1162                     getLoanProcessor().getLoanUserList(loginUserList, buffer);
1163                 }
1164             }
1165             ModelAndView overrideModelView = this.overRide(form, result, request, response);
1166            // if (getLoanProcessor().isValidCirculationDesk()) {
1167                 // if(loanProcessor.getCircDeskId()!=null){
1168                 //oleLoanForm.setCirculationDesk(loanProcessor.getCircDeskId());
1169                 // }
1170            // }
1171             if (overrideModelView == null){
1172                 oleLoanForm.setAlterDueDateFlag(true);
1173             }
1174         } else{
1175             oleLoanForm.setInformation(OLEConstants.ALTER_DUE_DATE_ERR_INFO);
1176         }
1177 
1178         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1179     }
1180 
1181     /**
1182      * Update the modified due date in loan.
1183      *
1184      * @param form
1185      * @param result
1186      * @param request
1187      * @param response
1188      * @return
1189      */
1190     @RequestMapping(params = "methodToCall=updateDueDate")
1191     public ModelAndView updateDueDate(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1192                                       HttpServletRequest request, HttpServletResponse response) {
1193         LOG.debug("Inside the update due date method");
1194         OleLoanForm oleLoanForm = (OleLoanForm) form;
1195         oleLoanForm.setInformation("");
1196         oleLoanForm.setSuccessInfo("");
1197         oleLoanForm.setReturnInformation("");
1198         boolean timeFlag = true;
1199         try {
1200             oleLoanForm.setAlterDueDateTimeInfo("");
1201             timeFlag = getLoanProcessor().updateLoan(oleLoanForm.getAlterDueDateList(),oleLoanForm.getPatronId(), false, false,oleLoanForm.getBorrowerCode());
1202             if (!timeFlag) {
1203                 oleLoanForm.setAlterDueDateTimeInfo(OLEConstants.ALTER_DUE_DATE_TIME_FORMAT_MESSAGE);
1204                 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1205             }
1206             // getLoanProcessor().updateItem(oleLoanForm.getAlterDueDateList(), false, false);
1207         } catch (Exception e) {
1208             oleLoanForm.setInformation(e.getMessage());
1209             LOG.error("Exception while updating due date", e);
1210         }
1211         oleLoanForm.setAlterDueDateFlag(false);
1212         List<OleLoanDocument> sortedExistingLoanList = oleLoanForm.getExistingLoanList();
1213         List<OleLoanDocument> LoanDocumentList = new ArrayList<>();
1214         List<OleLoanDocument> indefiniteLoanDocumentList = new ArrayList<>();
1215         for (OleLoanDocument loanDoc : sortedExistingLoanList) {
1216             if (loanDoc.getLoanDueDate() != null && !(loanDoc.getLoanDueDate().toString().isEmpty())) {
1217                 LoanDocumentList.add(loanDoc);
1218             } else {
1219                 indefiniteLoanDocumentList.add(loanDoc);
1220             }
1221 
1222         }
1223         Collections.sort(LoanDocumentList, new Comparator<OleLoanDocument>() {
1224             public int compare(OleLoanDocument o1, OleLoanDocument o2) {
1225                 return o1.getLoanDueDate().compareTo(o2.getLoanDueDate());
1226             }
1227         });
1228         LoanDocumentList.addAll(indefiniteLoanDocumentList);
1229         oleLoanForm.setExistingLoanList(LoanDocumentList);
1230         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1231     }
1232 
1233     /**
1234      * Close the Alter due date dialog.
1235      *
1236      * @param form
1237      * @param result
1238      * @param request
1239      * @param response
1240      * @return
1241      */
1242     @RequestMapping(params = "methodToCall=closeAlterDueDate")
1243     public ModelAndView closeAlterDueDate(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1244                                           HttpServletRequest request, HttpServletResponse response) {
1245         LOG.debug("Inside the close Alter due date method");
1246         OleLoanForm oleLoanForm = (OleLoanForm) form;
1247         /*String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
1248         if (LOG.isInfoEnabled()){
1249             LOG.info("session timeout" + maxSessionTime);
1250         }
1251         if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
1252             oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));*/
1253         List<OleLoanDocument> resetAlterDueDate = oleLoanForm.getAlterDueDateList();
1254         if (resetAlterDueDate != null) {
1255             for (int restDueDate = 0; restDueDate < resetAlterDueDate.size(); restDueDate++) {
1256                 OleLoanDocument oleLoanDocument = (OleLoanDocument) resetAlterDueDate.get(restDueDate);
1257                 if(oleLoanDocument!=null){
1258                     oleLoanDocument.setLoanDueDate(new Timestamp(oleLoanDocument.getPastDueDate().getTime()));
1259                     oleLoanDocument.setPastDueDate(null);
1260                 }
1261             }
1262         }
1263 
1264         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1265     }
1266 
1267     /**
1268      * Display the claims return dialog.
1269      *
1270      * @param form
1271      * @param result
1272      * @param request
1273      * @param response
1274      * @return
1275      */
1276     @RequestMapping(params = "methodToCall=claimsReturn")
1277     public ModelAndView claimsReturn(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1278                                      HttpServletRequest request, HttpServletResponse response) {
1279         LOG.debug("Inside the claims return method");
1280         if (loginUserList == null) {
1281             loginUserList = new ArrayList<>();
1282         }
1283         StringBuffer buffer = new StringBuffer();
1284         OleLoanForm oleLoanForm = (OleLoanForm) form;
1285         oleLoanForm.setInformation("");
1286         oleLoanForm.setSuccessInfo("");
1287         oleLoanForm.setReturnInformation("");
1288         oleLoanForm.setRemoveClaimsReturnFlag(false);
1289         boolean checkedItemsFlag = false;
1290         if (oleLoanForm.getLoanList().size() > 0) {
1291             for (int currentLoan = 0; currentLoan < oleLoanForm.getLoanList().size(); currentLoan++) {
1292                 OleLoanDocument oleLoanDocument = (OleLoanDocument) oleLoanForm.getLoanList().get(currentLoan);
1293                 if (oleLoanDocument.isCheckNo()) {
1294                     try {
1295                         String itemXmlContent = getLoanProcessor().getItemXML(oleLoanDocument.getItemUuid());
1296                         Item oleItem = getLoanProcessor().getItemPojo(itemXmlContent);
1297                         oleLoanForm.setClaimsReturnNote(oleItem.getClaimsReturnedNote());
1298                         oleLoanForm.setItemClaimsReturnFlag(oleItem.isClaimsReturnedFlag());
1299                     } catch (Exception e) {
1300                         throw new RuntimeException();
1301                     }
1302                     checkedItemsFlag = true;
1303                     break;
1304                 }
1305             }
1306         }
1307         if (oleLoanForm.getExistingLoanList().size() > 0) {
1308             for (int currentLoan = 0; currentLoan < oleLoanForm.getExistingLoanList().size(); currentLoan++) {
1309                 OleLoanDocument oleLoanDocument = (OleLoanDocument) oleLoanForm.getExistingLoanList().get(currentLoan);
1310                 if (oleLoanDocument.isCheckNo()) {
1311                     try {
1312                         String itemXmlContent = getLoanProcessor().getItemXML(oleLoanDocument.getItemUuid());
1313                         Item oleItem = getLoanProcessor().getItemPojo(itemXmlContent);
1314                         oleLoanForm.setItemClaimsReturnFlag(oleItem.isClaimsReturnedFlag());
1315                         oleLoanForm.setClaimsReturnNote(oleItem.getClaimsReturnedNote());
1316                     } catch (Exception e) {
1317                         throw new RuntimeException();
1318                     }
1319                     checkedItemsFlag = true;
1320                     break;
1321                 }
1322             }
1323         }
1324         if (checkedItemsFlag) {
1325             oleLoanForm.setInformation("");
1326             if (!oleLoanForm.getLoanLoginName().equalsIgnoreCase("") || !oleLoanForm.getLoanLoginName().isEmpty()) {
1327                 buffer.append(oleLoanForm.getLoanLoginName() + "," + oleLoanForm.getCirculationDesk());
1328                 getLoanProcessor().getLoanUserList(loginUserList, buffer);
1329             } else {
1330                 if (!oleLoanForm.getOldPrincipalId().equalsIgnoreCase("") || !oleLoanForm.getOldPrincipalId().isEmpty()) {
1331                     buffer.append(oleLoanForm.getOldPrincipalId() + "," + oleLoanForm.getCirculationDesk());
1332                     getLoanProcessor().getLoanUserList(loginUserList, buffer);
1333                 }
1334             }
1335             ModelAndView overrideModelView = this.overRide(form, result, request, response);
1336            // if (getLoanProcessor().isValidCirculationDesk()) {
1337                 // if(loanProcessor.getCircDeskId()!=null){
1338                 // oleLoanForm.setCirculationDesk(loanProcessor.getCircDeskId());
1339                 //  }
1340            // }
1341             if (overrideModelView == null)
1342                 oleLoanForm.setClaimsReturnFlag(true);
1343         } else
1344             oleLoanForm.setInformation(OLEConstants.CLAIMS_ITM_ERR_INFO);
1345         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1346     }
1347 
1348     /**
1349      * Save the claims return note in loan.
1350      *
1351      * @param form
1352      * @param result
1353      * @param request
1354      * @param response
1355      * @return
1356      */
1357     @RequestMapping(params = "methodToCall=applyClaimsReturn")
1358     public ModelAndView applyClaimsReturn(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1359                                           HttpServletRequest request, HttpServletResponse response) {
1360         LOG.debug("Inside the apply claims return method");
1361         OleLoanForm oleLoanForm = (OleLoanForm) form;
1362         oleLoanForm.setInformation("");
1363         oleLoanForm.setSuccessInfo("");
1364         oleLoanForm.setReturnInformation("");
1365         List<OleLoanDocument> claimsList = new ArrayList<OleLoanDocument>();
1366         claimsList = getLoanProcessor().setListValues(oleLoanForm.getLoanList(), oleLoanForm.getExistingLoanList(), oleLoanForm.isClaimsReturnFlag(), oleLoanForm.getClaimsReturnNote(), oleLoanForm.isRemoveClaimsReturnFlag());
1367         try {
1368             getLoanProcessor().updateLoan(claimsList, oleLoanForm.getPatronId(), true, oleLoanForm.isRemoveClaimsReturnFlag(),oleLoanForm.getBorrowerCode());
1369             //   getLoanProcessor().updateItem(claimsList, true, oleLoanForm.isRemoveClaimsReturnFlag());
1370         } catch (Exception e) {
1371             LOG.error("Exception while setting claims return", e);
1372             oleLoanForm.setInformation(e.getMessage());
1373         }
1374         oleLoanForm.setClaimsReturnFlag(false);
1375         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1376     }
1377 
1378 
1379     @RequestMapping(params = "methodToCall=showMissingPieceDialogBox")
1380     public ModelAndView showMissingPieceDialogBox(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1381                                                   HttpServletRequest request, HttpServletResponse response) {
1382         OleLoanForm oleLoanForm = (OleLoanForm) form;
1383         int count = 0;
1384         oleLoanForm.setDialogFlag(false);
1385         oleLoanForm.setDialogItemNoOfPieces(null);
1386         oleLoanForm.setDialogMissingPieceCount(null);
1387         oleLoanForm.setDialogText(null);
1388         oleLoanForm.setDialogItemNoOfPiecesReadOnly(false);
1389         oleLoanForm.setDialogMissingPieceCountReadOnly(false);
1390         oleLoanForm.setDialogErrorMessage(null);
1391         oleLoanForm.setInformation("");
1392         oleLoanForm.setSuccessInfo("");
1393         OleLoanDocument loanDocument = new OleLoanDocument();
1394         if (oleLoanForm.getLoanList().size() > 0) {
1395             for (OleLoanDocument oleLoanDocument : oleLoanForm.getLoanList()) {
1396                 if (oleLoanDocument.isCheckNo()) {
1397                     loanDocument = oleLoanDocument;
1398                     count++;
1399                 }
1400             }
1401         }
1402         if (oleLoanForm.getExistingLoanList().size() > 0) {
1403             for (OleLoanDocument oleLoanDocument : oleLoanForm.getExistingLoanList()) {
1404                 if (oleLoanDocument.isCheckNo()) {
1405                     loanDocument = oleLoanDocument;
1406                     count++;
1407                 }
1408             }
1409         }
1410         if (count == 1) {
1411             try {
1412                 String itemXmlContent = getLoanProcessor().getItemXML(loanDocument.getItemUuid());
1413                 Item oleItem = getLoanProcessor().getItemPojo(itemXmlContent);
1414                 oleLoanForm.setDialogText(oleItem.getMissingPieceFlagNote());
1415                 if (!oleItem.isMissingPieceFlag()) {
1416                     oleLoanForm.setDialogFlag(true);
1417                 } else {
1418                     oleLoanForm.setRemoveMissingPieceButton(true);
1419                 }
1420                 oleLoanForm.setDialogMissingPieceCount(oleItem.getMissingPiecesCount());
1421                 oleLoanForm.setDialogItemNoOfPieces(oleItem.getNumberOfPieces());
1422                 if (oleItem.getNumberOfPieces() != null && !oleItem.getNumberOfPieces().equalsIgnoreCase("")) {
1423                     oleLoanForm.setDialogItemNoOfPiecesReadOnly(true);
1424                 }
1425                 if (oleItem.isMissingPieceFlag()) {
1426                     if (oleItem.getMissingPiecesCount() != null && !oleItem.getMissingPiecesCount().equalsIgnoreCase("")) {
1427                         oleLoanForm.setDialogMissingPieceCountReadOnly(true);
1428                     }
1429 
1430                 }
1431             } catch (Exception e) {
1432                 throw new RuntimeException();
1433             }
1434             oleLoanForm.setMissingPieceDialog(true);
1435             oleLoanForm.setMissingPieceLoanDocument(loanDocument);
1436         } else
1437             oleLoanForm.setInformation(OLEConstants.SELECT_SINGLE_ITEM);
1438 
1439         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1440     }
1441 
1442     /**
1443      * Save the claims return note in loan.
1444      *
1445      * @param form
1446      * @param result
1447      * @param request
1448      * @param response
1449      * @return
1450      */
1451     @RequestMapping(params = "methodToCall=updateMissingPieceItem")
1452     public ModelAndView updateMissingPieceItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1453                                                HttpServletRequest request, HttpServletResponse response) {
1454         LOG.debug("Inside the claims return method");
1455         if (loginUserList == null) {
1456             loginUserList = new ArrayList<>();
1457         }
1458         MissingPieceItemRecord missingPieceItemRecord = new MissingPieceItemRecord();
1459         StringBuffer buffer = new StringBuffer();
1460         OleLoanForm oleLoanForm = (OleLoanForm) form;
1461        /* String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
1462         if (LOG.isInfoEnabled()){
1463             LOG.info("session timeout" + maxSessionTime);
1464         }
1465         if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
1466             oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));*/
1467         SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
1468         String parsedDate = df.format((new Date()));
1469         OleLoanDocument loanDocument = oleLoanForm.getMissingPieceLoanDocument();
1470         if (oleLoanForm.getDialogItemNoOfPieces() == null || oleLoanForm.getDialogItemNoOfPieces() != null && oleLoanForm.getDialogItemNoOfPieces().equalsIgnoreCase("")) {
1471             oleLoanForm.setDialogErrorMessage("Provide information for no of pieces");
1472             oleLoanForm.setDialogItemNoOfPiecesReadOnly(false);
1473             oleLoanForm.setMissingPieceDialog(true);
1474             return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1475         }
1476         if (oleLoanForm.getDialogMissingPieceCount() != null && oleLoanForm.getDialogItemNoOfPieces().equalsIgnoreCase("")) {
1477             int noOfPiece = Integer.parseInt(oleLoanForm.getDialogItemNoOfPieces());
1478             if (noOfPiece < 1) {
1479                 oleLoanForm.setMissingPieceDialog(true);
1480                 oleLoanForm.setDialogItemNoOfPiecesReadOnly(false);
1481                 oleLoanForm.setDialogErrorMessage(OLEConstants.ERROR_MISSING_ITEM_NO_GREATER);
1482                 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1483             }
1484         }
1485         oleLoanForm.setDialogItemNoOfPiecesReadOnly(true);
1486         if (oleLoanForm.getDialogMissingPieceCount() == null || (oleLoanForm.getDialogMissingPieceCount() != null && oleLoanForm.getDialogMissingPieceCount().equalsIgnoreCase(""))) {
1487             oleLoanForm.setMissingPieceDialog(true);
1488             oleLoanForm.setDialogMissingPieceCountReadOnly(false);
1489             oleLoanForm.setDialogErrorMessage(OLEConstants.ERROR_MISSING_ITEM_COUNT_REQUIRED);
1490             return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1491         }
1492         if (oleLoanForm.getDialogMissingPieceCount() != null && !oleLoanForm.getDialogMissingPieceCount().equalsIgnoreCase("")) {
1493             int count = Integer.parseInt(oleLoanForm.getDialogMissingPieceCount());
1494             int noOfPiece = Integer.parseInt(oleLoanForm.getDialogItemNoOfPieces());
1495             if (count < 1) {
1496                 oleLoanForm.setMissingPieceDialog(true);
1497                 oleLoanForm.setDialogErrorMessage(OLEConstants.ERROR_MISSING_COUNT_NO_LESS);
1498                 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1499             }
1500             if (count > noOfPiece) {
1501                 oleLoanForm.setMissingPieceDialog(true);
1502                 oleLoanForm.setDialogMissingPieceCountReadOnly(false);
1503                 oleLoanForm.setDialogErrorMessage(OLEConstants.ERROR_MISSING_ITEM_GREATER_COUNT);
1504                 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1505             }
1506         }
1507 
1508         if (oleLoanForm.getMissingPieceLoanDocument() != null && oleLoanForm.getMissingPieceLoanDocument().getItemUuid() != null) {
1509             org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
1510             try {
1511                 boolean isMissingPieceFlag = false;
1512                 String itemXmlContent = getLoanProcessor().getItemXML(oleLoanForm.getMissingPieceLoanDocument().getItemUuid());
1513                 Item oleItem = getLoanProcessor().getItemPojo(itemXmlContent);
1514                 boolean isUpdateNote=false;
1515                 boolean isCreateNote=false;
1516                 boolean isMissingFlagEnabledDB=(oleItem != null && oleItem.isMissingPieceFlag())?true:false;
1517                 isCreateNote=!isMissingFlagEnabledDB && !oleLoanForm.isRemoveMissingPieceFlag();
1518                 isUpdateNote=isMissingFlagEnabledDB && !oleLoanForm.isRemoveMissingPieceFlag();
1519                 if (oleLoanForm.isRemoveMissingPieceFlag()) {
1520                     oleItem.setMissingPieceFlag(false);
1521                     isMissingPieceFlag = false;
1522                 } else {
1523                     oleItem.setMissingPieceFlag(true);
1524                     isMissingPieceFlag = true;
1525                 }
1526                 if(isCreateNote){
1527                     missingPieceItemRecord.setMissingPieceCount(oleLoanForm.getDialogMissingPieceCount());
1528                     missingPieceItemRecord.setMissingPieceFlagNote(oleLoanForm.getDialogText());
1529                     missingPieceItemRecord.setMissingPieceDate(parsedDate);
1530                     missingPieceItemRecord.setItemId(oleLoanForm.getMissingPieceLoanDocument().getItemUuid());
1531                     missingPieceItemRecord.setOperatorId(GlobalVariables.getUserSession().getPrincipalId());
1532                     missingPieceItemRecord.setPatronBarcode(oleLoanForm.getPatronBarcode());
1533 
1534                     if(CollectionUtils.isNotEmpty(oleItem.getMissingPieceItemRecordList())){
1535 
1536                         oleItem.getMissingPieceItemRecordList().add(missingPieceItemRecord);
1537                     } else {
1538                         List<MissingPieceItemRecord> missingPieceItemRecords=new ArrayList<MissingPieceItemRecord>();
1539                         missingPieceItemRecords.add(missingPieceItemRecord);
1540                         oleItem.setMissingPieceItemRecordList(missingPieceItemRecords);
1541                     }
1542                 }else{
1543                     if(isUpdateNote){
1544                         /*missingPieceItemRecord.setMissingPieceCount(oleLoanForm.getDialogMissingPieceCount());
1545                         missingPieceItemRecord.setMissingPieceFlagNote(oleLoanForm.getDialogText());
1546                         missingPieceItemRecord.setMissingPieceDate(parsedDate);
1547                         missingPieceItemRecord.setItemId(oleLoanForm.getMissingPieceLoanDocument().getItemUuid());
1548                         missingPieceItemRecord.setOperatorId(GlobalVariables.getUserSession().getPrincipalId());
1549                         missingPieceItemRecord.setPatronBarcode(oleLoanForm.getPatronBarcode());
1550                         if(CollectionUtils.isNotEmpty(oleItem.getMissingPieceItemRecordList())){
1551 
1552                             oleItem.getMissingPieceItemRecordList().add(missingPieceItemRecord);
1553                         } else {
1554                             List<MissingPieceItemRecord> missingPieceItemRecords=new ArrayList<MissingPieceItemRecord>();
1555                             missingPieceItemRecords.add(missingPieceItemRecord);
1556                             oleItem.setMissingPieceItemRecordList(missingPieceItemRecords);
1557                     }*/
1558                         Map<String,String> map = new HashMap<>();
1559                         map.put("itemId", DocumentUniqueIDPrefix.getDocumentId(loanDocument.getItemUuid()));
1560                         List<org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.MissingPieceItemRecord> missingPieceItemRecordList = (List<org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.MissingPieceItemRecord>) KRADServiceLocator.getBusinessObjectService().findMatchingOrderBy(org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.MissingPieceItemRecord.class, map, "missingPieceItemId", true);
1561                         List<MissingPieceItemRecord> missingPieceItemRecords = new ArrayList<>();
1562                         for(int index=0 ; index < missingPieceItemRecordList.size() ; index++){
1563                             MissingPieceItemRecord missingPieceItemRecord1 = new MissingPieceItemRecord();
1564                             if(index == missingPieceItemRecordList.size()-1){
1565                                 /*if (oleLoanForm.getMissi != null) {
1566                                     claimsReturnedRecord.setClaimsReturnedFlagCreateDate(convertToString(loanObject.getClaimsReturnedDate()));
1567                                 }
1568                                 else{
1569                                     DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
1570                                     claimsReturnedRecord.setClaimsReturnedFlagCreateDate(df.format(getDateTimeService().getCurrentDate()));
1571                                 }*/
1572                                 DateFormat dfs = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
1573                                 String missingPieceItemDate = dfs.format((new Date()));
1574                                 missingPieceItemRecord1.setMissingPieceDate(missingPieceItemDate);
1575                                 missingPieceItemRecord1.setMissingPieceCount(oleLoanForm.getDialogMissingPieceCount());
1576                                 missingPieceItemRecord1.setPatronBarcode(oleLoanForm.getPatronBarcode());
1577                                 missingPieceItemRecord1.setOperatorId(GlobalVariables.getUserSession().getPrincipalId());
1578                                 missingPieceItemRecord1.setItemId(oleLoanForm.getMissingPieceLoanDocument().getItemUuid());
1579                                 missingPieceItemRecord1.setMissingPieceFlagNote(oleLoanForm.getDialogText());
1580 
1581                             } else {
1582                                 if (missingPieceItemRecordList.get(index).getMissingPieceDate() != null && !missingPieceItemRecordList.get(index).getMissingPieceDate().toString().isEmpty()) {
1583                                     SimpleDateFormat format1 = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
1584                                     SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
1585                                     Date missingPieceItemDate = null;
1586                                     try {
1587                                         missingPieceItemDate = format2.parse(missingPieceItemRecordList.get(index).getMissingPieceDate().toString());
1588                                     } catch (ParseException e) {
1589                                         LOG.error("format string to Date " + e);
1590                                     }
1591                                     missingPieceItemRecord1.setMissingPieceDate(format1.format(missingPieceItemDate).toString());
1592                                 }
1593                                 missingPieceItemRecord1.setMissingPieceFlagNote(missingPieceItemRecordList.get(index).getMissingPieceFlagNote());
1594                                 missingPieceItemRecord1.setMissingPieceCount(missingPieceItemRecordList.get(index).getMissingPieceCount());
1595                                 missingPieceItemRecord1.setOperatorId(missingPieceItemRecordList.get(index).getOperatorId());
1596                                 missingPieceItemRecord1.setPatronBarcode(missingPieceItemRecordList.get(index).getPatronBarcode());
1597                                 missingPieceItemRecord1.setItemId(missingPieceItemRecordList.get(index).getItemId());
1598                             }
1599                             missingPieceItemRecords.add(missingPieceItemRecord1);
1600                         }
1601                         oleItem.setMissingPieceItemRecordList(missingPieceItemRecords);
1602                     }
1603                 }
1604 
1605 
1606 
1607                     //getDocstoreClientLocator().getDocstoreClient().updateItem(item);
1608 
1609                 oleItem.setMissingPiecesCount(oleLoanForm.getDialogMissingPieceCount());
1610                 oleItem.setNumberOfPieces(oleLoanForm.getDialogItemNoOfPieces());
1611                 oleItem.setMissingPieceFlagNote(oleLoanForm.getDialogText());
1612                 itemXmlContent = new ItemOlemlRecordProcessor().toXML(oleItem);
1613                 if (LOG.isDebugEnabled()) {
1614                     LOG.debug("itemXmlContent" + itemXmlContent);
1615                 }
1616                 item.setContent(itemXmlContent);
1617                 item.setCategory(OLEConstants.WORK_CATEGORY);
1618                 item.setType(DocType.ITEM.getCode());
1619                 item.setFormat(OLEConstants.OLEML_FORMAT);
1620                 item.setId(oleLoanForm.getMissingPieceLoanDocument().getItemUuid());
1621                 getDocstoreClientLocator().getDocstoreClient().updateItem(item);
1622                 if (isMissingPieceFlag) {
1623                     oleLoanForm.getMissingPieceLoanDocument().setMissingPieceNote(oleLoanForm.getDialogText());
1624                 } else {
1625                     oleLoanForm.getMissingPieceLoanDocument().setMissingPieceNote("");
1626                 }
1627                 oleLoanForm.getMissingPieceLoanDocument().setCheckNo(false);
1628                 oleLoanForm.setRemoveMissingPieceFlag(false);
1629             } catch (Exception e) {
1630                 LOG.error("Exception occured when updating item" + e);
1631             }
1632         } else {
1633             oleLoanForm.setMissingPieceDialog(true);
1634             oleLoanForm.setErrorMessage("Not updated successfully");
1635 
1636         }
1637         oleLoanForm.setMissingPieceDialog(false);
1638         oleLoanForm.setRemoveMissingPieceButton(false);
1639         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1640     }
1641 
1642     @RequestMapping(params = "methodToCall=removeMissingPieceFromItem")
1643     public ModelAndView removeMissingPieceFromItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1644                                                    HttpServletRequest request, HttpServletResponse response) {
1645         LOG.debug("Inside the claims return method");
1646         if (loginUserList == null) {
1647             loginUserList = new ArrayList<>();
1648         }
1649         StringBuffer buffer = new StringBuffer();
1650         OleLoanForm oleLoanForm = (OleLoanForm) form;
1651       /*  String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
1652         if (LOG.isInfoEnabled()){
1653             LOG.info("session timeout" + maxSessionTime);
1654         }
1655         if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
1656             oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));*/
1657         oleLoanForm.setRemoveMissingPieceFlag(true);
1658         updateMissingPieceItem(form, result, request, response);
1659 
1660         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1661     }
1662 
1663     @RequestMapping(params = "methodToCall=removeDamagedFlagFromItem")
1664     public ModelAndView removeDamagedFlagFromItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1665                                                   HttpServletRequest request, HttpServletResponse response) {
1666         LOG.debug("Inside the claims return method");
1667         if (loginUserList == null) {
1668             loginUserList = new ArrayList<>();
1669         }
1670         StringBuffer buffer = new StringBuffer();
1671         OleLoanForm oleLoanForm = (OleLoanForm) form;
1672         /*String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
1673         if (LOG.isInfoEnabled()){
1674             LOG.info("session timeout" + maxSessionTime);
1675         }
1676         if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
1677             oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));*/
1678         oleLoanForm.setDialogFlag(false);
1679         updateDamagedItem(form, result, request, response);
1680         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1681     }
1682 
1683     @RequestMapping(params = "methodToCall=updateDamagedItem")
1684     public ModelAndView updateDamagedItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1685                                           HttpServletRequest request, HttpServletResponse response) {
1686         LOG.debug("Inside the claims return method");
1687         if (loginUserList == null) {
1688             loginUserList = new ArrayList<>();
1689         }
1690         StringBuffer buffer = new StringBuffer();
1691         OleLoanForm oleLoanForm = (OleLoanForm) form;
1692        /* String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
1693         if (LOG.isInfoEnabled()){
1694             LOG.info("session timeout" + maxSessionTime);
1695         }
1696         if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
1697             oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));*/
1698         if (oleLoanForm.getLoanList().size() > 0) {
1699             if (oleLoanForm.getLoanList().size() > 0) {
1700                 for (OleLoanDocument oleLoanDocument : oleLoanForm.getLoanList()) {
1701                     if (oleLoanDocument.isCheckNo()) {
1702                         try {
1703                             String itemXmlContent = getLoanProcessor().getItemXML(oleLoanDocument.getItemUuid());
1704                             Item oleItem = getLoanProcessor().getItemPojo(itemXmlContent);
1705                             if (oleLoanForm.isDialogFlag()) {
1706                                 oleLoanDocument.setItemDamagedNote(oleLoanForm.getDialogText());
1707                                 getLoanProcessor().updateItemDamagedHistory(oleItem,oleLoanDocument,oleLoanForm.getPatronId());
1708                             } else {
1709                                 oleLoanDocument.setItemDamagedNote("");
1710                             }
1711                             oleItem.setItemDamagedStatus(oleLoanForm.isDialogFlag());
1712                             oleItem.setDamagedItemNote(oleLoanForm.getDialogText());
1713                             itemXmlContent = new ItemOlemlRecordProcessor().toXML(oleItem);
1714                             if (LOG.isDebugEnabled()) {
1715                                 LOG.debug("itemXmlContent" + itemXmlContent);
1716                             }
1717                             org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
1718                             item.setContent(itemXmlContent);
1719                             item.setCategory(OLEConstants.WORK_CATEGORY);
1720                             item.setType(DocType.ITEM.getCode());
1721                             item.setFormat(OLEConstants.OLEML_FORMAT);
1722                             item.setId(oleLoanDocument.getItemUuid());
1723                             getDocstoreClientLocator().getDocstoreClient().updateItem(item);
1724                             if (oleLoanForm.isDialogFlag()) {
1725                                 oleLoanDocument.setItemDamagedNote(oleLoanForm.getDialogText());
1726                             } else {
1727                                 oleLoanDocument.setItemDamagedNote("");
1728                             }
1729                             oleLoanDocument.setCheckNo(false);
1730                         } catch (Exception e) {
1731                             throw new RuntimeException();
1732                         }
1733                     }
1734                 }
1735             }
1736         }
1737         if (oleLoanForm.getExistingLoanList().size() > 0) {
1738             for (OleLoanDocument oleLoanDocument : oleLoanForm.getExistingLoanList()) {
1739                 if (oleLoanDocument.isCheckNo()) {
1740                     try {
1741                         String itemXmlContent = getLoanProcessor().getItemXML(oleLoanDocument.getItemUuid());
1742                         Item oleItem = getLoanProcessor().getItemPojo(itemXmlContent);
1743                         if (oleLoanForm.isDialogFlag()) {
1744                             oleLoanDocument.setItemDamagedNote(oleLoanForm.getDialogText());
1745                             getLoanProcessor().updateItemDamagedHistory(oleItem,oleLoanDocument,oleLoanForm.getPatronId());
1746                         } else {
1747                             oleLoanDocument.setItemDamagedNote("");
1748                         }
1749                         oleItem.setItemDamagedStatus(oleLoanForm.isDialogFlag());
1750                         oleItem.setDamagedItemNote(oleLoanForm.getDialogText());
1751                         itemXmlContent = new ItemOlemlRecordProcessor().toXML(oleItem);
1752                         if (LOG.isDebugEnabled()) {
1753                             LOG.debug("itemXmlContent" + itemXmlContent);
1754                         }
1755                         org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
1756                         item.setContent(itemXmlContent);
1757                         item.setCategory(OLEConstants.WORK_CATEGORY);
1758                         item.setType(DocType.ITEM.getCode());
1759                         item.setFormat(OLEConstants.OLEML_FORMAT);
1760                         item.setId(oleLoanDocument.getItemUuid());
1761                         getDocstoreClientLocator().getDocstoreClient().updateItem(item);
1762                         if (oleLoanForm.isDialogFlag()) {
1763                             oleLoanDocument.setItemDamagedNote(oleLoanForm.getDialogText());
1764                         } else {
1765                             oleLoanDocument.setItemDamagedNote("");
1766                         }
1767                         oleLoanDocument.setCheckNo(false);
1768                     } catch (Exception e) {
1769                         throw new RuntimeException();
1770                     }
1771                 }
1772             }
1773 
1774         }
1775         oleLoanForm.setRemoveItemDamagedButton(false);
1776         oleLoanForm.setMissingPieceDialog(false);
1777         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1778     }
1779 
1780 
1781     @RequestMapping(params = "methodToCall=showDamagedDialogBox")
1782     public ModelAndView showDamagedDialogBox(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1783                                              HttpServletRequest request, HttpServletResponse response) {
1784 
1785         LOG.debug("Inside the apply claims return method");
1786         OleLoanForm oleLoanForm = (OleLoanForm) form;
1787         /*String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
1788         if (LOG.isInfoEnabled()){
1789             LOG.info("session timeout" + maxSessionTime);
1790         }
1791         if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
1792             oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));*/
1793         int count = 0;
1794         oleLoanForm.setDialogFlag(false);
1795         oleLoanForm.setDialogItemNoOfPieces(null);
1796         oleLoanForm.setDialogMissingPieceCount(null);
1797         oleLoanForm.setDialogText(null);
1798         oleLoanForm.setDialogItemNoOfPiecesReadOnly(false);
1799         oleLoanForm.setDialogMissingPieceCountReadOnly(false);
1800         oleLoanForm.setDialogErrorMessage(null);
1801         oleLoanForm.setInformation("");
1802         oleLoanForm.setSuccessInfo("");
1803         oleLoanForm.setRemoveItemDamagedButton(false);
1804         OleLoanDocument loanDocument = null;
1805         int damagedItemCount=0;
1806         if (oleLoanForm.getLoanList().size() > 0) {
1807             for (OleLoanDocument oleLoanDocument : oleLoanForm.getLoanList()) {
1808                 if (oleLoanDocument.isCheckNo()) {
1809                     loanDocument = oleLoanDocument;
1810                     count++;
1811                     if(StringUtils.isNotEmpty(loanDocument.getItemDamagedNote())){
1812                         damagedItemCount++;
1813                     }
1814                 }
1815             }
1816         }
1817         if (oleLoanForm.getExistingLoanList().size() > 0) {
1818             for (OleLoanDocument oleLoanDocument : oleLoanForm.getExistingLoanList()) {
1819                 if (oleLoanDocument.isCheckNo()) {
1820                     loanDocument = oleLoanDocument;
1821                     count++;
1822                     if(StringUtils.isNotEmpty(loanDocument.getItemDamagedNote())){
1823                         damagedItemCount++;
1824                     }
1825                 }
1826             }
1827         }
1828         if (count > 0) {
1829             oleLoanForm.setDamagedItemDialog(true);
1830             oleLoanForm.setDialogFlag(true);
1831             if(damagedItemCount>0){
1832                 oleLoanForm.setRemoveItemDamagedButton(true);
1833             }
1834             if (count == 1 && loanDocument != null && loanDocument.getItemUuid() != null) {
1835                 try {
1836                     String itemXmlContent = getLoanProcessor().getItemXML(loanDocument.getItemUuid());
1837                     Item oleItem = getLoanProcessor().getItemPojo(itemXmlContent);
1838                     if (oleItem != null) {
1839                         oleLoanForm.setDialogText(oleItem.getDamagedItemNote());
1840                     }
1841                 } catch (Exception e) {
1842                     if (LOG.isDebugEnabled()) {
1843                         LOG.error("while retrieving item damaged status info error" + e);
1844                     }
1845                 }
1846             }
1847         } else {
1848             oleLoanForm.setDamagedItemDialog(false);
1849             oleLoanForm.setInformation(OLEConstants.CLAIMS_ITM_ERR_INFO);
1850         }
1851         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1852     }
1853 
1854     @RequestMapping(params = "methodToCall=deactivateAllDialogs")
1855     public ModelAndView deactivateAllDialogs(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1856                                              HttpServletRequest request, HttpServletResponse response) {
1857 
1858         LOG.debug("Inside the apply claims return method");
1859         OleLoanForm oleLoanForm = (OleLoanForm) form;
1860        /* String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
1861         if (LOG.isInfoEnabled()){
1862             LOG.info("session timeout" + maxSessionTime);
1863         }
1864         if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
1865             oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));*/
1866         // int count=0;
1867         oleLoanForm.setDialogFlag(false);
1868         oleLoanForm.setDialogItemNoOfPieces(null);
1869         oleLoanForm.setDialogMissingPieceCount(null);
1870         oleLoanForm.setDialogText(null);
1871         oleLoanForm.setDialogItemNoOfPiecesReadOnly(false);
1872         oleLoanForm.setDialogMissingPieceCountReadOnly(false);
1873         oleLoanForm.setDialogErrorMessage(null);
1874         oleLoanForm.setMissingPieceDialog(false);
1875         oleLoanForm.setDamagedItemDialog(false);
1876         oleLoanForm.setRemoveItemDamagedButton(false);
1877         for(OleLoanDocument loanDocument:oleLoanForm.getLoanList()){
1878             loanDocument.setCheckNo(false);
1879         }
1880         for (OleLoanDocument loanDocument : oleLoanForm.getExistingLoanList()) {
1881             loanDocument.setCheckNo(false);
1882         }
1883         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1884 
1885     }
1886 
1887     /**
1888      * Change the circulation desk location and clear the screen.
1889      *
1890      * @param form
1891      * @param result
1892      * @param request
1893      * @param response
1894      * @return
1895      */
1896     @RequestMapping(params = "methodToCall=changeCirculationDeskLocation")
1897     public ModelAndView changeCirculationDeskLocation(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1898                                                       HttpServletRequest request, HttpServletResponse response) {
1899         LOG.debug("Inside the change circulation desk location method");
1900         OleLoanForm oleLoanForm = (OleLoanForm) form;
1901         oleLoanForm.setConfirmMessage(OLEConstants.CHANGE_LOC_MESS);
1902         oleLoanForm.setChangeLocationFlag(true);
1903 
1904        /* String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
1905         if (LOG.isInfoEnabled()){
1906             LOG.info("session timeout" + maxSessionTime);
1907         }
1908         if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
1909             oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));*/
1910 
1911         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1912     }
1913 
1914     @RequestMapping(params = "methodToCall=changeReturnCirculationDeskLocation")
1915     public ModelAndView changeReturnCirculationDeskLocation(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1916                                                             HttpServletRequest request, HttpServletResponse response) {
1917         LOG.debug("Inside the change circulation desk location method");
1918         OleLoanForm oleLoanForm = (OleLoanForm) form;
1919         oleLoanForm.setConfirmMessage(OLEConstants.CHANGE_LOC_MESS);
1920         oleLoanForm.setChangeLocationFlag(true);
1921         return getUIFModelAndView(oleLoanForm, "ReturnItemViewPage");
1922     }
1923 
1924     /**
1925      * Reset the old circulation location in loan.
1926      *
1927      * @param form
1928      * @param result
1929      * @param request
1930      * @param response
1931      * @return
1932      */
1933     @RequestMapping(params = "methodToCall=resetLocation")
1934     public ModelAndView resetLocation(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1935                                       HttpServletRequest request, HttpServletResponse response) {
1936         LOG.debug("Inside the reset location method");
1937         OleLoanForm oleLoanForm = (OleLoanForm) form;
1938         oleLoanForm.setCirculationDesk(oleLoanForm.getPreviousCirculationDesk());
1939         oleLoanForm.setChangeLocationFlag(false);
1940         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1941     }
1942 
1943     @RequestMapping(params = "methodToCall=resetReturnLocation")
1944     public ModelAndView resetReturnLocation(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1945                                             HttpServletRequest request, HttpServletResponse response) {
1946         LOG.debug("Inside the reset location method");
1947         OleLoanForm oleLoanForm = (OleLoanForm) form;
1948         oleLoanForm.setCirculationDesk(oleLoanForm.getPreviousCirculationDesk());
1949         oleLoanForm.setChangeLocationFlag(false);
1950         return getUIFModelAndView(oleLoanForm, "ReturnItemViewPage");
1951     }
1952 
1953     /**
1954      * This method clear UI for next borrower session..
1955      *
1956      * @param form
1957      * @param result
1958      * @param request
1959      * @param response
1960      * @return ModelAndView
1961      */
1962     @RequestMapping(params = "methodToCall=saveAndClear")
1963     public ModelAndView clearPatron(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1964                                     HttpServletRequest request, HttpServletResponse response) {
1965         LOG.debug("Inside the clear patron method");
1966         fastAddBarcode = "";
1967         OleLoanForm oleLoanForm = (OleLoanForm) form;
1968         String currentLocation = oleLoanForm.getCirculationDesk();
1969         oleLoanForm.setPreviousCirculationDesk(currentLocation);
1970         oleLoanForm.setNewPrincipalId("");
1971         oleLoanForm.setAddressVerified(false);
1972         oleLoanForm.setOverrideRenewItemFlag(false);
1973         oleLoanForm.setCurrentDate(null);
1974         oleLoanForm.setInformation("");
1975         oleLoanForm.setSuccessInfo("");
1976         oleLoanForm.setReturnInformation("");
1977         oleLoanForm.setBorrowerType(null);
1978         oleLoanForm.setPatronBarcode(null);
1979         oleLoanForm.setPatronName(null);
1980         oleLoanForm.setProxyPatronId(null);
1981         oleLoanForm.setRealPatronBarcode(null);
1982         oleLoanForm.setPatronId(null);
1983         oleLoanForm.setRealPatronList(null);
1984         oleLoanForm.setLoanList(null);
1985         oleLoanForm.setDueDateMap(null);
1986         oleLoanForm.setExistingLoanList(null);
1987         oleLoanForm.setDueDateMap(null);
1988         oleLoanForm.setMessage(null);
1989         oleLoanForm.setSuccess(true);
1990         oleLoanForm.setChangeLocationFlag(false);
1991         oleLoanForm.setBlockLoan(false);
1992         oleLoanForm.setItemFocus(false);
1993         oleLoanForm.setSelfCheckOut(false);
1994         oleLoanForm.setCurrentPatronList(null);
1995         oleLoanForm.setPatronFocus(true);
1996         oleLoanForm.setBackGroundCheckIn(false);
1997         oleLoanForm.setRemoveMissingPieceFlag(false);
1998         oleLoanForm.setRecordDamagedItemNote(false);
1999         oleLoanForm.setRecordMissingPieceNote(false);
2000         oleLoanForm.setRecordCheckoutMissingPieceNote(false);
2001         oleLoanForm.setDisplayRecordNotePopup(false);
2002         oleLoanForm.setCheckoutRecordFlag(false);
2003         oleLoanForm.setSkipMissingPieceRecordPopup(false);
2004         oleLoanForm.setSkipDamagedRecordPopup(false);
2005         oleLoanForm.setDisplayMissingPieceNotePopup(false);
2006         oleLoanForm.setCheckoutMissingPieceRecordFlag(false);
2007         oleLoanForm.setDisplayDamagedRecordNotePopup(false);
2008         oleLoanForm.setCheckoutDamagedRecordFlag(false);
2009         oleLoanForm.setPatronbill(false);
2010         oleLoanForm.setPopDateTimeInfo("");
2011         GlobalVariables.getUserSession().clearBackdoorUser();
2012         GlobalVariables.getUserSession().setBackdoorUser(oleLoanForm.getOldPrincipalId());
2013         oleLoanForm.setNewPrincipalId(null);
2014 
2015         if (!oleLoanForm.isClearUI()) {
2016             String principalId = GlobalVariables.getUserSession().getPrincipalId();
2017             OleCirculationDeskDetail oleCirculationDeskDetail = getLoanProcessor().getDefaultCirculationDesk(principalId);
2018             if (oleCirculationDeskDetail != null) {
2019                 oleLoanForm.setCirculationDesk(oleCirculationDeskDetail.getCirculationDeskId());
2020                 oleLoanForm.setPreviousCirculationDesk(oleLoanForm.getCirculationDesk());
2021             }
2022         }
2023         return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
2024 
2025     }
2026 
2027     /**
2028      * This method clear UI for next borrower.
2029      *
2030      * @param form
2031      * @param result
2032      * @param request
2033      * @param response
2034      * @return ModelAndView
2035      */
2036     @RequestMapping(params = "methodToCall=clearPatron")
2037     public ModelAndView clearPatronScreen(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2038                                           HttpServletRequest request, HttpServletResponse response) {
2039         LOG.debug("Inside the clear patron Screen method");
2040         fastAddBarcode = "";
2041         OleLoanForm oleLoanForm = (OleLoanForm) form;
2042         String currentLocation = oleLoanForm.getCirculationDesk();
2043         oleLoanForm.setPreviousCirculationDesk(currentLocation);
2044         if (oleLoanForm.getLoanList() != null && oleLoanForm.getLoanList().size() > 0 && !oleLoanForm.isChangeLocationFlag() && getLoanProcessor().getParameter(OLEConstants.PRINT_DUE_DATE_PER_TRANSACTION).equalsIgnoreCase("No")) {
2045             oleLoanForm.setDueDateSlip(true);
2046             printDueDateSlipList = oleLoanForm.getLoanList();
2047         }
2048         //oleLoanForm.setNewPrincipalId("");
2049         oleLoanForm.setAddressVerified(false);
2050         oleLoanForm.setOverrideRenewItemFlag(false);
2051         oleLoanForm.setInformation("");
2052         oleLoanForm.setSuccessInfo("");
2053         oleLoanForm.setReturnInformation("");
2054         oleLoanForm.setBorrowerType(null);
2055         oleLoanForm.setPatronBarcode(null);
2056         oleLoanForm.setPatronName(null);
2057         oleLoanForm.setProxyPatronId(null);
2058         oleLoanForm.setRealPatronBarcode(null);
2059         oleLoanForm.setPatronId(null);
2060         oleLoanForm.setRealPatronList(null);
2061         oleLoanForm.setLoanList(null);
2062         oleLoanForm.setDueDateMap(null);
2063         oleLoanForm.setExistingLoanList(null);
2064         oleLoanForm.setDueDateMap(null);
2065         oleLoanForm.setMessage(null);
2066         oleLoanForm.setSuccess(true);
2067         oleLoanForm.setChangeLocationFlag(false);
2068         //oleLoanForm.setItemStatusLost(false);
2069         oleLoanForm.setBlockLoan(false);
2070         oleLoanForm.setItemFocus(false);
2071         oleLoanForm.setSelfCheckOut(false);
2072         oleLoanForm.setCurrentPatronList(null);
2073         oleLoanForm.setPatronFocus(true);
2074         oleLoanForm.setBackGroundCheckIn(false);
2075         oleLoanForm.setRemoveMissingPieceFlag(false);
2076         oleLoanForm.setRecordDamagedItemNote(false);
2077         oleLoanForm.setRecordMissingPieceNote(false);
2078         oleLoanForm.setRecordCheckoutMissingPieceNote(false);
2079         oleLoanForm.setDisplayRecordNotePopup(false);
2080         oleLoanForm.setCheckoutRecordFlag(false);
2081         oleLoanForm.setSkipMissingPieceRecordPopup(false);
2082         oleLoanForm.setSkipDamagedRecordPopup(false);
2083         oleLoanForm.setDisplayMissingPieceNotePopup(false);
2084         oleLoanForm.setCheckoutMissingPieceRecordFlag(false);
2085         oleLoanForm.setDisplayDamagedRecordNotePopup(false);
2086         oleLoanForm.setCheckoutDamagedRecordFlag(false);
2087         oleLoanForm.setPatronbill(false);
2088         oleLoanForm.setSuccessMessage(null);
2089         oleLoanForm.setPopDateTimeInfo("");
2090         //GlobalVariables.getUserSession().clearBackdoorUser();
2091         //GlobalVariables.getUserSession().setBackdoorUser( oleLoanForm.getOldPrincipalId() );
2092         //oleLoanForm.setNewPrincipalId(null);
2093         //return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");\
2094         return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
2095 
2096     }
2097 
2098     /**
2099      * This method override permission..
2100      *
2101      * @param form
2102      * @param result
2103      * @param request
2104      * @param response
2105      * @return ModelAndView
2106      */
2107     @RequestMapping(params = "methodToCall=overRide")
2108     public ModelAndView overRide(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2109                                  HttpServletRequest request, HttpServletResponse response) {
2110         LOG.debug("Inside the override method");
2111         OleLoanForm oleLoanForm = (OleLoanForm) form;
2112        /* String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
2113         if (LOG.isInfoEnabled()){
2114             LOG.info("session timeout" + maxSessionTime);
2115         }
2116         if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
2117             oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));*/
2118         oleLoanForm.setInformation("");
2119         oleLoanForm.setSuccessInfo("");
2120         oleLoanForm.setReturnInformation("");
2121         oleLoanForm.setOverideMethodCall(oleLoanForm.getMethodToCall());
2122         oleLoanForm.setOverrideFlag(true);
2123         String principalId = GlobalVariables.getUserSession().getPrincipalId();
2124         boolean newPrincipalFlag = false;
2125         if (StringUtils.isNotBlank(oleLoanForm.getNewPrincipalName())) {
2126             newPrincipalFlag = true;
2127         }
2128         if (newPrincipalFlag) {
2129             Person people = SpringContext.getBean(PersonService.class).getPersonByPrincipalName(oleLoanForm.getNewPrincipalName());
2130             if(people!=null){
2131                 principalId=people.getPrincipalId();
2132                 oleLoanForm.setNewPrincipalId(principalId);
2133             }
2134             if (people == null) {
2135                 oleLoanForm.setOverrideLoginMessage(oleLoanForm.getNewPrincipalName() + " is invalid user Name.Please enter your user Name.");
2136                 oleLoanForm.setOverrideErrorMessage(null);
2137                 oleLoanForm.setNewPrincipalId(null);
2138                 oleLoanForm.setNewPrincipalName(null);
2139                 return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
2140             }
2141         } else {
2142         if(StringUtils.isNotBlank(principalId)){
2143             Person people = SpringContext.getBean(PersonService.class).getPerson(principalId);
2144             if(people == null) {
2145                     oleLoanForm.setOverrideLoginMessage(people.getPrincipalName() + " is invalid user Name.Please enter your user Name.");
2146                 oleLoanForm.setOverrideErrorMessage(null);
2147                 oleLoanForm.setNewPrincipalId(null);
2148                     oleLoanForm.setNewPrincipalName(null);
2149                 return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
2150             }
2151         }
2152         }
2153         Boolean overRideFlag = getLoanProcessor().checkOverRidePermission(principalId, oleLoanForm);
2154         if (overRideFlag) {
2155             if ((!"".equals(oleLoanForm.getNewPrincipalId()) && oleLoanForm.getNewPrincipalId() != null)) {
2156                 //oleLoanForm.setLoanLoginName(oleLoanForm.getNewPrincipalId());
2157                // GlobalVariables.getUserSession().setBackdoorUser(oleLoanForm.getNewPrincipalId());
2158                // String approverId = GlobalVariables.getUserSession().getPerson().getEntityId();
2159                 oleLoanForm.getDummyLoan().setLoanApproverId(oleLoanForm.getNewPrincipalId());
2160                // GlobalVariables.getUserSession().clearBackdoorUser();
2161             }
2162             if (!newPrincipalFlag) {
2163                // oleLoanForm.setLoanLoginName(principalId);
2164                // GlobalVariables.getUserSession().setBackdoorUser(principalId);
2165                // String approverId = GlobalVariables.getUserSession().getPerson().getEntityId();
2166                 oleLoanForm.getDummyLoan().setLoanApproverId(principalId);
2167                // GlobalVariables.getUserSession().clearBackdoorUser();
2168             }
2169             oleLoanForm.setNewPrincipalId("");
2170             oleLoanForm.setOverrideFlag(false);
2171             oleLoanForm.setOverideMethodCall("");
2172             return null;
2173         }
2174          oleLoanForm.setNewPrincipalId(null);
2175         //GlobalVariables.getUserSession().clearBackdoorUser();
2176         if (!"".equals(oleLoanForm.getNewPrincipalId())) {
2177             oleLoanForm.setOverrideLoginMessage(principalId + " " + OLEConstants.OVERRIDE_LOGIN_ERR_INFO + OLEConstants.BREAK + oleLoanForm.getOverrideErrorMessage());
2178             oleLoanForm.setOverrideErrorMessage(null);
2179         }
2180         /*return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");*/
2181         return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
2182     }
2183 
2184     /**
2185      * This method loanLogin permission..
2186      *
2187      * @param form
2188      * @param result
2189      * @param request
2190      * @param response
2191      * @return ModelAndView
2192      */
2193     @RequestMapping(params = "methodToCall=loanLogin")
2194     public ModelAndView loanLogin(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2195                                   HttpServletRequest request, HttpServletResponse response) {
2196         LOG.debug("Inside the loanLogin method");
2197         OleLoanForm oleLoanForm = (OleLoanForm) form;
2198         if (loginUserList == null) {
2199             loginUserList = new ArrayList<>();
2200         }
2201         oleLoanForm.setValidLogin(getLoanProcessor().isAuthorized(oleLoanForm.getLoanLoginName()));
2202         String patronNameURL = getLoanProcessor().patronNameURL(oleLoanForm.getLoanLoginName(), oleLoanForm.getPatronId());
2203         oleLoanForm.setPatronNameURL(patronNameURL);
2204         if (oleLoanForm.getLoanLoginName() != null && !oleLoanForm.getLoanLoginName().trim().isEmpty() && oleLoanForm.isValidLogin()) {
2205             oleLoanForm.setLoanLoginUserInfo("");
2206             oleLoanForm.setLoanLoginMessage(false);
2207             String loginUser = GlobalVariables.getUserSession().getPrincipalName();
2208             String circulationDesk = oleLoanForm.getCirculationDesk();
2209             GlobalVariables.getUserSession().setBackdoorUser(oleLoanForm.getLoanLoginName());
2210             start(form, result, request, response);
2211             if (getLoanProcessor().getCircDeskId() != null) {
2212                 oleLoanForm.setCirculationDesk(getLoanProcessor().getCircDeskId());
2213             }
2214             StringBuffer users = new StringBuffer();
2215             users.append(loginUser + "," + circulationDesk);
2216             loginUserList.add(users.toString());
2217         }
2218         return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
2219     }
2220 
2221     @RequestMapping(params = "methodToCall=loanLogout")
2222     public ModelAndView loanLogout(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2223                                    HttpServletRequest request, HttpServletResponse response) {
2224         LOG.debug("Inside the loanLogout method");
2225         int count;
2226         OleLoanForm oleLoanForm = (OleLoanForm) form;
2227         if (oleLoanForm.getOldPrincipalId() != null && !oleLoanForm.getOldPrincipalId().trim().isEmpty()) {
2228             oleLoanForm.setLoanLoginUserInfo("");
2229             oleLoanForm.setLoanLoginMessage(false);
2230             if (loginUserList == null) {
2231                 GlobalVariables.getUserSession().setBackdoorUser(null);
2232                 return cancel(form, result, request, response);
2233             }
2234             if (loginUserList.size() > 0) {
2235                 count = loginUserList.size() - 1;
2236                 String usersList = loginUserList.get(count);
2237                 loginUserList.remove(count);
2238                 String user = GlobalVariables.getUserSession().getPrincipalName();
2239                 String circulationId = oleLoanForm.getCirculationDesk();
2240                 StringBuffer currentUser = new StringBuffer();
2241                 currentUser.append(user + "," + circulationId);
2242                 if (usersList.equalsIgnoreCase(currentUser.toString())) {
2243                     if (loginUserList.size() > 0) {
2244                         int size = loginUserList.size() - 1;
2245                         usersList = loginUserList.get(size);
2246                         loginUserList.remove(size);
2247                     } else {
2248                         GlobalVariables.getUserSession().setBackdoorUser(null);
2249                         return cancel(form, result, request, response);
2250                     }
2251                 }
2252                 if (usersList == "" || usersList.isEmpty()) {
2253                     GlobalVariables.getUserSession().setBackdoorUser(null);
2254                     return cancel(form, result, request, response);
2255                 }
2256                 String[] usersAndCirculationId = usersList.split(",");
2257                 oleLoanForm.setLoginUser(usersAndCirculationId[0]);
2258                 String patronNameURL = getLoanProcessor().patronNameURL(oleLoanForm.getLoginUser(), oleLoanForm.getPatronId());
2259                 oleLoanForm.setPatronNameURL(patronNameURL);
2260                 if (oleLoanForm.getLoginUser().equalsIgnoreCase(OLEConstants.ADMIN_USER)) {
2261                     GlobalVariables.getUserSession().setBackdoorUser(null);
2262                     return cancel(form, result, request, response);
2263                 }
2264                 GlobalVariables.getUserSession().setBackdoorUser(oleLoanForm.getLoginUser());
2265                 start(form, result, request, response);
2266                 oleLoanForm.setCirculationDesk(usersAndCirculationId[1]);
2267             } else {
2268                 GlobalVariables.getUserSession().setBackdoorUser(null);
2269                 return cancel(form, result, request, response);
2270             }
2271         }
2272         return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
2273     }
2274 
2275     /**
2276      * This method no  override permission..
2277      *
2278      * @param form
2279      * @param result
2280      * @param request
2281      * @param response
2282      * @return ModelAndView
2283      */
2284     @RequestMapping(params = "methodToCall=noOverRide")
2285     public ModelAndView noOverRide(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2286                                    HttpServletRequest request, HttpServletResponse response) {
2287         LOG.debug("Inside the no override method");
2288         OleLoanForm oleLoanForm = (OleLoanForm) form;
2289         /*String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
2290         if (LOG.isInfoEnabled()){
2291             LOG.info("session timeout" + maxSessionTime);
2292         }
2293         if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
2294             oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));*/
2295         oleLoanForm.setOverrideFlag(false);
2296         oleLoanForm.setOverideMethodCall("");
2297         oleLoanForm.setOverrideLoginMessage("");
2298         oleLoanForm.setInformation("");
2299         oleLoanForm.setSuccessInfo("");
2300         oleLoanForm.setReturnInformation("");
2301         GlobalVariables.getUserSession().setBackdoorUser(oleLoanForm.getLoanLoginName());
2302         oleLoanForm.setNewPrincipalId(oleLoanForm.getLoanLoginName());
2303         /*return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");*/
2304         return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
2305     }
2306 
2307     /**
2308      * This method renewal the existing item
2309      *
2310      * @param form
2311      * @param result
2312      * @param request
2313      * @param response
2314      * @return ModelAndView
2315      */
2316     @RequestMapping(params = "methodToCall=renewalItem")
2317     public ModelAndView renewalItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2318                                     HttpServletRequest request, HttpServletResponse response) {
2319         LOG.debug("Inside the renewal item method");
2320         OleLoanForm oleLoanForm = (OleLoanForm) form;
2321         int renewCurrentCount = 0;
2322         oleLoanForm.setInformation("");
2323         oleLoanForm.setSuccessInfo("");
2324         oleLoanForm.setMessage("");
2325         oleLoanForm.setPopDateTimeInfo("");
2326         oleLoanForm.setOverrideRenewItemFlag(false);
2327         oleLoanForm.setRenewalFlag(false);
2328         List<OleLoanDocument> existingItemList = new ArrayList<OleLoanDocument>();
2329         existingItemList.addAll(oleLoanForm.getExistingLoanList());
2330         if (oleLoanForm.getLoanList() != null && !oleLoanForm.getLoanList().isEmpty())
2331             existingItemList.addAll(oleLoanForm.getLoanList());
2332         OleLoanDocument oleLoanDocument = null;
2333         for (int i = 0; i < existingItemList.size(); i++) {
2334             OleLoanDocument loanDocument = existingItemList.get(i);
2335             if (loanDocument.getItemId()!=null && loanDocument.getItemId().equals(oleLoanForm.getItem())) {
2336                 if(loanDocument.getLoanId()==null){
2337                     oleLoanDocument = getLoanProcessor().getLoanDocumentsUsingItemIdAndPatronId(loanDocument.getItemUuid(),oleLoanForm.getPatronId());
2338                     oleLoanDocument.setClaimsReturnNote(loanDocument.getClaimsReturnNote());
2339                     oleLoanDocument.setClaimsReturnedIndicator(loanDocument.isClaimsReturnedIndicator());
2340                     oleLoanDocument.setClaimsReturnedDate(loanDocument.getClaimsReturnedDate());
2341                     oleLoanDocument.setBibUuid(loanDocument.getBibUuid());
2342                 }else{
2343                     oleLoanDocument = loanDocument;
2344                 }
2345                 oleLoanDocument.setOleItem(loanDocument.getOleItem());
2346                 oleLoanDocument.setRenewalItemFlag(true);
2347                 oleLoanDocument.setErrorMessage(null);
2348                 renewCurrentCount = i;
2349                 break;
2350             }
2351         }
2352         if(oleLoanDocument==null){
2353             OleLoanDocument loanDocument = oleLoanForm.getRenewalLoan();
2354             if (loanDocument.getItemId()!=null && loanDocument.getItemId().equals(oleLoanForm.getItem())) {
2355                 if(loanDocument.getLoanId()==null){
2356                     oleLoanDocument = getLoanProcessor().getLoanDocumentsUsingItemIdAndPatronId(loanDocument.getItemUuid(),oleLoanForm.getPatronId());
2357                     oleLoanDocument.setClaimsReturnNote(loanDocument.getClaimsReturnNote());
2358                     oleLoanDocument.setClaimsReturnedIndicator(loanDocument.isClaimsReturnedIndicator());
2359                     oleLoanDocument.setClaimsReturnedDate(loanDocument.getClaimsReturnedDate());
2360                     oleLoanDocument.setBibUuid(loanDocument.getBibUuid());
2361                 }else{
2362                     oleLoanDocument = loanDocument;
2363                 }
2364                 oleLoanDocument.setOleItem(loanDocument.getOleItem());
2365                 oleLoanDocument.setRenewalItemFlag(true);
2366                 oleLoanDocument.setErrorMessage(null);
2367             }
2368         }
2369         if(oleLoanDocument.getRenewalLoanDueDate() == null && oleLoanForm.getDueDateMap() != null){
2370                 Timestamp timestamp;
2371                 Pattern pattern;
2372                 Matcher matcher;
2373                 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OlePatron.PATRON_MAINTENANCE_DATE_FORMAT);
2374                 boolean timeFlag = false;
2375                 if (oleLoanForm.getPopDateTime() != null && !oleLoanForm.getPopDateTime().isEmpty()) {
2376                     String[] str = oleLoanForm.getPopDateTime().split(":");
2377                     pattern = Pattern.compile(OLEConstants.TIME_24_HR_PATTERN);
2378                     matcher = pattern.matcher(oleLoanForm.getPopDateTime());
2379                     timeFlag = matcher.matches();
2380                     if (timeFlag) {
2381                         if (str != null && str.length <= 2) {
2382                             oleLoanForm.setPopDateTime(oleLoanForm.getPopDateTime() + OLEConstants.CHECK_IN_TIME_MS);
2383                         }
2384                         timestamp = Timestamp.valueOf(new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT).format(oleLoanForm.getDueDateMap()).concat(" ").concat(oleLoanForm.getPopDateTime()));
2385                     } else {
2386                         oleLoanForm.setPopDateTimeInfo(OLEConstants.DUE_DATE_TIME_FORMAT_MESSAGE);
2387                                      /*return getUIFModelAndView(oleLoanForm,"PatronItemViewPage");*/
2388                         return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
2389                     }
2390                 } else if (fmt.format(oleLoanForm.getDueDateMap()).compareTo(fmt.format(new Date())) == 0) {
2391                     timestamp = new Timestamp(new Date().getTime());
2392                 } else {
2393                     timestamp = Timestamp.valueOf(new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT).format(oleLoanForm.getDueDateMap()).concat(" ").concat(new SimpleDateFormat("HH:mm:ss").format(new Date())));
2394                 }
2395                 oleLoanDocument.setManualRenewalDueDate(timestamp);
2396             if(oleLoanDocument.getLoanDueDate() != null && oleLoanDocument.getLoanDueDate().equals(oleLoanDocument.getManualRenewalDueDate())){
2397                 oleLoanDocument.setRenewNotFlag(true);
2398             }else{
2399                 oleLoanDocument.setRenewNotFlag(false);
2400             }
2401            // Timestamp timestamp = Timestamp.valueOf(new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT).format(oleLoanForm.getDueDateMap()).concat(" ").concat(new SimpleDateFormat("HH:mm:ss").format(new Date())));
2402             oleLoanForm.setNonCirculatingFlag(false);
2403         }else{
2404             oleLoanDocument.setManualRenewalDueDate(null);
2405         }
2406         if(oleLoanDocument.getLoanDueDate() == null && oleLoanDocument.isRenewalItemFlag()){
2407             oleLoanForm.setInformation("");
2408             oleLoanForm.setReturnInformation("");
2409             oleLoanForm.setRenewalFlag(false);
2410             oleLoanForm.setSuccess(true);
2411             oleLoanForm.setMessage("");
2412             oleLoanForm.setOverrideRenewal(false);
2413             oleLoanForm.setRenewDueDateFlag(false);
2414             oleLoanForm.setOverrideRenewItemFlag(false);
2415             oleLoanForm.setNonCirculatingFlag(false);
2416             oleLoanForm.setRenewPermission(oleLoanDocument.isRenewPermission());
2417             oleLoanForm.setSuccessInfo(OLEConstants.RENEWAL_INDEFINITE_INFO);
2418             return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
2419         }
2420         if (!oleLoanForm.isOverrideRenewal()) {
2421          //   if (!getLoanProcessor().checkPendingRequestforItem(oleLoanDocument.getItemUuid())) {
2422 
2423                 try {
2424                     oleLoanDocument.setPatronId(oleLoanForm.getPatronId());
2425                     oleLoanDocument.setBorrowerTypeId(oleLoanForm.getBorrowerTypeId());
2426                     oleLoanDocument.setBorrowerTypeName(oleLoanForm.getBorrowerType());
2427                     oleLoanDocument.setBorrowerTypeCode(oleLoanForm.getBorrowerCode());
2428                     oleLoanDocument.setCirculationLocationId(oleLoanForm.getCirculationDesk());
2429                     oleLoanDocument = getLoanProcessor().addLoan(oleLoanDocument.getPatronBarcode(), oleLoanDocument.getItemId(), oleLoanDocument,  null);
2430                     if(oleLoanDocument.isNonCirculatingItem()){
2431                      oleLoanForm.setNonCirculatingFlag(oleLoanDocument.isNonCirculatingItem());
2432                     }
2433                     if(oleLoanDocument.isIndefiniteCheckFlag()){
2434                         oleLoanForm.setRenewalFlag(false);
2435                         oleLoanForm.setOverrideRenewItemFlag(false);
2436                         oleLoanForm.setSuccess(true);
2437                         oleLoanForm.setMessage("");
2438                         oleLoanForm.setRenewPermission(oleLoanDocument.isRenewPermission());
2439                         oleLoanForm.setSuccessInfo(OLEConstants.RENEWAL_INDEFINITE_INFO);
2440                     }
2441                     if (oleLoanDocument.getErrorMessage() == null && !oleLoanDocument.isRenewNotFlag()) {
2442                         oleLoanForm.setRenewalFlag(false);
2443                         oleLoanForm.setOverrideRenewItemFlag(false);
2444                         oleLoanForm.setSuccess(true);
2445                         oleLoanForm.setMessage("");
2446                         // oleLoanForm.getExistingLoanList().remove(renewCurrentCount);
2447                         oleLoanForm.setRenewPermission(oleLoanDocument.isRenewPermission());
2448                         oleLoanForm.setSuccessInfo(OLEConstants.RENEWAL_ITM_SUCCESS_INFO);
2449                     } else if(oleLoanDocument.isRenewNotFlag()){
2450                         oleLoanForm.setRenewalFlag(false);
2451                         oleLoanForm.setOverrideRenewItemFlag(false);
2452                         oleLoanForm.setSuccess(true);
2453                         oleLoanForm.setMessage("");
2454                         // oleLoanForm.getExistingLoanList().remove(renewCurrentCount);
2455                         oleLoanForm.setRenewPermission(oleLoanDocument.isRenewPermission());
2456                         oleLoanForm.setSuccessInfo(OLEConstants.RENEWAL_DUEDATE_SAME_INFO);
2457                     } else {
2458                         if (!oleLoanForm.isOverrideRenewal())
2459                             oleLoanForm.setOverrideRenewal(true);
2460                         oleLoanForm.setOverrideRenewItemFlag(true);
2461                         // Timestamp currentDate = new Timestamp(System.currentTimeMillis());
2462                       /*  if (currentDate.before(oleLoanDocument.getLoanDueDate()))
2463                             oleLoanForm.setRenewalFlag(true);*/
2464                         oleLoanForm.setRenewPermission(oleLoanDocument.isRenewPermission());
2465                         String errMsg = oleLoanDocument.getErrorMessage().substring(0, oleLoanDocument.getErrorMessage().lastIndexOf("(OR)"));
2466                         if(getLoanProcessor().checkPendingRequestforItem(oleLoanDocument.getItemUuid())){
2467                             PermissionService service = KimApiServiceLocator.getPermissionService();
2468                             boolean hasPermission = service.hasPermission(GlobalVariables.getUserSession().getPrincipalId(),OLEConstants.DLVR_NMSPC,OLEConstants.PENDING_RQST_RENEWAL_ITM_INFO);
2469                             oleLoanForm.setOverrideRenewItemFlag(true);
2470                             oleLoanForm.setRenewalFlag(true);
2471                             if (hasPermission) {
2472                                 oleLoanForm.setRenewalFlag(false);
2473                                 oleLoanForm.setRenewPermission(true);
2474                             }
2475                         }
2476                       oleLoanForm.setMessage(errMsg);
2477                     }
2478                     if(!oleLoanDocument.isIndefiniteCheckFlag()) {
2479                         if (oleLoanForm.getExistingLoanList() != null && oleLoanForm.getExistingLoanList().size() > 0) {
2480                             //  oleLoanForm.getExistingLoanList().remove(renewCurrentCount);
2481                             for (int i = 0; i < oleLoanForm.getExistingLoanList().size(); i++) {
2482                                 if ((oleLoanForm.getExistingLoanList().get(i).getItemId()).equalsIgnoreCase(oleLoanDocument.getItemId())) {
2483                                     oleLoanForm.getExistingLoanList().remove(i);
2484                                     break;
2485                                 }
2486                             }
2487                         }
2488                         if (oleLoanForm.getLoanList() != null && oleLoanForm.getLoanList().size() > 0) {
2489                             for (int i = 0; i < oleLoanForm.getLoanList().size(); i++) {
2490                                 if ((oleLoanForm.getLoanList().get(i).getItemId()).equalsIgnoreCase(oleLoanDocument.getItemId())) {
2491                                     oleLoanForm.getLoanList().remove(i);
2492                                     break;
2493                                 }
2494                             }
2495                         }
2496                         oleLoanForm.setOleLoanDocumentToLoanList(oleLoanDocument);
2497                     }
2498 
2499                 } catch (Exception e) {
2500                     oleLoanForm.setInformation(e.getMessage());
2501                     LOG.error("Exception", e);
2502                 }
2503         } else {
2504             try {
2505                 ModelAndView overrideModelView = this.overRide(form, result, request, response);
2506                 //Timestamp currentDate = new Timestamp(System.currentTimeMillis());
2507                 //if (currentDate.after(oleLoanDocument.getLoanDueDate())) {
2508                 if (overrideModelView == null) {
2509                     getLoanProcessor().overrideSaveLoanForRenewal(oleLoanDocument);
2510                     //existingItemList.addAll(oleLoanForm.getLoanList());
2511                     if (oleLoanForm.getExistingLoanList() != null && oleLoanForm.getExistingLoanList().size() > 0) {
2512                         //  oleLoanForm.getExistingLoanList().remove(renewCurrentCount);
2513                         for (int i = 0; i < oleLoanForm.getExistingLoanList().size(); i++) {
2514                             if ((oleLoanForm.getExistingLoanList().get(i).getItemId()).equalsIgnoreCase(oleLoanDocument.getItemId())) {
2515                                 oleLoanForm.getExistingLoanList().remove(i);
2516                                 break;
2517                             }
2518                         }
2519                     }
2520                     if (oleLoanForm.getLoanList() != null && oleLoanForm.getLoanList().size() > 0) {
2521                         for (int i = 0; i < oleLoanForm.getLoanList().size(); i++) {
2522                             if ((oleLoanForm.getLoanList().get(i).getItemId()).equalsIgnoreCase(oleLoanDocument.getItemId())) {
2523                                 oleLoanForm.getLoanList().remove(i);
2524                                 break;
2525                             }
2526                         }
2527                     }
2528                     oleLoanForm.setOleLoanDocumentToLoanList(oleLoanDocument);
2529                     oleLoanForm.setMessage("");
2530                     oleLoanForm.setSuccess(true);
2531                     oleLoanForm.setOverrideRenewal(false);
2532                     oleLoanForm.setRenewalFlag(false);
2533                     oleLoanForm.setOverrideRenewItemFlag(false);
2534                     if(!oleLoanDocument.isNonCirculatingItem()){
2535                        oleLoanForm.setNonCirculatingFlag(false);
2536                     }
2537                     if(oleLoanDocument.isRenewNotFlag()){
2538                         oleLoanForm.setSuccessInfo(OLEConstants.RENEWAL_DUEDATE_SAME_INFO);
2539                     }else {
2540                         oleLoanForm.setSuccessInfo(OLEConstants.RENEWAL_ITM_SUCCESS_INFO);
2541                     }
2542                 }
2543                 // } else
2544                 //   oleLoanForm.setMessage(OLEConstants.RENEWAL_ITM_AFTER_FIXED_DUEDATE);
2545 
2546                 if(oleLoanForm.getSuccessInfo().contains(OLEConstants.RENEWAL_ITM_SUCCESS_INFO)){
2547                     OleRenewalHistory oleRenewalHistory = new OleRenewalHistory();
2548                     oleRenewalHistory.setItemBarcode(oleLoanDocument.getItemId());
2549                     oleRenewalHistory.setItemId(oleLoanDocument.getItemUuid());
2550                     oleRenewalHistory.setLoanId(oleLoanDocument.getLoanId());
2551                     oleRenewalHistory.setOperatorId(oleLoanDocument.getLoanOperatorId());
2552                     oleRenewalHistory.setPatronBarcode(oleLoanForm.getPatronBarcode());
2553                     oleRenewalHistory.setRenewalDueDate(oleLoanDocument.getLoanDueDate());
2554                     oleRenewalHistory.setRenewedDate(new Timestamp(System.currentTimeMillis()));
2555                     KRADServiceLocator.getBusinessObjectService().save(oleRenewalHistory);
2556                 }
2557 
2558             } catch (Exception e) {
2559                 LOG.error("Exception", e);
2560                 oleLoanForm.setInformation(e.getMessage());
2561             }
2562 
2563         }
2564 
2565         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
2566     }
2567 
2568     /**
2569      * This method not renewal the existing item
2570      *
2571      * @param form
2572      * @param result
2573      * @param request
2574      * @param response
2575      * @return ModelAndView
2576      */
2577     @RequestMapping(params = "methodToCall=doNotRenewalItem")
2578     public ModelAndView doNotRenewalItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2579                                          HttpServletRequest request, HttpServletResponse response) {
2580         LOG.debug("Inside the do not renewal item method");
2581         OleLoanForm oleLoanForm = (OleLoanForm) form;
2582         oleLoanForm.setInformation("");
2583         oleLoanForm.setSuccessInfo("");
2584         oleLoanForm.setReturnInformation("");
2585         oleLoanForm.setRenewalFlag(false);
2586         oleLoanForm.setSuccess(true);
2587         oleLoanForm.setMessage("");
2588         oleLoanForm.setOverrideRenewal(false);
2589         oleLoanForm.setRenewDueDateFlag(false);
2590         oleLoanForm.setOverrideRenewItemFlag(false);
2591         oleLoanForm.setNonCirculatingFlag(false);
2592         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
2593     }
2594 
2595     /**
2596      * This method renewal the list of existing items
2597      *
2598      * @param form
2599      * @param result
2600      * @param request
2601      * @param response
2602      * @return ModelAndView
2603      */
2604     @RequestMapping(params = "methodToCall=renewalItems")
2605     public ModelAndView renewalItems(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2606                                      HttpServletRequest request, HttpServletResponse response) {
2607         LOG.debug("Inside the renewal items method");
2608         OleLoanForm oleLoanForm = (OleLoanForm) form;
2609         oleLoanForm.setInformation("");
2610         oleLoanForm.setSuccessInfo("");
2611         oleLoanForm.setMessage("");
2612         oleLoanForm.setOleFormKey(oleLoanForm.getFormKey());
2613         List<OleLoanDocument> existingItemList = new ArrayList<OleLoanDocument>(0);
2614         List<OleLoanDocument> renewalItemList = new ArrayList<OleLoanDocument>(0);
2615         existingItemList.addAll(oleLoanForm.getExistingLoanList());
2616         existingItemList.addAll(oleLoanForm.getLoanList());
2617         boolean renewSelectFlag = true;
2618         for (int i = 0; i < existingItemList.size(); i++) {
2619             OleLoanDocument loanDocument = existingItemList.get(i);
2620             if (loanDocument.isCheckNo()) {
2621                 renewSelectFlag = false;
2622                 break;
2623             }
2624         }
2625         if (!renewSelectFlag) {
2626             String errMsg = "";
2627             for (int i = 0; i < existingItemList.size(); i++) {
2628                 OleLoanDocument loanDocument = existingItemList.get(i);
2629                 loanDocument.setErrorMessage(null);
2630                 if (loanDocument.isCheckNo()) {
2631                     renewSelectFlag = false;
2632                     loanDocument.setCheckNo(false);
2633                     renewalItemList.add(loanDocument);
2634                     oleLoanForm.setRenewDueDateList(renewalItemList);
2635                 }
2636             }
2637             List<OleLoanDocument> renewObjects = (List<OleLoanDocument>) getLoanProcessor().getLoanObjectsFromDAO(renewalItemList,oleLoanForm.getPatronId());
2638             int i=0;
2639             renewalItemList = new ArrayList<OleLoanDocument>(0);
2640             for(Object loanObject : renewObjects){
2641                 OleLoanDocument loanDocument = (OleLoanDocument) loanObject;
2642                 try {
2643                     loanDocument.setPatronId(oleLoanForm.getPatronId());
2644                     loanDocument.setBorrowerTypeId(oleLoanForm.getBorrowerTypeId());
2645                     loanDocument.setBorrowerTypeName(oleLoanForm.getBorrowerType());
2646                     loanDocument.setBorrowerTypeCode(oleLoanForm.getBorrowerCode());
2647                     loanDocument.setRenewalItemFlag(true);
2648                     loanDocument.setCirculationLocationId(oleLoanForm.getCirculationDesk());
2649                     loanDocument = getLoanProcessor().addLoan(loanDocument.getPatronBarcode(), loanDocument.getItemId(), loanDocument,  null);
2650                         /*if (getLoanProcessor().checkPendingRequestforItem(loanDocument.getItemUuid())) {
2651                             loanDocument.setErrorMessage(OLEConstants.PENDING_RQST_RENEWAL_ITM_INFO);
2652                             oleLoanForm.setRenewDueDateFlag(true);
2653                             renewalItemList.add(loanDocument);
2654                             oleLoanForm.setRenewDueDateList(renewalItemList);
2655                         } else */
2656                     oleLoanForm.setNonCirculatingFlag(loanDocument.isNonCirculatingItem());
2657                     if(loanDocument.isIndefiniteCheckFlag()){
2658                         errMsg = errMsg + (i + 1) + ". " + OLEConstants.RENEWAL_INDEFINITE_INFO + "  (" + loanDocument.getItemId() + ")<br/>";
2659                         oleLoanForm.setRenewDueDateFlag(false);
2660                      /*   oleLoanForm.setRenewalFlag(false);
2661                         oleLoanForm.setOverrideRenewal(false);
2662                         oleLoanForm.setOverrideRenewItemFlag(false);*/
2663                         oleLoanForm.setNonCirculatingFlag(false);
2664                         i++;
2665                     } else if(loanDocument.isRenewNotFlag()){
2666                         errMsg = errMsg + (i + 1) + ". " + OLEConstants.RENEWAL_DUEDATE_SAME_INFO + "  (" + loanDocument.getItemId() + ")<br/>";
2667                         oleLoanForm.setRenewDueDateFlag(false);
2668                      /*   oleLoanForm.setRenewDueDateFlag(false);
2669                         oleLoanForm.setRenewalFlag(false);
2670                         oleLoanForm.setOverrideRenewal(false);
2671                         oleLoanForm.setOverrideRenewItemFlag(false);*/
2672                         oleLoanForm.setNonCirculatingFlag(false);
2673                     } else if (loanDocument.getErrorMessage() == null) {
2674                         errMsg = errMsg + (i + 1) + ". " + OLEConstants.RENEWAL_ITM_SUCCESS_INFO + "  (" + loanDocument.getItemId() + ")<br/>";
2675                         OleRenewalHistory oleRenewalHistory = new OleRenewalHistory();
2676                         oleRenewalHistory.setItemBarcode(loanDocument.getItemId());
2677                         oleRenewalHistory.setItemId(loanDocument.getItemUuid());
2678                         oleRenewalHistory.setLoanId(loanDocument.getLoanId());
2679                         oleRenewalHistory.setOperatorId(loanDocument.getLoanOperatorId());
2680                         oleRenewalHistory.setPatronBarcode(loanDocument.getPatronBarcode());
2681                         oleRenewalHistory.setRenewalDueDate(loanDocument.getLoanDueDate());
2682                         oleRenewalHistory.setRenewedDate(new Timestamp(System.currentTimeMillis()));
2683                         KRADServiceLocator.getBusinessObjectService().save(oleRenewalHistory);
2684                         i++;
2685                         //oleLoanForm.getExistingLoanList().remove(i);
2686                         if (oleLoanForm.getExistingLoanList() != null && oleLoanForm.getExistingLoanList().size() > 0) {
2687                             //  oleLoanForm.getExistingLoanList().remove(renewCurrentCount);
2688                             for (int existingList = 0; existingList < oleLoanForm.getExistingLoanList().size(); existingList++) {
2689                                 if ((oleLoanForm.getExistingLoanList().get(existingList).getItemId()).equalsIgnoreCase(loanDocument.getItemId())) {
2690                                     oleLoanForm.getExistingLoanList().remove(existingList);
2691                                     break;
2692                                 }
2693                             }
2694                         }
2695                         if (oleLoanForm.getLoanList()!=null && oleLoanForm.getLoanList().size()>0){
2696                             for (int loanList = 0; loanList < oleLoanForm.getLoanList().size(); loanList++) {
2697                                 if ((oleLoanForm.getLoanList().get(loanList).getItemId()).equalsIgnoreCase(loanDocument.getItemId())) {
2698                                     oleLoanForm.getLoanList().remove(loanList);
2699                                     break;
2700                                 }
2701                             }
2702                         }
2703                         oleLoanForm.setOleLoanDocumentToLoanList(loanDocument);
2704                     } else {
2705                         if (getLoanProcessor().checkPendingRequestforItem(loanDocument.getItemUuid())){
2706                             PermissionService service = KimApiServiceLocator.getPermissionService();
2707                             boolean hasPermission = service.hasPermission(GlobalVariables.getUserSession().getPrincipalId(),OLEConstants.DLVR_NMSPC,OLEConstants.PENDING_RQST_RENEWAL_ITM_INFO);
2708                             if (!hasPermission){
2709                                 loanDocument.setRenewPermissionForRequestedItem(true);
2710                             }
2711                         }
2712                         loanDocument.setErrorMessage(loanDocument.getErrorMessage().substring(0, loanDocument.getErrorMessage().lastIndexOf("(OR)")));
2713                         oleLoanForm.setRenewDueDateFlag(true);
2714                         renewalItemList.add(loanDocument);
2715                         oleLoanForm.setRenewDueDateList(renewalItemList);
2716                     }
2717                 } catch (Exception e) {
2718                     LOG.error("Exception", e);
2719                 }
2720 
2721             }
2722             if (errMsg!="")
2723                 oleLoanForm.setSuccessInfo(errMsg);
2724         }
2725         if (renewSelectFlag)
2726             oleLoanForm.setInformation(OLEConstants.RENEWAL_ITM_ERR_INFO);
2727         //}
2728         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
2729     }
2730 
2731 
2732     /**
2733      * This method renewal the list of existing items  by using override
2734      *
2735      * @param form
2736      * @param result
2737      * @param request
2738      * @param response
2739      * @return ModelAndView
2740      */
2741     @RequestMapping(params = "methodToCall=overrideRenewItems")
2742     public ModelAndView overrideRenewItems(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2743                                            HttpServletRequest request, HttpServletResponse response) {
2744         LOG.debug("Inside the renewal items method");
2745         OleLoanForm oleLoanForm = (OleLoanForm) form;
2746         oleLoanForm.setOleFormKey(oleLoanForm.getFormKey());
2747         oleLoanForm.setMessage("");
2748         oleLoanForm.setPopDateTimeInfo("");
2749         String info = oleLoanForm.getSuccessInfo()!=null ? oleLoanForm.getSuccessInfo() : "";
2750         List<OleLoanDocument> renewItemList = new ArrayList<OleLoanDocument>(0);
2751         renewItemList.addAll(oleLoanForm.getRenewDueDateList());
2752         try {
2753             boolean renewSelectFlag = true;
2754             for (int i = 0; i < renewItemList.size(); i++) {
2755                 OleLoanDocument loanDocument = renewItemList.get(i);
2756                 if (loanDocument.isRenewCheckNo()) {
2757                     renewSelectFlag = false;
2758                     break;
2759                 }
2760             }
2761             if (!renewSelectFlag) {
2762                 ModelAndView overrideModelView = this.overRide(form, result, request, response);
2763                 if (overrideModelView == null) {
2764 
2765                     for (int i = 0; i < renewItemList.size(); i++) {
2766                         OleLoanDocument loanDocument = renewItemList.get(i);
2767                      //   if (!getLoanProcessor().checkPendingRequestforItem(loanDocument.getItemUuid())) {
2768                             loanDocument.setErrorMessage(null);
2769                             Timestamp currentDate = new Timestamp(System.currentTimeMillis());
2770                             if (loanDocument.isRenewCheckNo()) {
2771                                 loanDocument.setRenewCheckNo(false);
2772                                 //if (currentDate.after(loanDocument.getLoanDueDate())) {
2773                                 if(loanDocument.isNonCirculatingItem() && loanDocument.getRenewalDateMap() != null){
2774                                     Timestamp timestamp;
2775                                     Pattern pattern;
2776                                     Matcher matcher;
2777                                     SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OlePatron.PATRON_MAINTENANCE_DATE_FORMAT);
2778                                     boolean timeFlag = false;
2779                                     oleLoanForm.setDueDateMap(loanDocument.getRenewalDateMap());
2780                                     if (loanDocument.getRenewalDateTime() != null && !loanDocument.getRenewalDateTime().isEmpty()) {
2781                                         String[] str = loanDocument.getRenewalDateTime().split(":");
2782                                         pattern = Pattern.compile(OLEConstants.TIME_24_HR_PATTERN);
2783                                         matcher = pattern.matcher(loanDocument.getRenewalDateTime());
2784                                         timeFlag = matcher.matches();
2785                                         if (timeFlag) {
2786                                             if (str != null && str.length <= 2) {
2787                                                 loanDocument.setRenewalDateTime(loanDocument.getRenewalDateTime() + OLEConstants.CHECK_IN_TIME_MS);
2788                                             }
2789                                             timestamp = Timestamp.valueOf(new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT).format(loanDocument.getRenewalDateMap()).concat(" ").concat(loanDocument.getRenewalDateTime()));
2790                                         } else {
2791                                             oleLoanForm.setPopDateTimeInfo(OLEConstants.DUE_DATE_TIME_FORMAT_MESSAGE);
2792                                      /*return getUIFModelAndView(oleLoanForm,"PatronItemViewPage");*/
2793                                             return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
2794                                         }
2795                                     } else if (fmt.format(oleLoanForm.getDueDateMap()).compareTo(fmt.format(new Date())) == 0) {
2796                                         timestamp = new Timestamp(new Date().getTime());
2797                                     } else {
2798                                         timestamp = Timestamp.valueOf(new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT).format(oleLoanForm.getDueDateMap()).concat(" ").concat(new SimpleDateFormat("HH:mm:ss").format(new Date())));
2799                                     }
2800                                     loanDocument.setManualRenewalDueDate(timestamp);
2801                                     // Timestamp timestamp = Timestamp.valueOf(new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT).format(oleLoanForm.getDueDateMap()).concat(" ").concat(new SimpleDateFormat("HH:mm:ss").format(new Date())));
2802                                     oleLoanForm.setNonCirculatingFlag(false);
2803                                 }else{
2804                                     loanDocument.setManualRenewalDueDate(null);
2805                                 }
2806                                 getLoanProcessor().overrideSaveLoanForRenewal(loanDocument);
2807                                 loanDocument.setErrorMessage(OLEConstants.RENEWAL_ITM_SUCCESS_INFO);
2808                                 for (int j = 0; j < oleLoanForm.getExistingLoanList().size(); j++) {
2809                                     if (loanDocument.getLoanId().equals(oleLoanForm.getExistingLoanList().get(j).getLoanId())) {
2810                                         oleLoanForm.getExistingLoanList().remove(j);
2811                                         oleLoanForm.setOleLoanDocumentToLoanList(loanDocument);
2812                                     }
2813                                     if(loanDocument.getItemId().equals(oleLoanForm.getExistingLoanList().get(j).getItemId())){
2814                                         OleLoanDocument existingLoan = oleLoanForm.getExistingLoanList().get(j);
2815                                         existingLoan.setLoanDueDate(loanDocument.getLoanDueDate());
2816                                         existingLoan.setNumberOfRenewals(loanDocument.getNumberOfRenewals());
2817                                         existingLoan.setCourtesyNoticeFlag(false);
2818                                     }
2819                                 }
2820                                 if (oleLoanForm.getLoanList()!=null && oleLoanForm.getLoanList().size()>0){
2821                                     for (int loanList = 0; loanList < oleLoanForm.getLoanList().size(); loanList++) {
2822                                         if ((oleLoanForm.getLoanList().get(loanList).getItemId()).equalsIgnoreCase(loanDocument.getItemId())) {
2823                                             OleLoanDocument existingLoan = oleLoanForm.getLoanList().get(loanList);
2824                                             existingLoan.setLoanDueDate(loanDocument.getLoanDueDate());
2825                                             existingLoan.setCourtesyNoticeFlag(false);
2826                                             existingLoan.setNumberOfRenewals(loanDocument.getNumberOfRenewals());
2827                                             break;
2828                                         }
2829                                     }
2830                                 }
2831                                 oleLoanForm.setMessage("");
2832                                 oleLoanForm.setSuccess(true);
2833                                 oleLoanForm.setOverrideRenewal(false);
2834                                 oleLoanForm.setNonCirculatingFlag(loanDocument.isNonCirculatingItem());
2835                                 if(loanDocument.isRenewNotFlag()){
2836                                     info = info + (i + 1) + ". " + OLEConstants.RENEWAL_DUEDATE_SAME_INFO + "  (" + loanDocument.getItemId() + ")<br/>";
2837                                 }else {
2838                                     info = info + (i + 1) + ". " + OLEConstants.RENEWAL_ITM_SUCCESS_INFO + "  (" + loanDocument.getItemId() + ")<br/>";
2839                                     OleRenewalHistory oleRenewalHistory = new OleRenewalHistory();
2840                                     oleRenewalHistory.setItemBarcode(loanDocument.getItemId());
2841                                     oleRenewalHistory.setItemId(loanDocument.getItemUuid());
2842                                     oleRenewalHistory.setLoanId(loanDocument.getLoanId());
2843                                     oleRenewalHistory.setOperatorId(loanDocument.getLoanOperatorId());
2844                                     oleRenewalHistory.setPatronBarcode(oleLoanForm.getPatronBarcode());
2845                                     oleRenewalHistory.setRenewalDueDate(loanDocument.getLoanDueDate());
2846                                     oleRenewalHistory.setRenewedDate(new Timestamp(System.currentTimeMillis()));
2847                                     KRADServiceLocator.getBusinessObjectService().save(oleRenewalHistory);
2848                                 }
2849                                 // } else
2850                                 //loanDocument.setErrorMessage(OLEConstants.RENEWAL_ITM_AFTER_FIXED_DUEDATE);
2851 
2852                             }
2853                      //   }
2854                         oleLoanForm.setOverrideRenewItemFlag(false);
2855 
2856                     }
2857 
2858                 }
2859             }
2860             if (info!=""){
2861                 oleLoanForm.setSuccessInfo(info);
2862             }
2863         } catch (Exception e) {
2864             LOG.error("Exception ---> " + e, e);
2865         }
2866         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
2867     }
2868 
2869 
2870     /**
2871      * This method initiate LoanProcessor.
2872      *
2873      * @return LoanProcessor
2874      */
2875     private LoanProcessor getLoanProcessor() {
2876         if (loanProcessor == null) {
2877             loanProcessor = SpringContext.getBean(LoanProcessor.class);
2878         }
2879         return loanProcessor;
2880     }
2881 
2882     /**
2883      * This method creates new loan for a patron..
2884      *
2885      * @param form
2886      * @param result
2887      * @param request
2888      * @param response
2889      * @return ModelAndView
2890      */
2891     @RequestMapping(params = "methodToCall=validateItem")
2892     public ModelAndView validateItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2893                                      HttpServletRequest request, HttpServletResponse response) {
2894         if (LOG.isDebugEnabled()) {
2895             LOG.debug(" Inside Validate Item ");
2896         }
2897         long begin = System.currentTimeMillis();
2898         OleLoanForm oleLoanForm = (OleLoanForm) form;
2899         oleLoanForm.setRouteToLocation(null);
2900         oleLoanForm.setSuccessMessage(null);
2901        /* String parameter = getLoanProcessor().getParameter(OLEConstants.MAX_TIME_CHECK_IN);
2902         oleLoanForm.setMaxTimeForCheckInDate(Integer.parseInt(parameter) * 60);*/
2903 
2904         String audioOption = getLoanProcessor().getParameter(OLEConstants.AUDIO_OPTION);
2905         oleLoanForm.setAudioEnable(audioOption != null && !audioOption.isEmpty() && audioOption.equalsIgnoreCase(OLEConstants.TRUE));
2906         oleLoanForm.setOleFormKey(oleLoanForm.getFormKey());
2907         oleLoanForm.setReturnInformation("");
2908         oleLoanForm.setErrorMessage("");
2909         OleLoanDocument oleLoanDocument = null;
2910         if (oleLoanForm.getCheckInItem() != null) {
2911             oleLoanDocument = getLoanProcessor().getOleLoanDocumentUsingItemBarcode(oleLoanForm.getCheckInItem());
2912         } else {
2913             oleLoanDocument = getLoanProcessor().getOleLoanDocumentUsingItemUUID(oleLoanForm.getReturnItemUuid());
2914         }
2915         if (oleLoanDocument == null) {
2916             oleLoanDocument = new OleLoanDocument();
2917         }
2918         Timestamp timestamp;
2919         Pattern pattern;
2920         Matcher matcher;
2921         boolean timeFlag = false;
2922         SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OlePatron.PATRON_MAINTENANCE_DATE_FORMAT);
2923         if (oleLoanForm.getCheckInTime() != null && !oleLoanForm.getCheckInTime().isEmpty()) {
2924             String[] str = oleLoanForm.getCheckInTime().split(":");
2925             pattern = Pattern.compile(OLEConstants.TIME_24_HR_PATTERN);
2926             matcher = pattern.matcher(oleLoanForm.getCheckInTime());
2927             timeFlag = matcher.matches();
2928             if (timeFlag) {
2929                 if (str != null && str.length <= 2) {
2930                     oleLoanForm.setCheckInTime(oleLoanForm.getCheckInTime() + OLEConstants.CHECK_IN_TIME_MS);
2931                 }
2932                 timestamp = Timestamp.valueOf(new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT).format(oleLoanForm.getCheckInDate()).concat(" ").concat(oleLoanForm.getCheckInTime()));
2933             } else {
2934                 //oleLoanForm.setReturnInformation(OLEConstants.CHECKIN_TIME_FORMAT_MESSAGE);
2935                 return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
2936             }
2937         } else if (fmt.format(oleLoanForm.getCheckInDate()).compareTo(fmt.format(new Date())) == 0) {
2938             timestamp = new Timestamp(new Date().getTime());
2939         } else {
2940             timestamp = Timestamp.valueOf(new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT).format(oleLoanForm.getCheckInDate()).concat(" ").concat(new SimpleDateFormat("HH:mm:ss").format(new Date())));
2941         }
2942         oleLoanDocument.setCheckInDate(timestamp);
2943         try {
2944             /*if (!loanProcessor.isValidCirculationDesk()) {
2945                 oleLoanForm.setLoanLoginMessage(true);
2946                 String loginInfo = loanProcessor.getErrorMessage();
2947                 oleLoanForm.setLoanLoginUserInfo(loginInfo);
2948                 return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
2949                 //throw new DocumentAuthorizationException(GlobalVariables.getUserSession().getPrincipalId(), "not Authorized", form.getViewId());
2950                 //return new OLEKRADAuthorizationResolver().resolveException(request,response,null,new Exception("is not authorized"));
2951             }*/
2952             // Modified as per comments in Jira OLE-4901
2953             if (!getLoanProcessor().isValidCirculationDesk()) {
2954                 oleLoanForm.setLoanLoginUserInfo(GlobalVariables.getUserSession().getPrincipalName() + " " + OLEConstants.OleCirculationDesk.OLE_CIRCULATION_DESK_VALIDATIONS);
2955                 return super.start(oleLoanForm, result, request, response);
2956             }
2957             oleLoanDocument.setCirculationLocationId(oleLoanForm.getCirculationDesk());
2958             //oleLoanDocument.setDamagedCheckInOption(oleLoanForm.isDamagedCheckInOption());
2959             if (LOG.isDebugEnabled()) {
2960                 LOG.debug("Check-in Item Barcode Number --->" + oleLoanForm.getCheckInItem());
2961             }
2962             oleLoanDocument.setItemUuid(oleLoanForm.getReturnItemUuid());
2963             oleLoanForm.getErrorsAndPermission().clear();
2964             oleLoanDocument.setSkipDamagedCheckIn(oleLoanForm.isSkipDamagedCheckIn());
2965             oleLoanDocument = getLoanProcessor().returnLoan(oleLoanForm.getCheckInItem(), oleLoanDocument);
2966             if(oleLoanDocument!=null && oleLoanDocument.getOleItem()!=null && oleLoanDocument.getOleItem().getCheckinNote()==null){
2967                 getLoanProcessor().updateInTransitHistory(oleLoanDocument,oleLoanForm.getRouteToLocation());
2968             }
2969             oleLoanForm.setItemDamagedStatus(oleLoanDocument.isItemDamagedStatus());
2970             if (oleLoanDocument.isItemDamagedStatus() && (!oleLoanDocument.isSkipDamagedCheckIn())) {
2971                 return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
2972             } else {
2973                 if (oleLoanForm.isRecordDamagedItemNote()) {
2974                     saveGeneralNoteForFlaggedItem(OLEConstants.DAMAGED_ITEM_CHECKED_IN_FLAG, true, oleLoanDocument, false, true, false, oleLoanForm.getPatronBarcode());
2975                     oleLoanForm.setRecordDamagedItemNote(false);
2976                 }
2977                 oleLoanForm.setSkipDamagedCheckIn(false);
2978                 oleLoanForm.setItemDamagedStatus(false);
2979             }
2980             org.kuali.ole.docstore.common.document.Item item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(oleLoanDocument.getItemUuid());
2981             String itemXmlContent = item.getContent();
2982             Item oleItem = getLoanProcessor().getItemPojo(itemXmlContent);
2983             getLoanProcessor().getLocation(oleItem, oleLoanDocument, item);
2984             if (oleLoanDocument.getLocation() == null || oleLoanDocument.getLocation().isEmpty()) {
2985                 getLoanProcessor().getDefaultHoldingLocation(oleLoanDocument);
2986             }
2987             if (oleItem.isClaimsReturnedFlag()) {
2988                 oleLoanForm.setDummyLoan(oleLoanDocument);
2989                 oleLoanForm.setClaimsReturned(true);
2990                 oleLoanForm.setRecordNote(false);
2991                 oleLoanForm.setReturnSuccess(false);
2992                 oleLoanForm.setReturnMessage(OLEConstants.CLAIMS_RETURNED_MESSAGE);
2993                 return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
2994             }
2995             //String requestCheck = oleLoanDocument.getOleDeliverRequestBo() != null ? OLEConstants.REQUEST_EXISTS : "";
2996             /*if(!requestCheck.isEmpty()){
2997                 oleLoanForm.setPatronRequest(true);
2998                 oleLoanForm.setReturnSuccess(false);
2999                 oleLoanForm.setReturnMessage(requestCheck);
3000             }*/
3001            /* if (oleLoanDocument.getItemStatusCode().contains(OLEConstants.ITEM_STATUS_RETURNED_DAMAGED)) {
3002                 oleLoanForm.setReturnSuccess(false);
3003                 oleLoanForm.setReturnMessage(OLEConstants.DAMAGED_CHECK_IN_HEADER + requestCheck);
3004                 oleLoanForm.setRouteToLocation(oleLoanDocument.getRouteToLocation());
3005                 oleLoanForm.setDamagedCheckIn(true);
3006             }*/
3007             oleLoanForm.setDummyLoan(oleLoanDocument);
3008             if (oleLoanDocument.isCopyRequest()) {
3009                 oleLoanForm.setCopyRequest(true);
3010                 oleLoanForm.setReturnSuccess(false);
3011                 oleLoanForm.setReturnMessage(OLEConstants.COPY_REQUEST_FULFILL);
3012                 return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
3013             }
3014             if (oleLoanDocument.isNumberOfPieces()) {
3015                 oleLoanForm.setNumberOfPieces(true);
3016                 oleLoanForm.setReturnSuccess(false);
3017                 if (oleLoanDocument.getOleItem() != null && oleLoanDocument.getOleItem().isMissingPieceFlag()) {
3018                     oleLoanForm.setReturnMessage(OLEConstants.VERIFY_PIECES + oleLoanDocument.getItemNumberOfPieces() + OLEConstants.PIECES_RETURNED
3019                             + OLEConstants.BREAK + "Total No of Pieces :      " + oleLoanDocument.getItemNumberOfPieces() + OLEConstants.BREAK + "No of missing Pieces : " + (oleLoanDocument.getOleItem().getMissingPiecesCount() != null ? oleLoanDocument.getOleItem().getMissingPiecesCount() : "0"));
3020                 } else {
3021                     oleLoanForm.setReturnMessage(OLEConstants.VERIFY_PIECES + oleLoanDocument.getItemNumberOfPieces() + OLEConstants.PIECES_RETURNED
3022                             + OLEConstants.BREAK + "Total No of Pieces :      " + oleLoanDocument.getItemNumberOfPieces() + OLEConstants.BREAK + "No of missing Pieces : " + (oleLoanDocument.getOleItem().getMissingPiecesCount() != null ? oleLoanDocument.getOleItem().getMissingPiecesCount() : "0"));
3023                 }
3024                 return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
3025             }
3026             String checkInNote = oleLoanDocument.getOleItem().getCheckinNote();
3027             if (checkInNote != null && !checkInNote.isEmpty() && oleLoanForm.getReturnMessage() == null) {
3028                 oleLoanForm.setCheckInNote(OLEConstants.CHECK_IN_NOTE_HEADER + checkInNote);
3029                 oleLoanForm.setRouteToLocation(oleLoanDocument.getRouteToLocation());
3030                 String principalId = GlobalVariables.getUserSession().getPrincipalId();
3031                 oleLoanForm.setOkOrRemoveNote(getLoanProcessor().checkPermissionForRemoveNote(principalId));
3032             }
3033             if (!oleLoanDocument.isBackGroundCheckOut() && oleLoanDocument.getErrorMessage() != null) {
3034                 oleLoanForm.setReturnSuccess(false);
3035                 oleLoanForm.setReturnMessage(oleLoanDocument.getErrorMessage());
3036             } else {
3037                 List<OleLoanDocument> oleLoanDocuments = new ArrayList<OleLoanDocument>();
3038                 if (!oleLoanDocument.isCheckOut() || oleLoanDocument.getErrorMessage() == null)
3039                     oleLoanDocuments.add(oleLoanDocument);
3040                 if (oleLoanForm.getItemReturnList() != null) {
3041                     oleLoanDocuments.addAll(oleLoanForm.getItemReturnList());
3042                 }
3043                 oleLoanForm.setItemReturnList(oleLoanDocuments);
3044                 //To refresh loan screen current and previous session loan list
3045             //    oleLoanForm.setExistingLoanList(getLoanProcessor().getPatronLoanedItemBySolr(oleLoanDocument.getPatronId()));
3046                 OleLoanDocument tempOleLoanDocumentObj = null;
3047                 List<OleLoanDocument> currentSessionList = oleLoanForm.getLoanList() != null ? oleLoanForm.getLoanList() : new ArrayList<OleLoanDocument>();
3048                 for (OleLoanDocument currentOleLoanDocument : currentSessionList) {
3049                     if (currentOleLoanDocument.getItemId().equals(oleLoanForm.getCheckInItem())) {
3050                         tempOleLoanDocumentObj = currentOleLoanDocument;
3051                         break;
3052                     }
3053                 }
3054                 currentSessionList.remove(tempOleLoanDocumentObj);
3055                 oleLoanForm.setLoanList(currentSessionList);
3056                 //To refresh loan screen current and previous session loan list
3057                 oleLoanForm.setCheckInItem("");
3058             }
3059         } catch (Exception e) {
3060             LOG.error("Exception in validate Item " + e);
3061             oleLoanForm.setReturnInformation(e.getMessage());
3062             oleLoanForm.setBillAvailability(false);
3063             try {
3064                 org.kuali.ole.docstore.common.document.content.instance.Item oleItem = getLoanProcessor().checkItemStatusForItemBarcode(oleLoanForm.getCheckInItem());
3065                 if(oleItem != null && oleItem.getItemStatus() != null && !oleItem.getItemStatus().getCodeValue().equalsIgnoreCase(OLEConstants.ITEM_STATUS_CHECKEDOUT)){
3066                     getLoanProcessor().rollbackItemStatus(oleItem,OLEConstants.ITEM_STATUS_CHECKEDOUT,oleLoanForm.getCheckInItem());
3067                     oleLoanForm.setReturnInformation(OLEConstants.RETURN_PROCESS_FAILURE);
3068                 }
3069 
3070             }catch (Exception rollback){
3071                 LOG.error("Exception occured during rollback item records " + rollback.getMessage());
3072             }
3073             return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
3074         }
3075         if (!oleLoanForm.isCheckInNoteExists() && oleLoanForm.getCheckInNote() != null && oleLoanForm.getReturnMessage() == null) {
3076             oleLoanForm.setDummyLoan(oleLoanDocument);
3077             oleLoanForm.setCheckInNoteExists(true);
3078             oleLoanForm.setReturnSuccess(false);
3079             oleLoanForm.setReturnMessage(oleLoanForm.getCheckInNote());
3080             long end = System.currentTimeMillis();
3081             long total = end - begin;
3082             LOG.info("Time taken Inside Validate Item - checkin note"+total);
3083             return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
3084         }
3085         if (oleLoanDocument.isCheckOut() && oleLoanDocument.getErrorMessage() != null && oleLoanForm.getReturnMessage() == null) {
3086             oleLoanForm.setDueDateEmpty(oleLoanDocument.isDueDateEmpty());
3087             oleLoanForm.setDummyLoan(oleLoanDocument);
3088             oleLoanForm.setReturnSuccess(false);
3089             oleLoanForm.setMessage(oleLoanDocument.getErrorMessage());
3090             oleLoanForm.setCheckOut(true);
3091             oleLoanForm.setItem(oleLoanForm.getCheckInItem());
3092             oleLoanForm.setOleItem(oleLoanDocument.getOleItem());
3093             return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
3094         }
3095         if ((oleLoanForm.getReturnMessage() == null) && oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isPrintSlip()) {
3096             if (oleLoanDocument.getOleItem().isMissingPieceFlag()) {
3097                 OleNoticeBo oleNoticeBo = getLoanProcessor().getNotice(oleLoanDocument);
3098                 // SimpleDateFormat simpleDateFormat=new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT);
3099                 SimpleDateFormat dateFormat = new SimpleDateFormat(OLEConstants.DATEFORMAT);
3100 
3101                 Date date = new Date(oleLoanDocument.getCheckInDate().getTime());
3102                 if (oleNoticeBo != null) {
3103                     oleNoticeBo.setCheckInDate(dateFormat.format(date));
3104 
3105                     String missingNoticeDetails = getOleDeliverBatchService().sendMissingNotice(oleNoticeBo);
3106                     OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
3107                     String replyToEmail = getCircDeskLocationResolver().getReplyToEmail(oleNoticeBo.getItemShelvingLocation());
3108                     if (replyToEmail != null) {
3109                         oleMailer.sendEmail(new EmailFrom(replyToEmail), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
3110                     } else {
3111                         String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
3112                         if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
3113                             fromAddress = OLEConstants.KUALI_MAIL;
3114                         }
3115                         oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
3116                     }
3117                     if (LOG.isInfoEnabled()) {
3118                         LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
3119                     }
3120                 }
3121             } else {
3122                 if (oleLoanDocument.getItemStatusCode() != null && oleLoanDocument.getItemStatusCode().equals(OLEConstants.ITEM_STATUS_ON_HOLD) && oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isHoldQueue()) {
3123                     oleLoanForm.setBillAvailability(false);
3124                 } else {
3125                     oleLoanForm.setBillAvailability(true);
3126                 }
3127             }
3128         }
3129         if (oleLoanDocument.isCheckOut()) {
3130             oleLoanForm.setDueDateSlip(true);
3131             oleLoanForm.setBillAvailability(false);
3132         }
3133         if (request != null && !"".equalsIgnoreCase(request.toString())) {
3134             oleLoanForm.setDueDateSlip(false);
3135         }
3136         if (oleLoanDocument.getItemStatus() != null && oleLoanDocument.getItemStatus().equalsIgnoreCase(OLEConstants.ITEM_STATUS_RECENTLY_RETURNED)) {
3137             oleLoanForm.setBillAvailability(false);
3138             oleLoanForm.setDueDateSlip(false);
3139         }
3140         long end = System.currentTimeMillis();
3141         long total = end - begin;
3142         LOG.info("Time taken Inside Validate Item"+total);
3143         return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
3144     }
3145 
3146     /**
3147      * This method  returns Item for a patron who is not able to return.
3148      *
3149      * @param form
3150      * @param result
3151      * @param request
3152      * @param response
3153      * @return ModelAndView
3154      */
3155     @RequestMapping(params = "methodToCall=returnItem")
3156     public ModelAndView returnItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
3157                                    HttpServletRequest request, HttpServletResponse response) {
3158         if (LOG.isDebugEnabled()) {
3159             LOG.debug(" Inside Return Item ");
3160         }
3161         long begin = System.currentTimeMillis();
3162         OleLoanForm oleLoanForm = (OleLoanForm) form;
3163       /*  String parameter = getLoanProcessor().getParameter(OLEConstants.MAX_TIME_CHECK_IN);
3164         if(parameter != null){
3165             oleLoanForm.setMaxTimeForCheckInDate(Integer.parseInt(parameter) * 60);
3166         }*/
3167 
3168 
3169         String audioOption = getLoanProcessor().getParameter(OLEConstants.AUDIO_OPTION);
3170         oleLoanForm.setAudioEnable(audioOption != null && !audioOption.isEmpty() && audioOption.equalsIgnoreCase(OLEConstants.TRUE));
3171         OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
3172         String principalId = GlobalVariables.getUserSession().getPrincipalId();
3173         Boolean overRideFlag = getLoanProcessor().checkOverRidePermission(principalId, oleLoanForm);
3174         if (oleLoanForm.getMissingPieceCount() != null) {
3175             oleLoanDocument.setMissingPiecesCount(oleLoanForm.getMissingPieceCount());
3176         }
3177         if (!overRideFlag) {
3178             ModelAndView modelAndView = this.overRide(form, result, request, response);
3179             if (modelAndView != null) {
3180                 return modelAndView;
3181             }
3182         }
3183         try {
3184             oleLoanForm.getErrorsAndPermission().clear();
3185             oleLoanDocument = getLoanProcessor().returnLoan(oleLoanDocument);
3186             //   oleLoanForm.setSuccessMessage(oleLoanDocument.getSuccessMessage());
3187             if (oleLoanDocument.isNumberOfPieces()) {
3188                 oleLoanForm.setNumberOfPieces(true);
3189                 oleLoanForm.setReturnSuccess(false);
3190                 //oleLoanForm.setReturnMessage(OLEConstants.VERIFY_PIECES + oleLoanDocument.getItemNumberOfPieces() + OLEConstants.PIECES_RETURNED);
3191                 oleLoanForm.setReturnMessage(OLEConstants.VERIFY_PIECES + oleLoanDocument.getItemNumberOfPieces() + OLEConstants.PIECES_RETURNED
3192                         + OLEConstants.BREAK + "Total No of Pieces :      " + oleLoanDocument.getItemNumberOfPieces() + OLEConstants.BREAK + "No of missing Pieces : " + (oleLoanDocument.getOleItem().getMissingPiecesCount() != null ? oleLoanDocument.getOleItem().getMissingPiecesCount() : "0"));
3193                 return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
3194             }
3195             String checkInNote = oleLoanDocument.getOleItem().getCheckinNote();
3196             if (!oleLoanForm.isBackGroundCheckIn() && checkInNote != null && !checkInNote.isEmpty()) {
3197                 oleLoanForm.setNumberOfPieces(false);
3198                 oleLoanForm.setCheckInNote(OLEConstants.CHECK_IN_NOTE_HEADER + checkInNote);
3199                 oleLoanForm.setRouteToLocation(oleLoanDocument.getRouteToLocation());
3200                 oleLoanForm.setOkOrRemoveNote(getLoanProcessor().checkPermissionForRemoveNote(principalId));
3201             }
3202             List<OleLoanDocument> oleLoanDocuments = new ArrayList<OleLoanDocument>();
3203             if (!oleLoanDocument.isCheckOut() || oleLoanDocument.getErrorMessage() == null)
3204                 oleLoanDocuments.add(oleLoanDocument);
3205             if (oleLoanForm.getItemReturnList() != null) {
3206                 oleLoanDocuments.addAll(oleLoanForm.getItemReturnList());
3207             }
3208             if (!oleLoanForm.isTempClaimsFlag()) {
3209                 oleLoanForm.setItemReturnList(oleLoanDocuments);
3210             } else {
3211                 oleLoanForm.setTempClaimsFlag(false);
3212             }
3213 
3214         } catch (Exception e) {
3215             LOG.error("Exception in return Item " + e, e);
3216         }
3217         oleLoanForm.setReturnSuccess(true);
3218         oleLoanForm.setReturnMessage(null);
3219         oleLoanForm.setCheckInItem("");
3220         oleLoanForm.setReturnInformation("");
3221         if (!oleLoanForm.isCheckInNoteExists() && oleLoanForm.getCheckInNote() != null) {
3222             oleLoanForm.setDummyLoan(oleLoanDocument);
3223             oleLoanForm.setCheckInNoteExists(true);
3224             oleLoanForm.setReturnSuccess(false);
3225             oleLoanForm.setReturnMessage(oleLoanForm.getCheckInNote());
3226             return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
3227         }
3228         if (oleLoanDocument.isCheckOut() && oleLoanDocument.getErrorMessage() != null) {
3229             oleLoanForm.setDueDateEmpty(oleLoanDocument.isDueDateEmpty());
3230             oleLoanForm.setDummyLoan(oleLoanDocument);
3231             oleLoanForm.setReturnSuccess(false);
3232             oleLoanForm.setMessage(oleLoanDocument.getErrorMessage());
3233             oleLoanForm.setCheckOut(true);
3234             oleLoanForm.setItem(oleLoanForm.getCheckInItem());
3235             oleLoanForm.setOleItem(oleLoanDocument.getOleItem());
3236             return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
3237         }
3238         if (oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isPrintSlip()) {
3239             if (oleLoanDocument.getOleItem().isMissingPieceFlag()) {
3240                 OleNoticeBo oleNoticeBo = getLoanProcessor().getNotice(oleLoanDocument);
3241                 // SimpleDateFormat simpleDateFormat=new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT);
3242                 SimpleDateFormat dateFormat = new SimpleDateFormat(OLEConstants.DATEFORMAT);
3243 
3244                 Date date = new Date(oleLoanDocument.getCheckInDate().getTime());
3245                 if (oleNoticeBo != null) {
3246                     oleNoticeBo.setCheckInDate(dateFormat.format(date));
3247 
3248                     String missingNoticeDetails = getOleDeliverBatchService().sendMissingNotice(oleNoticeBo);
3249                     OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
3250                     String replyToEmail = getCircDeskLocationResolver().getReplyToEmail(oleNoticeBo.getItemShelvingLocation());
3251                     if (replyToEmail != null) {
3252                         oleMailer.sendEmail(new EmailFrom(replyToEmail), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
3253                     } else {
3254                         String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
3255                         if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
3256                             fromAddress = OLEConstants.KUALI_MAIL;
3257                         }
3258                         oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
3259                     }
3260                     if (LOG.isInfoEnabled()) {
3261                         LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
3262                     }
3263                 }
3264             } else {
3265                 if (oleLoanDocument.getItemStatusCode() != null && oleLoanDocument.getItemStatusCode().equals(OLEConstants.ITEM_STATUS_ON_HOLD) && oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isHoldQueue()) {
3266                     oleLoanForm.setBillAvailability(false);
3267                 } else {
3268                     oleLoanForm.setBillAvailability(true);
3269                 }
3270             }
3271         }
3272         if (oleLoanDocument.isCheckOut()) {
3273             oleLoanForm.setDueDateSlip(true);
3274             oleLoanForm.setBillAvailability(false);
3275         }
3276         if (oleLoanForm.isBackGroundCheckIn()) {
3277             oleLoanForm.setItem(oleLoanForm.getCheckInItem());
3278             oleLoanForm.setOleItem(oleLoanDocument.getOleItem());
3279             oleLoanDocument.setItemLoanStatus(oleLoanDocument.getItemStatusCode());
3280             loanPatron(oleLoanForm, result, request, response);
3281         }
3282         long end = System.currentTimeMillis();
3283         long total = end - begin;
3284         LOG.info("Time taken Inside Return Item"+total);
3285         return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
3286     }
3287 
3288     /**
3289      * This method  doesn't allow to return an item.
3290      *
3291      * @param form
3292      * @param result
3293      * @param request
3294      * @param response
3295      * @return ModelAndView
3296      */
3297     @RequestMapping(params = "methodToCall=noReturnItem")
3298     public ModelAndView doNotReturnItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
3299                                         HttpServletRequest request, HttpServletResponse response) {
3300         if (LOG.isDebugEnabled()) {
3301             LOG.debug(" Inside Do Not Return Item ");
3302         }
3303         OleLoanForm oleLoanForm = (OleLoanForm) form;
3304        /* String parameter = getLoanProcessor().getParameter(OLEConstants.MAX_TIME_CHECK_IN);
3305         if(parameter != null){
3306             oleLoanForm.setMaxTimeForCheckInDate(Integer.parseInt(parameter) * 60);
3307         }*/
3308         oleLoanForm.setReturnInformation("");
3309         oleLoanForm.setCheckInItem("");
3310         oleLoanForm.setReturnMessage(null);
3311         oleLoanForm.setReturnSuccess(true);
3312         oleLoanForm.setCheckInNote(null);
3313         oleLoanForm.setNumberOfPieces(false);
3314         OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
3315         if (oleLoanForm.getDummyLoan().isCheckOut() && oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isPrintSlip()) {
3316             if (oleLoanDocument.getOleItem().isMissingPieceFlag()) {
3317                 OleNoticeBo oleNoticeBo = getLoanProcessor().getNotice(oleLoanDocument);
3318                 //SimpleDateFormat simpleDateFormat=new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT);
3319                 SimpleDateFormat dateFormat = new SimpleDateFormat(OLEConstants.DATEFORMAT);
3320                 Date date = new Date(oleLoanDocument.getCheckInDate().getTime());
3321                 if (oleNoticeBo != null) {
3322                     oleNoticeBo.setCheckInDate(dateFormat.format(date));
3323                     String missingNoticeDetails = getOleDeliverBatchService().sendMissingNotice(oleNoticeBo);
3324                     OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
3325                     String replyToEmail = getCircDeskLocationResolver().getReplyToEmail(oleNoticeBo.getItemShelvingLocation());
3326                     if (replyToEmail != null) {
3327                         oleMailer.sendEmail(new EmailFrom(replyToEmail), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
3328                     } else {
3329                         String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
3330                         if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
3331                             fromAddress = OLEConstants.KUALI_MAIL;
3332                         }
3333                         oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
3334                     }
3335                     if (LOG.isInfoEnabled()) {
3336                         LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
3337                     }
3338                 }
3339             } else {
3340                 if (oleLoanDocument.getItemStatusCode() != null && oleLoanDocument.getItemStatusCode().equals(OLEConstants.ITEM_STATUS_ON_HOLD) && oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isHoldQueue()) {
3341                     oleLoanForm.setBillAvailability(false);
3342                 } else {
3343                     oleLoanForm.setBillAvailability(true);
3344                 }
3345             }
3346         }
3347         if (oleLoanForm.getDummyLoan() != null && oleLoanForm.getDummyLoan().isCheckOut()) {
3348             oleLoanForm.setDueDateSlip(true);
3349             oleLoanForm.setBillAvailability(false);
3350         }
3351         return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
3352     }
3353 
3354     /**
3355      * This method  allows to continue Check-in.
3356      *
3357      * @param form
3358      * @param result
3359      * @param request
3360      * @param response
3361      * @return ModelAndView
3362      */
3363     @RequestMapping(params = "methodToCall=continueCheckIn")
3364     public ModelAndView continueCheckIn(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
3365                                         HttpServletRequest request, HttpServletResponse response) {
3366         if (LOG.isDebugEnabled()) {
3367             LOG.debug(" Inside Continue Check-in ");
3368         }
3369         long begin = System.currentTimeMillis();
3370         OleLoanForm oleLoanForm = (OleLoanForm) form;
3371        /* String parameter = getLoanProcessor().getParameter(OLEConstants.MAX_TIME_CHECK_IN);
3372         if(parameter != null){
3373             oleLoanForm.setMaxTimeForCheckInDate(Integer.parseInt(parameter) * 60);
3374         }*/
3375 
3376         String audioOption = getLoanProcessor().getParameter(OLEConstants.AUDIO_OPTION);
3377         oleLoanForm.setAudioEnable(audioOption != null && !audioOption.isEmpty() && audioOption.equalsIgnoreCase(OLEConstants.TRUE));
3378         String description = oleLoanForm.getDescription();
3379         String matchCheck = oleLoanForm.getMatchCheck();
3380         String copyCheck = oleLoanForm.getCopyCheck();
3381         oleLoanForm.getErrorsAndPermission().clear();
3382         OleLoanDocument oleLoanDocument = new OleLoanDocument();
3383         oleLoanDocument = oleLoanForm.getDummyLoan();
3384         oleLoanDocument.setDescription(oleLoanForm.getDescription());
3385         oleLoanDocument.setMissingPieceNote(oleLoanForm.getMissingPieceNote());
3386         if (oleLoanForm.getMissingPieceCount() != null) {
3387             oleLoanDocument.setMissingPiecesCount(oleLoanForm.getMissingPieceCount());
3388         }
3389         try {
3390             if (copyCheck != null && copyCheck.equalsIgnoreCase(OLEConstants.TRUE)) {
3391                 oleLoanForm.setCopyCheck("");
3392                 getLoanProcessor().deleteRequestRecord(oleLoanDocument.getOleDeliverRequestBo());
3393                 oleLoanDocument = getLoanProcessor().returnLoan(oleLoanDocument);
3394                 //  oleLoanForm.setCopyRequest(false);
3395             } else if (copyCheck != null && copyCheck.equalsIgnoreCase(OLEConstants.FALSE)) {
3396                 return endCheckInSession(form, result, request, response);
3397             }
3398             /*if (oleLoanForm.isCopyRequest() && oleLoanDocument.isNumberOfPieces()) {
3399                 oleLoanForm.setCopyRequest(false);
3400                 oleLoanForm.setNumberOfPieces(true);
3401                 oleLoanForm.setReturnSuccess(false);
3402                 oleLoanForm.setReturnMessage(OLEConstants.VERIFY_PIECES + oleLoanDocument.getItemNumberOfPieces() + OLEConstants.PIECES_RETURNED);
3403                 return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
3404             }*/
3405             String itemUUid = oleLoanDocument.getItemUuid();
3406             org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
3407             item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(itemUUid);
3408             String itemXmlContent = item.getContent();
3409             Item oleItem = getLoanProcessor().getItemPojo(itemXmlContent);
3410             getLoanProcessor().getLocation(oleItem, oleLoanDocument, item);
3411             if (oleLoanDocument.getLocation() == null || oleLoanDocument.getLocation().isEmpty()) {
3412                 getLoanProcessor().getDefaultHoldingLocation(oleLoanDocument);
3413             }
3414             org.kuali.ole.docstore.common.document.Item itemXml = new ItemOleml();
3415             boolean claimsFlag = false;
3416             if (oleItem.isClaimsReturnedFlag()) {
3417                 oleLoanForm.setTempClaimsFlag(true);
3418                 claimsFlag = true;
3419                 oleLoanForm.setClaimsReturned(false);
3420                 oleLoanForm.setReturnSuccess(true);
3421                 oleLoanForm.setReturnMessage(null);
3422                 oleItem.setClaimsReturnedFlag(false);
3423                 oleItem.setClaimsReturnedFlagCreateDate(null);
3424                 oleItem.setClaimsReturnedNote(null);
3425                 oleLoanDocument.getOleItem().setClaimsReturnedFlag(false);
3426                 oleLoanDocument.getOleItem().setClaimsReturnedNote(null);
3427                 oleLoanDocument.getOleItem().setClaimsReturnedFlagCreateDate(null);
3428                 ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
3429                 itemXml.setContent(itemOlemlRecordProcessor.toXML(oleItem));
3430                 itemXml.setCategory(OLEConstants.WORK_CATEGORY);
3431                 itemXml.setType(DocType.ITEM.getCode());
3432                 itemXml.setFormat(OLEConstants.OLEML_FORMAT);
3433                 itemXml.setId(oleLoanDocument.getItemUuid());
3434                 getDocstoreClientLocator().getDocstoreClient().updateItem(itemXml);
3435                 if (oleLoanForm.isRecordNote()) {
3436                     saveGeneralNoteForFlaggedItem(OLEConstants.CLAIMS_CHECKED_IN_FLAG, true, oleLoanDocument, false, true, false, oleLoanForm.getPatronBarcode());
3437                 }
3438                 oleLoanDocument = getLoanProcessor().returnLoan(oleLoanDocument);
3439             }
3440             if (oleLoanDocument.isCopyRequest()) {
3441                 oleLoanForm.setCopyRequest(true);
3442                 oleLoanForm.setReturnSuccess(false);
3443                 oleLoanForm.setNumberOfPieces(true);
3444                 oleLoanForm.setReturnMessage(OLEConstants.COPY_REQUEST_FULFILL);
3445                 return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
3446             }
3447             if ((oleLoanDocument.isNumberOfPieces() && (matchCheck == null)) || (oleItem != null && StringUtils.isNotEmpty(oleItem.getNumberOfPieces())) && (matchCheck == null)) {
3448                 int noOfPiece = 0;
3449                 if (oleItem.getNumberOfPieces() != null && !oleItem.getNumberOfPieces().equalsIgnoreCase("")) {
3450                     noOfPiece = Integer.parseInt(oleItem.getNumberOfPieces());
3451                 }
3452                 if (noOfPiece > 1) {
3453                     oleLoanForm.setNumberOfPieces(true);
3454                     oleLoanForm.setReturnSuccess(false);
3455                     oleLoanForm.setReturnMessage(OLEConstants.VERIFY_PIECES + oleLoanDocument.getItemNumberOfPieces() + OLEConstants.PIECES_RETURNED
3456                             + OLEConstants.BREAK + "Total No of Pieces :      " + oleLoanDocument.getItemNumberOfPieces() + OLEConstants.BREAK + "No of missing Pieces : " + (oleLoanDocument.getOleItem().getMissingPiecesCount() != null ? oleLoanDocument.getOleItem().getMissingPiecesCount() : "0"));
3457 
3458                     return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
3459                 }
3460             }
3461 
3462             if (matchCheck != null && matchCheck.equalsIgnoreCase(OLEConstants.TRUE)) {
3463                 oleLoanDocument.setContinueCheckIn(true);
3464                 oleLoanDocument = getLoanProcessor().returnLoan(oleLoanDocument);
3465                 oleLoanForm.setMatchCheck(null);
3466                 oleLoanForm.setErrorMessage("");
3467                 oleLoanForm.setMissingPieceCount("");
3468                 oleLoanForm.setDescription("");
3469                 oleLoanForm.setMissingPieceNote("");
3470                 oleLoanForm.setSendMissingPieceMail(false);
3471             } else if (matchCheck != null && matchCheck.equalsIgnoreCase(OLEConstants.FALSE)) {
3472                 Integer numberOfPieces = Integer.parseInt(oleItem != null && oleItem.getNumberOfPieces() != null && !oleItem.getNumberOfPieces().isEmpty() ? oleItem.getNumberOfPieces() : "0");
3473                 if (numberOfPieces > 1) {
3474                     if (oleLoanForm.getMissingPieceCount() != null && !oleLoanForm.getMissingPieceCount().equalsIgnoreCase("")) {
3475                         if (oleLoanDocument.getOleItem() != null && oleLoanDocument.getOleItem().getNumberOfPieces() != null && (!oleLoanDocument.getOleItem().getNumberOfPieces().equalsIgnoreCase(""))) {
3476                             int noOfPieces = Integer.parseInt(oleLoanDocument.getOleItem().getNumberOfPieces());
3477                             int missingPieceCount = Integer.parseInt(oleLoanDocument.getMissingPiecesCount());
3478                             int userMissingPieceCount = Integer.parseInt((oleLoanDocument.getOleItem().getMissingPiecesCount() != null ? oleLoanDocument.getOleItem().getMissingPiecesCount() : "0"));
3479                             if (missingPieceCount < 0) {
3480                                 oleLoanForm.setCheckOut(true);
3481                                 oleLoanForm.setMissingPieceValidationSuccess(true);
3482                                 oleLoanForm.setErrorMessage("Missing piece should not less than 0");
3483                                 return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
3484                             }
3485                             if (missingPieceCount + userMissingPieceCount > noOfPieces) {
3486                                 oleLoanForm.setCheckOut(true);
3487                                 oleLoanForm.setMissingPieceValidationSuccess(true);
3488                                 oleLoanForm.setErrorMessage("Missing piece should not be greater than sum of no of pieces and missing pieces ");
3489                                 return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
3490                             }
3491                         }
3492                     }
3493                 }
3494                 oleLoanForm.setSendMissingPieceMail(true);
3495                 oleLoanDocument.setDescription(description);
3496                 oleLoanForm.setMissingPieceMessage(oleLoanDocument.getDescription());
3497                 //loanProcessor.updateItemStatusWithMissingItem(oleLoanDocument);
3498                 getLoanProcessor().updateMissingPiecesItemInfo(oleLoanDocument);
3499                 if (oleLoanForm.isRecordMissingPieceNote() || oleLoanForm.isRecordCheckoutMissingPieceNote()) {
3500                     if (!oleLoanForm.isRecordCheckoutMissingPieceNote()) {
3501                         if (oleLoanForm.isRecordMissingPieceNote()) {
3502                             saveGeneralNoteForFlaggedItem(OLEConstants.MISSING_PIECE_ITEM_CHECKED_IN_FLAG, true, oleLoanDocument, false, true, false, oleLoanForm.getPatronBarcode());
3503                         }
3504                     } else {
3505                         saveGeneralNoteForFlaggedItem(OLEConstants.MISSING_PIECE_ITEM_CHECKED_IN_FLAG, true, oleLoanDocument, false, true, true, oleLoanForm.getPatronBarcode());
3506                     }
3507                     oleLoanForm.setRecordMissingPieceNote(false);
3508                     oleLoanForm.setRecordCheckoutMissingPieceNote(false);
3509                 }
3510                 /*loanProcessor.saveMissingPieceInfoForPatron(oleLoanDocument,true,oleLoanForm.getMissingPieceMessage());*/
3511                 oleLoanDocument.setContinueCheckIn(true);
3512                 oleLoanDocument = getLoanProcessor().returnLoan(oleLoanDocument);
3513                 oleLoanForm.setMatchCheck(null);
3514                 oleLoanForm.setErrorMessage("");
3515                 oleLoanForm.setMissingPieceCount("");
3516                 oleLoanForm.setDescription("");
3517                 oleLoanForm.setMissingPieceNote("");
3518                 if (itemUUid != null) {
3519                     itemXmlContent = getLoanProcessor().getItemXML(oleLoanDocument.getItemUuid());
3520                     oleItem = getLoanProcessor().getItemPojo(itemXmlContent);
3521                     oleLoanDocument.setOleItem(oleItem);
3522                     oleLoanDocument.setMissingPiecesCount(oleItem.getMissingPiecesCount());
3523                     oleLoanDocument.setMissingPieceFlag(oleItem.isMissingPieceFlag());
3524                     if (oleItem != null) {
3525                         OleItemAvailableStatus oleItemAvailableStatus = getLoanProcessor().validateAndGetItemStatus(oleLoanDocument.getItemStatusCode());
3526                         oleLoanDocument.setItemStatus(oleItemAvailableStatus != null ? oleItemAvailableStatus.getItemAvailableStatusName() : null);
3527                     }
3528                 }
3529             } else if ((copyCheck == null || copyCheck.isEmpty()) && !oleLoanForm.isNumberOfPieces() && oleItem.isClaimsReturnedFlag()) {
3530                 oleLoanDocument = getLoanProcessor().returnLoan(oleLoanDocument);
3531             }
3532             String checkInNote = oleLoanDocument.getOleItem().getCheckinNote();
3533             if (!oleLoanForm.isBackGroundCheckIn() && (oleLoanForm.isCopyRequest() || oleLoanForm.isNumberOfPieces() || claimsFlag) && checkInNote != null && !checkInNote.isEmpty()) {
3534                 oleLoanForm.setNumberOfPieces(false);
3535                 oleLoanForm.setCopyRequest(false);
3536                 oleLoanForm.setCheckInNote(OLEConstants.CHECK_IN_NOTE_HEADER + checkInNote);
3537                 oleLoanForm.setRouteToLocation(oleLoanDocument.getRouteToLocation());
3538                 String principalId = GlobalVariables.getUserSession().getPrincipalId();
3539                 oleLoanForm.setOkOrRemoveNote(getLoanProcessor().checkPermissionForRemoveNote(principalId));
3540             }
3541             List<OleLoanDocument> oleLoanDocuments = new ArrayList<OleLoanDocument>();
3542             if (!oleLoanDocument.isCheckOut() || oleLoanDocument.getErrorMessage() == null)
3543                 oleLoanDocuments.add(oleLoanDocument);
3544             if (oleLoanForm.getItemReturnList() != null) {
3545                 oleLoanDocuments.addAll(oleLoanForm.getItemReturnList());
3546             }
3547             if (!oleLoanForm.isBackGroundCheckIn()) {
3548                 oleLoanForm.setItemReturnList(oleLoanDocuments);
3549 
3550                 //To refresh loan screen current and previous session loan list
3551                // oleLoanForm.setExistingLoanList(getLoanProcessor().getPatronLoanedItemBySolr(oleLoanDocument.getPatronId()));
3552                 OleLoanDocument tempOleLoanDocumentObj = null;
3553                 List<OleLoanDocument> currentSessionList = oleLoanForm.getLoanList() != null ? oleLoanForm.getLoanList() : new ArrayList<OleLoanDocument>();
3554                 for (OleLoanDocument currentOleLoanDocument : currentSessionList) {
3555                     if (currentOleLoanDocument != null && currentOleLoanDocument.getItemId() != null && currentOleLoanDocument.getItemId().equals(oleLoanForm.getCheckInItem())) {
3556                         tempOleLoanDocumentObj = currentOleLoanDocument;
3557                         break;
3558                     }
3559                 }
3560                 currentSessionList.remove(tempOleLoanDocumentObj);
3561                 oleLoanForm.setLoanList(currentSessionList);
3562                 //To refresh loan screen current and previous session loan list
3563             }
3564 
3565         } catch (Exception e) {
3566             LOG.error("Exception in Continue Check-in " + e);
3567         }
3568 
3569         oleLoanForm.setNumberOfPieces(false);
3570         oleLoanForm.setReturnSuccess(true);
3571         oleLoanForm.setReturnMessage(null);
3572         oleLoanForm.setCheckInItem("");
3573         oleLoanForm.setReturnInformation("");
3574         if (LOG.isDebugEnabled()) {
3575             LOG.debug("oleLoanForm.getFormKey()" + oleLoanForm.getFormKey());
3576         }
3577         if (oleLoanForm.isBackGroundCheckIn()) {
3578             oleLoanForm.setItem(oleLoanForm.getCheckInItem());
3579             oleLoanForm.setOleItem(oleLoanDocument.getOleItem());
3580             oleLoanDocument.setItemLoanStatus(oleLoanDocument.getItemStatusCode());
3581             loanPatron(oleLoanForm, result, request, response);
3582         }
3583         if (oleLoanForm.isTempClaimsFlag()) {
3584            /* oleLoanForm.setTempClaimsFlag(false);*/
3585             if (!oleLoanDocument.isBackGroundCheckOut() && oleLoanDocument.getErrorMessage() != null) {
3586                 oleLoanForm.setReturnSuccess(false);
3587                 oleLoanForm.setReturnMessage(oleLoanDocument.getErrorMessage());
3588                 return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
3589             }
3590         }
3591         if (!oleLoanForm.isCheckInNoteExists() && oleLoanForm.getCheckInNote() != null) {
3592             oleLoanForm.setDummyLoan(oleLoanDocument);
3593             oleLoanForm.setCheckInNoteExists(true);
3594             oleLoanForm.setReturnSuccess(false);
3595             oleLoanForm.setReturnMessage(oleLoanForm.getCheckInNote());
3596             return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
3597         }
3598         if (oleLoanDocument.isCheckOut() && oleLoanDocument.getErrorMessage() != null) {
3599             oleLoanForm.setDueDateEmpty(oleLoanDocument.isDueDateEmpty());
3600             oleLoanForm.setDummyLoan(oleLoanDocument);
3601             oleLoanForm.setReturnSuccess(false);
3602             oleLoanForm.setMessage(oleLoanDocument.getErrorMessage());
3603             oleLoanForm.setCheckOut(true);
3604             oleLoanForm.setItem(oleLoanForm.getCheckInItem());
3605             oleLoanForm.setOleItem(oleLoanDocument.getOleItem());
3606             return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
3607         }
3608         if (oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isPrintSlip()) {
3609             if (oleLoanDocument.getOleItem().isMissingPieceFlag()) {
3610                 OleNoticeBo oleNoticeBo = getLoanProcessor().getNotice(oleLoanDocument);
3611                 // SimpleDateFormat simpleDateFormat=new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT);
3612                 SimpleDateFormat dateFormat = new SimpleDateFormat(OLEConstants.DATEFORMAT);
3613                 Date date = new Date(oleLoanDocument.getCheckInDate().getTime());
3614                 if (oleNoticeBo != null && (!oleLoanDocument.isBackgroundCheckInMissingPiece()) && oleLoanForm.isSendMissingPieceMail()) {
3615                     oleNoticeBo.setCheckInDate(dateFormat.format(date));
3616                     String missingNoticeDetails = getOleDeliverBatchService().sendMissingNotice(oleNoticeBo);
3617                     OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
3618                     String replyToEmail = getCircDeskLocationResolver().getReplyToEmail(oleNoticeBo.getItemShelvingLocation());
3619                     if (replyToEmail != null) {
3620                         oleMailer.sendEmail(new EmailFrom(replyToEmail), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
3621                     } else {
3622                         String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
3623                         if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
3624                             fromAddress = OLEConstants.KUALI_MAIL;
3625                         }
3626                         oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
3627                     }
3628                     if (LOG.isInfoEnabled()) {
3629                         LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
3630                     }
3631                 }
3632             } else {
3633                 if (oleLoanDocument.getItemStatusCode() != null && oleLoanDocument.getItemStatusCode().equals(OLEConstants.ITEM_STATUS_ON_HOLD) && oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isHoldQueue()) {
3634                     oleLoanForm.setBillAvailability(false);
3635                 } else {
3636                     oleLoanForm.setBillAvailability(true);
3637                 }
3638             }
3639         }
3640         if (oleLoanDocument.isCheckOut()) {
3641             oleLoanForm.setDueDateSlip(true);
3642             oleLoanForm.setBillAvailability(false);
3643         }
3644         long end = System.currentTimeMillis();
3645         long total = end - begin;
3646         LOG.info("Time taken Inside Continue checkin Item"+total);
3647         return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
3648     }
3649 
3650     /**
3651      * This method  ends Check-in session
3652      *
3653      * @param form
3654      * @param result
3655      * @param request
3656      * @param response
3657      * @return ModelAndView
3658      */
3659     @RequestMapping(params = "methodToCall=endCheckInSession")
3660     public ModelAndView endCheckInSession(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
3661                                           HttpServletRequest request, HttpServletResponse response) {
3662         if (LOG.isDebugEnabled()) {
3663             LOG.debug(" Inside End Check-in session ");
3664         }
3665         OleLoanForm oleLoanForm = (OleLoanForm) form;
3666 
3667         String parameter = getLoanProcessor().getParameter(OLEConstants.MAX_TIME_CHECK_IN);
3668         if (parameter != null) {
3669             oleLoanForm.setMaxTimeForCheckInDate(Integer.parseInt(parameter));
3670         }
3671         if (oleLoanForm.getItemReturnList() != null) {
3672             List<OleLoanDocument> holdSlipList = new ArrayList<OleLoanDocument>();
3673             for (OleLoanDocument oleLoanDocument : oleLoanForm.getItemReturnList()) {
3674                 if (oleLoanDocument.getItemStatusCode() != null && oleLoanDocument.getItemStatusCode().equals(OLEConstants.ITEM_STATUS_ON_HOLD)) {
3675                     holdSlipList.add(oleLoanDocument);
3676                 }
3677             }
3678             OleCirculationDesk oleCirculationDesk = null;
3679             oleCirculationDesk = getCircDeskLocationResolver().getOleCirculationDesk(oleLoanForm.getCirculationDesk());
3680             if (holdSlipList.size() > 0 && oleCirculationDesk != null && oleCirculationDesk.isPrintSlip() && oleCirculationDesk.isHoldQueue()) {
3681                 printHoldSlipList = holdSlipList;
3682                 oleLoanForm.setHoldSlip(true);
3683             }
3684         }
3685         oleLoanForm.setCopyRequest(false);
3686         oleLoanForm.setNumberOfPieces(false);
3687         oleLoanForm.setReturnInformation("");
3688         oleLoanForm.setCheckInItem("");
3689         oleLoanForm.setReturnMessage(null);
3690         oleLoanForm.setReturnSuccess(true);
3691         oleLoanForm.setItemReturnList(null);
3692         oleLoanForm.setCheckInNote(null);
3693         oleLoanForm.setBillAvailability(false);
3694         oleLoanForm.setCheckInDate(new Timestamp(new Date().getTime()));
3695         oleLoanForm.setCheckInTime(null);
3696         if (!oleLoanForm.isClearUI()) {
3697             String principalId = GlobalVariables.getUserSession().getPrincipalId();
3698             OleCirculationDeskDetail oleCirculationDeskDetail = getLoanProcessor().getDefaultCirculationDesk(principalId);
3699             if (oleCirculationDeskDetail != null) {
3700                 oleLoanForm.setCirculationDesk(oleCirculationDeskDetail.getCirculationDeskId());
3701                 oleLoanForm.setPreviousCirculationDesk(oleLoanForm.getCirculationDesk());
3702             }
3703         }
3704         oleLoanForm.setSuccessMessage(null);
3705         //return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
3706         return getUIFModelAndView(oleLoanForm, "ReturnItemViewPage");
3707     }
3708 
3709     /**
3710      * This method will allow  library operator to print slips for user
3711      *
3712      * @param form
3713      * @param result
3714      * @param request
3715      * @param response
3716      * @return ModelAndView
3717      */
3718     @RequestMapping(params = "methodToCall=printBill")
3719     public ModelAndView printBill(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
3720                                   HttpServletRequest request, HttpServletResponse response) {
3721         OlePrintSlip olePrintSlip = new OlePrintSlip();
3722         if (LOG.isDebugEnabled()) {
3723             LOG.debug(" Inside Print Bill ");
3724         }
3725         String formKey = request.getParameter("formKey");
3726         OleLoanForm oleLoanForm = (OleLoanForm) GlobalVariables.getUifFormManager().getSessionForm(formKey);
3727         OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
3728         if (oleLoanForm.getRouteToLocation() != null) {
3729             oleLoanDocument.setRouteToLocation(oleLoanForm.getRouteToLocation());
3730         }
3731         olePrintSlip.createPdfForPrintingSlip(oleLoanDocument, response);
3732         oleLoanForm.setBackGroundCheckIn(false);
3733         return null;
3734     }
3735 
3736     /**
3737      * This method will allow library operator to print due date slips for user.
3738      *
3739      * @param form
3740      * @param result
3741      * @param request
3742      * @param response
3743      * @return
3744      */
3745     @RequestMapping(params = "methodToCall=printLoanBill")
3746     public ModelAndView printLoanBill(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
3747                                       HttpServletRequest request, HttpServletResponse response) {
3748         OlePrintSlip olePrintSlip = new OlePrintSlip();
3749         if (LOG.isDebugEnabled()) {
3750             LOG.debug(" Inside Print Loan Bill ");
3751         }
3752         String formKey = request.getParameter("formKey");
3753         OleLoanForm oleLoanForm = (OleLoanForm) GlobalVariables.getUifFormManager().getSessionForm(formKey);
3754         OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
3755         List<OleLoanDocument> oleLoanDocumentList = new ArrayList<OleLoanDocument>();
3756         if (getLoanProcessor().getParameter(OLEConstants.PRINT_DUE_DATE_PER_TRANSACTION).equalsIgnoreCase("No")) {
3757             oleLoanDocumentList = printDueDateSlipList;
3758         } else {
3759             if (oleLoanForm.getLoanList() != null && (oleLoanForm.getLoanList().size() > 0)) {
3760                 oleLoanDocumentList.add(oleLoanForm.getLoanList().get(0));
3761             }
3762         }
3763         if (oleLoanDocument.isCheckOut()) {
3764             olePrintSlip.createPdfForBackGroundCheckOut(oleLoanDocument, response);
3765         } else if (oleLoanDocumentList != null && oleLoanDocumentList.size() > 0) {
3766             olePrintSlip.createDueDateSlipPdf(oleLoanDocumentList, response);
3767         }
3768         return null;
3769     }
3770 
3771 
3772     /**
3773      * This method will allow library operator to even if the check-in note exists
3774      *
3775      * @param form
3776      * @param result
3777      * @param request
3778      * @param response
3779      * @return ModelAndView
3780      */
3781     @RequestMapping(params = "methodToCall=checkInNote")
3782     public ModelAndView checkInNote(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
3783                                     HttpServletRequest request, HttpServletResponse response) {
3784         if (LOG.isDebugEnabled()) {
3785             LOG.debug("Check in Note Exists ");
3786         }
3787         long begin = System.currentTimeMillis();
3788         OleLoanForm oleLoanForm = (OleLoanForm) form;
3789        /* String parameter = getLoanProcessor().getParameter(OLEConstants.MAX_TIME_CHECK_IN);
3790         if(parameter != null){
3791             oleLoanForm.setMaxTimeForCheckInDate(Integer.parseInt(parameter) * 60);
3792         }*/
3793         OleCirculationDesk oleCirculationDesk = getCircDeskLocationResolver().getCirculationDeskByLocationCode(oleLoanForm.getRouteToLocation());
3794         OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
3795         if ((oleLoanForm.getRouteToLocation() == null || oleLoanForm.getRouteToLocation().isEmpty()) && oleLoanDocument.getItemStatusCode().contains(OLEConstants.ITEM_STATUS_IN_TRANSIT)) {
3796             oleLoanForm.setInformation(OLEConstants.CIRC_DESK_REQUIRED);
3797             return getUIFModelAndView(form, "ReturnItemViewPage");
3798         } else if (oleCirculationDesk == null) {
3799             oleLoanForm.setInformation(OLEConstants.CIRC_DESK_INVALID);
3800             return getUIFModelAndView(form, "ReturnItemViewPage");
3801         } else {
3802             oleLoanDocument.setRouteToLocationName(oleCirculationDesk.getCirculationDeskPublicName());
3803         }
3804         oleLoanForm.setCheckInNoteExists(false);
3805         oleLoanForm.setReturnSuccess(true);
3806         oleLoanForm.setReturnMessage(null);
3807         oleLoanForm.setCheckInNote(null);
3808         oleLoanForm.setInformation("");
3809         oleLoanForm.setSuccessInfo("");
3810         Item oleItem = oleLoanDocument.getOleItem();
3811         if (oleItem != null) {
3812             try {
3813                 getLoanProcessor().removeCheckInNote(oleItem);
3814             } catch (Exception e) {
3815                 LOG.error("Exception while removing check-in note", e);
3816             }
3817         }
3818         if (oleLoanDocument.isCheckOut() && oleLoanDocument.getErrorMessage() != null) {
3819             oleLoanForm.setDueDateEmpty(oleLoanDocument.isDueDateEmpty());
3820             oleLoanForm.setDummyLoan(oleLoanDocument);
3821             oleLoanForm.setReturnSuccess(false);
3822             oleLoanForm.setMessage(oleLoanDocument.getErrorMessage());
3823             oleLoanForm.setCheckOut(true);
3824             oleLoanForm.setItem(oleLoanForm.getCheckInItem());
3825             oleLoanForm.setOleItem(oleLoanDocument.getOleItem());
3826             return getUIFModelAndView(form, "ReturnItemViewPage");
3827         }
3828         if (oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isPrintSlip()) {
3829             if (oleLoanDocument.getOleItem().isMissingPieceFlag()) {
3830                 OleNoticeBo oleNoticeBo = getLoanProcessor().getNotice(oleLoanDocument);
3831                 //SimpleDateFormat simpleDateFormat = new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT);
3832                 SimpleDateFormat dateFormat = new SimpleDateFormat(OLEConstants.DATEFORMAT);
3833                 Date date = new Date(oleLoanDocument.getCheckInDate().getTime());
3834                 if (oleNoticeBo != null) {
3835                     oleNoticeBo.setCheckInDate(dateFormat.format(date));
3836                     String missingNoticeDetails = getOleDeliverBatchService().sendMissingNotice(oleNoticeBo);
3837                     OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
3838                     String replyToEmail = getCircDeskLocationResolver().getReplyToEmail(oleNoticeBo.getItemShelvingLocation());
3839                     if (replyToEmail != null) {
3840                         oleMailer.sendEmail(new EmailFrom(replyToEmail), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
3841                     } else {
3842                         String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
3843                         if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
3844                             fromAddress = OLEConstants.KUALI_MAIL;
3845                         }
3846                         oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
3847                     }
3848                     if (LOG.isInfoEnabled()) {
3849                         LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
3850                     }
3851                 }
3852             } else {
3853                 if (oleLoanDocument.getItemStatusCode() != null && oleLoanDocument.getItemStatusCode().equals(OLEConstants.ITEM_STATUS_ON_HOLD) && oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isHoldQueue()) {
3854                     oleLoanForm.setBillAvailability(false);
3855                 } else {
3856                     oleLoanForm.setBillAvailability(true);
3857                 }
3858 
3859             }
3860         }
3861         if (oleLoanDocument.isCheckOut() && oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isPrintSlip()) {
3862             oleLoanForm.setDueDateSlip(true);
3863             oleLoanForm.setBillAvailability(false);
3864         }
3865         long end = System.currentTimeMillis();
3866         long total = end - begin;
3867         LOG.info("Time taken Inside Checkin note "+total);
3868         return getUIFModelAndView(form, "ReturnItemViewPage");
3869     }
3870 
3871     /**
3872      * This method will allow library operator to even if the check-in note exists
3873      *
3874      * @param form
3875      * @param result
3876      * @param request
3877      * @param response
3878      * @return ModelAndView
3879      */
3880     @RequestMapping(params = "methodToCall=okCheckInNote")
3881     public ModelAndView okCheckInNote(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
3882                                       HttpServletRequest request, HttpServletResponse response) {
3883         if (LOG.isDebugEnabled()) {
3884             LOG.debug("Check in Note Exists ");
3885         }
3886         long begin = System.currentTimeMillis();
3887         OleLoanForm oleLoanForm = (OleLoanForm) form;
3888        /* String parameter = getLoanProcessor().getParameter(OLEConstants.MAX_TIME_CHECK_IN);
3889         if(parameter != null){
3890             oleLoanForm.setMaxTimeForCheckInDate(Integer.parseInt(parameter) * 60);
3891         }*/
3892         OleCirculationDesk oleCirculationDesk = getCircDeskLocationResolver().getCirculationDeskByLocationCode(oleLoanForm.getRouteToLocation());
3893         OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
3894         if ((oleLoanForm.getRouteToLocation() == null || oleLoanForm.getRouteToLocation().isEmpty()) && oleLoanDocument.getItemStatusCode().contains(OLEConstants.ITEM_STATUS_IN_TRANSIT)) {
3895             oleLoanForm.setInformation(OLEConstants.CIRC_DESK_REQUIRED);
3896             return getUIFModelAndView(form, "ReturnItemViewPage");
3897         } else if (oleCirculationDesk == null) {
3898             oleLoanForm.setInformation(OLEConstants.CIRC_DESK_INVALID);
3899             return getUIFModelAndView(form, "ReturnItemViewPage");
3900         } else {
3901             oleLoanDocument.setRouteToLocationName(oleCirculationDesk.getCirculationDeskPublicName());
3902             oleLoanDocument.setRouteToLocation(oleCirculationDesk.getCirculationDeskCode());
3903         }
3904         oleLoanForm.setCheckInNoteExists(false);
3905         oleLoanForm.setReturnSuccess(true);
3906         oleLoanForm.setReturnMessage(null);
3907         oleLoanForm.setCheckInNote(null);
3908         oleLoanForm.setInformation("");
3909         oleLoanForm.setSuccessInfo("");
3910         /*if(oleLoanDocument.getItemStatus()!=null && (oleLoanDocument.getItemStatus().contains(OLEConstants.OleDeliverRequest.INTRANSIT)||oleLoanDocument.getItemStatus().contains(OLEConstants.OleDeliverRequest.HOLD))){
3911             oleLoanForm.setInTransit(true);
3912         } else {
3913             oleLoanForm.setInTransit(false);
3914         }*/
3915         if (oleLoanDocument.isCheckOut() && oleLoanDocument.getErrorMessage() != null) {
3916             oleLoanForm.setDueDateEmpty(oleLoanDocument.isDueDateEmpty());
3917             oleLoanForm.setDummyLoan(oleLoanDocument);
3918             oleLoanForm.setReturnSuccess(false);
3919             oleLoanForm.setMessage(oleLoanDocument.getErrorMessage());
3920             oleLoanForm.setCheckOut(true);
3921             oleLoanForm.setItem(oleLoanForm.getCheckInItem());
3922             oleLoanForm.setOleItem(oleLoanDocument.getOleItem());
3923             return getUIFModelAndView(form, "ReturnItemViewPage");
3924         }
3925         getLoanProcessor().updateInTransitHistory(oleLoanDocument,oleLoanForm.getRouteToLocation());
3926         if (oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isPrintSlip()) {
3927             if (oleLoanDocument.getOleItem().isMissingPieceFlag() && oleLoanForm.isSendMissingPieceMail()) {
3928                 OleNoticeBo oleNoticeBo = getLoanProcessor().getNotice(oleLoanDocument);
3929                 // SimpleDateFormat simpleDateFormat = new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT);
3930                 SimpleDateFormat dateFormat = new SimpleDateFormat(OLEConstants.DATEFORMAT);
3931 
3932                 Date date = new Date(oleLoanDocument.getCheckInDate().getTime());
3933                 if (oleNoticeBo != null) {
3934                     oleNoticeBo.setCheckInDate(dateFormat.format(date));
3935                     String missingNoticeDetails = getOleDeliverBatchService().sendMissingNotice(oleNoticeBo);
3936                     OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
3937                     String replyToEmail = getCircDeskLocationResolver().getReplyToEmail(oleNoticeBo.getItemShelvingLocation());
3938                     if (replyToEmail != null) {
3939                         oleMailer.sendEmail(new EmailFrom(replyToEmail), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
3940                     } else {
3941                         String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
3942                         if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
3943                             fromAddress = OLEConstants.KUALI_MAIL;
3944                         }
3945                         oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
3946                     }
3947                     if (LOG.isInfoEnabled()) {
3948                         LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
3949                     }
3950                 }
3951             } else {
3952                 if (oleLoanDocument.getItemStatusCode() != null && oleLoanDocument.getItemStatusCode().equals(OLEConstants.ITEM_STATUS_ON_HOLD) && oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isHoldQueue()) {
3953                     oleLoanForm.setBillAvailability(false);
3954                 } else {
3955                     oleLoanForm.setBillAvailability(true);
3956                 }
3957             }
3958         }
3959         if (oleLoanDocument.isCheckOut() && oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isPrintSlip()) {
3960             oleLoanForm.setDueDateSlip(true);
3961             oleLoanForm.setBillAvailability(false);
3962         }
3963         if (oleLoanDocument.getItemStatus() != null && oleLoanDocument.getItemStatus().equalsIgnoreCase(OLEConstants.ITEM_STATUS_RECENTLY_RETURNED)) {
3964             oleLoanForm.setBillAvailability(false);
3965             oleLoanForm.setDueDateSlip(false);
3966         }
3967         long end = System.currentTimeMillis();
3968         long total = end - begin;
3969         LOG.info("Time taken Inside okcheckin note"+total);
3970         return getUIFModelAndView(form, "ReturnItemViewPage");
3971     }
3972 
3973     /**
3974      * This method clear UI for next borrower session..
3975      *
3976      * @param form
3977      * @param result
3978      * @param request
3979      * @param response
3980      * @return ModelAndView
3981      */
3982     @RequestMapping(params = "methodToCall=clearUI")
3983     public ModelAndView clearUI(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
3984                                 HttpServletRequest request, HttpServletResponse response) {
3985         OleLoanForm oleLoanForm = (OleLoanForm) form;
3986         oleLoanForm.setClearUI(true);
3987         clearPatronScreen(oleLoanForm, result, request, response);
3988         endCheckInSession(oleLoanForm, result, request, response);
3989         oleLoanForm.setClearUI(false);
3990         return getUIFModelAndView(form, "PatronItemViewPage");
3991     }
3992 
3993     @RequestMapping(params = "methodToCall=clearReturnUI")
3994     public ModelAndView clearReturnUI(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
3995                                       HttpServletRequest request, HttpServletResponse response) {
3996         OleLoanForm oleLoanForm = (OleLoanForm) form;
3997         oleLoanForm.setClearUI(true);
3998         clearPatronScreen(oleLoanForm, result, request, response);
3999         endCheckInSession(oleLoanForm, result, request, response);
4000         oleLoanForm.setClearUI(false);
4001         return getUIFModelAndView(form, "ReturnItemViewPage");
4002     }
4003 
4004     /**
4005      * To refresh patron record.
4006      *
4007      * @param form
4008      * @param result
4009      * @param request
4010      * @param response
4011      * @return
4012      * @throws Exception
4013      */
4014     @RequestMapping(params = "methodToCall=setItemBarcode")
4015     public ModelAndView setItemBarcode(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
4016                                        HttpServletRequest request, HttpServletResponse response) throws Exception {
4017         OleLoanForm oleLoanForm = (OleLoanForm) form;
4018         oleLoanForm.setItem(fastAddBarcode);
4019         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
4020     }
4021 
4022     @RequestMapping(params = "methodToCall=gotoReturn")
4023     public ModelAndView gotoReturn(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
4024                                    HttpServletRequest request, HttpServletResponse response) throws IOException {
4025         OleLoanForm oleLoanForm = (OleLoanForm) form;
4026         String baseUrl = ConfigContext.getCurrentContextConfig().getProperty(OLEPropertyConstants.OLE_URL_BASE);
4027         String url = baseUrl + "/portal.do?channelTitle=Loan&channelUrl=" + baseUrl + "/ole-kr-krad/loancontroller?viewId=ReturnItemView&methodToCall=start&formKey=" + oleLoanForm.getFormKey();
4028         Properties props = new Properties();
4029         props.put(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.REFRESH);
4030         if (StringUtils.isNotBlank(form.getReturnFormKey())) {
4031             props.put(UifParameters.FORM_KEY, form.getReturnFormKey());
4032         }
4033         oleLoanForm.setSuccessMessage(null);
4034         oleLoanForm.setInformation("");
4035         oleLoanForm.setSuccessInfo("");
4036         return performRedirect(oleLoanForm, url, props);
4037     }
4038 
4039 
4040     @RequestMapping(params = "methodToCall=gotoLoan")
4041     public ModelAndView gotoLoan(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
4042                                  HttpServletRequest request, HttpServletResponse response) throws Exception {
4043         OleLoanForm oleLoanForm = (OleLoanForm) form;
4044         oleLoanForm.setReturnCheck(false);
4045         String baseUrl = ConfigContext.getCurrentContextConfig().getProperty(OLEPropertyConstants.OLE_URL_BASE);
4046         String requestKey = request.getParameter("formKey");
4047         String url = baseUrl + "/portal.do?channelTitle=Loan&channelUrl=" + baseUrl + "/ole-kr-krad/loancontroller?viewId=PatronItemView&methodToCall=start&formKey=" + requestKey;
4048         Properties props = new Properties();
4049         props.put(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.REFRESH);
4050         if (StringUtils.isNotBlank(form.getReturnFormKey())) {
4051             props.put(UifParameters.FORM_KEY, form.getReturnFormKey());
4052         }
4053         oleLoanForm.setSuccessMessage(null);
4054         oleLoanForm.setShowExistingLoan(false);
4055         return performRedirect(oleLoanForm, url, props);
4056     }
4057 
4058     /**
4059      * This method will allow library operator to even if it is damagedCheckIn
4060      *
4061      * @param form
4062      * @param result
4063      * @param request
4064      * @param response
4065      * @return ModelAndView
4066      */
4067     @RequestMapping(params = "methodToCall=damagedCheckIn")
4068     public ModelAndView damagedCheckIn(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
4069                                        HttpServletRequest request, HttpServletResponse response) {
4070         if (LOG.isDebugEnabled()) {
4071             LOG.debug("Check in Note Exists ");
4072         }
4073         OleLoanForm oleLoanForm = (OleLoanForm) form;
4074         OleCirculationDesk oleCirculationDesk = getCircDeskLocationResolver().getCirculationDeskByLocationCode(oleLoanForm.getRouteToLocation());
4075         OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
4076         if ((oleLoanForm.getRouteToLocation() == null || oleLoanForm.getRouteToLocation().isEmpty()) && oleLoanDocument.getItemStatusCode().contains(OLEConstants.ITEM_STATUS_IN_TRANSIT)) {
4077             oleLoanForm.setInformation(OLEConstants.CIRC_DESK_REQUIRED);
4078             return getUIFModelAndView(form, "ReturnItemViewPage");
4079         } else if (oleCirculationDesk == null) {
4080             oleLoanForm.setInformation(OLEConstants.CIRC_DESK_INVALID);
4081             return getUIFModelAndView(form, "ReturnItemViewPage");
4082         } else {
4083             oleLoanDocument.setRouteToLocationName(oleCirculationDesk.getCirculationDeskPublicName());
4084         }
4085         oleLoanForm.setDamagedCheckIn(false);
4086         oleLoanForm.setReturnSuccess(true);
4087         oleLoanForm.setReturnMessage(null);
4088         oleLoanForm.setInformation("");
4089         oleLoanForm.setSuccessInfo("");
4090         if (oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isPrintSlip()) {
4091             if (oleLoanDocument.getOleItem().isMissingPieceFlag()) {
4092                 OleNoticeBo oleNoticeBo = getLoanProcessor().getNotice(oleLoanDocument);
4093                 //SimpleDateFormat simpleDateFormat = new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT);
4094                 SimpleDateFormat dateFormat = new SimpleDateFormat(OLEConstants.DATEFORMAT);
4095                 Date date = new Date(oleLoanDocument.getCheckInDate().getTime());
4096                 if (oleNoticeBo != null) {
4097                     oleNoticeBo.setCheckInDate(dateFormat.format(date));
4098                     String missingNoticeDetails = getOleDeliverBatchService().sendMissingNotice(oleNoticeBo);
4099                     OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
4100                     String replyToEmail = getCircDeskLocationResolver().getReplyToEmail(oleNoticeBo.getItemShelvingLocation());
4101                     if (replyToEmail != null) {
4102                         oleMailer.sendEmail(new EmailFrom(replyToEmail), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
4103                     } else {
4104                         String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
4105                         if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
4106                             fromAddress = OLEConstants.KUALI_MAIL;
4107                         }
4108                         oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
4109                     }
4110                     if (LOG.isInfoEnabled()) {
4111                         LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
4112                     }
4113                 }
4114             } else {
4115                 if (oleLoanDocument.getItemStatusCode() != null && oleLoanDocument.getItemStatusCode().equals(OLEConstants.ITEM_STATUS_ON_HOLD) && oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isHoldQueue()) {
4116                     oleLoanForm.setBillAvailability(false);
4117                 } else {
4118                     oleLoanForm.setBillAvailability(true);
4119                 }
4120             }
4121         }
4122         return getUIFModelAndView(form, "ReturnItemViewPage");
4123     }
4124 
4125     @RequestMapping(params = "methodToCall=proceedLoan")
4126     public ModelAndView proceedLoan(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
4127                                     HttpServletRequest request, HttpServletResponse response) {
4128         OleLoanForm oleLoanForm = (OleLoanForm) form;
4129         OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
4130         oleLoanDocument.setItemUuid(oleLoanForm.getItemUuid());
4131         try {
4132             getLoanProcessor().isClaimsReturnedItem(oleLoanForm.getItem(), oleLoanDocument);
4133             oleLoanForm.setAddressVerified(false);
4134             oleLoanForm.getErrorsAndPermission().clear();
4135             oleLoanForm.setClaimsFlag(false);
4136             getLoanProcessor().processLoan(oleLoanForm, oleLoanDocument);
4137         } catch (Exception e) {
4138             e.printStackTrace();
4139         }
4140         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
4141     }
4142 
4143     private void saveGeneralNoteForFlaggedItem(String systemParameter, boolean multiValue, OleLoanDocument oleLoanDocument, boolean isCheckOut, boolean isCheckIn, boolean backgroundCheckin, String formBarcode) {
4144         String note = getLoanProcessor().getParameter(systemParameter);
4145         SimpleDateFormat df = new SimpleDateFormat(OLEConstants.TIMESTAMP);
4146         if (multiValue) {
4147             note = note.replace("[0]", oleLoanDocument.getItemId());
4148             if (isCheckOut) {
4149                 note = note.replace("[0]", oleLoanDocument.getItemId());
4150                 note = note.replace("[1]", df.format(oleLoanDocument.getCreateDate()).toString());
4151                 Map map = new HashMap();
4152                 map.put("circulationDeskId", oleLoanDocument.getCirculationLocationId());
4153                 OleCirculationDesk oleCirculationDesk = getLoanProcessor().getBusinessObjectService().findByPrimaryKey(OleCirculationDesk.class, map);
4154                 note = note.replace("[2]", oleCirculationDesk.getCirculationDeskCode());
4155                 if (systemParameter.equalsIgnoreCase(OLEConstants.MISSING_PIECE_ITEM_CHECKED_OUT_FLAG)) {
4156                     int noOfMissingPiece = 0;
4157                     if (oleLoanDocument.getOleItem().isMissingPieceFlag()) {
4158                         if (oleLoanDocument.getOleItem() != null && oleLoanDocument.getOleItem().getMissingPiecesCount() != null && !oleLoanDocument.getOleItem().getMissingPiecesCount().equalsIgnoreCase("")) {
4159                             noOfMissingPiece = Integer.parseInt(oleLoanDocument.getOleItem().getMissingPiecesCount());
4160                         }
4161                     }
4162                     note = note.replace("[3]", noOfMissingPiece + "");
4163                 }
4164                 map.clear();
4165                 map.put("olePatronId", oleLoanDocument.getPatronId());
4166                 OlePatronDocument olePatronDocument = getLoanProcessor().getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, map);
4167                 OlePatronNotes olePatronNotes = new OlePatronNotes();
4168                 olePatronNotes.setPatronNoteText(note);
4169                 map.clear();
4170                 map.put("patronNoteTypeCode", "GENERAL");
4171                 OlePatronNoteType olePatronNoteType = (OlePatronNoteType) getLoanProcessor().getBusinessObjectService().findByPrimaryKey(OlePatronNoteType.class, map);
4172                 olePatronNotes.setPatronNoteTypeId(olePatronNoteType.getPatronNoteTypeId());
4173                 olePatronNotes.setOlePatronId(olePatronDocument.getOlePatronId());
4174                 olePatronDocument.getNotes().add(olePatronNotes);
4175                 OlePatronDocument patronDocument = (OlePatronDocument) ObjectUtils.deepCopy(olePatronDocument);
4176                 getLoanProcessor().getBusinessObjectService().save(patronDocument);
4177             }
4178             if (isCheckIn) {
4179                 note = note.replace("[0]", oleLoanDocument.getItemId());
4180                 note = note.replace("[1]", df.format(oleLoanDocument.getCheckInDate()).toString());
4181                 note = note.replace("[2]", oleLoanDocument.getOleCirculationDesk().getCirculationDeskCode());
4182                 if (oleLoanDocument != null && oleLoanDocument.getOlePatron() != null && oleLoanDocument.getOlePatron().getOlePatronId() != null) {
4183                     Map map = new HashMap();
4184                     OlePatronDocument olePatronDocument = new OlePatronDocument();
4185                    /* if (backgroundCheckin) {
4186                         map.put("barcode", formBarcode);
4187                         olePatronDocument = getLoanProcessor().getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, map);
4188                     } else {*/
4189                     map.put("olePatronId", oleLoanDocument.getPatronId());
4190                     olePatronDocument = getLoanProcessor().getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, map);
4191                     /*}*/
4192                     if (systemParameter.equalsIgnoreCase(OLEConstants.MISSING_PIECE_ITEM_CHECKED_IN_FLAG)) {
4193                         int noOfMissingPiece = 0;
4194                         if (oleLoanDocument.getOleItem().isMissingPieceFlag()) {
4195                             if (oleLoanDocument != null && oleLoanDocument.getMissingPiecesCount() != null && !oleLoanDocument.getMissingPiecesCount().equalsIgnoreCase("")) {
4196                                 noOfMissingPiece = Integer.parseInt(oleLoanDocument.getMissingPiecesCount());
4197                             }
4198                         }
4199                         note = note.replace("[3]", noOfMissingPiece + "");
4200                     }
4201                     List<OlePatronNotes> olePatronNotesList = olePatronDocument.getNotes();
4202                     OlePatronNotes olePatronNotes = new OlePatronNotes();
4203                     olePatronNotes.setPatronNoteText(note);
4204                     map.clear();
4205                     map.put("patronNoteTypeCode", "GENERAL");
4206                     OlePatronNoteType olePatronNoteType = (OlePatronNoteType) getLoanProcessor().getBusinessObjectService().findByPrimaryKey(OlePatronNoteType.class, map);
4207                     olePatronNotes.setPatronNoteTypeId(olePatronNoteType.getPatronNoteTypeId());
4208                     olePatronNotes.setOlePatronId(olePatronDocument.getOlePatronId());
4209                     olePatronNotesList.add(olePatronNotes);
4210                     getLoanProcessor().getBusinessObjectService().save(olePatronDocument);
4211                 }
4212             }
4213 
4214         }
4215 
4216 
4217     }
4218 
4219     @RequestMapping(params = "methodToCall=flaggedNoteSave")
4220     public ModelAndView flaggedNoteSave(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
4221                                         HttpServletRequest request, HttpServletResponse response) {
4222         OleLoanForm oleLoanForm = (OleLoanForm) form;
4223         OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
4224         oleLoanForm.setOleFormKey(oleLoanForm.getFormKey());
4225         Item oleItem = oleLoanDocument.getOleItem();
4226        /* if(oleItem==null){*/
4227         try {
4228             String itemUUid = oleLoanDocument.getItemUuid();
4229             String itemXmlContent = getLoanProcessor().getItemXML(oleLoanDocument.getItemUuid());
4230             oleItem = getLoanProcessor().getItemPojo(itemXmlContent);
4231             itemXmlContent = getLoanProcessor().getItemXML(oleLoanDocument.getItemUuid());
4232             oleLoanDocument.setOleItem(oleItem);
4233 
4234         } catch (Exception e) {
4235             if (LOG.isDebugEnabled()) {
4236                 LOG.error("Error occurred while retrieving item in flaggedNoteSave" + e);
4237             }
4238         }
4239 
4240        /* }*/
4241         if (oleLoanDocument.isItemDamagedStatus()) {
4242             if (oleLoanForm.isSkipDamagedRecordPopup()) {
4243                 if (oleLoanForm.isCheckoutDamagedRecordFlag()) {
4244                     oleLoanForm.setMessage(null);
4245                     saveGeneralNoteForFlaggedItem(OLEConstants.DAMAGED_ITEM_CHECKED_OUT_FLAG, true, oleLoanDocument, true, false, oleLoanForm.isBackGroundCheckIn(), oleLoanForm.getPatronBarcode());
4246                     oleLoanForm.setCheckoutDamagedRecordFlag(false);
4247                 }
4248                 oleLoanForm.setDisplayDamagedRecordNotePopup(false);
4249                 oleLoanForm.setSuccessMessage(oleLoanDocument.getSuccessMessage());
4250             } else {
4251                 oleLoanForm.setDisplayDamagedRecordNotePopup(true);
4252                 oleLoanForm.setSkipDamagedRecordPopup(true);
4253                 oleLoanForm.setMessage(null);
4254                 oleLoanForm.setSuccessMessage(null);
4255                 return getUIFModelAndView(form);
4256             }
4257         }
4258         if (oleLoanDocument.isMissingPieceFlag() || (oleLoanDocument.getOleItem() != null && oleLoanDocument.getOleItem().isMissingPieceFlag())) {
4259             if (oleLoanForm.isSkipMissingPieceRecordPopup()) {
4260                 if (oleLoanForm.isCheckoutMissingPieceRecordFlag()) {
4261                     oleLoanForm.setMessage(null);
4262                     saveGeneralNoteForFlaggedItem(OLEConstants.MISSING_PIECE_ITEM_CHECKED_OUT_FLAG, true, oleLoanDocument, true, false, false, oleLoanForm.getPatronBarcode());
4263                     oleLoanForm.setCheckoutMissingPieceRecordFlag(false);
4264                 }
4265                 oleLoanForm.setDisplayMissingPieceNotePopup(false);
4266                 oleLoanForm.setSuccessMessage(oleLoanDocument.getSuccessMessage());
4267             } else {
4268                 oleLoanForm.setDisplayMissingPieceNotePopup(true);
4269                 oleLoanForm.setSkipMissingPieceRecordPopup(true);
4270                 oleLoanForm.setMessage(null);
4271                 oleLoanForm.setSuccessMessage(null);
4272                 return getUIFModelAndView(form);
4273             }
4274         }
4275         oleLoanForm.setSkipDamagedRecordPopup(false);
4276         oleLoanForm.setSkipMissingPieceRecordPopup(false);
4277         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
4278     }
4279 
4280     @RequestMapping(params = "methodToCall=refreshReturnLoanList")
4281     public ModelAndView refreshReturnLoanList(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
4282                                               HttpServletRequest request, HttpServletResponse response) {
4283         long begin = System.currentTimeMillis();
4284         OleLoanForm oleLoanForm = (OleLoanForm) form;
4285         OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
4286         List<OleLoanDocument> documentList = oleLoanForm.getItemReturnList();
4287         if (documentList != null && documentList.size() > 0) {
4288             OleCirculationDesk oleCirculationDesk = null;
4289             OleLocation oleLocation = null;
4290             if (oleLoanDocument.getCirculationLocationId() != null) {
4291                 // oleCirculationDesk = loanProcessor.getOleCirculationDesk(oleLoanDocument.getCirculationLocationId());
4292                 try{
4293                     oleLocation = getCircDeskLocationResolver().getLocationByLocationCode(oleLoanDocument.getItemLocation());
4294                 }
4295                 catch (Exception e){
4296                     LOG.error("Exception while fetching OleLocation based on item location" +e);
4297                 }
4298                 String routeTo = oleLoanForm.getRouteToLocation() != null ? oleLoanForm.getRouteToLocation() :
4299                         (oleLoanDocument.getRouteToLocation() != null ? oleLoanDocument.getRouteToLocation() :
4300                                 (oleLocation != null ? oleLocation.getLocationCode() : null));
4301                 documentList.get(0).setRouteToLocation(routeTo);
4302             }
4303         }
4304         long end = System.currentTimeMillis();
4305         long total = end - begin;
4306         LOG.info("Time taken Inside refreshReturnLoanList"+total);
4307         return getUIFModelAndView(form, "ReturnItemViewPage");
4308     }
4309 
4310     @RequestMapping(params = "methodToCall=printHoldSlips")
4311     public ModelAndView printHoldSlips(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
4312                                        HttpServletRequest request, HttpServletResponse response) {
4313         try {
4314             OlePrintSlip olePrintSlip = new OlePrintSlip();
4315             if (LOG.isDebugEnabled()) {
4316                 LOG.debug(" Inside Print Hold Slips ");
4317             }
4318             String formKey = request.getParameter("formKey");
4319             OleLoanForm oleLoanForm = (OleLoanForm) GlobalVariables.getUifFormManager().getSessionForm(formKey);
4320             OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
4321             OleCirculationDesk oleCirculationDesk = null;
4322             oleCirculationDesk = getCircDeskLocationResolver().getOleCirculationDesk(oleLoanDocument.getCirculationLocationId());
4323             olePrintSlip.createHoldSlipPdf(printHoldSlipList, response, oleCirculationDesk);
4324 
4325         } catch (Exception e) {
4326             LOG.error("Exception while generating printHoldSlips " + e);
4327         }
4328         return null;
4329     }
4330 
4331     @RequestMapping(params = "methodToCall=refreshExport")
4332     public ModelAndView refreshExport(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
4333                                        HttpServletRequest request, HttpServletResponse response) {
4334         OleLoanForm loanForm=(OleLoanForm)form;
4335         Date checkInDate=loanForm.getCheckInDate();
4336         start(form,result,request,response);
4337         loanForm.setCheckInDate(checkInDate);
4338         return getUIFModelAndView(form);
4339     }
4340 
4341 
4342     @RequestMapping(params = "methodToCall=showExistingLoan")
4343     public ModelAndView showExistingLoan(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
4344                                       HttpServletRequest request, HttpServletResponse response) {
4345         try {
4346             OleLoanForm loanForm = (OleLoanForm) form;
4347             loanForm.setShowExistingLoan(true);
4348             if(loanForm.getExistingLoanList().size()==0){
4349                 OleLoanDocument oleLoanDocument = loanForm.getDummyLoan();
4350                 if (oleLoanDocument.getRealPatronBarcode() != null) {
4351                     if (loanForm.getRealPatronId() != null && (loanForm.getRealPatronId() != null && !loanForm.getRealPatronId().equalsIgnoreCase(""))) {
4352                         loanForm.setExistingLoanList(getOleLoanDocumentsFromSolrBuilder().getPatronLoanedItemBySolr
4353                                 (loanForm.getRealPatronId(), null));
4354                     }
4355                 } else {
4356                     loanForm.setExistingLoanList(getOleLoanDocumentsFromSolrBuilder().getPatronLoanedItemBySolr
4357                             (oleLoanDocument.getPatronId(), null));
4358                 }
4359                 if(loanForm.getLoanList() != null && loanForm.getLoanList().size()>0){
4360                     for(OleLoanDocument oleLoanDocument1 : loanForm.getLoanList()){
4361                         if(loanForm.getExistingLoanList().contains(oleLoanDocument1)){
4362                             loanForm.getExistingLoanList().remove(oleLoanDocument1);
4363                         }
4364                     }
4365                    /*if(loanForm.getLoanList().containsAll(loanForm.getExistingLoanList())){
4366                        loanForm.getExistingLoanList().removeAll(loanForm.getLoanList());
4367                    }*/
4368                 }
4369             }
4370         } catch (Exception e) {
4371             e.printStackTrace();        }
4372         return getUIFModelAndView(form);
4373     }
4374 
4375     private OleLoanDocumentsFromSolrBuilder getOleLoanDocumentsFromSolrBuilder() {
4376         if (null == oleLoanDocumentsFromSolrBuilder) {
4377             oleLoanDocumentsFromSolrBuilder = new OleLoanDocumentsFromSolrBuilder();
4378         }
4379         return oleLoanDocumentsFromSolrBuilder;
4380     }
4381 
4382     public void setOleLoanDocumentsFromSolrBuilder(OleLoanDocumentsFromSolrBuilder oleLoanDocumentsFromSolrBuilder) {
4383         this.oleLoanDocumentsFromSolrBuilder = oleLoanDocumentsFromSolrBuilder;
4384     }
4385 
4386     @RequestMapping(params = "methodToCall=hideExistingLoan")
4387     public ModelAndView hideExistingLoan(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
4388                                          HttpServletRequest request, HttpServletResponse response) {
4389         OleLoanForm loanForm=(OleLoanForm)form;
4390         loanForm.setShowExistingLoan(false);
4391         //loanForm.setExistingLoanList(new ArrayList<OleLoanDocument>());
4392         return getUIFModelAndView(form);
4393     }
4394 
4395 
4396 }