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.deliver.batch.OleDeliverBatchServiceImpl;
9   import org.kuali.ole.deliver.batch.OleMailer;
10  import org.kuali.ole.deliver.batch.OleNoticeBo;
11  import org.kuali.ole.deliver.bo.OleCirculationDeskDetail;
12  import org.kuali.ole.deliver.bo.OleLoanDocument;
13  import org.kuali.ole.deliver.bo.OlePatronDocument;
14  import org.kuali.ole.deliver.bo.OleProxyPatronDocument;
15  import org.kuali.ole.deliver.form.OleLoanForm;
16  import org.kuali.ole.deliver.printSlip.OlePrintSlip;
17  import org.kuali.ole.deliver.processor.LoanProcessor;
18  import org.kuali.ole.describe.bo.OleItemAvailableStatus;
19  import org.kuali.ole.docstore.model.xmlpojo.work.instance.oleml.Item;
20  import org.kuali.rice.core.api.config.property.ConfigContext;
21  import org.kuali.rice.core.api.mail.EmailBody;
22  import org.kuali.rice.core.api.mail.EmailFrom;
23  import org.kuali.rice.core.api.mail.EmailSubject;
24  import org.kuali.rice.core.api.mail.EmailTo;
25  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
26  import org.kuali.rice.krad.exception.DocumentAuthorizationException;
27  import org.kuali.rice.krad.uif.UifConstants;
28  import org.kuali.rice.krad.uif.UifParameters;
29  import org.kuali.rice.krad.util.GlobalVariables;
30  import org.kuali.rice.krad.web.controller.UifControllerBase;
31  import org.kuali.rice.krad.web.form.UifFormBase;
32  import org.springframework.stereotype.Controller;
33  import org.springframework.validation.BindingResult;
34  import org.springframework.web.bind.annotation.ModelAttribute;
35  import org.springframework.web.bind.annotation.RequestMapping;
36  import org.springframework.web.servlet.ModelAndView;
37  
38  import javax.servlet.http.HttpServletRequest;
39  import javax.servlet.http.HttpServletResponse;
40  import java.io.IOException;
41  import java.sql.Timestamp;
42  import java.text.SimpleDateFormat;
43  import java.util.ArrayList;
44  import java.util.Date;
45  import java.util.List;
46  import java.util.Properties;
47  import java.util.regex.Matcher;
48  import java.util.regex.Pattern;
49  
50  /**
51   * The LoanController is the controller class for processing all the actions that corresponds to the Loan functionality in OLE.
52   * The request mapping tag takes care of mapping the individual action to the corresponding functions.
53   */
54  @Controller
55  @RequestMapping(value = "/loancontroller")
56  public class LoanController extends UifControllerBase {
57  
58      private static final Logger LOG = Logger.getLogger(LoanController.class);
59  
60      private List<OleLoanDocument> printDueDateSlipList = new ArrayList<OleLoanDocument>();
61  
62      private LoanProcessor loanProcessor;
63  
64      private OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
65  
66      public static String fastAddBarcode = "";
67  
68      private List<String> loginUserList;
69  
70      /**
71       * This method creates new OleLoan form
72       *
73       * @param request
74       * @return OleLoanForm
75       */
76      @Override
77      protected OleLoanForm createInitialForm(HttpServletRequest request) {
78          return new OleLoanForm();
79      }
80  
81      /**
82       * This method converts UifFormBase to OleLoanForm
83       *
84       * @param form
85       * @param result
86       * @param request
87       * @param response
88       * @return ModelAndView
89       */
90      @Override
91      @RequestMapping(params = "methodToCall=start")
92      public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
93                                HttpServletRequest request, HttpServletResponse response) {
94          LOG.debug("Inside the loan start method");
95          fastAddBarcode = "";
96          OleLoanForm oleLoanForm = null;
97          if (form.getViewId().equalsIgnoreCase("PatronItemView")) {
98              String formKey = request.getParameter("formKey");
99              if (formKey == null) {
100                 if (loginUserList != null) {
101                     loginUserList.clear();
102                 }
103                 oleLoanForm = (OleLoanForm) form;
104                 oleLoanForm.setReturnCheck(false);
105                 if (oleLoanForm.getOldPrincipalId() == null || "".equals(oleLoanForm.getOldPrincipalId()))
106                     oleLoanForm.setOldPrincipalId(GlobalVariables.getUserSession().getPrincipalId());
107                 Integer maxTimeForCheckInDate = 0;
108                 String parameter = getLoanProcessor().getParameter(OLEConstants.MAX_TIME_CHECK_IN);
109                 String loanParameter = getLoanProcessor().getParameter(OLEConstants.MAX_TIME_LOAN);
110                 String audioOption = getLoanProcessor().getParameter(OLEConstants.AUDIO_OPTION);
111                 String maxSessionTime = loanParameter;
112                 LOG.info("session timeout" + maxSessionTime);
113                 if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
114                     oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));
115 
116                 if (!loanProcessor.isValidCirculationDesk()) {
117                     oleLoanForm.setLoanLoginMessage(true);
118                     String loginInfo = loanProcessor.getErrorMessage();
119                     oleLoanForm.setLoanLoginUserInfo(loginInfo);
120                     return super.start(oleLoanForm, result, request, response);
121                     //throw new DocumentAuthorizationException(GlobalVariables.getUserSession().getPrincipalId(), "not Authorized", form.getViewId());
122                     // return new OLEKRADAuthorizationResolver().resolveException(request,response,null,new Exception("is not authorized"));
123                 }
124                 //To set circulation desk value initially
125                 oleLoanForm.setCirculationDesk(loanProcessor.getCircDesk());
126                 oleLoanForm.setAudioForPastDate(audioOption != null && !audioOption.isEmpty() && audioOption.equalsIgnoreCase(OLEConstants.TRUE));
127                 if (parameter != null) {
128                     maxTimeForCheckInDate = Integer.parseInt(parameter) * 60;
129                 }
130                 oleLoanForm.setMaxTimeForCheckOutConstant(loanParameter);
131 
132                 oleLoanForm.setMaxTimeForCheckInDate(maxTimeForCheckInDate);
133                 oleLoanForm.setCheckInDateMaxTime(maxTimeForCheckInDate);
134                 oleLoanForm.setDateAlertMessage(OLEConstants.CHECK_IN_DATE);
135                 oleLoanForm.setCurrentDate(new Date());
136                 oleLoanForm.setPatronFocus(true);
137                 if (oleLoanForm.getCheckInDate() == null) {
138                     oleLoanForm.setCheckInDate(new Date());
139                 }
140             } else {
141                 oleLoanForm = (OleLoanForm) GlobalVariables.getUifFormManager().getSessionForm(formKey);
142                 if (oleLoanForm.getOldPrincipalId() == null || "".equals(oleLoanForm.getOldPrincipalId()))
143                     oleLoanForm.setOldPrincipalId(GlobalVariables.getUserSession().getPrincipalId());
144                 oleLoanForm.setReturnCheck(false);
145                 oleLoanForm.setAjaxRequest(false);
146                 oleLoanForm.setAjaxReturnType("update-view");
147                 oleLoanForm = (OleLoanForm) form;
148                 oleLoanForm.setPageId(null);
149                 Integer maxTimeForCheckInDate = 0;
150                 String parameter = getLoanProcessor().getParameter(OLEConstants.MAX_TIME_CHECK_IN);
151                 String loanParameter = getLoanProcessor().getParameter(OLEConstants.MAX_TIME_LOAN);
152                 String audioOption = getLoanProcessor().getParameter(OLEConstants.AUDIO_OPTION);
153 
154                 String maxSessionTime = loanParameter;
155                 LOG.info("session timeout" + maxSessionTime);
156                 if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
157                     oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));
158 
159                 if (!loanProcessor.isValidCirculationDesk()) {
160                     oleLoanForm.setLoanLoginMessage(true);
161                     String loginInfo = loanProcessor.getErrorMessage();
162                     oleLoanForm.setLoanLoginUserInfo(loginInfo);
163                     return super.start(oleLoanForm, result, request, response);
164                     //throw new DocumentAuthorizationException(GlobalVariables.getUserSession().getPrincipalId(), "not Authorized", form.getViewId());
165                     // return new OLEKRADAuthorizationResolver().resolveException(request,response,null,new Exception("is not authorized"));
166                 }
167                 oleLoanForm.setAudioForPastDate(audioOption != null && !audioOption.isEmpty() && audioOption.equalsIgnoreCase(OLEConstants.TRUE));
168                 if (parameter != null) {
169                     maxTimeForCheckInDate = Integer.parseInt(parameter) * 60;
170                 }
171                 oleLoanForm.setMaxTimeForCheckOutConstant(loanParameter);
172 
173                 oleLoanForm.setMaxTimeForCheckInDate(maxTimeForCheckInDate);
174                 oleLoanForm.setCheckInDateMaxTime(maxTimeForCheckInDate);
175                 oleLoanForm.setDateAlertMessage(OLEConstants.CHECK_IN_DATE);
176                 oleLoanForm.setCurrentDate(new Date());
177                 oleLoanForm.setPatronFocus(true);
178                 if (oleLoanForm.getCheckInDate() == null) {
179                     oleLoanForm.setCheckInDate(new Date());
180                 }
181             }
182 
183 
184         } else {
185             oleLoanForm = (OleLoanForm) form;
186             //To set circulation desk value initially
187             String formKey = request.getParameter("formKey");
188             if (formKey == null) {
189                 oleLoanForm.setCirculationDesk(loanProcessor.getCircDesk());
190             }
191             if (oleLoanForm.getOldPrincipalId() == null || "".equals(oleLoanForm.getOldPrincipalId()))
192                 oleLoanForm.setOldPrincipalId(GlobalVariables.getUserSession().getPrincipalId());
193             oleLoanForm.setPageId(null);
194             oleLoanForm.setReturnCheck(true);
195             Integer maxTimeForCheckInDate = 0;
196             String parameter = getLoanProcessor().getParameter(OLEConstants.MAX_TIME_CHECK_IN);
197             String loanParameter = getLoanProcessor().getParameter(OLEConstants.MAX_TIME_LOAN);
198             String audioOption = getLoanProcessor().getParameter(OLEConstants.AUDIO_OPTION);
199 
200             String maxSessionTime = loanParameter;
201             LOG.info("session timeout" + maxSessionTime);
202             if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
203                 oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));
204 
205             if (!loanProcessor.isValidCirculationDesk()) {
206                 oleLoanForm.setLoanLoginMessage(true);
207                 String loginInfo = loanProcessor.getErrorMessage();
208                 oleLoanForm.setLoanLoginUserInfo(loginInfo);
209                 return super.start(oleLoanForm, result, request, response);
210                 //throw new DocumentAuthorizationException(GlobalVariables.getUserSession().getPrincipalId(), "not Authorized", form.getViewId());
211                 //return new OLEKRADAuthorizationResolver().resolveException(request,response,null,new Exception("is not authorized"));
212             }
213             oleLoanForm.setAudioForPastDate(audioOption != null && !audioOption.isEmpty() && audioOption.equalsIgnoreCase(OLEConstants.TRUE));
214             if (parameter != null) {
215                 maxTimeForCheckInDate = Integer.parseInt(parameter) * 60;
216             }
217             oleLoanForm.setMaxTimeForCheckOutConstant(loanParameter);
218 
219             oleLoanForm.setMaxTimeForCheckInDate(maxTimeForCheckInDate);
220             oleLoanForm.setCheckInDateMaxTime(maxTimeForCheckInDate);
221             oleLoanForm.setDateAlertMessage(OLEConstants.CHECK_IN_DATE);
222             oleLoanForm.setCurrentDate(new Date());
223             oleLoanForm.setPatronFocus(true);
224             if (oleLoanForm.getCheckInDate() == null) {
225                 oleLoanForm.setCheckInDate(new Date());
226             }
227         }
228         return super.start(oleLoanForm, result, request, response);
229     }
230 
231     /**
232      * To refresh patron record.
233      *
234      * @param form
235      * @param result
236      * @param request
237      * @param response
238      * @return
239      * @throws Exception
240      */
241     @Override
242     @RequestMapping(params = "methodToCall=refresh")
243     public ModelAndView refresh(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
244                                 HttpServletRequest request, HttpServletResponse response) throws Exception {
245         OleLoanForm oleLoanForm = (OleLoanForm) form;
246         if (oleLoanForm.getPatronFirstName() != null) {
247             oleLoanForm.setReturnCheck(false);
248             oleLoanForm.setPatronFirstName(null);
249             super.refresh(oleLoanForm, result, request, response);
250             return searchPatron(oleLoanForm, result, request, response);
251         }
252         if (oleLoanForm.getItemUuid() != null && oleLoanForm.getInstanceUuid() != null) {
253             oleLoanForm.setReturnCheck(false);
254             super.refresh(oleLoanForm, result, request, response);
255             ModelAndView modelAndView = addItem(oleLoanForm, result, request, response);
256             oleLoanForm.setItemUuid(null);
257             oleLoanForm.setInstanceUuid(null);
258             return modelAndView;
259         }
260         if (oleLoanForm.getReturnItemUuid() != null && oleLoanForm.getReturnInstanceUuid() != null) {
261             oleLoanForm.setReturnCheck(true);
262             super.refresh(oleLoanForm, result, request, response);
263             ModelAndView modelAndView = validateItem(oleLoanForm, result, request, response);
264             oleLoanForm.setReturnItemUuid(null);
265             oleLoanForm.setReturnInstanceUuid(null);
266             return modelAndView;
267         }
268         return super.refresh(oleLoanForm, result, request, response);
269     }
270 
271     /**
272      * This method displays information about a patron in UI.
273      *
274      * @param form
275      * @param result
276      * @param request
277      * @param response
278      * @return ModelAndView
279      */
280     @RequestMapping(params = "methodToCall=searchPatron")
281     public ModelAndView searchPatron(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
282                                      HttpServletRequest request, HttpServletResponse response) {
283         LOG.debug("Inside the search patron method");
284         fastAddBarcode = "";
285         OleLoanForm oleLoanForm = (OleLoanForm) form;
286         oleLoanForm.setLoanList(new ArrayList<OleLoanDocument>(0));
287         oleLoanForm.setBlockPatron(false);
288         oleLoanForm.setExistingLoanList(new ArrayList<OleLoanDocument>(0));
289         oleLoanForm.setInformation("");
290         oleLoanForm.setReturnInformation("");
291         LoanProcessor loanProcessor = getLoanProcessor();
292         try {
293             String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
294             LOG.info("session timeout" + maxSessionTime);
295             if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
296                 oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));
297 
298             if (!loanProcessor.isValidCirculationDesk()) {
299                 oleLoanForm.setLoanLoginMessage(true);
300                 String loginInfo = loanProcessor.getErrorMessage();
301                 oleLoanForm.setLoanLoginUserInfo(loginInfo);
302                 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
303                 //throw new DocumentAuthorizationException(GlobalVariables.getUserSession().getPrincipalId(), "not Authorized", form.getViewId());
304                 //return new OLEKRADAuthorizationResolver().resolveException(request,response,null,new Exception("is not authorized"));
305                 /*return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());*/
306             }
307             OleLoanDocument oleProxyLoanDocument = null;
308             List<OlePatronDocument> oleRealPatron = oleLoanForm.getRealPatronList();
309             List<OlePatronDocument> oleCurrentPatronDocumentList = oleLoanForm.getCurrentPatronList();
310             OlePatronDocument oleCurrentPatronDocument = new OlePatronDocument();
311             if (oleCurrentPatronDocumentList != null && oleCurrentPatronDocumentList.size() > 0) {
312                 oleCurrentPatronDocument = oleCurrentPatronDocumentList.get(0);
313             }
314             if (oleRealPatron != null && oleRealPatron.size() > 0 && !oleCurrentPatronDocument.isSelfCheckOut()) {
315                 for (int realPatron = 0; realPatron < oleRealPatron.size(); realPatron++) {
316                     OlePatronDocument olePatronDocument = oleRealPatron.get(realPatron);
317                     if (olePatronDocument.isRealPatronCheck()) {
318                         oleLoanForm.setRealPatronBarcode(olePatronDocument.getBarcode());
319                         oleLoanForm.setRealPatronFlag(false);
320                         oleProxyLoanDocument = loanProcessor.getLoanDocument(olePatronDocument.getBarcode(), null, oleLoanForm.isSelfCheckOut());
321                         break;
322                     }
323                 }
324             }
325             if (oleCurrentPatronDocument.isSelfCheckOut()) {
326                 oleLoanForm.setSelfCheckOut(true);
327                 oleLoanForm.setRealPatronFlag(false);
328             }
329 
330             OleLoanDocument oleLoanDocument = loanProcessor.getLoanDocument(oleLoanForm.getPatronBarcode(), oleLoanForm.getRealPatronBarcode(), oleLoanForm.isSelfCheckOut());
331             if (oleLoanDocument.getPatronUserNotes() != null) {
332                 oleLoanForm.setPatronNoteFlag(true);
333                 oleLoanForm.setPatronUserNote(oleLoanDocument.getPatronUserNotes());
334                 oleLoanForm.setPatronNoteTypeId(oleLoanDocument.getPatronNoteTypeId());
335             }
336             if (oleLoanDocument.getRealPatron() != null && oleLoanDocument.getRealPatron().size() > 0) {
337                 List<OlePatronDocument> realPatronActiveListOld = new ArrayList<OlePatronDocument>();
338                 for (OlePatronDocument oleRealPatronDocument : oleLoanDocument.getRealPatron()) {
339                     if (!realPatronActiveListOld.contains(oleRealPatronDocument)) {
340                         realPatronActiveListOld.add(oleRealPatronDocument);
341                     }
342                 }
343 
344                 List<OlePatronDocument> realPatronActiveList = new ArrayList<OlePatronDocument>();
345                 for (OlePatronDocument oleRealPatronDocument : realPatronActiveListOld) {
346                     List<OleProxyPatronDocument> proxyPatronActiveList = new ArrayList<OleProxyPatronDocument>();
347                     for (OleProxyPatronDocument oleProxyPatronDocument : oleRealPatronDocument.getOleProxyPatronDocuments()) {
348                         if (oleProxyPatronDocument.getProxyPatronId().equalsIgnoreCase(oleLoanDocument.getPatronId()) && !oleProxyPatronDocument.getProxyPatronExpirationDate().before(new Timestamp(System.currentTimeMillis()))) {
349 
350                             proxyPatronActiveList.add(oleProxyPatronDocument);
351 
352                         }
353                     }
354                     if (proxyPatronActiveList.size() > 0) {
355                         oleRealPatronDocument.setOleProxyPatronDocuments(proxyPatronActiveList);
356                         oleRealPatronDocument.setOleProxyPatronDocumentList(proxyPatronActiveList);
357                         realPatronActiveList.add(oleRealPatronDocument);
358 
359                     }
360                 }
361                 if (realPatronActiveList.size() > 0) {
362                     oleLoanForm.setRealPatronList(realPatronActiveList);
363                     oleLoanForm.setCurrentPatronList(loanProcessor.getPatronList(oleLoanDocument.getPatronId()));
364                     oleLoanForm.setRealPatronFlag(true);
365 
366                 }
367             }
368             oleLoanForm.setBorrowerCode(oleLoanDocument.getBorrowerTypeCode());
369             oleLoanForm.setPatronId(oleLoanDocument.getPatronId());
370             String patronNameURL = loanProcessor.patronNameURL(oleLoanForm.getOldPrincipalId(), oleLoanForm.getPatronId());
371             oleLoanForm.setPatronNameURL(patronNameURL);
372             oleLoanForm.setProxyPatronId(oleLoanDocument.getProxyPatronId());
373             //oleLoanForm.setRealPatronName(oleLoanDocument.getRealPatronName());
374             oleLoanForm.setRealPatronType(oleLoanDocument.getRealPatronType());
375             oleLoanForm.setAddressVerified(oleLoanDocument.isAddressVerified());
376             oleLoanForm.setBlockLoan(oleLoanDocument.isBlockLoan());
377             oleLoanForm.setBorrowerTypeId(oleLoanDocument.getBorrowerTypeId());
378             oleLoanForm.setInformation("");
379             oleLoanForm.setExistingLoanList(loanProcessor.getPatronLoanedItem(oleLoanDocument.getPatronId()));
380             oleLoanForm.setDummyLoan(oleLoanDocument);
381             oleLoanForm.setBlockItem(false);
382             oleLoanForm.setBlockPatron(false);
383             oleLoanForm.setNonCirculatingFlag(false);
384             oleLoanForm.setItem(null);
385             oleLoanForm.setOleItem(null);
386             if (oleLoanDocument.getErrorMessage() != null) {
387                 oleLoanForm.setSuccess(false);
388                 oleLoanForm.setInformation("");
389                 oleLoanForm.setMessage(oleLoanDocument.getErrorMessage());
390                 getLoanProcessor().setErrorFlagForPatron(oleLoanDocument, oleLoanForm);
391                 oleLoanForm.setPatronName(null);
392                 String audioOption = getLoanProcessor().getParameter(OLEConstants.AUDIO_OPTION);
393                 oleLoanForm.setAudioEnable(audioOption != null && !audioOption.isEmpty() && audioOption.equalsIgnoreCase(OLEConstants.TRUE));
394             }
395             if (oleProxyLoanDocument != null) {
396                 oleLoanForm.setRealPatronName(oleLoanDocument.getPatronName());
397                 oleLoanDocument = oleProxyLoanDocument;
398                 patronNameURL = loanProcessor.patronNameURL(oleLoanForm.getOldPrincipalId(), oleLoanForm.getProxyPatronId());
399                 oleLoanForm.setPatronNameURL(patronNameURL);
400             } else {
401                 oleLoanForm.setRealPatronName(null);
402             }
403             oleLoanForm.setPatronName(oleLoanDocument.getPatronName());
404             oleLoanForm.setBorrowerType(oleLoanDocument.getBorrowerTypeName());
405             oleLoanForm.setPreferredAddress(oleLoanDocument.getPreferredAddress());
406             oleLoanForm.setEmail(oleLoanDocument.getEmail());
407             oleLoanForm.setPhoneNumber(oleLoanDocument.getPhoneNumber());
408             oleLoanForm.setItemFocus(true);
409             oleLoanForm.setPatronFocus(false);
410         } catch (Exception e) {
411             oleLoanForm.setInformation(e.getMessage());
412             LOG.error(e, e);
413         }
414         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
415     }
416 
417     /**
418      * This method creates new loan for a patron and also renew the existing item.
419      *
420      * @param form
421      * @param result
422      * @param request
423      * @param response
424      * @return ModelAndView
425      */
426     @RequestMapping(params = "methodToCall=addItem")
427     public ModelAndView addItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
428                                 HttpServletRequest request, HttpServletResponse response) {
429         LOG.debug("Inside the add item method");
430         OleLoanForm oleLoanForm = (OleLoanForm) form;
431         oleLoanForm.setBlockItem(false);
432         try {
433             loanProcessor = getLoanProcessor();
434             oleLoanForm.setOleFormKey(oleLoanForm.getFormKey());
435             String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
436             LOG.info("session timeout" + maxSessionTime);
437             if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
438                 oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));
439             oleLoanForm.setInformation("");
440             oleLoanForm.setReturnInformation("");
441             if (!loanProcessor.isValidCirculationDesk()) {
442                 oleLoanForm.setLoanLoginMessage(true);
443                 String loginInfo = loanProcessor.getErrorMessage();
444                 oleLoanForm.setLoanLoginUserInfo(loginInfo);
445                 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
446                 //throw new DocumentAuthorizationException(GlobalVariables.getUserSession().getPrincipalId(), "not Authorized", form.getViewId());
447                 //return new OLEKRADAuthorizationResolver().resolveException(request, response, null, new Exception("is not authorized"));
448             }
449             boolean renewalFlag = false;
450             List<OleLoanDocument> existItemList = new ArrayList<OleLoanDocument>();
451             if (oleLoanForm.getExistingLoanList() != null && !oleLoanForm.getExistingLoanList().isEmpty())
452                 existItemList.addAll(oleLoanForm.getExistingLoanList());
453             if (oleLoanForm.getLoanList() != null && !oleLoanForm.getLoanList().isEmpty())
454                 existItemList.addAll(oleLoanForm.getLoanList());
455             String item = oleLoanForm.getItem();
456             for (int i = 0; i < existItemList.size(); i++) {
457                 OleLoanDocument oleLoanDocument = existItemList.get(i);
458                 if (oleLoanDocument.getItemId() != null && oleLoanDocument.getItemId().equals(item)) {
459                     oleLoanForm.setRenewalFlag(true);
460                     oleLoanForm.setBlockItem(true);
461                     oleLoanForm.setBlockPatron(true);
462                     oleLoanForm.setSuccess(false);
463                     oleLoanForm.setMessage(OLEConstants.RENEWAL_ITM_POPUP);
464                     renewalFlag = true;
465                     break;
466                 }
467             }
468 
469             if (!renewalFlag) {
470 
471                 try {
472                     List<OleLoanDocument> existingItemList = new ArrayList<OleLoanDocument>();
473                     OleLoanDocument oleLoanDocument = new OleLoanDocument();
474                     oleLoanDocument.setPatronId(oleLoanForm.getPatronId());
475                     oleLoanDocument.setProxyPatronId(oleLoanForm.getProxyPatronId());
476                     oleLoanDocument.setRealPatronBarcode(oleLoanForm.getRealPatronBarcode());
477                     oleLoanDocument.setRealPatronType(oleLoanForm.getRealPatronType());
478                     oleLoanDocument.setCirculationLocationId(oleLoanForm.getCirculationDesk());
479                     oleLoanDocument.setBorrowerTypeId(oleLoanForm.getBorrowerTypeId());
480                     oleLoanDocument.setBorrowerTypeName(oleLoanForm.getBorrowerType());
481                     oleLoanDocument.setBorrowerTypeCode(oleLoanForm.getBorrowerCode());
482                     oleLoanDocument.setItemUuid(oleLoanForm.getItemUuid());
483                     oleLoanForm.setAddressVerified(false);
484                     oleLoanDocument = getLoanProcessor().addLoan(oleLoanForm.getPatronBarcode(), oleLoanForm.getItem(), oleLoanDocument);
485                     oleLoanForm.setItemUuid(oleLoanDocument.getItemUuid());
486                     oleLoanForm.setNonCirculatingFlag(oleLoanDocument.isNonCirculatingItem());
487                    /* if (oleLoanDocument.isStatusLost()) {
488                         oleLoanForm.setItemStatusLost(true);
489                     }*/
490                     oleLoanForm.setInstanceUuid(oleLoanDocument.getInstanceUuid());
491                     oleLoanForm.setOleItem(oleLoanDocument.getOleItem());
492                     oleLoanForm.setDueDateMap(oleLoanDocument.getLoanDueDate());
493                     oleLoanForm.setMessage(oleLoanDocument.getErrorMessage());
494                     oleLoanForm.setRoleName(oleLoanDocument.getRoleName());
495                     if (oleLoanForm.getPatronName() == null) {
496                         oleLoanForm.setPatronName(oleLoanDocument.getPatronName());
497                     }
498                     if (oleLoanDocument.getErrorMessage() == null) {
499                         existingItemList.add(oleLoanDocument);
500                         oleLoanForm.setBlockItem(false);
501                         oleLoanForm.setBlockPatron(false);
502                         oleLoanForm.setItem("");
503                         oleLoanForm.setInformation("");
504                         // oleLoanForm.setReturnWithMissingItem(false);
505                     } else {
506                         // oleLoanForm.setReturnWithMissingItem(oleLoanDocument.getOleItem().getItemStatus().getCodeValue().equalsIgnoreCase(OLEConstants.RETURN_MISSING_ITM));
507                         oleLoanForm.setDueDateEmpty(oleLoanDocument.isDueDateEmpty());
508                         oleLoanForm.setDummyLoan(oleLoanDocument);
509                         oleLoanForm.setSuccess(false);
510                         if (oleLoanDocument.getOleItem() != null) {
511                             oleLoanForm.setDescription(oleLoanDocument.getOleItem().getCheckinNote());
512                         }
513                         oleLoanForm.setInformation("");
514                         getLoanProcessor().setErrorFlagForItem(oleLoanDocument, oleLoanForm);
515                     }
516                     if (oleLoanForm.getLoanList() != null && !oleLoanForm.getLoanList().isEmpty()) {
517                         existingItemList.addAll(oleLoanForm.getLoanList());
518                     }
519                     oleLoanForm.setLoanList(existingItemList);
520                     List<OleLoanDocument> oleLoanDocumentList = new ArrayList<OleLoanDocument>();
521                     oleLoanDocumentList.add(oleLoanDocument);
522 
523                     if (getLoanProcessor().getParameter(OLEConstants.PRINT_DUE_DATE_PER_TRANSACTION).equalsIgnoreCase("Yes")) {
524                         oleLoanForm.setDueDateSlip(true);
525                     }
526                     oleLoanForm.setItemFocus(true);
527                     oleLoanForm.setPatronFocus(false);
528                 } catch (Exception e) {
529                     LOG.error(e, e);
530                     oleLoanForm.setInformation(e.getMessage());
531                 }
532             }
533         } catch (Exception e) {
534             LOG.error(e, e);
535         }
536         String audioOption = getLoanProcessor().getParameter(OLEConstants.AUDIO_OPTION);
537         oleLoanForm.setAudioEnable(audioOption != null && !audioOption.isEmpty() && audioOption.equalsIgnoreCase(OLEConstants.TRUE));
538         oleLoanForm.setItemUuid(null);
539         oleLoanForm.setInstanceUuid(null);
540         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
541     }
542 
543     /**
544      * This method  creates loan for a patron who is not able to borrow.
545      *
546      * @param form
547      * @param result
548      * @param request
549      * @param response
550      * @return ModelAndView
551      */
552     @RequestMapping(params = "methodToCall=loan")
553     public ModelAndView loanPatron(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
554                                    HttpServletRequest request, HttpServletResponse response) {
555         LOG.debug("Inside the loan patron method");
556         if (loginUserList == null) {
557             loginUserList = new ArrayList<>();
558         }
559         StringBuffer buffer = new StringBuffer();
560         int count;
561         OleLoanForm oleLoanForm = (OleLoanForm) form;
562         String newPrincipalId = oleLoanForm.getNewPrincipalId();
563         oleLoanForm.setInformation("");
564         oleLoanForm.setReturnInformation("");
565         String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
566         LOG.info("session timeout" + maxSessionTime);
567         if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
568             oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));
569         OleLoanDocument oleLoanDocumentChk = null;
570         ModelAndView overrideModelView = null;
571         if (oleLoanForm.getItem() == null) {
572             try {
573 
574                 String principalId = GlobalVariables.getUserSession().getPrincipalId();
575                 Boolean overRideFlag = getLoanProcessor().checkOverRidePermission(principalId, oleLoanForm);
576                 if (!overRideFlag) {
577                     oleLoanDocumentChk = getLoanProcessor().getLoanDocument(oleLoanForm.getPatronBarcode(), oleLoanForm.getRealPatronBarcode(), oleLoanForm.isSelfCheckOut());
578                     if (oleLoanDocumentChk.getErrorMessage() != null) {
579                         if (!oleLoanForm.getLoanLoginName().equalsIgnoreCase("") || !oleLoanForm.getLoanLoginName().isEmpty()) {
580                             buffer.append(oleLoanForm.getLoanLoginName() + "," + oleLoanForm.getCirculationDesk());
581                             loanProcessor.getLoanUserList(loginUserList, buffer);
582                         } else {
583                             if (!oleLoanForm.getOldPrincipalId().equalsIgnoreCase("") || !oleLoanForm.getOldPrincipalId().isEmpty()) {
584                                 buffer.append(oleLoanForm.getOldPrincipalId() + "," + oleLoanForm.getCirculationDesk());
585                                 loanProcessor.getLoanUserList(loginUserList, buffer);
586                             }
587                         }
588 
589                         overrideModelView = this.overRide(form, result, request, response);
590                     }
591                 }
592             } catch (Exception e) {
593                 LOG.error("Check for Address Verified and Block Failed." + e.getMessage(), e);
594 
595             }
596 
597         } else {
598             if (!oleLoanForm.getLoanLoginName().equalsIgnoreCase("") || !oleLoanForm.getLoanLoginName().isEmpty()) {
599                 buffer.append(oleLoanForm.getLoanLoginName() + "," + oleLoanForm.getCirculationDesk());
600                 loanProcessor.getLoanUserList(loginUserList, buffer);
601             } else {
602                 if (!oleLoanForm.getOldPrincipalId().equalsIgnoreCase("") || !oleLoanForm.getOldPrincipalId().isEmpty()) {
603                     buffer.append(oleLoanForm.getOldPrincipalId() + "," + oleLoanForm.getCirculationDesk());
604                     loanProcessor.getLoanUserList(loginUserList, buffer);
605                 }
606             }
607 
608             overrideModelView = this.overRide(form, result, request, response);
609         }
610 
611 
612         if (overrideModelView == null) {
613             try {
614                 List<OleLoanDocument> existingItemList = new ArrayList<OleLoanDocument>();
615                 OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
616                 if (oleLoanDocument != null) {
617                     if (oleLoanDocument.getItemLoanStatus() != null && oleLoanDocument.getItemLoanStatus().equalsIgnoreCase(OLEConstants.ITEM_STATUS_CHECKEDOUT)) {
618                         oleLoanForm.setCheckInItem(oleLoanForm.getItem());
619                         oleLoanForm.setBackGroundCheckIn(true);
620                         //   validateItem(oleLoanForm,result,request,response);
621                         oleLoanForm.setBackUpDummyLoan(oleLoanDocument);
622                         oleLoanDocument = loanProcessor.getOleLoanDocumentUsingItemBarcode(oleLoanForm.getCheckInItem());
623                         oleLoanDocument.setCheckInDate(new Timestamp(System.currentTimeMillis()));
624                         oleLoanDocument = loanProcessor.returnLoan(oleLoanForm.getCheckInItem(), oleLoanDocument);
625                         oleLoanForm.setDummyLoan(oleLoanDocument);
626                         if (oleLoanDocument.getErrorMessage() != null) {
627                             oleLoanForm.setSuccess(true);
628                             oleLoanForm.setMessage(null);
629                             oleLoanForm.setReturnSuccess(false);
630                             oleLoanForm.setReturnMessage(oleLoanDocument.getErrorMessage());
631                             return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
632                         }
633                         if (oleLoanDocument.isClaimsReturnedIndicator()) {
634                             oleLoanForm.setSuccess(true);
635                             oleLoanForm.setMessage(null);
636                             oleLoanForm.setClaimsReturned(true);
637                             oleLoanForm.setReturnSuccess(false);
638                             oleLoanForm.setReturnMessage(LoanUtil.getLoanUtil().getProperty("CLAIMS_RETURNED_MESSAGE"));
639                             return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
640                         }
641                         if (oleLoanDocument.isCopyRequest()) {
642                             oleLoanForm.setSuccess(true);
643                             oleLoanForm.setMessage(null);
644                             oleLoanForm.setCopyRequest(true);
645                             oleLoanForm.setReturnSuccess(false);
646                             oleLoanForm.setReturnMessage(OLEConstants.COPY_REQUEST_FULFILL);
647                             return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
648                         }
649                         if (oleLoanDocument.isNumberOfPieces()) {
650                             oleLoanForm.setSuccess(true);
651                             oleLoanForm.setMessage(null);
652                             oleLoanForm.setNumberOfPieces(true);
653                             oleLoanForm.setReturnSuccess(false);
654                             oleLoanForm.setReturnMessage(OLEConstants.VERIFY_PIECES + oleLoanDocument.getItemNumberOfPieces() + OLEConstants.PIECES_RETURNED);
655                             return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
656                         }
657                         OleLoanForm oleReturnLoanForm = (OleLoanForm) oleLoanForm;
658 
659                         if (oleReturnLoanForm.getDummyLoan() != null) {
660                             oleLoanDocument.setItemLoanStatus(oleReturnLoanForm.getDummyLoan().getItemStatus());
661                             oleLoanForm.getDummyLoan().setItemLoanStatus(oleReturnLoanForm.getDummyLoan().getItemStatus());
662                         }
663 
664 
665                     } else if (oleLoanForm.getBackUpDummyLoan() != null) {
666                         oleLoanDocument = oleLoanForm.getBackUpDummyLoan();
667                         oleLoanDocument.setItemLoanStatus(oleLoanForm.getDummyLoan().getItemStatus());
668                         oleLoanForm.setBackUpDummyLoan(null);
669                     }
670                     boolean indefinite = false;
671                     if (oleLoanForm.getItem() != null && !oleLoanForm.getItem().isEmpty() && oleLoanForm.getDueDateMap() == null && oleLoanDocument.getExpirationDate() == null) {
672                         indefinite = true;
673                     }
674                     if ((oleLoanForm.getItem() != null && !oleLoanForm.getItem().isEmpty()) || (oleLoanForm.getOleItem() != null && !oleLoanForm.getOleItem().getItemIdentifier().isEmpty()) || indefinite) {
675                         if (oleLoanForm.getDueDateMap() != null) {
676                             Timestamp timestamp;
677                             Pattern pattern;
678                             Matcher matcher;
679                             SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OlePatron.PATRON_MAINTENANCE_DATE_FORMAT);
680                             boolean timeFlag = false;
681                             if (oleLoanForm.getPopDateTime() != null && !oleLoanForm.getPopDateTime().isEmpty()) {
682                                 String[] str = oleLoanForm.getPopDateTime().split(":");
683                                 pattern = Pattern.compile(OLEConstants.TIME_24_HR_PATTERN);
684                                 matcher = pattern.matcher(oleLoanForm.getPopDateTime());
685                                 timeFlag = matcher.matches();
686                                 if (timeFlag) {
687                                     if (str != null && str.length <= 2) {
688                                         oleLoanForm.setPopDateTime(oleLoanForm.getPopDateTime() + OLEConstants.CHECK_IN_TIME_MS);
689                                     }
690                                     timestamp = Timestamp.valueOf(new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT).format(oleLoanForm.getDueDateMap()).concat(" ").concat(oleLoanForm.getPopDateTime()));
691                                 } else {
692                                     oleLoanForm.setPopDateTimeInfo(OLEConstants.DUE_DATE_TIME_FORMAT_MESSAGE);
693                                      /*return getUIFModelAndView(oleLoanForm,"PatronItemViewPage");*/
694                                     return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
695                                 }
696                             } else if (fmt.format(oleLoanForm.getDueDateMap()).compareTo(fmt.format(new Date())) == 0) {
697                                 timestamp = new Timestamp(new Date().getTime());
698                             } else {
699                                 timestamp = Timestamp.valueOf(new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT).format(oleLoanForm.getDueDateMap()).concat(" ").concat(new SimpleDateFormat("HH:mm:ss").format(new Date())));
700                             }
701                             oleLoanDocument.setLoanDueDate(timestamp);
702                         }
703                         if (oleLoanDocument.getItemLoanStatus() != null && !oleLoanDocument.getItemLoanStatus().equalsIgnoreCase(OLEConstants.ITEM_STATUS_CHECKEDOUT)) {
704                             getLoanProcessor().saveLoan(oleLoanForm.getBackUpDummyLoan() != null ? oleLoanForm.getBackUpDummyLoan() : oleLoanDocument);
705                             if (!oleLoanForm.isCheckOut())
706                                 existingItemList.add(oleLoanDocument);
707                         }
708 
709                         if (oleLoanForm.getLoanList() != null && !oleLoanForm.getLoanList().isEmpty()) {
710                             existingItemList.addAll(oleLoanForm.getLoanList());
711                         }
712                         oleLoanForm.setLoanList(existingItemList);
713                     }
714                     if (oleLoanForm.getPatronName() == null) {
715                         oleLoanForm.setPatronName(oleLoanDocument.getPatronName());
716                     }
717                     if (oleLoanForm.isCheckOut()) {
718                         if (!oleLoanDocument.getItemLoanStatus().equalsIgnoreCase(OLEConstants.ITEM_STATUS_CHECKEDOUT))
719                             getLoanProcessor().saveLoan(oleLoanForm.getBackUpDummyLoan() != null ? oleLoanForm.getBackUpDummyLoan() : oleLoanDocument);
720                         List<OleLoanDocument> oleLoanDocuments = new ArrayList<OleLoanDocument>();
721                         if (oleLoanDocument.getOleItem().getItemStatus() != null) {
722                             oleLoanDocument.setItemStatusCode(oleLoanDocument.getOleItem().getItemStatus().getCodeValue());
723                         } else {
724                             oleLoanDocument.setItemStatusCode(oleLoanDocument.getItemLoanStatus());
725                         }
726                         OleItemAvailableStatus oleItemAvailableStatus = loanProcessor.validateAndGetItemStatus(oleLoanDocument.getItemStatusCode());
727                         oleLoanDocument.setItemStatus(oleItemAvailableStatus != null ? oleItemAvailableStatus.getItemAvailableStatusName() : null);
728                         oleLoanDocument.setDescription(oleLoanForm.getDescription());
729                         oleLoanDocuments.add(oleLoanDocument);
730                         if (oleLoanForm.getItemReturnList() != null) {
731                             oleLoanDocuments.addAll(oleLoanForm.getItemReturnList());
732                         }
733                         oleLoanForm.setItemReturnList(oleLoanDocuments);
734                         if (oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isPrintSlip()) {
735                             if (oleLoanDocument.getOleItem().getItemStatus().equals(OLEConstants.ITEM_STATUS_RETURNED_MISSING)) {
736                                 OleNoticeBo oleNoticeBo = loanProcessor.getNotice(oleLoanDocument);
737                                 if (oleNoticeBo != null) {
738                                     String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
739                                     if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
740                                         fromAddress = OLEConstants.KUALI_MAIL;
741                                     }
742                                     String missingNoticeDetails = oleDeliverBatchService.sendMissingNotice(oleNoticeBo);
743                                     OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
744                                     oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
745                                     LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
746                                 }
747                             } else {
748                                 oleLoanForm.setBillAvailability(true);
749                             }
750                         }
751                         if (oleLoanDocument.isCheckOut()) {
752                             oleLoanForm.setDueDateSlip(true);
753                             oleLoanForm.setBillAvailability(false);
754                         }
755                         oleLoanForm.setReturnSuccess(true);
756                         oleLoanForm.setCheckOut(false);
757                     }
758                     oleLoanForm.setSuccess(true);
759                     oleLoanForm.setMessage(null);
760                     oleLoanForm.setItem("");
761                     oleLoanForm.setInformation("");
762                     oleLoanForm.setPopDateTimeInfo("");
763                     oleLoanForm.setAddressVerified(false);
764                 }
765             } catch (Exception e) {
766                 oleLoanForm.setInformation(e.getMessage());
767                 LOG.error(e, e);
768             }
769         }
770         if (StringUtils.isNotEmpty(newPrincipalId)) {
771             if (loanProcessor.isValidCirculationDesk()) {
772                 if(loanProcessor.getCircDeskId()!=null){
773                         oleLoanForm.setCirculationDesk(loanProcessor.getCircDeskId());
774                 }
775             }
776         }
777 
778         oleLoanForm.setOleFormKey(oleLoanForm.getFormKey());
779         String audioOption = getLoanProcessor().getParameter(OLEConstants.AUDIO_OPTION);
780         oleLoanForm.setAudioEnable(audioOption != null && !audioOption.isEmpty() && audioOption.equalsIgnoreCase(OLEConstants.TRUE));
781         oleLoanForm.setItemUuid(null);
782         oleLoanForm.setInstanceUuid(null);
783        /* return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");*/
784         return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
785     }
786 
787     /**
788      * This method doesn't allow a patron to be loaned.
789      *
790      * @param form
791      * @param result
792      * @param request
793      * @param response
794      * @return ModelAndView
795      */
796     @RequestMapping(params = "methodToCall=noLoan")
797     public ModelAndView doNotLoanPatron(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
798                                         HttpServletRequest request, HttpServletResponse response) {
799         LOG.debug("Inside the do not loan patron method");
800         OleLoanForm oleLoanForm = (OleLoanForm) form;
801         String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
802         LOG.info("session timeout" + maxSessionTime);
803         if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
804             oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));
805         OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
806         if (oleLoanForm.isCheckOut()) {
807             List<OleLoanDocument> oleLoanDocuments = new ArrayList<OleLoanDocument>();
808             if (oleLoanDocument.getOleItem().getItemStatus() != null) {
809                 oleLoanDocument.setItemStatusCode(oleLoanDocument.getOleItem().getItemStatus().getCodeValue());
810             } else {
811                 oleLoanDocument.setItemStatusCode(oleLoanDocument.getItemLoanStatus());
812             }
813             OleItemAvailableStatus oleItemAvailableStatus = loanProcessor.validateAndGetItemStatus(oleLoanDocument.getItemStatusCode());
814             oleLoanDocument.setItemStatus(oleItemAvailableStatus != null ? oleItemAvailableStatus.getItemAvailableStatusName() : null);
815             oleLoanDocuments.add(oleLoanDocument);
816             if (oleLoanForm.getItemReturnList() != null) {
817                 oleLoanDocuments.addAll(oleLoanForm.getItemReturnList());
818             }
819             if (oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isPrintSlip()) {
820                 if (oleLoanDocument.getOleItem().getItemStatus().equals(OLEConstants.ITEM_STATUS_RETURNED_MISSING)) {
821                     OleNoticeBo oleNoticeBo = loanProcessor.getNotice(oleLoanDocument);
822                     if (oleNoticeBo != null) {
823                         String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
824                         if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
825                             fromAddress = OLEConstants.KUALI_MAIL;
826                         }
827                         String missingNoticeDetails = oleDeliverBatchService.sendMissingNotice(oleNoticeBo);
828                         OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
829                         oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
830                         LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
831                     }
832                 } else {
833                     oleLoanForm.setBillAvailability(true);
834                 }
835             }
836             oleLoanForm.setItemReturnList(oleLoanDocuments);
837             oleLoanForm.setReturnSuccess(true);
838             oleLoanForm.setCheckOut(false);
839             String audioOption = getLoanProcessor().getParameter(OLEConstants.AUDIO_OPTION);
840             oleLoanForm.setAudioEnable(audioOption != null && !audioOption.isEmpty() && audioOption.equalsIgnoreCase(OLEConstants.TRUE));
841         }
842         /*if(oleLoanForm.getPatronName()==null){
843             oleLoanForm.setPatronName(oleLoanDocument.getPatronName());
844         }*/
845         if (oleLoanForm.getItem() == null || "".equals(oleLoanForm.getItem())) {
846             clearPatronScreen(oleLoanForm, result, request, response);
847         }
848         oleLoanForm.setAddressVerified(false);
849         oleLoanForm.setItem("");
850         oleLoanForm.setInformation("");
851         oleLoanForm.setReturnInformation("");
852         oleLoanForm.setDueDateSlip(false);
853         oleLoanForm.setMessage(null);
854         oleLoanForm.setSuccess(true);
855         /*return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");*/
856         oleLoanForm.setItemUuid(null);
857         oleLoanForm.setInstanceUuid(null);
858         return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
859     }
860 
861     /**
862      * Display the Fast-Add item dialog.
863      *
864      * @param form
865      * @param result
866      * @param request
867      * @param response
868      * @return
869      */
870     @RequestMapping(params = "methodToCall=openFastAdd")
871     public ModelAndView openFastAdd(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
872                                     HttpServletRequest request, HttpServletResponse response) {
873         LOG.debug("Inside the openFastAdd method");
874         OleLoanForm oleLoanForm = (OleLoanForm) form;
875 
876         String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
877         LOG.info("session timeout" + maxSessionTime);
878         if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
879             oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));
880 
881         oleLoanForm.setFastAddItemIndicator(true);
882         String url = ConfigContext.getCurrentContextConfig().getProperty("ole.rice2.url.base") + "/ole-kr-krad/fastAddController?viewId=FastAddItemView&methodToCall=start";
883         oleLoanForm.setFastAddUrl(url);
884         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
885     }
886 
887 
888     /**
889      * Delete the patron user note.
890      *
891      * @param form
892      * @param result
893      * @param request
894      * @param response
895      * @return
896      */
897     @RequestMapping(params = "methodToCall=deletePatronUserNote")
898     public ModelAndView deletePatronUserNote(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
899                                              HttpServletRequest request, HttpServletResponse response) {
900         LOG.debug("Inside the delete patron user note method");
901         OleLoanForm oleLoanForm = (OleLoanForm) form;
902         String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
903         LOG.info("session timeout" + maxSessionTime);
904         if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
905             oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));
906         oleLoanForm.setPatronNoteFlag(false);
907 
908         try {
909             getLoanProcessor().deletePatronUserNote(oleLoanForm.getPatronId(), oleLoanForm.getPatronNoteTypeId());
910         } catch (Exception e) {
911             oleLoanForm.setInformation(e.getMessage());
912             LOG.error(e, e);
913         }
914         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
915     }
916 
917     /**
918      * Display the Alter due date dialog.
919      *
920      * @param form
921      * @param result
922      * @param request
923      * @param response
924      * @return
925      */
926     @RequestMapping(params = "methodToCall=editDueDate")
927     public ModelAndView editDueDate(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
928                                     HttpServletRequest request, HttpServletResponse response) {
929         LOG.debug("Inside the edit due date method");
930         if (loginUserList == null) {
931             loginUserList = new ArrayList<>();
932         }
933         StringBuffer buffer = new StringBuffer();
934         OleLoanForm oleLoanForm = (OleLoanForm) form;
935         String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
936         LOG.info("session timeout" + maxSessionTime);
937         if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
938             oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));
939         oleLoanForm.setInformation("");
940         oleLoanForm.setReturnInformation("");
941         List<OleLoanDocument> alterDueDateList = new ArrayList<OleLoanDocument>();
942         alterDueDateList = getLoanProcessor().setListValues(oleLoanForm.getLoanList(), oleLoanForm.getExistingLoanList(), false, null);
943 
944         if (alterDueDateList.size() != 0) {
945             oleLoanForm.setAlterDueDateList(alterDueDateList);
946             oleLoanForm.setInformation("");
947             if (!oleLoanForm.getLoanLoginName().equalsIgnoreCase("") || !oleLoanForm.getLoanLoginName().isEmpty()) {
948                 buffer.append(oleLoanForm.getLoanLoginName() + "," + oleLoanForm.getCirculationDesk());
949                 loanProcessor.getLoanUserList(loginUserList, buffer);
950             } else {
951                 if (!oleLoanForm.getOldPrincipalId().equalsIgnoreCase("") || !oleLoanForm.getOldPrincipalId().isEmpty()) {
952                     buffer.append(oleLoanForm.getOldPrincipalId() + "," + oleLoanForm.getCirculationDesk());
953                     loanProcessor.getLoanUserList(loginUserList, buffer);
954                 }
955             }
956             ModelAndView overrideModelView = this.overRide(form, result, request, response);
957             if (loanProcessor.isValidCirculationDesk()) {
958                 // if(loanProcessor.getCircDeskId()!=null){
959                 //oleLoanForm.setCirculationDesk(loanProcessor.getCircDeskId());
960                 // }
961             }
962             if (overrideModelView == null)
963                 oleLoanForm.setAlterDueDateFlag(true);
964         } else
965             oleLoanForm.setInformation(OLEConstants.ALTER_DUE_DATE_ERR_INFO);
966 
967         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
968     }
969 
970     /**
971      * Update the modified due date in loan.
972      *
973      * @param form
974      * @param result
975      * @param request
976      * @param response
977      * @return
978      */
979     @RequestMapping(params = "methodToCall=updateDueDate")
980     public ModelAndView updateDueDate(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
981                                       HttpServletRequest request, HttpServletResponse response) {
982         LOG.debug("Inside the update due date method");
983         OleLoanForm oleLoanForm = (OleLoanForm) form;
984         String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
985         LOG.info("session timeout" + maxSessionTime);
986         if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
987             oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));
988         oleLoanForm.setInformation("");
989         oleLoanForm.setReturnInformation("");
990         boolean timeFlag = true;
991         try {
992             oleLoanForm.setAlterDueDateTimeInfo("");
993             timeFlag = getLoanProcessor().updateLoan(oleLoanForm.getAlterDueDateList());
994             if (!timeFlag) {
995                 oleLoanForm.setAlterDueDateTimeInfo(OLEConstants.ALTER_DUE_DATE_TIME_FORMAT_MESSAGE);
996                 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
997             }
998             getLoanProcessor().updateItem(oleLoanForm.getAlterDueDateList(),false);
999         } catch (Exception e) {
1000             oleLoanForm.setInformation(e.getMessage());
1001             LOG.error(e, e);
1002         }
1003         oleLoanForm.setAlterDueDateFlag(false);
1004         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1005     }
1006 
1007     /**
1008      * Close the Alter due date dialog.
1009      *
1010      * @param form
1011      * @param result
1012      * @param request
1013      * @param response
1014      * @return
1015      */
1016     @RequestMapping(params = "methodToCall=closeAlterDueDate")
1017     public ModelAndView closeAlterDueDate(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1018                                           HttpServletRequest request, HttpServletResponse response) {
1019         LOG.debug("Inside the close Alter due date method");
1020         OleLoanForm oleLoanForm = (OleLoanForm) form;
1021         String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
1022         LOG.info("session timeout" + maxSessionTime);
1023         if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
1024             oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));
1025         List<OleLoanDocument> resetAlterDueDate = oleLoanForm.getAlterDueDateList();
1026         if (resetAlterDueDate != null) {
1027             for (int restDueDate = 0; restDueDate < resetAlterDueDate.size(); restDueDate++) {
1028                 OleLoanDocument oleLoanDocument = (OleLoanDocument) resetAlterDueDate.get(restDueDate);
1029                 oleLoanDocument.setLoanDueDate(new Timestamp(oleLoanDocument.getPastDueDate().getTime()));
1030                 oleLoanDocument.setPastDueDate(null);
1031             }
1032         }
1033 
1034         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1035     }
1036 
1037     /**
1038      * Display the claims return dialog.
1039      *
1040      * @param form
1041      * @param result
1042      * @param request
1043      * @param response
1044      * @return
1045      */
1046     @RequestMapping(params = "methodToCall=claimsReturn")
1047     public ModelAndView claimsReturn(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1048                                      HttpServletRequest request, HttpServletResponse response) {
1049         LOG.debug("Inside the claims return method");
1050         if (loginUserList == null) {
1051             loginUserList = new ArrayList<>();
1052         }
1053         StringBuffer buffer = new StringBuffer();
1054         OleLoanForm oleLoanForm = (OleLoanForm) form;
1055         String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
1056         LOG.info("session timeout" + maxSessionTime);
1057         if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
1058             oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));
1059         oleLoanForm.setInformation("");
1060         oleLoanForm.setReturnInformation("");
1061         boolean checkedItemsFlag = false;
1062         if (oleLoanForm.getLoanList().size() > 0) {
1063             for (int curremtLoan = 0; curremtLoan < oleLoanForm.getLoanList().size(); curremtLoan++) {
1064                 OleLoanDocument oleLoanDocument = (OleLoanDocument) oleLoanForm.getLoanList().get(curremtLoan);
1065                 if (oleLoanDocument.isCheckNo()) {
1066                     checkedItemsFlag = true;
1067                     break;
1068                 }
1069             }
1070         }
1071         if (oleLoanForm.getExistingLoanList().size() > 0) {
1072             for (int curremtLoan = 0; curremtLoan < oleLoanForm.getExistingLoanList().size(); curremtLoan++) {
1073                 OleLoanDocument oleLoanDocument = (OleLoanDocument) oleLoanForm.getExistingLoanList().get(curremtLoan);
1074                 if (oleLoanDocument.isCheckNo()) {
1075                     checkedItemsFlag = true;
1076                     break;
1077                 }
1078             }
1079         }
1080         if (checkedItemsFlag) {
1081             oleLoanForm.setInformation("");
1082             if (!oleLoanForm.getLoanLoginName().equalsIgnoreCase("") || !oleLoanForm.getLoanLoginName().isEmpty()) {
1083                 buffer.append(oleLoanForm.getLoanLoginName() + "," + oleLoanForm.getCirculationDesk());
1084                 loanProcessor.getLoanUserList(loginUserList, buffer);
1085             } else {
1086                 if (!oleLoanForm.getOldPrincipalId().equalsIgnoreCase("") || !oleLoanForm.getOldPrincipalId().isEmpty()) {
1087                     buffer.append(oleLoanForm.getOldPrincipalId() + "," + oleLoanForm.getCirculationDesk());
1088                     loanProcessor.getLoanUserList(loginUserList, buffer);
1089                 }
1090             }
1091             ModelAndView overrideModelView = this.overRide(form, result, request, response);
1092             if (loanProcessor.isValidCirculationDesk()) {
1093                 // if(loanProcessor.getCircDeskId()!=null){
1094                 // oleLoanForm.setCirculationDesk(loanProcessor.getCircDeskId());
1095                 //  }
1096             }
1097             if (overrideModelView == null)
1098                 oleLoanForm.setClaimsReturnFlag(true);
1099         } else
1100             oleLoanForm.setInformation(OLEConstants.CLAIMS_ITM_ERR_INFO);
1101         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1102     }
1103 
1104     /**
1105      * Save the claims return note in loan.
1106      *
1107      * @param form
1108      * @param result
1109      * @param request
1110      * @param response
1111      * @return
1112      */
1113     @RequestMapping(params = "methodToCall=applyClaimsReturn")
1114     public ModelAndView applyClaimsReturn(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1115                                           HttpServletRequest request, HttpServletResponse response) {
1116         LOG.debug("Inside the apply claims return method");
1117         OleLoanForm oleLoanForm = (OleLoanForm) form;
1118         String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
1119         LOG.info("session timeout" + maxSessionTime);
1120         if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
1121             oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));
1122         oleLoanForm.setInformation("");
1123         oleLoanForm.setReturnInformation("");
1124         List<OleLoanDocument> claimsList = new ArrayList<OleLoanDocument>();
1125         LoanProcessor loanProcessor = getLoanProcessor();
1126         claimsList = loanProcessor.setListValues(oleLoanForm.getLoanList(), oleLoanForm.getExistingLoanList(), oleLoanForm.isClaimsReturnFlag(), oleLoanForm.getClaimsReturnNote());
1127         try {
1128             loanProcessor.updateLoan(claimsList);
1129             loanProcessor.updateItem(claimsList,true);
1130         } catch (Exception e) {
1131             LOG.error(e, e);
1132             oleLoanForm.setInformation(e.getMessage());
1133         }
1134         oleLoanForm.setClaimsReturnFlag(false);
1135         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1136     }
1137 
1138     /**
1139      * Change the circulation desk location and clear the screen.
1140      *
1141      * @param form
1142      * @param result
1143      * @param request
1144      * @param response
1145      * @return
1146      */
1147     @RequestMapping(params = "methodToCall=changeCirculationDeskLocation")
1148     public ModelAndView changeCirculationDeskLocation(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1149                                                       HttpServletRequest request, HttpServletResponse response) {
1150         LOG.debug("Inside the change circulation desk location method");
1151         OleLoanForm oleLoanForm = (OleLoanForm) form;
1152         oleLoanForm.setConfirmMessage(OLEConstants.CHANGE_LOC_MESS);
1153         oleLoanForm.setChangeLocationFlag(true);
1154 
1155         String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
1156         LOG.info("session timeout" + maxSessionTime);
1157         if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
1158             oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));
1159 
1160         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1161     }
1162 
1163     @RequestMapping(params = "methodToCall=changeReturnCirculationDeskLocation")
1164     public ModelAndView changeReturnCirculationDeskLocation(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1165                                                             HttpServletRequest request, HttpServletResponse response) {
1166         LOG.debug("Inside the change circulation desk location method");
1167         OleLoanForm oleLoanForm = (OleLoanForm) form;
1168         oleLoanForm.setConfirmMessage(OLEConstants.CHANGE_LOC_MESS);
1169         oleLoanForm.setChangeLocationFlag(true);
1170         return getUIFModelAndView(oleLoanForm, "ReturnItemViewPage");
1171     }
1172 
1173     /**
1174      * Reset the old circulation location in loan.
1175      *
1176      * @param form
1177      * @param result
1178      * @param request
1179      * @param response
1180      * @return
1181      */
1182     @RequestMapping(params = "methodToCall=resetLocation")
1183     public ModelAndView resetLocation(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1184                                       HttpServletRequest request, HttpServletResponse response) {
1185         LOG.debug("Inside the reset location method");
1186         OleLoanForm oleLoanForm = (OleLoanForm) form;
1187         oleLoanForm.setCirculationDesk(oleLoanForm.getPreviousCirculationDesk());
1188         oleLoanForm.setChangeLocationFlag(false);
1189         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1190     }
1191 
1192     @RequestMapping(params = "methodToCall=resetReturnLocation")
1193     public ModelAndView resetReturnLocation(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1194                                             HttpServletRequest request, HttpServletResponse response) {
1195         LOG.debug("Inside the reset location method");
1196         OleLoanForm oleLoanForm = (OleLoanForm) form;
1197         oleLoanForm.setCirculationDesk(oleLoanForm.getPreviousCirculationDesk());
1198         oleLoanForm.setChangeLocationFlag(false);
1199         return getUIFModelAndView(oleLoanForm, "ReturnItemViewPage");
1200     }
1201 
1202     /**
1203      * This method clear UI for next borrower session..
1204      *
1205      * @param form
1206      * @param result
1207      * @param request
1208      * @param response
1209      * @return ModelAndView
1210      */
1211     @RequestMapping(params = "methodToCall=saveAndClear")
1212     public ModelAndView clearPatron(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1213                                     HttpServletRequest request, HttpServletResponse response) {
1214         LOG.debug("Inside the clear patron method");
1215         fastAddBarcode = "";
1216         OleLoanForm oleLoanForm = (OleLoanForm) form;
1217         String currentLocation = oleLoanForm.getCirculationDesk();
1218         oleLoanForm.setPreviousCirculationDesk(currentLocation);
1219        /* if(oleLoanForm.getLoanList() != null && oleLoanForm.getLoanList().size()>0 && !oleLoanForm.isChangeLocationFlag() && getLoanProcessor().getParameter(OLEConstants.PRINT_DUE_DATE_PER_TRANSACTION).equalsIgnoreCase("No")){
1220             oleLoanForm.setDueDateSlip(true);
1221             printDueDateSlipList = oleLoanForm.getLoanList();
1222         }*/
1223         oleLoanForm.setNewPrincipalId("");
1224         oleLoanForm.setAddressVerified(false);
1225         oleLoanForm.setInformation("");
1226         oleLoanForm.setReturnInformation("");
1227         oleLoanForm.setBorrowerType(null);
1228         oleLoanForm.setPatronBarcode(null);
1229         oleLoanForm.setPatronName(null);
1230         oleLoanForm.setProxyPatronId(null);
1231         oleLoanForm.setRealPatronBarcode(null);
1232         oleLoanForm.setPatronId(null);
1233         oleLoanForm.setRealPatronList(null);
1234         oleLoanForm.setLoanList(null);
1235         oleLoanForm.setDueDateMap(null);
1236         oleLoanForm.setExistingLoanList(null);
1237         oleLoanForm.setDueDateMap(null);
1238         oleLoanForm.setMessage(null);
1239         oleLoanForm.setSuccess(true);
1240         oleLoanForm.setChangeLocationFlag(false);
1241         oleLoanForm.setBlockLoan(false);
1242         oleLoanForm.setItemFocus(false);
1243         oleLoanForm.setSelfCheckOut(false);
1244         // oleLoanForm.setItemStatusLost(false);
1245         oleLoanForm.setCurrentPatronList(null);
1246         oleLoanForm.setPatronFocus(true);
1247         oleLoanForm.setBackGroundCheckIn(false);
1248         GlobalVariables.getUserSession().clearBackdoorUser();
1249         GlobalVariables.getUserSession().setBackdoorUser(oleLoanForm.getOldPrincipalId());
1250         oleLoanForm.setNewPrincipalId(null);
1251 
1252         if (!oleLoanForm.isClearUI()) {
1253             String principalId = GlobalVariables.getUserSession().getPrincipalId();
1254             OleCirculationDeskDetail oleCirculationDeskDetail = getLoanProcessor().getDefaultCirculationDesk(principalId);
1255             if (oleCirculationDeskDetail != null) {
1256                 oleLoanForm.setCirculationDesk(oleCirculationDeskDetail.getCirculationDeskId());
1257                 oleLoanForm.setPreviousCirculationDesk(oleLoanForm.getCirculationDesk());
1258             }
1259         }
1260         //return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");\
1261         return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
1262 
1263     }
1264 
1265     /**
1266      * This method clear UI for next borrower.
1267      *
1268      * @param form
1269      * @param result
1270      * @param request
1271      * @param response
1272      * @return ModelAndView
1273      */
1274     @RequestMapping(params = "methodToCall=clearPatron")
1275     public ModelAndView clearPatronScreen(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1276                                           HttpServletRequest request, HttpServletResponse response) {
1277         LOG.debug("Inside the clear patron Screen method");
1278         fastAddBarcode = "";
1279         OleLoanForm oleLoanForm = (OleLoanForm) form;
1280         String currentLocation = oleLoanForm.getCirculationDesk();
1281         oleLoanForm.setPreviousCirculationDesk(currentLocation);
1282         if (oleLoanForm.getLoanList() != null && oleLoanForm.getLoanList().size() > 0 && !oleLoanForm.isChangeLocationFlag() && getLoanProcessor().getParameter(OLEConstants.PRINT_DUE_DATE_PER_TRANSACTION).equalsIgnoreCase("No")) {
1283             oleLoanForm.setDueDateSlip(true);
1284             printDueDateSlipList = oleLoanForm.getLoanList();
1285         }
1286         //oleLoanForm.setNewPrincipalId("");
1287         oleLoanForm.setAddressVerified(false);
1288         oleLoanForm.setInformation("");
1289         oleLoanForm.setReturnInformation("");
1290         oleLoanForm.setBorrowerType(null);
1291         oleLoanForm.setPatronBarcode(null);
1292         oleLoanForm.setPatronName(null);
1293         oleLoanForm.setProxyPatronId(null);
1294         oleLoanForm.setRealPatronBarcode(null);
1295         oleLoanForm.setPatronId(null);
1296         oleLoanForm.setRealPatronList(null);
1297         oleLoanForm.setLoanList(null);
1298         oleLoanForm.setDueDateMap(null);
1299         oleLoanForm.setExistingLoanList(null);
1300         oleLoanForm.setDueDateMap(null);
1301         oleLoanForm.setMessage(null);
1302         oleLoanForm.setSuccess(true);
1303         oleLoanForm.setChangeLocationFlag(false);
1304         //oleLoanForm.setItemStatusLost(false);
1305         oleLoanForm.setBlockLoan(false);
1306         oleLoanForm.setItemFocus(false);
1307         oleLoanForm.setSelfCheckOut(false);
1308         oleLoanForm.setCurrentPatronList(null);
1309         oleLoanForm.setPatronFocus(true);
1310         oleLoanForm.setBackGroundCheckIn(false);
1311         //GlobalVariables.getUserSession().clearBackdoorUser();
1312         //GlobalVariables.getUserSession().setBackdoorUser( oleLoanForm.getOldPrincipalId() );
1313         //oleLoanForm.setNewPrincipalId(null);
1314         //return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");\
1315         return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
1316 
1317     }
1318 
1319     /**
1320      * This method override permission..
1321      *
1322      * @param form
1323      * @param result
1324      * @param request
1325      * @param response
1326      * @return ModelAndView
1327      */
1328     @RequestMapping(params = "methodToCall=overRide")
1329     public ModelAndView overRide(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1330                                  HttpServletRequest request, HttpServletResponse response) {
1331         LOG.debug("Inside the override method");
1332         OleLoanForm oleLoanForm = (OleLoanForm) form;
1333         String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
1334         LOG.info("session timeout" + maxSessionTime);
1335         if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
1336             oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));
1337         oleLoanForm.setInformation("");
1338         oleLoanForm.setReturnInformation("");
1339         oleLoanForm.setOverideMethodCall(oleLoanForm.getMethodToCall());
1340         oleLoanForm.setOverrideFlag(true);
1341         String principalId = GlobalVariables.getUserSession().getPrincipalId();
1342         if (oleLoanForm.getNewPrincipalId() != null && !oleLoanForm.getNewPrincipalId().trim().isEmpty())
1343             principalId = oleLoanForm.getNewPrincipalId();
1344 
1345 
1346         Boolean overRideFlag = getLoanProcessor().checkOverRidePermission(principalId, oleLoanForm);
1347 
1348         if (overRideFlag) {
1349             if (!"".equals(oleLoanForm.getNewPrincipalId()) && oleLoanForm.getNewPrincipalId() != null) {
1350                 oleLoanForm.setLoanLoginName(oleLoanForm.getNewPrincipalId());
1351                 GlobalVariables.getUserSession().setBackdoorUser(oleLoanForm.getLoanLoginName());
1352             }
1353             oleLoanForm.setNewPrincipalId("");
1354             oleLoanForm.setOverrideFlag(false);
1355             oleLoanForm.setOverideMethodCall("");
1356 
1357             return null;
1358         }
1359         oleLoanForm.setNewPrincipalId(null);
1360         GlobalVariables.getUserSession().clearBackdoorUser();
1361         if (!"".equals(oleLoanForm.getNewPrincipalId()))
1362             oleLoanForm.setOverrideLoginMessage(principalId + " " + OLEConstants.OVERRIDE_LOGIN_ERR_INFO);
1363         /*return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");*/
1364         return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
1365     }
1366 
1367     /**
1368      * This method loanLogin permission..
1369      *
1370      * @param form
1371      * @param result
1372      * @param request
1373      * @param response
1374      * @return ModelAndView
1375      */
1376     @RequestMapping(params = "methodToCall=loanLogin")
1377     public ModelAndView loanLogin(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1378                                   HttpServletRequest request, HttpServletResponse response) {
1379         LOG.debug("Inside the loanLogin method");
1380         OleLoanForm oleLoanForm = (OleLoanForm) form;
1381         if (loginUserList == null) {
1382             loginUserList = new ArrayList<>();
1383         }
1384         oleLoanForm.setValidLogin(getLoanProcessor().isAuthorized(oleLoanForm.getLoanLoginName()));
1385         String patronNameURL = loanProcessor.patronNameURL(oleLoanForm.getLoanLoginName(), oleLoanForm.getPatronId());
1386         oleLoanForm.setPatronNameURL(patronNameURL);
1387         if (oleLoanForm.getLoanLoginName() != null && !oleLoanForm.getLoanLoginName().trim().isEmpty() && oleLoanForm.isValidLogin()) {
1388             oleLoanForm.setLoanLoginUserInfo("");
1389             oleLoanForm.setLoanLoginMessage(false);
1390             String loginUser = GlobalVariables.getUserSession().getPrincipalName();
1391             String circulationDesk = oleLoanForm.getCirculationDesk();
1392             GlobalVariables.getUserSession().setBackdoorUser(oleLoanForm.getLoanLoginName());
1393             start(form, result, request, response);
1394             if (loanProcessor.getCircDeskId() != null) {
1395                 oleLoanForm.setCirculationDesk(loanProcessor.getCircDeskId());
1396             }
1397             StringBuffer users = new StringBuffer();
1398             users.append(loginUser + "," + circulationDesk);
1399             loginUserList.add(users.toString());
1400         }
1401         return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
1402     }
1403 
1404     @RequestMapping(params = "methodToCall=loanLogout")
1405     public ModelAndView loanLogout(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1406                                    HttpServletRequest request, HttpServletResponse response) {
1407         LOG.debug("Inside the loanLogout method");
1408         int count;
1409         OleLoanForm oleLoanForm = (OleLoanForm) form;
1410         if (oleLoanForm.getOldPrincipalId() != null && !oleLoanForm.getOldPrincipalId().trim().isEmpty()) {
1411             oleLoanForm.setLoanLoginUserInfo("");
1412             oleLoanForm.setLoanLoginMessage(false);
1413             if (loginUserList == null) {
1414                 GlobalVariables.getUserSession().setBackdoorUser(null);
1415                 return cancel(form, result, request, response);
1416             }
1417             if (loginUserList.size() > 0) {
1418                 count = loginUserList.size() - 1;
1419                 String usersList = loginUserList.get(count);
1420                 loginUserList.remove(count);
1421                 String user = GlobalVariables.getUserSession().getPrincipalName();
1422                 String circulationId = oleLoanForm.getCirculationDesk();
1423                 StringBuffer currentUser = new StringBuffer();
1424                 currentUser.append(user + "," + circulationId);
1425                 if (usersList.equalsIgnoreCase(currentUser.toString())) {
1426                     if (loginUserList.size() > 0) {
1427                         int size = loginUserList.size() - 1;
1428                         usersList = loginUserList.get(size);
1429                         loginUserList.remove(size);
1430                     } else {
1431                         GlobalVariables.getUserSession().setBackdoorUser(null);
1432                         return cancel(form, result, request, response);
1433                     }
1434                 }
1435                 if (usersList == "" || usersList.isEmpty()) {
1436                     GlobalVariables.getUserSession().setBackdoorUser(null);
1437                     return cancel(form, result, request, response);
1438                 }
1439                 String[] usersAndCirculationId = usersList.split(",");
1440                 oleLoanForm.setLoginUser(usersAndCirculationId[0]);
1441                 String patronNameURL = loanProcessor.patronNameURL(oleLoanForm.getLoginUser(), oleLoanForm.getPatronId());
1442                 oleLoanForm.setPatronNameURL(patronNameURL);
1443                 if (oleLoanForm.getLoginUser().equalsIgnoreCase(OLEConstants.ADMIN_USER)) {
1444                     GlobalVariables.getUserSession().setBackdoorUser(null);
1445                     return cancel(form, result, request, response);
1446                 }
1447                 GlobalVariables.getUserSession().setBackdoorUser(oleLoanForm.getLoginUser());
1448                 start(form, result, request, response);
1449                 oleLoanForm.setCirculationDesk(usersAndCirculationId[1]);
1450             } else {
1451                 GlobalVariables.getUserSession().setBackdoorUser(null);
1452                 return cancel(form, result, request, response);
1453             }
1454         }
1455         return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
1456     }
1457 
1458     /**
1459      * This method no  override permission..
1460      *
1461      * @param form
1462      * @param result
1463      * @param request
1464      * @param response
1465      * @return ModelAndView
1466      */
1467     @RequestMapping(params = "methodToCall=noOverRide")
1468     public ModelAndView noOverRide(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1469                                    HttpServletRequest request, HttpServletResponse response) {
1470         LOG.debug("Inside the no override method");
1471         OleLoanForm oleLoanForm = (OleLoanForm) form;
1472         String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
1473         LOG.info("session timeout" + maxSessionTime);
1474         if (maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
1475             oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));
1476         oleLoanForm.setOverrideFlag(false);
1477         oleLoanForm.setOverideMethodCall("");
1478         oleLoanForm.setOverrideLoginMessage("");
1479         oleLoanForm.setInformation("");
1480         oleLoanForm.setReturnInformation("");
1481         oleLoanForm.setNewPrincipalId(null);
1482         /*return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");*/
1483         return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
1484     }
1485 
1486     /**
1487      * This method renewal the existing item
1488      *
1489      * @param form
1490      * @param result
1491      * @param request
1492      * @param response
1493      * @return ModelAndView
1494      */
1495     @RequestMapping(params = "methodToCall=renewalItem")
1496     public ModelAndView renewalItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1497                                     HttpServletRequest request, HttpServletResponse response) {
1498         LOG.debug("Inside the renewal item method");
1499         OleLoanForm oleLoanForm = (OleLoanForm) form;
1500         int renewCurrentCount = 0;
1501         oleLoanForm.setInformation("");
1502         oleLoanForm.setMessage("");
1503         oleLoanForm.setRenewalFlag(false);
1504         List<OleLoanDocument> existingItemList = new ArrayList<OleLoanDocument>();
1505         existingItemList.addAll(oleLoanForm.getExistingLoanList());
1506         if (oleLoanForm.getLoanList() != null && !oleLoanForm.getLoanList().isEmpty())
1507             existingItemList.addAll(oleLoanForm.getLoanList());
1508         OleLoanDocument oleLoanDocument = null;
1509         for (int i = 0; i < existingItemList.size(); i++) {
1510             OleLoanDocument loanDocument = existingItemList.get(i);
1511             if (loanDocument.getItemId().equals(oleLoanForm.getItem())) {
1512                 oleLoanDocument = loanDocument;
1513                 oleLoanDocument.setRenewalItemFlag(true);
1514                 oleLoanDocument.setErrorMessage(null);
1515                 renewCurrentCount = i;
1516                 break;
1517             }
1518         }
1519         if (!oleLoanForm.isOverrideRenewal()) {
1520             if (!getLoanProcessor().checkPendingRequestforItem(oleLoanDocument.getItemUuid())) {
1521 
1522                 try {
1523                     oleLoanDocument.setPatronId(oleLoanForm.getPatronId());
1524                     oleLoanDocument.setBorrowerTypeId(oleLoanForm.getBorrowerTypeId());
1525                     oleLoanDocument.setBorrowerTypeName(oleLoanForm.getBorrowerType());
1526                     oleLoanDocument.setBorrowerTypeCode(oleLoanForm.getBorrowerCode());
1527                     oleLoanDocument.setCirculationLocationId(oleLoanForm.getCirculationDesk());
1528                     oleLoanDocument = getLoanProcessor().addLoan(oleLoanDocument.getPatronBarcode(), oleLoanDocument.getItemId(), oleLoanDocument);
1529                     if (oleLoanDocument.getErrorMessage() == null) {
1530                         oleLoanForm.setRenewalFlag(false);
1531                         oleLoanForm.setOverrideRenewItemFlag(false);
1532                         oleLoanForm.setSuccess(true);
1533                         oleLoanForm.setMessage("");
1534                         oleLoanForm.getExistingLoanList().remove(renewCurrentCount);
1535                         oleLoanForm.setOleLoanDocumentToLoanList(oleLoanDocument);
1536                         oleLoanForm.setInformation(OLEConstants.RENEWAL_ITM_SUCCESS_INFO);
1537                     } else {
1538                         if (!oleLoanForm.isOverrideRenewal())
1539                             oleLoanForm.setOverrideRenewal(true);
1540                         oleLoanForm.setOverrideRenewItemFlag(true);
1541                         Timestamp currentDate = new Timestamp(System.currentTimeMillis());
1542                         if (currentDate.before(oleLoanDocument.getLoanDueDate()))
1543                             oleLoanForm.setRenewalFlag(true);
1544                         String errMsg = oleLoanDocument.getErrorMessage().substring(0, oleLoanDocument.getErrorMessage().lastIndexOf("(OR)"));
1545                         oleLoanForm.setMessage(errMsg);
1546                     }
1547 
1548                 } catch (Exception e) {
1549                     oleLoanForm.setInformation(e.getMessage());
1550                     LOG.error(e, e);
1551                 }
1552             } else {
1553                 oleLoanForm.setMessage(OLEConstants.PENDING_RQST_RENEWAL_ITM_INFO + "( Title: " + oleLoanDocument.getTitle() + " , Author: " + oleLoanDocument.getAuthor() + " , Item : " + oleLoanDocument.getItemId() + " )");
1554                 oleLoanForm.setOverrideRenewItemFlag(true);
1555                 oleLoanForm.setRenewalFlag(true);
1556             }
1557         } else {
1558             try {
1559                 ModelAndView overrideModelView = this.overRide(form, result, request, response);
1560                 Timestamp currentDate = new Timestamp(System.currentTimeMillis());
1561                 if (currentDate.after(oleLoanDocument.getLoanDueDate())) {
1562                     if (overrideModelView == null) {
1563                         getLoanProcessor().overrideSaveLoanForRenewal(oleLoanDocument);
1564                         oleLoanForm.getExistingLoanList().remove(renewCurrentCount);
1565                         oleLoanForm.setOleLoanDocumentToLoanList(oleLoanDocument);
1566                         oleLoanForm.setMessage("");
1567                         oleLoanForm.setSuccess(true);
1568                         oleLoanForm.setOverrideRenewal(false);
1569                         oleLoanForm.setRenewalFlag(false);
1570                         oleLoanForm.setOverrideRenewItemFlag(false);
1571                     }
1572                 } else
1573                     oleLoanForm.setMessage(OLEConstants.RENEWAL_ITM_AFTER_FIXED_DUEDATE);
1574             } catch (Exception e) {
1575                 LOG.error(e, e);
1576                 oleLoanForm.setInformation(e.getMessage());
1577             }
1578 
1579         }
1580 
1581         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1582     }
1583 
1584     /**
1585      * This method not renewal the existing item
1586      *
1587      * @param form
1588      * @param result
1589      * @param request
1590      * @param response
1591      * @return ModelAndView
1592      */
1593     @RequestMapping(params = "methodToCall=doNotRenewalItem")
1594     public ModelAndView doNotRenewalItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1595                                          HttpServletRequest request, HttpServletResponse response) {
1596         LOG.debug("Inside the do not renewal item method");
1597         OleLoanForm oleLoanForm = (OleLoanForm) form;
1598         oleLoanForm.setInformation("");
1599         oleLoanForm.setReturnInformation("");
1600         oleLoanForm.setRenewalFlag(false);
1601         oleLoanForm.setSuccess(true);
1602         oleLoanForm.setMessage("");
1603         oleLoanForm.setOverrideRenewal(false);
1604         oleLoanForm.setRenewDueDateFlag(false);
1605         oleLoanForm.setOverrideRenewItemFlag(false);
1606         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1607     }
1608 
1609     /**
1610      * This method renewal the list of existing items
1611      *
1612      * @param form
1613      * @param result
1614      * @param request
1615      * @param response
1616      * @return ModelAndView
1617      */
1618     @RequestMapping(params = "methodToCall=renewalItems")
1619     public ModelAndView renewalItems(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1620                                      HttpServletRequest request, HttpServletResponse response) {
1621         LOG.debug("Inside the renewal items method");
1622         OleLoanForm oleLoanForm = (OleLoanForm) form;
1623         oleLoanForm.setInformation("");
1624         oleLoanForm.setMessage("");
1625 
1626         List<OleLoanDocument> existingItemList = new ArrayList<OleLoanDocument>(0);
1627         List<OleLoanDocument> renewalItemList = new ArrayList<OleLoanDocument>(0);
1628         existingItemList.addAll(oleLoanForm.getExistingLoanList());
1629         boolean renewSelectFlag = true;
1630         for (int i = 0; i < existingItemList.size(); i++) {
1631             OleLoanDocument loanDocument = existingItemList.get(i);
1632             if (loanDocument.isCheckNo()) {
1633                 renewSelectFlag = false;
1634                 break;
1635             }
1636         }
1637         if (!renewSelectFlag) {
1638             String errMsg = "";
1639             boolean errFlag = false;
1640             for (int i = 0; i < existingItemList.size(); i++) {
1641                 OleLoanDocument loanDocument = existingItemList.get(i);
1642                 loanDocument.setErrorMessage(null);
1643                 if (loanDocument.isCheckNo()) {
1644                     renewSelectFlag = false;
1645                     loanDocument.setCheckNo(false);
1646 
1647                     try {
1648                         loanDocument.setPatronId(oleLoanForm.getPatronId());
1649                         loanDocument.setBorrowerTypeId(oleLoanForm.getBorrowerTypeId());
1650                         loanDocument.setBorrowerTypeName(oleLoanForm.getBorrowerType());
1651                         loanDocument.setBorrowerTypeCode(oleLoanForm.getBorrowerCode());
1652                         loanDocument.setRenewalItemFlag(true);
1653                         loanDocument = getLoanProcessor().addLoan(loanDocument.getPatronBarcode(), loanDocument.getItemId(), loanDocument);
1654                         if (getLoanProcessor().checkPendingRequestforItem(loanDocument.getItemUuid())) {
1655                             errFlag = true;
1656                             loanDocument.setErrorMessage(OLEConstants.PENDING_RQST_RENEWAL_ITM_INFO);
1657                             oleLoanForm.setRenewDueDateFlag(true);
1658                             renewalItemList.add(loanDocument);
1659                             oleLoanForm.setRenewDueDateList(renewalItemList);
1660                         } else if (loanDocument.getErrorMessage() == null) {
1661                             errMsg = errMsg + (i + 1) + ". " + OLEConstants.RENEWAL_ITM_SUCCESS_INFO + "  (" + loanDocument.getItemId() + ")<br/>";
1662                             oleLoanForm.getExistingLoanList().remove(i);
1663                             oleLoanForm.setOleLoanDocumentToLoanList(loanDocument);
1664                         } else {
1665                             errFlag = true;
1666                             loanDocument.setErrorMessage(loanDocument.getErrorMessage().substring(0, loanDocument.getErrorMessage().lastIndexOf("(OR)")));
1667                             oleLoanForm.setRenewDueDateFlag(true);
1668                             renewalItemList.add(loanDocument);
1669                             oleLoanForm.setRenewDueDateList(renewalItemList);
1670                         }
1671                     } catch (Exception e) {
1672                         LOG.error(e, e);
1673                     }
1674 
1675                 }
1676             }
1677             if (!errFlag)
1678                 oleLoanForm.setInformation(errMsg);
1679         }
1680         if (renewSelectFlag)
1681             oleLoanForm.setInformation(OLEConstants.RENEWAL_ITM_ERR_INFO);
1682         //}
1683         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1684     }
1685 
1686 
1687     /**
1688      * This method renewal the list of existing items  by using override
1689      *
1690      * @param form
1691      * @param result
1692      * @param request
1693      * @param response
1694      * @return ModelAndView
1695      */
1696     @RequestMapping(params = "methodToCall=overrideRenewItems")
1697     public ModelAndView overrideRenewItems(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1698                                            HttpServletRequest request, HttpServletResponse response) {
1699         LOG.debug("Inside the renewal items method");
1700         OleLoanForm oleLoanForm = (OleLoanForm) form;
1701         oleLoanForm.setInformation("");
1702         oleLoanForm.setMessage("");
1703 
1704         List<OleLoanDocument> renewItemList = new ArrayList<OleLoanDocument>(0);
1705         renewItemList.addAll(oleLoanForm.getRenewDueDateList());
1706         try {
1707             boolean renewSelectFlag = true;
1708             for (int i = 0; i < renewItemList.size(); i++) {
1709                 OleLoanDocument loanDocument = renewItemList.get(i);
1710                 if (loanDocument.isRenewCheckNo()) {
1711                     renewSelectFlag = false;
1712                     break;
1713                 }
1714             }
1715             if (!renewSelectFlag) {
1716                 ModelAndView overrideModelView = this.overRide(form, result, request, response);
1717                 if (overrideModelView == null) {
1718 
1719                     for (int i = 0; i < renewItemList.size(); i++) {
1720                         OleLoanDocument loanDocument = renewItemList.get(i);
1721                         if (!getLoanProcessor().checkPendingRequestforItem(loanDocument.getItemUuid())) {
1722                             loanDocument.setErrorMessage(null);
1723                             Timestamp currentDate = new Timestamp(System.currentTimeMillis());
1724                             if (loanDocument.isRenewCheckNo()) {
1725                                 loanDocument.setRenewCheckNo(false);
1726                                 if (currentDate.after(loanDocument.getLoanDueDate())) {
1727                                     getLoanProcessor().overrideSaveLoanForRenewal(loanDocument);
1728                                     loanDocument.setErrorMessage(OLEConstants.RENEWAL_ITM_SUCCESS_INFO);
1729                                     for (int j = 0; j < oleLoanForm.getExistingLoanList().size(); j++) {
1730                                         if (loanDocument.getLoanId().equals(oleLoanForm.getExistingLoanList().get(j).getLoanId())) {
1731                                             oleLoanForm.getExistingLoanList().remove(j);
1732                                             oleLoanForm.setOleLoanDocumentToLoanList(loanDocument);
1733                                         }
1734                                     }
1735                                     oleLoanForm.setMessage("");
1736                                     oleLoanForm.setSuccess(true);
1737                                     oleLoanForm.setOverrideRenewal(false);
1738                                 } else
1739                                     loanDocument.setErrorMessage(OLEConstants.RENEWAL_ITM_AFTER_FIXED_DUEDATE);
1740 
1741                             }
1742                         }
1743                         oleLoanForm.setOverrideRenewItemFlag(false);
1744                     }
1745 
1746                 }
1747             }
1748         } catch (Exception e) {
1749             LOG.error("exception ---> " + e, e);
1750         }
1751         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
1752     }
1753 
1754 
1755     /**
1756      * This method initiate LoanProcessor.
1757      *
1758      * @return LoanProcessor
1759      */
1760     private LoanProcessor getLoanProcessor() {
1761         if (loanProcessor == null) {
1762             loanProcessor = new LoanProcessor();
1763         }
1764         return loanProcessor;
1765     }
1766 
1767     /**
1768      * This method creates new loan for a patron..
1769      *
1770      * @param form
1771      * @param result
1772      * @param request
1773      * @param response
1774      * @return ModelAndView
1775      */
1776     @RequestMapping(params = "methodToCall=validateItem")
1777     public ModelAndView validateItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1778                                      HttpServletRequest request, HttpServletResponse response) {
1779         if (LOG.isDebugEnabled()) {
1780             LOG.info(" Inside Validate Item ");
1781         }
1782         LoanProcessor loanProcessor = getLoanProcessor();
1783         OleLoanForm oleLoanForm = (OleLoanForm) form;
1784         String audioOption = getLoanProcessor().getParameter(OLEConstants.AUDIO_OPTION);
1785         oleLoanForm.setAudioEnable(audioOption != null && !audioOption.isEmpty() && audioOption.equalsIgnoreCase(OLEConstants.TRUE));
1786         oleLoanForm.setOleFormKey(oleLoanForm.getFormKey());
1787         oleLoanForm.setReturnInformation("");
1788         OleLoanDocument oleLoanDocument = null;
1789         if (oleLoanForm.getCheckInItem() != null) {
1790             oleLoanDocument = loanProcessor.getOleLoanDocumentUsingItemBarcode(oleLoanForm.getCheckInItem());
1791         } else {
1792             oleLoanDocument = loanProcessor.getOleLoanDocumentUsingItemUUID(oleLoanForm.getReturnItemUuid());
1793         }
1794         if (oleLoanDocument == null) {
1795             oleLoanDocument = new OleLoanDocument();
1796         }
1797         Timestamp timestamp;
1798         Pattern pattern;
1799         Matcher matcher;
1800         boolean timeFlag = false;
1801         SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OlePatron.PATRON_MAINTENANCE_DATE_FORMAT);
1802         if (oleLoanForm.getCheckInTime() != null && !oleLoanForm.getCheckInTime().isEmpty()) {
1803             String[] str = oleLoanForm.getCheckInTime().split(":");
1804             pattern = Pattern.compile(OLEConstants.TIME_24_HR_PATTERN);
1805             matcher = pattern.matcher(oleLoanForm.getCheckInTime());
1806             timeFlag = matcher.matches();
1807             if (timeFlag) {
1808                 if (str != null && str.length <= 2) {
1809                     oleLoanForm.setCheckInTime(oleLoanForm.getCheckInTime() + OLEConstants.CHECK_IN_TIME_MS);
1810                 }
1811                 timestamp = Timestamp.valueOf(new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT).format(oleLoanForm.getCheckInDate()).concat(" ").concat(oleLoanForm.getCheckInTime()));
1812             } else {
1813                 oleLoanForm.setReturnInformation(OLEConstants.CHECKIN_TIME_FORMAT_MESSAGE);
1814                 return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
1815             }
1816         } else if (fmt.format(oleLoanForm.getCheckInDate()).compareTo(fmt.format(new Date())) == 0) {
1817             timestamp = new Timestamp(new Date().getTime());
1818         } else {
1819             timestamp = Timestamp.valueOf(new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT).format(oleLoanForm.getCheckInDate()).concat(" ").concat(new SimpleDateFormat("HH:mm:ss").format(new Date())));
1820         }
1821         oleLoanDocument.setCheckInDate(timestamp);
1822         try {
1823             if (!loanProcessor.isValidCirculationDesk()) {
1824                 oleLoanForm.setLoanLoginMessage(true);
1825                 String loginInfo = loanProcessor.getErrorMessage();
1826                 oleLoanForm.setLoanLoginUserInfo(loginInfo);
1827                 return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
1828                 //throw new DocumentAuthorizationException(GlobalVariables.getUserSession().getPrincipalId(), "not Authorized", form.getViewId());
1829                 //return new OLEKRADAuthorizationResolver().resolveException(request,response,null,new Exception("is not authorized"));
1830             }
1831             oleLoanDocument.setCirculationLocationId(oleLoanForm.getCirculationDesk());
1832             oleLoanDocument.setDamagedCheckInOption(oleLoanForm.isDamagedCheckInOption());
1833             LOG.info("Check-in Item Barcode Number --->" + oleLoanForm.getCheckInItem());
1834             oleLoanDocument.setItemUuid(oleLoanForm.getReturnItemUuid());
1835             oleLoanDocument = loanProcessor.returnLoan(oleLoanForm.getCheckInItem(), oleLoanDocument);
1836             if (oleLoanDocument.isClaimsReturnedIndicator()) {
1837                 oleLoanForm.setDummyLoan(oleLoanDocument);
1838                 oleLoanForm.setClaimsReturned(true);
1839                 oleLoanForm.setReturnSuccess(false);
1840                 oleLoanForm.setReturnMessage(OLEConstants.CLAIMS_RETURNED_MESSAGE);
1841                 return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
1842             }
1843             String requestCheck = oleLoanDocument.getOleDeliverRequestBo() != null ? OLEConstants.REQUEST_EXISTS : "";
1844             /*if(!requestCheck.isEmpty()){
1845                 oleLoanForm.setPatronRequest(true);
1846                 oleLoanForm.setReturnSuccess(false);
1847                 oleLoanForm.setReturnMessage(requestCheck);
1848             }*/
1849             if (oleLoanDocument.getItemStatusCode().contains(OLEConstants.ITEM_STATUS_RETURNED_DAMAGED)) {
1850                 oleLoanForm.setReturnSuccess(false);
1851                 oleLoanForm.setReturnMessage(OLEConstants.DAMAGED_CHECK_IN_HEADER + requestCheck);
1852                 oleLoanForm.setRouteToLocation(oleLoanDocument.getRouteToLocation());
1853                 oleLoanForm.setDamagedCheckIn(true);
1854             }
1855             oleLoanForm.setDummyLoan(oleLoanDocument);
1856             if (oleLoanDocument.isCopyRequest()) {
1857                 oleLoanForm.setCopyRequest(true);
1858                 oleLoanForm.setReturnSuccess(false);
1859                 oleLoanForm.setReturnMessage(OLEConstants.COPY_REQUEST_FULFILL);
1860                 return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
1861             }
1862             if (oleLoanDocument.isNumberOfPieces()) {
1863                 oleLoanForm.setNumberOfPieces(true);
1864                 oleLoanForm.setReturnSuccess(false);
1865                 oleLoanForm.setReturnMessage(OLEConstants.VERIFY_PIECES + oleLoanDocument.getItemNumberOfPieces() + OLEConstants.PIECES_RETURNED);
1866                 return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
1867             }
1868             String checkInNote = oleLoanDocument.getOleItem().getCheckinNote();
1869             if (checkInNote != null && !checkInNote.isEmpty() && oleLoanForm.getReturnMessage() == null) {
1870                 oleLoanForm.setCheckInNote(OLEConstants.CHECK_IN_NOTE_HEADER + checkInNote);
1871                 oleLoanForm.setRouteToLocation(oleLoanDocument.getRouteToLocation());
1872                 String principalId = GlobalVariables.getUserSession().getPrincipalId();
1873                 oleLoanForm.setOkOrRemoveNote(loanProcessor.checkPermissionForRemoveNote(principalId));
1874             }
1875             if (!oleLoanDocument.isBackGroundCheckOut() && oleLoanDocument.getErrorMessage() != null) {
1876                 oleLoanForm.setReturnSuccess(false);
1877                 oleLoanForm.setReturnMessage(oleLoanDocument.getErrorMessage());
1878             } else {
1879                 List<OleLoanDocument> oleLoanDocuments = new ArrayList<OleLoanDocument>();
1880                 if (!oleLoanDocument.isCheckOut() || oleLoanDocument.getErrorMessage() == null)
1881                     oleLoanDocuments.add(oleLoanDocument);
1882                 if (oleLoanForm.getItemReturnList() != null) {
1883                     oleLoanDocuments.addAll(oleLoanForm.getItemReturnList());
1884                 }
1885                 oleLoanForm.setItemReturnList(oleLoanDocuments);
1886                 //To refresh loan screen current and previous session loan list
1887                 oleLoanForm.setExistingLoanList(loanProcessor.getPatronLoanedItem(oleLoanDocument.getPatronId()));
1888                 OleLoanDocument tempOleLoanDocumentObj = null;
1889                 List<OleLoanDocument> currentSessionList = oleLoanForm.getLoanList() != null ? oleLoanForm.getLoanList() : new ArrayList<OleLoanDocument>();
1890                 for (OleLoanDocument currentOleLoanDocument : currentSessionList) {
1891                     if (currentOleLoanDocument.getItemId().equals(oleLoanForm.getCheckInItem())) {
1892                         tempOleLoanDocumentObj = currentOleLoanDocument;
1893                         break;
1894                     }
1895                 }
1896                 currentSessionList.remove(tempOleLoanDocumentObj);
1897                 oleLoanForm.setLoanList(currentSessionList);
1898                 //To refresh loan screen current and previous session loan list
1899                 oleLoanForm.setCheckInItem("");
1900             }
1901         } catch (Exception e) {
1902             LOG.error("Error in validate Item " + e, e);
1903             oleLoanForm.setReturnInformation(e.getMessage());
1904             return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
1905         }
1906         if (!oleLoanForm.isCheckInNoteExists() && oleLoanForm.getCheckInNote() != null && oleLoanForm.getReturnMessage() == null) {
1907             oleLoanForm.setDummyLoan(oleLoanDocument);
1908             oleLoanForm.setCheckInNoteExists(true);
1909             oleLoanForm.setReturnSuccess(false);
1910             oleLoanForm.setReturnMessage(oleLoanForm.getCheckInNote());
1911             return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
1912         }
1913         if (oleLoanDocument.isCheckOut() && oleLoanDocument.getErrorMessage() != null && oleLoanForm.getReturnMessage() == null) {
1914             oleLoanForm.setDueDateEmpty(oleLoanDocument.isDueDateEmpty());
1915             oleLoanForm.setDummyLoan(oleLoanDocument);
1916             oleLoanForm.setReturnSuccess(false);
1917             oleLoanForm.setMessage(oleLoanDocument.getErrorMessage());
1918             oleLoanForm.setCheckOut(true);
1919             oleLoanForm.setItem(oleLoanForm.getCheckInItem());
1920             oleLoanForm.setOleItem(oleLoanDocument.getOleItem());
1921             return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
1922         }
1923         if ((oleLoanForm.getReturnMessage() == null) && oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isPrintSlip()) {
1924             if (oleLoanDocument.getOleItem().getItemStatus().equals(OLEConstants.ITEM_STATUS_RETURNED_MISSING)) {
1925                 OleNoticeBo oleNoticeBo = loanProcessor.getNotice(oleLoanDocument);
1926                 if (oleNoticeBo != null) {
1927                     String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
1928                     if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
1929                         fromAddress = OLEConstants.KUALI_MAIL;
1930                     }
1931                     String missingNoticeDetails = oleDeliverBatchService.sendMissingNotice(oleNoticeBo);
1932                     OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
1933                     oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
1934                     LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
1935                 }
1936             } else {
1937                 oleLoanForm.setBillAvailability(true);
1938             }
1939         }
1940         if (oleLoanDocument.isCheckOut()) {
1941             oleLoanForm.setDueDateSlip(true);
1942             oleLoanForm.setBillAvailability(false);
1943         }
1944         return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
1945     }
1946 
1947     /**
1948      * This method  returns Item for a patron who is not able to return.
1949      *
1950      * @param form
1951      * @param result
1952      * @param request
1953      * @param response
1954      * @return ModelAndView
1955      */
1956     @RequestMapping(params = "methodToCall=returnItem")
1957     public ModelAndView returnItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1958                                    HttpServletRequest request, HttpServletResponse response) {
1959         if (LOG.isDebugEnabled()) {
1960             LOG.info(" Inside Return Item ");
1961         }
1962         OleLoanForm oleLoanForm = (OleLoanForm) form;
1963         String audioOption = getLoanProcessor().getParameter(OLEConstants.AUDIO_OPTION);
1964         oleLoanForm.setAudioEnable(audioOption != null && !audioOption.isEmpty() && audioOption.equalsIgnoreCase(OLEConstants.TRUE));
1965         OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
1966         String principalId = GlobalVariables.getUserSession().getPrincipalId();
1967         Boolean overRideFlag = getLoanProcessor().checkOverRidePermission(principalId, oleLoanForm);
1968         if (!overRideFlag) {
1969             ModelAndView modelAndView = this.overRide(form, result, request, response);
1970             if (modelAndView != null) {
1971                 return modelAndView;
1972             }
1973         }
1974         try {
1975             oleLoanDocument = getLoanProcessor().returnLoan(oleLoanDocument);
1976             if (oleLoanDocument.isNumberOfPieces()) {
1977                 oleLoanForm.setNumberOfPieces(true);
1978                 oleLoanForm.setReturnSuccess(false);
1979                 oleLoanForm.setReturnMessage(OLEConstants.VERIFY_PIECES + oleLoanDocument.getItemNumberOfPieces() + OLEConstants.PIECES_RETURNED);
1980                 return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
1981             }
1982             String checkInNote = oleLoanDocument.getOleItem().getCheckinNote();
1983             if (!oleLoanForm.isBackGroundCheckIn() && checkInNote != null && !checkInNote.isEmpty()) {
1984                 oleLoanForm.setNumberOfPieces(false);
1985                 oleLoanForm.setCheckInNote(OLEConstants.CHECK_IN_NOTE_HEADER + checkInNote);
1986                 oleLoanForm.setRouteToLocation(oleLoanDocument.getRouteToLocation());
1987                 oleLoanForm.setOkOrRemoveNote(loanProcessor.checkPermissionForRemoveNote(principalId));
1988             }
1989             List<OleLoanDocument> oleLoanDocuments = new ArrayList<OleLoanDocument>();
1990             if (!oleLoanDocument.isCheckOut() || oleLoanDocument.getErrorMessage() == null)
1991                 oleLoanDocuments.add(oleLoanDocument);
1992             if (oleLoanForm.getItemReturnList() != null) {
1993                 oleLoanDocuments.addAll(oleLoanForm.getItemReturnList());
1994             }
1995             oleLoanForm.setItemReturnList(oleLoanDocuments);
1996         } catch (Exception e) {
1997             LOG.error("Error in return Item " + e, e);
1998         }
1999         oleLoanForm.setReturnSuccess(true);
2000         oleLoanForm.setReturnMessage(null);
2001         oleLoanForm.setCheckInItem("");
2002         oleLoanForm.setReturnInformation("");
2003         if (!oleLoanForm.isCheckInNoteExists() && oleLoanForm.getCheckInNote() != null) {
2004             oleLoanForm.setDummyLoan(oleLoanDocument);
2005             oleLoanForm.setCheckInNoteExists(true);
2006             oleLoanForm.setReturnSuccess(false);
2007             oleLoanForm.setReturnMessage(oleLoanForm.getCheckInNote());
2008             return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
2009         }
2010         if (oleLoanDocument.isCheckOut() && oleLoanDocument.getErrorMessage() != null) {
2011             oleLoanForm.setDueDateEmpty(oleLoanDocument.isDueDateEmpty());
2012             oleLoanForm.setDummyLoan(oleLoanDocument);
2013             oleLoanForm.setReturnSuccess(false);
2014             oleLoanForm.setMessage(oleLoanDocument.getErrorMessage());
2015             oleLoanForm.setCheckOut(true);
2016             oleLoanForm.setItem(oleLoanForm.getCheckInItem());
2017             oleLoanForm.setOleItem(oleLoanDocument.getOleItem());
2018             return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
2019         }
2020         if (oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isPrintSlip()) {
2021             if (oleLoanDocument.getOleItem().getItemStatus().equals(OLEConstants.ITEM_STATUS_RETURNED_MISSING)) {
2022                 OleNoticeBo oleNoticeBo = loanProcessor.getNotice(oleLoanDocument);
2023                 if (oleNoticeBo != null) {
2024                     String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
2025                     if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
2026                         fromAddress = OLEConstants.KUALI_MAIL;
2027                     }
2028                     String missingNoticeDetails = oleDeliverBatchService.sendMissingNotice(oleNoticeBo);
2029                     OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
2030                     oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
2031                     LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
2032                 }
2033             } else {
2034                 oleLoanForm.setBillAvailability(true);
2035             }
2036         }
2037         if (oleLoanDocument.isCheckOut()) {
2038             oleLoanForm.setDueDateSlip(true);
2039             oleLoanForm.setBillAvailability(false);
2040         }
2041         if (oleLoanForm.isBackGroundCheckIn()) {
2042             oleLoanForm.setItem(oleLoanForm.getCheckInItem());
2043             oleLoanForm.setOleItem(oleLoanDocument.getOleItem());
2044             oleLoanDocument.setItemLoanStatus(oleLoanDocument.getItemStatusCode());
2045             loanPatron(oleLoanForm, result, request, response);
2046         }
2047         return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
2048     }
2049 
2050     /**
2051      * This method  doesn't allow to return an item.
2052      *
2053      * @param form
2054      * @param result
2055      * @param request
2056      * @param response
2057      * @return ModelAndView
2058      */
2059     @RequestMapping(params = "methodToCall=noReturnItem")
2060     public ModelAndView doNotReturnItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2061                                         HttpServletRequest request, HttpServletResponse response) {
2062         if (LOG.isDebugEnabled()) {
2063             LOG.info(" Inside Do Not Return Item ");
2064         }
2065         OleLoanForm oleLoanForm = (OleLoanForm) form;
2066         oleLoanForm.setReturnInformation("");
2067         oleLoanForm.setCheckInItem("");
2068         oleLoanForm.setReturnMessage(null);
2069         oleLoanForm.setReturnSuccess(true);
2070         oleLoanForm.setCheckInNote(null);
2071         OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
2072         if (oleLoanForm.getDummyLoan().isCheckOut() && oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isPrintSlip()) {
2073             if (oleLoanDocument.getOleItem().getItemStatus().equals(OLEConstants.ITEM_STATUS_RETURNED_MISSING)) {
2074                 OleNoticeBo oleNoticeBo = loanProcessor.getNotice(oleLoanDocument);
2075                 if (oleNoticeBo != null) {
2076                     String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
2077                     if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
2078                         fromAddress = OLEConstants.KUALI_MAIL;
2079                     }
2080                     String missingNoticeDetails = oleDeliverBatchService.sendMissingNotice(oleNoticeBo);
2081                     OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
2082                     oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
2083                     LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
2084                 }
2085             } else {
2086                 oleLoanForm.setBillAvailability(true);
2087             }
2088         }
2089         if (oleLoanForm.getDummyLoan() != null && oleLoanForm.getDummyLoan().isCheckOut()) {
2090             oleLoanForm.setDueDateSlip(true);
2091             oleLoanForm.setBillAvailability(false);
2092         }
2093         return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
2094     }
2095 
2096     /**
2097      * This method  allows to continue Check-in.
2098      *
2099      * @param form
2100      * @param result
2101      * @param request
2102      * @param response
2103      * @return ModelAndView
2104      */
2105     @RequestMapping(params = "methodToCall=continueCheckIn")
2106     public ModelAndView continueCheckIn(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2107                                         HttpServletRequest request, HttpServletResponse response) {
2108         if (LOG.isDebugEnabled()) {
2109             LOG.info(" Inside Continue Check-in ");
2110         }
2111         OleLoanForm oleLoanForm = (OleLoanForm) form;
2112         String audioOption = getLoanProcessor().getParameter(OLEConstants.AUDIO_OPTION);
2113         oleLoanForm.setAudioEnable(audioOption != null && !audioOption.isEmpty() && audioOption.equalsIgnoreCase(OLEConstants.TRUE));
2114         String description = oleLoanForm.getDescription();
2115         String matchCheck = oleLoanForm.getMatchCheck();
2116         String copyCheck = oleLoanForm.getCopyCheck();
2117         OleLoanDocument oleLoanDocument = new OleLoanDocument();
2118         oleLoanDocument = oleLoanForm.getDummyLoan();
2119         oleLoanDocument.setDescription(oleLoanForm.getDescription());
2120         LoanProcessor loanProcessor = getLoanProcessor();
2121         try {
2122             if (copyCheck != null && copyCheck.equalsIgnoreCase(OLEConstants.TRUE)) {
2123                 oleLoanForm.setCopyCheck("");
2124                 loanProcessor.deleteRequestRecord(oleLoanDocument.getOleDeliverRequestBo());
2125                 oleLoanDocument = loanProcessor.returnLoan(oleLoanDocument);
2126                 //  oleLoanForm.setCopyRequest(false);
2127             } else if (copyCheck != null && copyCheck.equalsIgnoreCase(OLEConstants.FALSE)) {
2128                 return endCheckInSession(form, result, request, response);
2129             }
2130             if (oleLoanForm.isCopyRequest() && oleLoanDocument.isNumberOfPieces()) {
2131                 oleLoanForm.setCopyRequest(false);
2132                 oleLoanForm.setNumberOfPieces(true);
2133                 oleLoanForm.setReturnSuccess(false);
2134                 oleLoanForm.setReturnMessage(OLEConstants.VERIFY_PIECES + oleLoanDocument.getItemNumberOfPieces() + OLEConstants.PIECES_RETURNED);
2135                 return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
2136             }
2137             if (oleLoanDocument.isClaimsReturnedIndicator()) {
2138                 oleLoanForm.setClaimsReturned(false);
2139                 oleLoanForm.setReturnSuccess(true);
2140                 oleLoanForm.setReturnMessage(null);
2141                 loanProcessor.updateClaimsReturnedInLoanDocument(oleLoanDocument, false);
2142                 if (oleLoanDocument.isCopyRequest()) {
2143                     oleLoanForm.setCopyRequest(true);
2144                     oleLoanForm.setReturnSuccess(false);
2145                     oleLoanForm.setReturnMessage(OLEConstants.COPY_REQUEST_FULFILL);
2146                     return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
2147                 }
2148                 if (oleLoanDocument.isNumberOfPieces()) {
2149                     oleLoanForm.setNumberOfPieces(true);
2150                     oleLoanForm.setReturnSuccess(false);
2151                     oleLoanForm.setReturnMessage(OLEConstants.VERIFY_PIECES + oleLoanDocument.getItemNumberOfPieces() + OLEConstants.PIECES_RETURNED);
2152                     return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
2153                 }
2154             }
2155             if (matchCheck != null && matchCheck.equalsIgnoreCase(OLEConstants.TRUE)) {
2156                 oleLoanDocument.setContinueCheckIn(true);
2157                 oleLoanDocument = loanProcessor.returnLoan(oleLoanDocument);
2158             } else if (matchCheck != null && matchCheck.equalsIgnoreCase(OLEConstants.FALSE)) {
2159                 oleLoanDocument.setDescription(description);
2160                 loanProcessor.updateItemStatusWithMissingItem(oleLoanDocument);
2161             } else if ((copyCheck == null || copyCheck.isEmpty()) && !oleLoanForm.isNumberOfPieces()) {
2162                 oleLoanDocument = loanProcessor.returnLoan(oleLoanDocument);
2163             }
2164             String checkInNote = oleLoanDocument.getOleItem().getCheckinNote();
2165             if (!oleLoanForm.isBackGroundCheckIn() && (oleLoanForm.isCopyRequest() || oleLoanForm.isNumberOfPieces()) && checkInNote != null && !checkInNote.isEmpty()) {
2166                 oleLoanForm.setNumberOfPieces(false);
2167                 oleLoanForm.setCopyRequest(false);
2168                 oleLoanForm.setCheckInNote(OLEConstants.CHECK_IN_NOTE_HEADER + checkInNote);
2169                 oleLoanForm.setRouteToLocation(oleLoanDocument.getRouteToLocation());
2170                 String principalId = GlobalVariables.getUserSession().getPrincipalId();
2171                 oleLoanForm.setOkOrRemoveNote(loanProcessor.checkPermissionForRemoveNote(principalId));
2172             }
2173             List<OleLoanDocument> oleLoanDocuments = new ArrayList<OleLoanDocument>();
2174             if (!oleLoanDocument.isCheckOut() || oleLoanDocument.getErrorMessage() == null)
2175                 oleLoanDocuments.add(oleLoanDocument);
2176             if (oleLoanForm.getItemReturnList() != null) {
2177                 oleLoanDocuments.addAll(oleLoanForm.getItemReturnList());
2178             }
2179             if (!oleLoanForm.isBackGroundCheckIn()) {
2180                 oleLoanForm.setItemReturnList(oleLoanDocuments);
2181 
2182                 //To refresh loan screen current and previous session loan list
2183                 oleLoanForm.setExistingLoanList(loanProcessor.getPatronLoanedItem(oleLoanDocument.getPatronId()));
2184                 OleLoanDocument tempOleLoanDocumentObj = null;
2185                 List<OleLoanDocument> currentSessionList = oleLoanForm.getLoanList() != null ? oleLoanForm.getLoanList() : new ArrayList<OleLoanDocument>();
2186                 for (OleLoanDocument currentOleLoanDocument : currentSessionList) {
2187                     if (currentOleLoanDocument.getItemId().equals(oleLoanForm.getCheckInItem())) {
2188                         tempOleLoanDocumentObj = currentOleLoanDocument;
2189                         break;
2190                     }
2191                 }
2192                 currentSessionList.remove(tempOleLoanDocumentObj);
2193                 oleLoanForm.setLoanList(currentSessionList);
2194                 //To refresh loan screen current and previous session loan list
2195             }
2196 
2197         } catch (Exception e) {
2198             LOG.error("Error in Continue Check-in " + e);
2199             LOG.error(e, e);
2200         }
2201         oleLoanForm.setNumberOfPieces(false);
2202         oleLoanForm.setReturnSuccess(true);
2203         oleLoanForm.setReturnMessage(null);
2204         oleLoanForm.setCheckInItem("");
2205         oleLoanForm.setReturnInformation("");
2206         LOG.info("oleLoanForm.getFormKey()" + oleLoanForm.getFormKey());
2207         if (oleLoanForm.isBackGroundCheckIn()) {
2208             oleLoanForm.setItem(oleLoanForm.getCheckInItem());
2209             oleLoanForm.setOleItem(oleLoanDocument.getOleItem());
2210             oleLoanDocument.setItemLoanStatus(oleLoanDocument.getItemStatusCode());
2211             loanPatron(oleLoanForm, result, request, response);
2212         }
2213         if (!oleLoanForm.isCheckInNoteExists() && oleLoanForm.getCheckInNote() != null) {
2214             oleLoanForm.setDummyLoan(oleLoanDocument);
2215             oleLoanForm.setCheckInNoteExists(true);
2216             oleLoanForm.setReturnSuccess(false);
2217             oleLoanForm.setReturnMessage(oleLoanForm.getCheckInNote());
2218             return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
2219         }
2220         if (oleLoanDocument.isCheckOut() && oleLoanDocument.getErrorMessage() != null) {
2221             oleLoanForm.setDueDateEmpty(oleLoanDocument.isDueDateEmpty());
2222             oleLoanForm.setDummyLoan(oleLoanDocument);
2223             oleLoanForm.setReturnSuccess(false);
2224             oleLoanForm.setMessage(oleLoanDocument.getErrorMessage());
2225             oleLoanForm.setCheckOut(true);
2226             oleLoanForm.setItem(oleLoanForm.getCheckInItem());
2227             oleLoanForm.setOleItem(oleLoanDocument.getOleItem());
2228             return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
2229         }
2230         if (oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isPrintSlip()) {
2231             if (oleLoanDocument.getOleItem().getItemStatus().equals(OLEConstants.ITEM_STATUS_RETURNED_MISSING)) {
2232                 OleNoticeBo oleNoticeBo = loanProcessor.getNotice(oleLoanDocument);
2233                 if (oleNoticeBo != null) {
2234                     String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
2235                     if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
2236                         fromAddress = OLEConstants.KUALI_MAIL;
2237                     }
2238                     String missingNoticeDetails = oleDeliverBatchService.sendMissingNotice(oleNoticeBo);
2239                     OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
2240                     oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
2241                     LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
2242                 }
2243             } else {
2244                 oleLoanForm.setBillAvailability(true);
2245             }
2246         }
2247         if (oleLoanDocument.isCheckOut()) {
2248             oleLoanForm.setDueDateSlip(true);
2249             oleLoanForm.setBillAvailability(false);
2250         }
2251         return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
2252     }
2253 
2254     /**
2255      * This method  ends Check-in session
2256      *
2257      * @param form
2258      * @param result
2259      * @param request
2260      * @param response
2261      * @return ModelAndView
2262      */
2263     @RequestMapping(params = "methodToCall=endCheckInSession")
2264     public ModelAndView endCheckInSession(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2265                                           HttpServletRequest request, HttpServletResponse response) {
2266         if (LOG.isDebugEnabled()) {
2267             LOG.info(" Inside End Check-in session ");
2268         }
2269         OleLoanForm oleLoanForm = (OleLoanForm) form;
2270         oleLoanForm.setCopyRequest(false);
2271         oleLoanForm.setNumberOfPieces(false);
2272         oleLoanForm.setReturnInformation("");
2273         oleLoanForm.setCheckInItem("");
2274         oleLoanForm.setReturnMessage(null);
2275         oleLoanForm.setReturnSuccess(true);
2276         oleLoanForm.setItemReturnList(null);
2277         oleLoanForm.setCheckInNote(null);
2278         if (!oleLoanForm.isClearUI()) {
2279             String principalId = GlobalVariables.getUserSession().getPrincipalId();
2280             OleCirculationDeskDetail oleCirculationDeskDetail = getLoanProcessor().getDefaultCirculationDesk(principalId);
2281             if (oleCirculationDeskDetail != null) {
2282                 oleLoanForm.setCirculationDesk(oleCirculationDeskDetail.getCirculationDeskId());
2283                 oleLoanForm.setPreviousCirculationDesk(oleLoanForm.getCirculationDesk());
2284             }
2285         }
2286         //return getUIFModelAndView(oleLoanForm, oleLoanForm.getPageId());
2287         return getUIFModelAndView(oleLoanForm, "ReturnItemViewPage");
2288     }
2289 
2290     /**
2291      * This method will allow  library operator to print slips for user
2292      *
2293      * @param form
2294      * @param result
2295      * @param request
2296      * @param response
2297      * @return ModelAndView
2298      */
2299     @RequestMapping(params = "methodToCall=printBill")
2300     public ModelAndView printBill(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2301                                   HttpServletRequest request, HttpServletResponse response) {
2302         OlePrintSlip olePrintSlip = new OlePrintSlip();
2303         if (LOG.isDebugEnabled()) {
2304             LOG.info(" Inside Print Bill ");
2305         }
2306         String formKey = request.getParameter("formKey");
2307         OleLoanForm oleLoanForm = (OleLoanForm) GlobalVariables.getUifFormManager().getSessionForm(formKey);
2308         OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
2309         oleLoanDocument.setRouteToLocation(oleLoanForm.getRouteToLocation());
2310         olePrintSlip.createPdfForPrintingSlip(oleLoanDocument, response);
2311         return null;
2312     }
2313 
2314     /**
2315      * This method will allow library operator to print due date slips for user.
2316      *
2317      * @param form
2318      * @param result
2319      * @param request
2320      * @param response
2321      * @return
2322      */
2323     @RequestMapping(params = "methodToCall=printLoanBill")
2324     public ModelAndView printLoanBill(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2325                                       HttpServletRequest request, HttpServletResponse response) {
2326         OlePrintSlip olePrintSlip = new OlePrintSlip();
2327         if (LOG.isDebugEnabled()) {
2328             LOG.info(" Inside Print Loan Bill ");
2329         }
2330         String formKey = request.getParameter("formKey");
2331         OleLoanForm oleLoanForm = (OleLoanForm) GlobalVariables.getUifFormManager().getSessionForm(formKey);
2332         OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
2333         List<OleLoanDocument> oleLoanDocumentList = new ArrayList<OleLoanDocument>();
2334         if (getLoanProcessor().getParameter(OLEConstants.PRINT_DUE_DATE_PER_TRANSACTION).equalsIgnoreCase("No")) {
2335             oleLoanDocumentList = printDueDateSlipList;
2336         } else {
2337             if (oleLoanForm.getLoanList() != null && (oleLoanForm.getLoanList().size() > 0)) {
2338                 oleLoanDocumentList.add(oleLoanForm.getLoanList().get(0));
2339             }
2340         }
2341         if (oleLoanDocument.isCheckOut()) {
2342             olePrintSlip.createPdfForBackGroundCheckOut(oleLoanDocument, response);
2343         } else if (oleLoanDocumentList != null && oleLoanDocumentList.size() > 0) {
2344             olePrintSlip.createDueDateSlipPdf(oleLoanDocumentList, response);
2345         }
2346         return null;
2347     }
2348 
2349 
2350     /**
2351      * This method will allow library operator to even if the check-in note exists
2352      *
2353      * @param form
2354      * @param result
2355      * @param request
2356      * @param response
2357      * @return ModelAndView
2358      */
2359     @RequestMapping(params = "methodToCall=checkInNote")
2360     public ModelAndView checkInNote(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2361                                     HttpServletRequest request, HttpServletResponse response) {
2362         if (LOG.isDebugEnabled()) {
2363             LOG.info("Check in Note Exists ");
2364         }
2365         OleLoanForm oleLoanForm = (OleLoanForm) form;
2366         OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
2367         if ((oleLoanForm.getRouteToLocation() == null || oleLoanForm.getRouteToLocation().isEmpty()) && oleLoanDocument.getItemStatusCode().contains(OLEConstants.ITEM_STATUS_IN_TRANSIT)) {
2368             oleLoanForm.setInformation(OLEConstants.CIRC_DESK_REQUIRED);
2369             return getUIFModelAndView(form, "ReturnItemViewPage");
2370 
2371         }
2372         oleLoanForm.setCheckInNoteExists(false);
2373         oleLoanForm.setReturnSuccess(true);
2374         oleLoanForm.setReturnMessage(null);
2375         oleLoanForm.setCheckInNote(null);
2376         oleLoanForm.setInformation("");
2377         Item oleItem = oleLoanDocument.getOleItem();
2378         if (oleItem != null) {
2379             try {
2380                 getLoanProcessor().removeCheckInNote(oleItem);
2381             } catch (Exception e) {
2382                 LOG.error(e, e);
2383             }
2384         }
2385         if (oleLoanDocument.isCheckOut() && oleLoanDocument.getErrorMessage() != null) {
2386             oleLoanForm.setDueDateEmpty(oleLoanDocument.isDueDateEmpty());
2387             oleLoanForm.setDummyLoan(oleLoanDocument);
2388             oleLoanForm.setReturnSuccess(false);
2389             oleLoanForm.setMessage(oleLoanDocument.getErrorMessage());
2390             oleLoanForm.setCheckOut(true);
2391             oleLoanForm.setItem(oleLoanForm.getCheckInItem());
2392             oleLoanForm.setOleItem(oleLoanDocument.getOleItem());
2393             return getUIFModelAndView(form, "ReturnItemViewPage");
2394         }
2395         if (oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isPrintSlip()) {
2396             if (oleLoanDocument.getOleItem().getItemStatus().equals(OLEConstants.ITEM_STATUS_RETURNED_MISSING)) {
2397                 OleNoticeBo oleNoticeBo = loanProcessor.getNotice(oleLoanDocument);
2398                 if (oleNoticeBo != null) {
2399                     String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
2400                     if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
2401                         fromAddress = OLEConstants.KUALI_MAIL;
2402                     }
2403                     String missingNoticeDetails = oleDeliverBatchService.sendMissingNotice(oleNoticeBo);
2404                     OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
2405                     oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
2406                     LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
2407                 }
2408             } else {
2409                 oleLoanForm.setBillAvailability(true);
2410             }
2411         }
2412         if (oleLoanDocument.isCheckOut() && oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isPrintSlip()) {
2413             oleLoanForm.setDueDateSlip(true);
2414             oleLoanForm.setBillAvailability(false);
2415         }
2416         return getUIFModelAndView(form, "ReturnItemViewPage");
2417     }
2418 
2419     /**
2420      * This method will allow library operator to even if the check-in note exists
2421      *
2422      * @param form
2423      * @param result
2424      * @param request
2425      * @param response
2426      * @return ModelAndView
2427      */
2428     @RequestMapping(params = "methodToCall=okCheckInNote")
2429     public ModelAndView okCheckInNote(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2430                                       HttpServletRequest request, HttpServletResponse response) {
2431         if (LOG.isDebugEnabled()) {
2432             LOG.info("Check in Note Exists ");
2433         }
2434         OleLoanForm oleLoanForm = (OleLoanForm) form;
2435         OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
2436         if ((oleLoanForm.getRouteToLocation() == null || oleLoanForm.getRouteToLocation().isEmpty()) && oleLoanDocument.getItemStatusCode().contains(OLEConstants.ITEM_STATUS_IN_TRANSIT)) {
2437             oleLoanForm.setInformation(OLEConstants.CIRC_DESK_REQUIRED);
2438             return getUIFModelAndView(form, "ReturnItemViewPage");
2439         }
2440         oleLoanForm.setCheckInNoteExists(false);
2441         oleLoanForm.setReturnSuccess(true);
2442         oleLoanForm.setReturnMessage(null);
2443         oleLoanForm.setCheckInNote(null);
2444         oleLoanForm.setInformation("");
2445         if (oleLoanDocument.isCheckOut() && oleLoanDocument.getErrorMessage() != null) {
2446             oleLoanForm.setDueDateEmpty(oleLoanDocument.isDueDateEmpty());
2447             oleLoanForm.setDummyLoan(oleLoanDocument);
2448             oleLoanForm.setReturnSuccess(false);
2449             oleLoanForm.setMessage(oleLoanDocument.getErrorMessage());
2450             oleLoanForm.setCheckOut(true);
2451             oleLoanForm.setItem(oleLoanForm.getCheckInItem());
2452             oleLoanForm.setOleItem(oleLoanDocument.getOleItem());
2453             return getUIFModelAndView(form, "ReturnItemViewPage");
2454         }
2455         if (oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isPrintSlip()) {
2456             if (oleLoanDocument.getOleItem().getItemStatus().equals(OLEConstants.ITEM_STATUS_RETURNED_MISSING)) {
2457                 OleNoticeBo oleNoticeBo = loanProcessor.getNotice(oleLoanDocument);
2458                 if (oleNoticeBo != null) {
2459                     String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
2460                     if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
2461                         fromAddress = OLEConstants.KUALI_MAIL;
2462                     }
2463                     String missingNoticeDetails = oleDeliverBatchService.sendMissingNotice(oleNoticeBo);
2464                     OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
2465                     oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
2466                     LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
2467                 }
2468             } else {
2469                 oleLoanForm.setBillAvailability(true);
2470             }
2471         }
2472         if (oleLoanDocument.isCheckOut() && oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isPrintSlip()) {
2473             oleLoanForm.setDueDateSlip(true);
2474             oleLoanForm.setBillAvailability(false);
2475         }
2476         return getUIFModelAndView(form, "ReturnItemViewPage");
2477     }
2478 
2479     /**
2480      * This method clear UI for next borrower session..
2481      *
2482      * @param form
2483      * @param result
2484      * @param request
2485      * @param response
2486      * @return ModelAndView
2487      */
2488     @RequestMapping(params = "methodToCall=clearUI")
2489     public ModelAndView clearUI(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2490                                 HttpServletRequest request, HttpServletResponse response) {
2491         OleLoanForm oleLoanForm = (OleLoanForm) form;
2492         oleLoanForm.setClearUI(true);
2493         clearPatronScreen(oleLoanForm, result, request, response);
2494         endCheckInSession(oleLoanForm, result, request, response);
2495         oleLoanForm.setClearUI(false);
2496         return getUIFModelAndView(form, "PatronItemViewPage");
2497     }
2498 
2499     @RequestMapping(params = "methodToCall=clearReturnUI")
2500     public ModelAndView clearReturnUI(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2501                                       HttpServletRequest request, HttpServletResponse response) {
2502         OleLoanForm oleLoanForm = (OleLoanForm) form;
2503         oleLoanForm.setClearUI(true);
2504         clearPatronScreen(oleLoanForm, result, request, response);
2505         endCheckInSession(oleLoanForm, result, request, response);
2506         oleLoanForm.setClearUI(false);
2507         return getUIFModelAndView(form, "ReturnItemViewPage");
2508     }
2509 
2510     /**
2511      * To refresh patron record.
2512      *
2513      * @param form
2514      * @param result
2515      * @param request
2516      * @param response
2517      * @return
2518      * @throws Exception
2519      */
2520     @RequestMapping(params = "methodToCall=setItemBarcode")
2521     public ModelAndView setItemBarcode(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2522                                        HttpServletRequest request, HttpServletResponse response) throws Exception {
2523         OleLoanForm oleLoanForm = (OleLoanForm) form;
2524         oleLoanForm.setItem(fastAddBarcode);
2525         return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
2526     }
2527 
2528     @RequestMapping(params = "methodToCall=gotoReturn")
2529     public ModelAndView gotoReturn(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2530                                    HttpServletRequest request, HttpServletResponse response) throws IOException {
2531         OleLoanForm oleLoanForm = (OleLoanForm) form;
2532         String baseUrl = ConfigContext.getCurrentContextConfig().getProperty("ole.rice2.url.base");
2533         String url = baseUrl + "/portal.do?channelTitle=Loan&channelUrl=" + baseUrl + "/ole-kr-krad/loancontroller?viewId=ReturnItemView&methodToCall=start&formKey=" + oleLoanForm.getFormKey();
2534         Properties props = new Properties();
2535         props.put(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.REFRESH);
2536         if (StringUtils.isNotBlank(form.getReturnFormKey())) {
2537             props.put(UifParameters.FORM_KEY, form.getReturnFormKey());
2538         }
2539         response.sendRedirect(url);
2540         return performRedirect(oleLoanForm, url, props);
2541     }
2542 
2543 
2544     @RequestMapping(params = "methodToCall=gotoLoan")
2545     public ModelAndView gotoLoan(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2546                                  HttpServletRequest request, HttpServletResponse response) throws Exception {
2547         OleLoanForm oleLoanForm = (OleLoanForm) form;
2548         oleLoanForm.setReturnCheck(false);
2549         String baseUrl = ConfigContext.getCurrentContextConfig().getProperty("ole.rice2.url.base");
2550         String requestKey = request.getParameter("formKey");
2551         String url = baseUrl + "/portal.do?channelTitle=Loan&channelUrl=" + baseUrl + "/ole-kr-krad/loancontroller?viewId=PatronItemView&methodToCall=start&formKey=" + requestKey;
2552         Properties props = new Properties();
2553         props.put(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.REFRESH);
2554         if (StringUtils.isNotBlank(form.getReturnFormKey())) {
2555             props.put(UifParameters.FORM_KEY, form.getReturnFormKey());
2556         }
2557         response.sendRedirect(url);
2558         return performRedirect(oleLoanForm, url, props);
2559     }
2560 
2561     /**
2562      * This method will allow library operator to even if it is damagedCheckIn
2563      *
2564      * @param form
2565      * @param result
2566      * @param request
2567      * @param response
2568      * @return ModelAndView
2569      */
2570     @RequestMapping(params = "methodToCall=damagedCheckIn")
2571     public ModelAndView damagedCheckIn(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2572                                        HttpServletRequest request, HttpServletResponse response) {
2573         if (LOG.isDebugEnabled()) {
2574             LOG.info("Check in Note Exists ");
2575         }
2576         OleLoanForm oleLoanForm = (OleLoanForm) form;
2577         OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
2578         if ((oleLoanForm.getRouteToLocation() == null || oleLoanForm.getRouteToLocation().isEmpty()) && oleLoanDocument.getItemStatusCode().contains(OLEConstants.ITEM_STATUS_IN_TRANSIT)) {
2579             oleLoanForm.setInformation(OLEConstants.CIRC_DESK_REQUIRED);
2580             return getUIFModelAndView(form, "ReturnItemViewPage");
2581         }
2582         oleLoanForm.setDamagedCheckIn(false);
2583         oleLoanForm.setReturnSuccess(true);
2584         oleLoanForm.setReturnMessage(null);
2585         oleLoanForm.setInformation("");
2586         if (oleLoanDocument.getOleCirculationDesk() != null && oleLoanDocument.getOleCirculationDesk().isPrintSlip()) {
2587             if (oleLoanDocument.getOleItem().getItemStatus().equals(OLEConstants.ITEM_STATUS_RETURNED_MISSING)) {
2588                 OleNoticeBo oleNoticeBo = loanProcessor.getNotice(oleLoanDocument);
2589                 if (oleNoticeBo != null) {
2590                     String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
2591                     if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
2592                         fromAddress = OLEConstants.KUALI_MAIL;
2593                     }
2594                     String missingNoticeDetails = oleDeliverBatchService.sendMissingNotice(oleNoticeBo);
2595                     OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
2596                     oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(missingNoticeDetails), true);
2597                     LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
2598                 }
2599             } else {
2600                 oleLoanForm.setBillAvailability(true);
2601             }
2602         }
2603         return getUIFModelAndView(form, "ReturnItemViewPage");
2604     }
2605 }