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