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