View Javadoc

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