View Javadoc
1   package org.kuali.ole.deliver.controller;
2   
3   import org.apache.commons.lang.StringUtils;
4   import org.kuali.asr.service.ASRHelperServiceImpl;
5   import org.kuali.ole.OLEConstants;
6   import org.kuali.ole.deliver.bo.*;
7   import org.kuali.ole.deliver.form.OLEPlaceRequestForm;
8   import org.kuali.ole.deliver.processor.LoanProcessor;
9   import org.kuali.ole.deliver.service.CircDeskLocationResolver;
10  import org.kuali.ole.deliver.service.OleDeliverRequestDocumentHelperServiceImpl;
11  import org.kuali.ole.describe.bo.OleLocation;
12  import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
13  import org.kuali.ole.docstore.common.document.BibTree;
14  import org.kuali.ole.docstore.common.document.HoldingsTree;
15  import org.kuali.ole.docstore.common.document.Item;
16  import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
17  import org.kuali.ole.ncip.bo.OLEPlaceRequest;
18  import org.kuali.ole.ncip.converter.OLEPlaceRequestConverter;
19  import org.kuali.ole.ncip.service.OLECirculationService;
20  import org.kuali.ole.ncip.service.impl.OLECirculationServiceImpl;
21  import org.kuali.ole.service.OleCirculationPolicyService;
22  import org.kuali.ole.service.OleCirculationPolicyServiceImpl;
23  import org.kuali.ole.sys.context.SpringContext;
24  import org.kuali.rice.core.api.config.property.ConfigContext;
25  import org.kuali.rice.kim.api.identity.IdentityService;
26  import org.kuali.rice.kim.api.identity.address.EntityAddress;
27  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
28  import org.kuali.rice.kim.impl.identity.address.EntityAddressBo;
29  import org.kuali.rice.kim.impl.identity.address.EntityAddressTypeBo;
30  import org.kuali.rice.kim.impl.identity.entity.EntityBo;
31  import org.kuali.rice.krad.service.BusinessObjectService;
32  import org.kuali.rice.krad.service.KRADServiceLocator;
33  import org.kuali.rice.krad.util.GlobalVariables;
34  import org.kuali.rice.krad.util.KRADConstants;
35  import org.kuali.rice.krad.web.controller.UifControllerBase;
36  import org.kuali.rice.krad.web.form.UifFormBase;
37  import org.springframework.stereotype.Controller;
38  import org.springframework.validation.BindingResult;
39  import org.springframework.web.bind.annotation.ModelAttribute;
40  import org.springframework.web.bind.annotation.RequestMapping;
41  import org.springframework.web.servlet.ModelAndView;
42  
43  import javax.servlet.http.HttpServletRequest;
44  import javax.servlet.http.HttpServletResponse;
45  import java.sql.Date;
46  import java.text.SimpleDateFormat;
47  import java.util.*;
48  
49  /**
50   * Created by arunag on 12/16/14.
51   */
52  @Controller
53  @RequestMapping(value = "/placeRequestController")
54  public class OLEPlaceRequestController extends UifControllerBase{
55  
56      private OLEPlaceRequestConverter olePlaceRequestConverter = new OLEPlaceRequestConverter();
57      private DocstoreClientLocator docstoreClientLocator;
58  
59      private ItemOlemlRecordProcessor itemOlemlRecordProcessor;
60  
61      private BusinessObjectService businessObjectService;
62  
63      private OleCirculationPolicyService oleCirculationPolicyService;
64  
65      private LoanProcessor loanProcessor = new LoanProcessor();
66  
67      private OleDeliverRequestDocumentHelperServiceImpl oleDeliverRequestDocumentHelperService;
68  
69      private OLECirculationService oleCirculationService ;
70  
71      private CircDeskLocationResolver circDeskLocationResolver;
72  
73      private CircDeskLocationResolver getCircDeskLocationResolver() {
74          if (circDeskLocationResolver == null) {
75              circDeskLocationResolver = new CircDeskLocationResolver();
76          }
77          return circDeskLocationResolver;
78      }
79  
80      public void setCircDeskLocationResolver(CircDeskLocationResolver circDeskLocationResolver) {
81          this.circDeskLocationResolver = circDeskLocationResolver;
82      }
83  
84      public DocstoreClientLocator getDocstoreClientLocator() {
85  
86          if (docstoreClientLocator == null) {
87              docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
88  
89          }
90          return docstoreClientLocator;
91      }
92  
93  
94      public ItemOlemlRecordProcessor getItemOlemlRecordProcessor() {
95          if(itemOlemlRecordProcessor == null){
96              itemOlemlRecordProcessor = SpringContext.getBean(ItemOlemlRecordProcessor.class);
97          }
98          return itemOlemlRecordProcessor;
99      }
100 
101     public BusinessObjectService getBusinessObjectService() {
102         if (null == businessObjectService) {
103             businessObjectService = KRADServiceLocator.getBusinessObjectService();
104         }
105         return businessObjectService;
106     }
107 
108     public OleCirculationPolicyService getOleCirculationPolicyService() {
109         if (null == oleCirculationPolicyService) {
110             oleCirculationPolicyService = SpringContext.getBean(OleCirculationPolicyServiceImpl.class);
111         }
112         return oleCirculationPolicyService;
113     }
114 
115     public LoanProcessor getLoanProcessor() {
116         return loanProcessor;
117     }
118 
119     public void setDocstoreClientLocator(DocstoreClientLocator docstoreClientLocator) {
120         this.docstoreClientLocator = docstoreClientLocator;
121     }
122 
123     public void setItemOlemlRecordProcessor(ItemOlemlRecordProcessor itemOlemlRecordProcessor) {
124         this.itemOlemlRecordProcessor = itemOlemlRecordProcessor;
125     }
126 
127     public void setBusinessObjectService(BusinessObjectService businessObjectService) {
128         this.businessObjectService = businessObjectService;
129     }
130 
131     public void setOleCirculationPolicyService(OleCirculationPolicyService oleCirculationPolicyService) {
132         this.oleCirculationPolicyService = oleCirculationPolicyService;
133     }
134 
135     public void setLoanProcessor(LoanProcessor loanProcessor) {
136         this.loanProcessor = loanProcessor;
137     }
138 
139     public OleDeliverRequestDocumentHelperServiceImpl getOleDeliverRequestDocumentHelperService() {
140         if(oleDeliverRequestDocumentHelperService == null){
141             this.oleDeliverRequestDocumentHelperService = new OleDeliverRequestDocumentHelperServiceImpl();
142         }
143         return oleDeliverRequestDocumentHelperService;
144     }
145 
146     public void setOleDeliverRequestDocumentHelperService(OleDeliverRequestDocumentHelperServiceImpl oleDeliverRequestDocumentHelperService) {
147         this.oleDeliverRequestDocumentHelperService = oleDeliverRequestDocumentHelperService;
148     }
149 
150     public OLECirculationService getOleCirculationService() {
151         if(oleCirculationService == null){
152             oleCirculationService = new OLECirculationServiceImpl();
153         }
154         return oleCirculationService;
155     }
156 
157     public void setOleCirculationService(OLECirculationService oleCirculationService) {
158         this.oleCirculationService = oleCirculationService;
159     }
160 
161     private IdentityService identityService;
162 
163     public IdentityService getIdentityService() {
164         if (identityService == null) {
165             identityService = KimApiServiceLocator.getIdentityService();
166         }
167         return identityService;
168     }
169 
170     @Override
171     protected UifFormBase createInitialForm(HttpServletRequest request) {
172         return new OLEPlaceRequestForm();
173     }
174 
175     @Override
176     @RequestMapping(params = "methodToCall=start")
177     public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
178                               HttpServletRequest request, HttpServletResponse response) {
179         OLEPlaceRequestForm olePlaceRequestForm=(OLEPlaceRequestForm)form;
180 
181         org.kuali.ole.docstore.common.document.Item item = null;
182         try {
183             item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(olePlaceRequestForm.getItemId());
184         } catch (Exception e) {
185             e.printStackTrace();
186         }
187         org.kuali.ole.docstore.common.document.content.instance.Item itemContent = getItemOlemlRecordProcessor().fromXML(item.getContent());
188         olePlaceRequestForm.setTitle(item.getHolding().getBib().getTitle());
189         olePlaceRequestForm.setAuthor(item.getHolding().getBib().getAuthor());
190         olePlaceRequestForm.setHoldingId(item.getHolding().getId());
191         olePlaceRequestForm.setItemBarcode(itemContent.getAccessInformation().getBarcode());
192         olePlaceRequestForm.setItemLocation(item.getHolding().getLocationName());
193         olePlaceRequestForm.setItemStatus(itemContent.getItemStatus().getCodeValue());
194         olePlaceRequestForm.setItemType(itemContent.getItemType().getCodeValue());
195        if(itemContent.isClaimsReturnedFlag()){
196                 olePlaceRequestForm.setErrorMessage("Item has been claimed returned .So request cannot be placed for this item");
197                 olePlaceRequestForm.setItemEligible(false);
198                 olePlaceRequestForm.setBlockOverride(true);
199                 olePlaceRequestForm.setBlockSubmit(true);
200            }
201           else if(!validateItemStatus(olePlaceRequestForm)){
202             olePlaceRequestForm.setErrorMessage("Request cannot be place for an item with item status : " + olePlaceRequestForm.getItemStatus());
203             olePlaceRequestForm.setItemEligible(false);
204             olePlaceRequestForm.setBlockOverride(true);
205             olePlaceRequestForm.setBlockSubmit(true);
206         }
207         if(getCircDeskLocationResolver().getLocationMap(olePlaceRequestForm.getItemLocation()).get(OLEConstants.ITEM_SHELVING)!=null){
208             Map<String,String> locationMap = new HashMap<String,String>();
209             locationMap.put("locationCode",getCircDeskLocationResolver().getLocationMap(olePlaceRequestForm.getItemLocation()).get(OLEConstants.ITEM_SHELVING));
210             List<OleLocation> oleLocationBos = (List<OleLocation>)KRADServiceLocator.getBusinessObjectService().findMatching(OleLocation.class,locationMap);
211             if(oleLocationBos!=null && oleLocationBos.size()>0){
212                 Map<String,String> circulationDeskLocationMap = new HashMap<String,String>();
213                 circulationDeskLocationMap.put("circulationDeskLocation",oleLocationBos.get(0).getLocationId());
214                 List<OleCirculationDeskLocation> oleCirculationDeskLocationList = (List<OleCirculationDeskLocation>) KRADServiceLocator.getBusinessObjectService().findMatching(OleCirculationDeskLocation.class,circulationDeskLocationMap);
215                 if(oleCirculationDeskLocationList!=null && oleCirculationDeskLocationList.size()>0){
216                     for(OleCirculationDeskLocation oleCirculationDeskLocation : oleCirculationDeskLocationList){
217                         if(oleCirculationDeskLocation.getCirculationPickUpDeskLocation()==null || (oleCirculationDeskLocation.getCirculationPickUpDeskLocation() !=null && oleCirculationDeskLocation.getCirculationPickUpDeskLocation().trim().isEmpty())) {
218                         String requestExpirationDays= oleCirculationDeskLocation.getOleCirculationDesk().getRequestExpirationDays();
219                             if(requestExpirationDays!=null && !requestExpirationDays.equalsIgnoreCase("0")){
220                                 olePlaceRequestForm.setRequestExpiryDate(addDate(new Date(System.currentTimeMillis()),Integer.parseInt(requestExpirationDays)));
221                             }
222                         }
223                     }
224                 }
225 
226             }
227         }
228         return getUIFModelAndView(form);
229     }
230 
231     @RequestMapping(params = "methodToCall=retrievePatronDetails")
232     public ModelAndView retrievePatronDetails(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
233                                               HttpServletRequest request, HttpServletResponse response) throws Exception {
234         OLEPlaceRequestForm olePlaceRequestForm=(OLEPlaceRequestForm)form;
235         if (olePlaceRequestForm.getPatronBarcode()!=null && !olePlaceRequestForm.getPatronBarcode().isEmpty()) {
236             Map<String, String> patronMap = new HashMap<String, String>();
237             patronMap.put(OLEConstants.OleDeliverRequest.PATRON_BARCODE, olePlaceRequestForm.getPatronBarcode());
238             List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) getBusinessObjectService().findMatching(OlePatronDocument.class, patronMap);
239             if (olePatronDocumentList != null && olePatronDocumentList.size() > 0) {
240                 EntityBo entityBo = olePatronDocumentList.get(0).getEntity();
241                 olePlaceRequestForm.setPatronType(olePatronDocumentList.get(0).getOleBorrowerType().getBorrowerTypeName());
242                 olePlaceRequestForm.setPatronName(getLoanProcessor().getPatronName(entityBo));
243                 olePlaceRequestForm.setPatronFirstName(getLoanProcessor().getPatronName(entityBo));
244                 olePlaceRequestForm.setPatronId(olePatronDocumentList.get(0).getOlePatronId());
245                 olePlaceRequestForm.setPatronBarcode(olePatronDocumentList.get(0).getBarcode());
246                 olePlaceRequestForm.setProcessRequest(false);
247                 olePlaceRequestForm.setOlePatronDocument(olePatronDocumentList.get(0));
248                 olePlaceRequestForm.setPatronFound(true);
249                 String existingAddressType = null;
250                 if(olePlaceRequestForm.getOlePatronDocument() != null && olePlaceRequestForm.getOlePatronDocument().getOleAddresses() != null && olePlaceRequestForm.getOlePatronDocument().getOleAddresses().size() > 0){
251                     for(OleAddressBo oleAddressBo : olePlaceRequestForm.getOlePatronDocument().getOleAddresses()){
252                         if(oleAddressBo.isDeliverAddress()){
253                             for(EntityAddressBo entityAddressBo :olePlaceRequestForm.getOlePatronDocument().getEntity().getEntityTypeContactInfos().get(0).getAddresses()){
254                                if(entityAddressBo.getId().equals(oleAddressBo.getId())){
255                                     olePlaceRequestForm.setOleEntityAddressBo(entityAddressBo);
256                                 }
257                             }
258                             break;
259                         }else{olePlaceRequestForm.setOleEntityAddressBo(new EntityAddressBo());}
260                     }
261                     if(olePlaceRequestForm.getOlePatronDocument() != null && olePlaceRequestForm.getOlePatronDocument().getEntity() != null &&
262                             olePlaceRequestForm.getOlePatronDocument().getEntity().getEntityTypeContactInfos()!=null &&
263                             olePlaceRequestForm.getOlePatronDocument().getEntity().getEntityTypeContactInfos().size()>0 &&
264                             olePlaceRequestForm.getOlePatronDocument().getEntity().getEntityTypeContactInfos().get(0).getAddresses() != null &&
265                             olePlaceRequestForm.getOlePatronDocument().getEntity().getEntityTypeContactInfos().get(0).getAddresses().size()>0 ) {
266                         for(EntityAddressBo entityAddressBo :olePlaceRequestForm.getOlePatronDocument().getEntity().getEntityTypeContactInfos().get(0).getAddresses()) {
267                             if (StringUtils.isNotBlank(existingAddressType)) {
268                                 existingAddressType = existingAddressType + "," + entityAddressBo.getAddressTypeCode();
269                             } else {
270                                 existingAddressType = entityAddressBo.getAddressTypeCode();
271                             }
272                         }
273                     }
274                     olePlaceRequestForm.setExistingAddressType(existingAddressType);
275                 }
276             } else {
277                 olePlaceRequestForm.setErrorMessage("Not a valid patron barcode");
278                 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OleDeliverRequest.INVALID_PATRON);
279             }
280         }
281 
282 
283 
284         return getUIFModelAndView(olePlaceRequestForm);
285     }
286 
287 
288 
289 
290     @RequestMapping(params = "methodToCall=confirmPatron")
291     public ModelAndView confirmPatron(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
292                               HttpServletRequest request, HttpServletResponse response) throws Exception {
293 
294         OLEPlaceRequestForm olePlaceRequestForm=(OLEPlaceRequestForm)form;
295         olePlaceRequestForm.setErrorMessage("");
296         if(olePlaceRequestForm.getOlePatronDocument() != null)
297             olePlaceRequestForm.getOlePatronDocument().setErrorMessage("");
298         OlePatronDocument patronErrorMessage = getOleDeliverRequestDocumentHelperService().validateGeneralChecks(olePlaceRequestForm.getOlePatronDocument());
299         olePlaceRequestForm.setAddressUpdated(false);
300         if(!isRequestAlreadyRaisedByPatron(olePlaceRequestForm.getPatronId(),olePlaceRequestForm.getItemBarcode())){
301 
302         boolean blockPatron = false;
303         if (StringUtils.isBlank(olePlaceRequestForm.getOleEntityAddressBo().getId())) {
304             if(validatePatronNewAddress(olePlaceRequestForm)){
305                 if (StringUtils.isNotBlank((olePlaceRequestForm.getOleEntityAddressBo().getAddressTypeCode()))) {
306                     olePlaceRequestForm.getOleEntityAddressBo().setAddressTypeCode(olePlaceRequestForm.getOleEntityAddressBo().getAddressTypeCode());
307                     olePlaceRequestForm.getOleEntityAddressBo().setAddressType(EntityAddressTypeBo.from(getIdentityService().getAddressType(olePlaceRequestForm.getOleEntityAddressBo().getAddressTypeCode())));
308                     if (StringUtils.isNotBlank(olePlaceRequestForm.getExistingAddressType())) {
309                         if (olePlaceRequestForm.getExistingAddressType() != null && olePlaceRequestForm.getExistingAddressType().contains(olePlaceRequestForm.getOleEntityAddressBo().getAddressTypeCode())) {
310                             blockPatron = true;
311                             String patronNameURL = getLoanProcessor().patronNameURL(GlobalVariables.getUserSession().getPrincipalId(), olePlaceRequestForm.getPatronId());
312                             String url = "<a target=\"_blank\" href=" + patronNameURL + ">" + olePlaceRequestForm.getPatronName() + "</a>";
313                             if(StringUtils.isNotBlank(patronErrorMessage.getErrorMessage())) {
314                                 String[] count =patronErrorMessage.getErrorMessage().split(OLEConstants.BREAK);
315                                 patronErrorMessage.setErrorMessage(patronErrorMessage.getErrorMessage() + (count.length+1)+". The Address type already exist for "+OLEConstants.H5 +url+OLEConstants.H5_CLOSE);
316                             }else {
317                                 patronErrorMessage.setErrorMessage("1. The Address type already exist to " + OLEConstants.H5 + url + OLEConstants.H5_CLOSE);
318                             }
319                             // return getUIFModelAndView(form);
320                         }
321                     }
322                     patronErrorMessage.setBlockPatron(blockPatron);
323                 }
324             }else{
325                 blockPatron = true;
326                 patronErrorMessage.setBlockPatron(blockPatron);
327                 if(StringUtils.isNotBlank(patronErrorMessage.getErrorMessage())) {
328                     String[] count =patronErrorMessage.getErrorMessage().split(OLEConstants.BREAK);
329                     patronErrorMessage.setErrorMessage(patronErrorMessage.getErrorMessage() + (count.length+1)+". Please select address type "+OLEConstants.BREAK);
330                 }else {
331                     patronErrorMessage.setErrorMessage("1. Please select address type " + OLEConstants.BREAK);
332                 }
333             }
334         }
335 
336         if(StringUtils.isNotBlank(patronErrorMessage.getErrorMessage())){
337 
338             olePlaceRequestForm.setBlockOverride(patronErrorMessage.isBlockPatron());
339             olePlaceRequestForm.setErrorMessage(patronErrorMessage.getErrorMessage());
340             return getUIFModelAndView(form);
341         }
342 
343         boolean isDeliverAddress = false;
344         isDeliverAddress = (boolean) getOleDeliverRequestDocumentHelperService().deliverAddressExist(olePlaceRequestForm.getPatronId());
345         olePlaceRequestForm.setAddress(isDeliverAddress);
346         olePlaceRequestForm.setProcessRequest(true);
347         Map<String,List<String>> requestStatusMap = getOleDeliverRequestDocumentHelperService().getItemStatusBasedOnRequestTypeMap();
348         if(requestStatusMap.get("recall").contains(olePlaceRequestForm.getItemStatus())){
349             olePlaceRequestForm.setRecallRequest(true);
350         }
351         if(requestStatusMap.get("hold").contains(olePlaceRequestForm.getItemStatus())){
352             olePlaceRequestForm.setHoldRequest(true);
353         }
354         if(requestStatusMap.get("page").contains(olePlaceRequestForm.getItemStatus())){
355             olePlaceRequestForm.setPageRequest(true);
356         }
357         if(requestStatusMap.get("copy").contains(olePlaceRequestForm.getItemStatus())){
358             olePlaceRequestForm.setCopyRequest(true);
359         }
360         if(requestStatusMap.get("asr").contains(olePlaceRequestForm.getItemStatus())){
361             olePlaceRequestForm.setAsrRequest(true);
362         }
363         String requestLevel =loanProcessor.getParameter("DEFAULT_REQUEST_LEVEL");
364         if(requestLevel.equalsIgnoreCase("Item")){
365             requestLevel = "itemLevel";
366         }else if(requestLevel.equalsIgnoreCase("Title")){
367             requestLevel = "titleLevel";
368         }
369         olePlaceRequestForm.setRequestLevel(requestLevel);
370 
371         String titleLevelRequest =loanProcessor.getParameter("TITLE_LEVEL_REQUEST_INDICATOR");
372         if(titleLevelRequest!=null && titleLevelRequest.equalsIgnoreCase("Y")){
373             olePlaceRequestForm.setTitleLevelRequest(true);
374         }
375         }else{
376             olePlaceRequestForm.setBlockOverride(true);
377             olePlaceRequestForm.setErrorMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RQST_ALRDY_RAISD));
378 
379         }
380 
381         return getUIFModelAndView(form);
382     }
383 
384     @RequestMapping(params = "methodToCall=searchPatron")
385     public ModelAndView searchPatron(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
386                                       HttpServletRequest request, HttpServletResponse response) throws Exception {
387         OLEPlaceRequestForm olePlaceRequestForm=(OLEPlaceRequestForm)form;
388         if (olePlaceRequestForm.getPatronBarcode()!=null && !olePlaceRequestForm.getPatronBarcode().isEmpty()) {
389             Map<String, String> patronMap = new HashMap<String, String>();
390             patronMap.put(OLEConstants.OleDeliverRequest.PATRON_BARCODE, olePlaceRequestForm.getPatronBarcode());
391             List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) getBusinessObjectService().findMatching(OlePatronDocument.class, patronMap);
392             if (olePatronDocumentList != null && olePatronDocumentList.size() > 0) {
393                 EntityBo entityBo = olePatronDocumentList.get(0).getEntity();
394                 olePlaceRequestForm.setPatronType(olePatronDocumentList.get(0).getOleBorrowerType().getBorrowerTypeName());
395                 olePlaceRequestForm.setPatronName(getLoanProcessor().getPatronName(entityBo));
396                 olePlaceRequestForm.setPatronId(olePatronDocumentList.get(0).getOlePatronId());
397                 olePlaceRequestForm.setPatronBarcode(olePatronDocumentList.get(0).getBarcode());
398                 olePlaceRequestForm.setProcessRequest(false);
399                 olePlaceRequestForm.setOlePatronDocument(olePatronDocumentList.get(0));
400                 olePlaceRequestForm.setPatronFound(true);
401 
402             }else{
403                 olePlaceRequestForm.setErrorMessage("Not a valid patron barcode");
404             }
405 
406         }
407      return getUIFModelAndView(form);
408     }
409 
410     @RequestMapping(params = "methodToCall=refresh")
411     public ModelAndView refresh(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
412                                 HttpServletRequest request, HttpServletResponse response) throws Exception {
413         OLEPlaceRequestForm olePlaceRequestForm=(OLEPlaceRequestForm)form;
414         if (StringUtils.isBlank(olePlaceRequestForm.getPatronFirstName()) || (olePlaceRequestForm.getOlePatronDocument() != null && !olePlaceRequestForm.getOlePatronDocument().getBarcode().equals(olePlaceRequestForm.getPatronBarcode()))) {
415             super.refresh(olePlaceRequestForm, result, request, response);
416             olePlaceRequestForm.setErrorMessage(null);
417             return retrievePatronDetails(olePlaceRequestForm, result, request, response);
418         }
419         return super.refresh(olePlaceRequestForm, result, request, response);
420     }
421 
422     @RequestMapping(params = "methodToCall=processRequest")
423     public ModelAndView processRequest(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
424                                 HttpServletRequest request, HttpServletResponse response) throws Exception {
425         OLEPlaceRequestForm olePlaceRequestForm=(OLEPlaceRequestForm)form;
426 
427         return getUIFModelAndView(form);
428     }
429 
430 
431     @RequestMapping(params = "methodToCall=submit")
432     public ModelAndView submit(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
433                                        HttpServletRequest request, HttpServletResponse response) throws Exception {
434         OLEPlaceRequestForm olePlaceRequestForm=(OLEPlaceRequestForm)form;
435         StringBuffer successMessageBuffer = new StringBuffer();
436         StringBuffer failureMessageBuffer = new StringBuffer();
437         olePlaceRequestForm.setErrorMessage(null);
438         olePlaceRequestForm.setSuccessMessage(null);
439         ASRHelperServiceImpl asrHelperService = new ASRHelperServiceImpl();
440         if(olePlaceRequestForm.getPickUpLocationId()!=null && !olePlaceRequestForm.getPickUpLocationId().trim().isEmpty()){
441             OleCirculationDesk oleCirculationDesks = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(OleCirculationDesk.class,olePlaceRequestForm.getPickUpLocationId());
442             olePlaceRequestForm.setPickUpLocationCode(oleCirculationDesks.getCirculationDeskCode());
443         }
444         if(olePlaceRequestForm.getRecallRequestType()!=null){
445             olePlaceRequestForm.setRequestType("recall");
446         }else if(olePlaceRequestForm.getHoldRequestType()!=null){
447             olePlaceRequestForm.setRequestType("hold");
448         }else if(olePlaceRequestForm.getPageRequestType()!=null){
449             olePlaceRequestForm.setRequestType("page");
450         }else if(olePlaceRequestForm.getCopyRequestType()!=null){
451             olePlaceRequestForm.setRequestType("copy");
452         }else if(olePlaceRequestForm.getAsrRequestType()!=null){
453             olePlaceRequestForm.setRequestType("asr");
454         }
455 
456 
457         if(olePlaceRequestForm.getRequestType()==null || (olePlaceRequestForm.getRequestType()!=null && olePlaceRequestForm.getRequestType().trim().isEmpty())){
458             olePlaceRequestForm.setErrorMessage("Please select a request request type");
459             olePlaceRequestForm.setBlockOverride(true);
460             return getUIFModelAndView(form);
461         }
462 
463 
464         if(olePlaceRequestForm.getRequestType().equalsIgnoreCase("recall")){
465             if(olePlaceRequestForm.getPickUpLocationId()==null ||(olePlaceRequestForm.getPickUpLocationId()!=null &&  olePlaceRequestForm.getPickUpLocationId().trim().isEmpty())){
466                 olePlaceRequestForm.setRequestType("Recall/Delivery Request");
467             }else{
468                 olePlaceRequestForm.setRequestType("Recall/Hold Request");
469             }
470         }
471         if(olePlaceRequestForm.getRequestType().equalsIgnoreCase("hold")){
472             if(olePlaceRequestForm.getPickUpLocationId()==null ||(olePlaceRequestForm.getPickUpLocationId()!=null &&  olePlaceRequestForm.getPickUpLocationId().trim().isEmpty())){
473                 olePlaceRequestForm.setRequestType("Hold/Delivery Request");
474             }else{
475                 olePlaceRequestForm.setRequestType("Hold/Hold Request");
476             }
477         }
478         if(olePlaceRequestForm.getRequestType().equalsIgnoreCase("page")){
479             if(olePlaceRequestForm.getPickUpLocationId()==null ||(olePlaceRequestForm.getPickUpLocationId()!=null &&  olePlaceRequestForm.getPickUpLocationId().trim().isEmpty())){
480                 olePlaceRequestForm.setRequestType("Page/Delivery Request");
481             }else{
482                 olePlaceRequestForm.setRequestType("Page/Hold Request");
483             }
484         }
485         if(olePlaceRequestForm.getRequestType().equalsIgnoreCase("copy")){
486             olePlaceRequestForm.setRequestType("Copy Request");
487         }
488         if(olePlaceRequestForm.getRequestType().equalsIgnoreCase("asr")){
489             olePlaceRequestForm.setRequestType("ASR Request");
490         }
491 
492         if(olePlaceRequestForm.getRequestType().equalsIgnoreCase("ASR Request")){
493           if(!asrHelperService.isAnASRItem(olePlaceRequestForm.getItemLocation())){
494               olePlaceRequestForm.setBlockOverride(true);
495               olePlaceRequestForm.setErrorMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_ASR_REQUEST));
496               return getUIFModelAndView(form);
497           }
498         }
499 
500         if(!olePlaceRequestForm.getOlePatronDocument().isDeliveryPrivilege() && (olePlaceRequestForm.getPickUpLocationId()==null || (olePlaceRequestForm.getPickUpLocationId()!=null && olePlaceRequestForm.getPickUpLocationId().trim().isEmpty()))){
501             olePlaceRequestForm.setErrorMessage("Patron is not having the delivery privilege .Choose a pick up Location ");
502             olePlaceRequestForm.setBlockOverride(false);
503             return getUIFModelAndView(form);
504         }
505 
506         if (StringUtils.isNotBlank(olePlaceRequestForm.getOleEntityAddressBo().getId()) &&  !olePlaceRequestForm.isAddressUpdated()){
507             getIdentityService().updateAddress(EntityAddressBo.to(olePlaceRequestForm.getOleEntityAddressBo()));
508             olePlaceRequestForm.setAddressUpdated(true);
509         } else if(StringUtils.isNotBlank(olePlaceRequestForm.getOleEntityAddressBo().getAddressTypeCode())){
510             olePlaceRequestForm.getOleEntityAddressBo().setEntityId(olePlaceRequestForm.getPatronId());
511             if(StringUtils.isNotBlank((olePlaceRequestForm.getOleEntityAddressBo().getAddressTypeCode()))) {
512                 olePlaceRequestForm.getOleEntityAddressBo().setAddressTypeCode(olePlaceRequestForm.getOleEntityAddressBo().getAddressTypeCode());
513                 olePlaceRequestForm.getOleEntityAddressBo().setAddressType(EntityAddressTypeBo.from(getIdentityService().getAddressType(olePlaceRequestForm.getOleEntityAddressBo().getAddressTypeCode())));
514             }
515             olePlaceRequestForm.getOleEntityAddressBo().setEntityTypeCode("PERSON");
516             olePlaceRequestForm.getOleEntityAddressBo().setActive(true);
517             if(StringUtils.isNotBlank(olePlaceRequestForm.getExistingAddressType())){
518                 if(olePlaceRequestForm.getExistingAddressType() != null && olePlaceRequestForm.getExistingAddressType().contains(olePlaceRequestForm.getOleEntityAddressBo().getAddressTypeCode())){
519                     String patronNameURL = getLoanProcessor().patronNameURL(GlobalVariables.getUserSession().getPrincipalId(), olePlaceRequestForm.getPatronId());
520                     String url="<a target=\"_blank\" href="+patronNameURL+">"+olePlaceRequestForm.getPatronName()+"</a>";
521                     //failureMessageBuffer.append("The Address type already exist to "+OLEConstants.H5+url+OLEConstants.H5_CLOSE);
522                     olePlaceRequestForm.setBlockOverride(true);
523                     olePlaceRequestForm.setErrorMessage("The Address type already exist to "+OLEConstants.H5+url+OLEConstants.H5_CLOSE);
524                     return getUIFModelAndView(form);
525                 }else {
526                     EntityAddress entityAddress = getIdentityService().addAddressToEntity(EntityAddressBo.to(olePlaceRequestForm.getOleEntityAddressBo()));
527                     HashMap<String, String> map = new HashMap<String, String>();
528                     map.put(OLEConstants.OlePatron.OLE_ADD_SRC_CD, "OPT");
529                     List<OleAddressSourceBo> addressSourceList = (List<OleAddressSourceBo>) getBusinessObjectService().findMatching(OleAddressSourceBo.class, map);
530                     OleAddressBo oleAddressBo = new OleAddressBo();
531                     oleAddressBo.setId(entityAddress.getId());
532                     oleAddressBo.setDeliverAddress(true);
533                     oleAddressBo.setAddressVerified(true);
534                     oleAddressBo.setOleAddressId(KRADServiceLocator.getSequenceAccessorService().getNextAvailableSequenceNumber("OLE_DLVR_ADD_S").toString());
535                     oleAddressBo.setOlePatronId(olePlaceRequestForm.getPatronId());
536                     oleAddressBo.setAddressSource(addressSourceList!=null && addressSourceList.size()>0?addressSourceList.get(0).getOleAddressSourceId():null);
537                     oleAddressBo.setAddressSourceBo(addressSourceList!=null && addressSourceList.size()>0?addressSourceList.get(0):null);
538                     KRADServiceLocator.getBusinessObjectService().save(oleAddressBo);
539                 }
540             }
541 
542         }
543 
544         SimpleDateFormat expirationDate = new SimpleDateFormat("yyyyMMdd");
545         if(olePlaceRequestForm.getRequestLevel().equals("itemLevel")){
546 
547          String circulationResponse = getOleCirculationService().placeRequest(olePlaceRequestForm.getPatronBarcode(),GlobalVariables.getUserSession().getPrincipalId(),olePlaceRequestForm.getItemBarcode(),olePlaceRequestForm.getRequestType(),olePlaceRequestForm.getPickUpLocationCode(),olePlaceRequestForm.getItemLocation(),olePlaceRequestForm.getBibId(),"Item Level",olePlaceRequestForm.getRequestExpiryDate());
548             OLEPlaceRequest olePlaceRequest = (OLEPlaceRequest) olePlaceRequestConverter.generatePlaceRequestObject(circulationResponse);
549             if(olePlaceRequest.getMessage().contains(OLEConstants.RQST_SUCCESS)){
550                 successMessageBuffer.append(olePlaceRequest.getMessage() + " with Barcode "+olePlaceRequestForm.getItemBarcode() +OLEConstants.BREAK);
551             }else{
552                 failureMessageBuffer.append(olePlaceRequest.getMessage() + OLEConstants.BREAK);
553             }
554             if(olePlaceRequest.getMessage().equalsIgnoreCase(OLEConstants.NO_RULE_FOUND) || olePlaceRequest.getMessage().equalsIgnoreCase(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RQST_ALRDY_RAISD))){
555                 olePlaceRequest.setBlockOverride(true);
556             }
557             if(olePlaceRequest.getExpirationDate()!=null) {
558                 olePlaceRequestForm.setRequestExpiryDate(new java.sql.Date(expirationDate.parse(olePlaceRequest.getExpirationDate()).getTime()));
559             }
560             olePlaceRequestForm.setBlockOverride(olePlaceRequest.isBlockOverride());
561             olePlaceRequestForm.setSuccessMessage(successMessageBuffer.toString());
562             olePlaceRequestForm.setErrorMessage(failureMessageBuffer.toString());
563         }
564 
565         if(olePlaceRequestForm.getRequestLevel().equals("titleLevel")){
566             try{
567                 OLEPlaceRequest olePlaceRequest = null;
568                 String circulationResponse = null;
569                 boolean overrideBlock = false;
570                 if(olePlaceRequestForm.getTitleLevelRequestItems()!=null && olePlaceRequestForm.getTitleLevelRequestItems().size()>0){
571                   for(OleTitleLevelRequestItem oleTitleLevelRequestItem :olePlaceRequestForm.getTitleLevelRequestItems()){
572                       circulationResponse = getOleCirculationService().placeRequest(olePlaceRequestForm.getPatronBarcode(),GlobalVariables.getUserSession().getPrincipalId(),oleTitleLevelRequestItem.getItemBarcode(),olePlaceRequestForm.getRequestType(),olePlaceRequestForm.getPickUpLocationCode(),oleTitleLevelRequestItem.getItemLocation(),olePlaceRequestForm.getBibId(),"Title Level",olePlaceRequestForm.getRequestExpiryDate());
573                       olePlaceRequest = (OLEPlaceRequest) olePlaceRequestConverter.generatePlaceRequestObject(circulationResponse);
574                       overrideBlock = olePlaceRequest.isBlockOverride();
575                       if(olePlaceRequest.getMessage().contains(OLEConstants.RQST_SUCCESS)){
576                           successMessageBuffer.append(olePlaceRequest.getMessage() + " with Barcode "+oleTitleLevelRequestItem.getItemBarcode() +OLEConstants.BREAK);
577                       }else{
578                           failureMessageBuffer.append(olePlaceRequest.getMessage() +OLEConstants.BREAK);
579                       }
580                   }
581                 }else{
582                     olePlaceRequestForm.setBlockOverride(true);
583                     olePlaceRequestForm.setErrorMessage("Please select an item for placing a request");
584                   return  getUIFModelAndView(form);
585                 }
586                 if(olePlaceRequest.getExpirationDate()!=null) {
587                     olePlaceRequestForm.setRequestExpiryDate(new java.sql.Date(expirationDate.parse(olePlaceRequest.getExpirationDate()).getTime()));
588                 }
589                 olePlaceRequestForm.setBlockOverride(overrideBlock);
590                 olePlaceRequestForm.setSuccessMessage(successMessageBuffer.toString());
591                 olePlaceRequestForm.setErrorMessage(failureMessageBuffer.toString());
592             }catch(Exception e){
593                 e.printStackTrace();
594             }
595         }
596 
597         return getUIFModelAndView(form);
598     }
599 
600     @RequestMapping(params = "methodToCall=overRide")
601     public ModelAndView overRide(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
602                                  HttpServletRequest request, HttpServletResponse response) {
603         OLEPlaceRequestForm olePlaceRequestForm = (OLEPlaceRequestForm) form;
604             olePlaceRequestForm.setErrorMessage(null);
605             olePlaceRequestForm.setOverrideFlag(true);
606             String principalId = GlobalVariables.getUserSession().getPrincipalId();
607             boolean newPrincipalFlag = false;
608             if (olePlaceRequestForm.getNewPrincipalId() != null && !olePlaceRequestForm.getNewPrincipalId().trim().isEmpty()) {
609                 principalId = olePlaceRequestForm.getNewPrincipalId();
610                 newPrincipalFlag = true;
611             }
612             //  Boolean overRideFlag = getLoanProcessor().checkOverRidePermission(principalId, olePlaceRequestForm);
613             Boolean overRideFlag = false;
614             if (overRideFlag) {
615                 if ((!"".equals(olePlaceRequestForm.getNewPrincipalId()) && olePlaceRequestForm.getNewPrincipalId() != null)) {
616                     olePlaceRequestForm.setLoanLoginName(olePlaceRequestForm.getNewPrincipalId());
617                     GlobalVariables.getUserSession().setBackdoorUser(olePlaceRequestForm.getNewPrincipalId());
618                     //oleLoanForm.getDummyLoan().setLoanApproverId(GlobalVariables.getUserSession().getPerson().getEntityId());
619                 }
620                 if (!newPrincipalFlag) {
621                     olePlaceRequestForm.setLoanLoginName(principalId);
622                     GlobalVariables.getUserSession().setBackdoorUser(principalId);
623                 }
624                 olePlaceRequestForm.setNewPrincipalId("");
625                 olePlaceRequestForm.setOverrideFlag(false);
626                 // olePlaceRequestForm.setOverideMethodCall("");
627                 return null;
628             }
629             olePlaceRequestForm.setNewPrincipalId(null);
630             GlobalVariables.getUserSession().clearBackdoorUser();
631             if (!"".equals(olePlaceRequestForm.getNewPrincipalId())) {
632                 olePlaceRequestForm.setOverrideLoginMessage(principalId + " " + OLEConstants.OVERRIDE_LOGIN_ERR_INFO + OLEConstants.BREAK + olePlaceRequestForm.getOverrideErrorMessage());
633                 olePlaceRequestForm.setOverrideErrorMessage(null);
634             }
635 
636         return getUIFModelAndView(olePlaceRequestForm, olePlaceRequestForm.getPageId());
637     }
638 
639 
640     @RequestMapping(params = "methodToCall=overrideRequest")
641     public ModelAndView overrideRequest(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
642                                                      HttpServletRequest request, HttpServletResponse response) throws Exception {
643         OLEPlaceRequestForm olePlaceRequestForm=(OLEPlaceRequestForm)form;
644       olePlaceRequestForm.setErrorMessage(null);
645         if(!olePlaceRequestForm.isProcessRequest()) {
646             boolean isDeliverAddress = false;
647             isDeliverAddress = (boolean) getOleDeliverRequestDocumentHelperService().deliverAddressExist(olePlaceRequestForm.getPatronId());
648             olePlaceRequestForm.setAddress(isDeliverAddress);
649             olePlaceRequestForm.setProcessRequest(true);
650             Map<String, List<String>> requestStatusMap = getOleDeliverRequestDocumentHelperService().getItemStatusBasedOnRequestTypeMap();
651             if (requestStatusMap.get("recall").contains(olePlaceRequestForm.getItemStatus())) {
652                 olePlaceRequestForm.setRecallRequest(true);
653             }
654             if (requestStatusMap.get("hold").contains(olePlaceRequestForm.getItemStatus())) {
655                 olePlaceRequestForm.setHoldRequest(true);
656             }
657             if (requestStatusMap.get("page").contains(olePlaceRequestForm.getItemStatus())) {
658                 olePlaceRequestForm.setPageRequest(true);
659             }
660             if (requestStatusMap.get("copy").contains(olePlaceRequestForm.getItemStatus())) {
661                 olePlaceRequestForm.setCopyRequest(true);
662             }
663             if (requestStatusMap.get("asr").contains(olePlaceRequestForm.getItemStatus())) {
664                 olePlaceRequestForm.setAsrRequest(true);
665             }
666             String requestLevel = loanProcessor.getParameter("DEFAULT_REQUEST_LEVEL");
667             if (requestLevel.equalsIgnoreCase("Item")) {
668                 requestLevel = "itemLevel";
669             } else if (requestLevel.equalsIgnoreCase("Title")) {
670                 requestLevel = "titleLevel";
671             }
672             olePlaceRequestForm.setRequestLevel(requestLevel);
673 
674             String titleLevelRequest = loanProcessor.getParameter("TITLE_LEVEL_REQUEST_INDICATOR");
675             if (titleLevelRequest != null && titleLevelRequest.equalsIgnoreCase("Y")) {
676                 olePlaceRequestForm.setTitleLevelRequest(true);
677             }
678 
679 
680         }else {
681 
682             StringBuffer successMessageBuffer = new StringBuffer();
683             StringBuffer failureMessageBuffer = new StringBuffer();
684             olePlaceRequestForm.setErrorMessage(null);
685             olePlaceRequestForm.setSuccessMessage(null);
686             ModelAndView overrideModelView = null;
687             String principalId = GlobalVariables.getUserSession().getPrincipalId();
688             //Boolean overRideFlag = getLoanProcessor().checkOverRidePermission(principalId, olePlaceRequestForm);
689             //if (!overRideFlag) {
690             //overrideModelView = this.overRide(form, result, request, response);
691             // }
692            /* if (StringUtils.isNotBlank(olePlaceRequestForm.getOleEntityAddressBo().getId())) {
693                 getIdentityService().updateAddress(EntityAddressBo.to(olePlaceRequestForm.getOleEntityAddressBo()));
694             } else {
695                 olePlaceRequestForm.getOleEntityAddressBo().setEntityId(olePlaceRequestForm.getPatronId());
696                 if(StringUtils.isNotBlank((olePlaceRequestForm.getOleEntityAddressBo().getAddressTypeCode()))) {
697                     olePlaceRequestForm.getOleEntityAddressBo().setAddressTypeCode(olePlaceRequestForm.getOleEntityAddressBo().getAddressTypeCode());
698                     olePlaceRequestForm.getOleEntityAddressBo().setAddressType(EntityAddressTypeBo.from(getIdentityService().getAddressType(olePlaceRequestForm.getOleEntityAddressBo().getAddressTypeCode())));
699                 }
700                 olePlaceRequestForm.getOleEntityAddressBo().setEntityTypeCode("PERSON");
701                 olePlaceRequestForm.getOleEntityAddressBo().setActive(true);
702                 if(StringUtils.isNotBlank(olePlaceRequestForm.getExistingAddressType())){
703                     if(olePlaceRequestForm.getOleEntityAddressBo().getAddressTypeCode().contains(olePlaceRequestForm.getExistingAddressType())){
704                         String patronNameURL = getLoanProcessor().patronNameURL(GlobalVariables.getUserSession().getPrincipalId(), olePlaceRequestForm.getPatronId());
705                         String url="<a target=\"_blank\" href="+patronNameURL+">"+olePlaceRequestForm.getPatronName()+"</a>";
706                         successMessageBuffer.append("The Address type already exist to "+OLEConstants.H5+url+OLEConstants.H5_CLOSE);
707                         olePlaceRequestForm.setBlockOverride(true);
708                         return getUIFModelAndView(form);
709                     }else {
710                         getIdentityService().addAddressToEntity(EntityAddressBo.to(olePlaceRequestForm.getOleEntityAddressBo()));
711                     }
712                 }
713 
714             }*/
715             SimpleDateFormat expirationDate = new SimpleDateFormat("yyyyMMdd");
716             if (olePlaceRequestForm.getRequestLevel().equals("itemLevel")) {
717                 String circulationResponse = "";
718                 circulationResponse = getOleCirculationService().overridePlaceRequest(olePlaceRequestForm.getPatronBarcode(), GlobalVariables.getUserSession().getPrincipalId(), olePlaceRequestForm.getItemBarcode(), olePlaceRequestForm.getRequestType(), olePlaceRequestForm.getPickUpLocationCode(), olePlaceRequestForm.getItemLocation(), olePlaceRequestForm.getBibId(), "Item Level", olePlaceRequestForm.getRequestExpiryDate());
719                 OLEPlaceRequest olePlaceRequest = (OLEPlaceRequest) olePlaceRequestConverter.generatePlaceRequestObject(circulationResponse);
720               if(olePlaceRequest.getMessage().equals(OLEConstants.NO_RULE_FOUND) || olePlaceRequest.getMessage().equalsIgnoreCase(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RQST_ALRDY_RAISD))){
721                   failureMessageBuffer.append(olePlaceRequest.getMessage());
722                   olePlaceRequest.setBlockOverride(true);
723                   olePlaceRequestForm.setBlockOverride(true);
724               }
725                     else if (olePlaceRequest.getMessage().contains(OLEConstants.RQST_SUCCESS)) {
726                     successMessageBuffer.append(olePlaceRequest.getMessage() + " with Barcode " + olePlaceRequestForm.getItemBarcode() + OLEConstants.BREAK);
727                     if(olePlaceRequest.getExpirationDate()!=null) {
728                         olePlaceRequestForm.setRequestExpiryDate(new java.sql.Date(expirationDate.parse(olePlaceRequest.getExpirationDate()).getTime()));
729                     }
730                 }else{
731                   failureMessageBuffer.append(olePlaceRequest.getMessage());
732                   if(olePlaceRequest.getMessage()!=null && olePlaceRequest.getMessage().contains("Cannot create")){
733                   olePlaceRequestForm.setBlockOverride(true);
734                   }
735               }
736                 olePlaceRequestForm.setSuccessMessage(successMessageBuffer.toString());
737                 olePlaceRequestForm.setErrorMessage(failureMessageBuffer.toString());
738             }
739 
740             if (olePlaceRequestForm.getRequestLevel().equals("titleLevel")) {
741                 try {
742                     OLEPlaceRequest olePlaceRequest = null;
743                     String circulationResponse = null;
744 
745                     if (olePlaceRequestForm.getTitleLevelRequestItems() != null && olePlaceRequestForm.getTitleLevelRequestItems().size() > 0) {
746                         for (OleTitleLevelRequestItem oleTitleLevelRequestItem : olePlaceRequestForm.getTitleLevelRequestItems()) {
747                             circulationResponse = getOleCirculationService().overridePlaceRequest(olePlaceRequestForm.getPatronBarcode(), GlobalVariables.getUserSession().getPrincipalId(), oleTitleLevelRequestItem.getItemBarcode(), olePlaceRequestForm.getRequestType(), olePlaceRequestForm.getPickUpLocationCode(), oleTitleLevelRequestItem.getItemLocation(), olePlaceRequestForm.getBibId(), "Title Level", olePlaceRequestForm.getRequestExpiryDate());
748                             olePlaceRequest = (OLEPlaceRequest) olePlaceRequestConverter.generatePlaceRequestObject(circulationResponse);
749                             if(olePlaceRequest.getMessage().equals(OLEConstants.NO_RULE_FOUND) || olePlaceRequest.getMessage().equalsIgnoreCase(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RQST_ALRDY_RAISD))){
750                                 failureMessageBuffer.append(olePlaceRequest.getMessage());
751                                 olePlaceRequest.setBlockOverride(false);
752                                 olePlaceRequestForm.setBlockOverride(false);
753                             }
754                             else  if (olePlaceRequest.getMessage().contains(OLEConstants.RQST_SUCCESS)) {
755                                 successMessageBuffer.append(olePlaceRequest.getMessage() + " with Barcode " + oleTitleLevelRequestItem.getItemBarcode() + OLEConstants.BREAK);
756                                 if(olePlaceRequest.getExpirationDate()!=null) {
757                                     olePlaceRequestForm.setRequestExpiryDate(new java.sql.Date(expirationDate.parse(olePlaceRequest.getExpirationDate()).getTime()));
758                                 }
759                             }
760                         }
761                     }
762                     olePlaceRequestForm.setSuccessMessage(successMessageBuffer.toString());
763                     olePlaceRequestForm.setErrorMessage(failureMessageBuffer.toString());
764                 } catch (Exception e) {
765                     e.printStackTrace();
766                 }
767             }
768         }
769 
770         return getUIFModelAndView(form);
771     }
772 
773     @RequestMapping(params = "methodToCall=getItemsForTitleLevelRequest")
774     public ModelAndView getItemsForTitleLevelRequest(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
775                                        HttpServletRequest request, HttpServletResponse response) throws Exception {
776         OLEPlaceRequestForm olePlaceRequestForm=(OLEPlaceRequestForm)form;
777         String bibIb = olePlaceRequestForm.getBibId();
778         List<OleTitleLevelRequestItem> titleLevelRequestItems = new ArrayList<OleTitleLevelRequestItem>();
779         OleTitleLevelRequestItem oleTitleLevelRequestItem;
780         try{
781             OLEPlaceRequest olePlaceRequest = null;
782             String circulationResponse = null;
783             StringBuffer successMessageBuffer = new StringBuffer();
784             StringBuffer failureMessageBuffer = new StringBuffer();
785             BibTree bibTree =  getDocstoreClientLocator().getDocstoreClient().retrieveBibTree(bibIb);
786             if(bibTree!=null && bibTree.getHoldingsTrees()!=null){
787                 for(HoldingsTree holdingsTree : bibTree.getHoldingsTrees()){
788                     if(holdingsTree!=null && holdingsTree.getItems()!=null){
789                         for(Item item : holdingsTree.getItems()){
790                             org.kuali.ole.docstore.common.document.content.instance.Item itemContent = getItemOlemlRecordProcessor().fromXML(item.getContent());
791                             if(itemContent.getAccessInformation()!=null && itemContent.getAccessInformation().getBarcode()!=null){
792                             oleTitleLevelRequestItem = new OleTitleLevelRequestItem();
793                             oleTitleLevelRequestItem.setItemStatus(itemContent.getItemStatus().getCodeValue());
794                             oleTitleLevelRequestItem.setHoldingsId(item.getHolding().getId());
795                             oleTitleLevelRequestItem.setItemBarcode(itemContent.getAccessInformation().getBarcode());
796                             oleTitleLevelRequestItem.setItemLocation(item.getHolding().getLocationName());
797                             oleTitleLevelRequestItem.setItemType(itemContent.getItemType().getCodeValue());
798                             oleTitleLevelRequestItem.setVolumeNumber(itemContent.getEnumeration());
799                             titleLevelRequestItems.add(oleTitleLevelRequestItem);
800                             }
801                         }
802 
803                     }
804 
805                 }
806             }
807             olePlaceRequestForm.setTitleLevelRequestItems(titleLevelRequestItems);
808 
809         }catch(Exception e){
810             e.printStackTrace();
811         }
812         return getUIFModelAndView(form);
813     }
814 
815 
816     @RequestMapping(params = "methodToCall=getSelectedItemsFromResults")
817     public ModelAndView getSelectedItemsFromResults(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
818                                                      HttpServletRequest request, HttpServletResponse response) throws Exception {
819 
820         OLEPlaceRequestForm olePlaceRequestForm=(OLEPlaceRequestForm)form;
821         List<OleTitleLevelRequestItem> oleTitleLevelRequestItems = new ArrayList<>();
822         if(olePlaceRequestForm.getTitleLevelRequestItems()!=null && olePlaceRequestForm.getTitleLevelRequestItems().size()>0){
823             for(OleTitleLevelRequestItem oleTitleLevelRequestItem : olePlaceRequestForm.getTitleLevelRequestItems()){
824                 if(oleTitleLevelRequestItem.isSelectedItem()){
825                     oleTitleLevelRequestItems.add(oleTitleLevelRequestItem);
826                 }
827             }
828         }
829         olePlaceRequestForm.setTitleLevelRequestItems(oleTitleLevelRequestItems);
830 
831         return getUIFModelAndView(form);
832 
833     }
834     @RequestMapping(params = "methodToCall=clearItemsForTitleLevelRequest")
835     public ModelAndView clearItemsForTitleLevelRequest(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
836                                                     HttpServletRequest request, HttpServletResponse response) throws Exception {
837 
838         OLEPlaceRequestForm olePlaceRequestForm=(OLEPlaceRequestForm)form;
839         List<OleTitleLevelRequestItem> oleTitleLevelRequestItems = new ArrayList<>();
840         olePlaceRequestForm.setTitleLevelRequestItems(oleTitleLevelRequestItems);
841 
842         return getUIFModelAndView(form);
843 
844     }
845 
846 
847     @RequestMapping(params = "methodToCall=cancelRequest")
848     public ModelAndView cancelRequest(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
849                                                        HttpServletRequest request, HttpServletResponse response) throws Exception {
850 
851         OLEPlaceRequestForm olePlaceRequestForm=(OLEPlaceRequestForm)form;
852         olePlaceRequestForm.setRecallRequestType(null);
853         olePlaceRequestForm.setPageRequestType(null);
854         olePlaceRequestForm.setCopyRequestType(null);
855         olePlaceRequestForm.setAsrRequestType(null);
856         olePlaceRequestForm.setHoldRequestType(null);
857         return getUIFModelAndView(form);
858 
859     }
860 
861     private java.sql.Date addDate(java.sql.Date in, int daysToAdd) {
862         if (in == null) {
863             return null;
864         }
865         GregorianCalendar cal = new GregorianCalendar();
866         cal.setTime(in);
867         cal.add(Calendar.DAY_OF_MONTH, daysToAdd);
868         return new java.sql.Date(cal.getTime().getTime());
869     }
870 
871     public boolean validatePatronNewAddress(OLEPlaceRequestForm olePlaceRequestForm){
872         boolean validAddress = true;
873         EntityAddressBo oleEntityAddressBo = olePlaceRequestForm.getOleEntityAddressBo();
874         if(StringUtils.isNotBlank(oleEntityAddressBo.getLine1()) || StringUtils.isNotBlank(oleEntityAddressBo.getLine2()) ||StringUtils.isNotBlank(oleEntityAddressBo.getLine3())
875                || StringUtils.isNotBlank(oleEntityAddressBo.getCity()) || StringUtils.isNotBlank(oleEntityAddressBo.getStateProvinceCode()) || StringUtils.isNotBlank(oleEntityAddressBo.getPostalCode())
876                 || StringUtils.isNotBlank(oleEntityAddressBo.getCountryCode())){
877             if(StringUtils.isBlank(oleEntityAddressBo.getAddressTypeCode())){
878                 validAddress = false;
879             }
880         }
881         return validAddress;
882 
883     }
884 
885     public boolean validateItemStatus(OLEPlaceRequestForm olePlaceRequestForm){
886         boolean valid = false;
887         String copyRequestItemStatus = getLoanProcessor().getParameter(OLEConstants.COPY_REQUEST_ITEM_STATUS);
888         if (StringUtils.isNotBlank(copyRequestItemStatus)) {
889             String[] itemStatusArray = copyRequestItemStatus.split(";");
890             for(String itemStatus : itemStatusArray){
891                 if(itemStatus.trim().equalsIgnoreCase(olePlaceRequestForm.getItemStatus())){
892                     valid = true;
893                     return valid;
894                 }
895             }
896         }
897 
898         String holdDeliveryItemStatus = getLoanProcessor().getParameter(OLEConstants.HOLD_DELIVERY_ITEM_STATUS);
899         if (StringUtils.isNotBlank(holdDeliveryItemStatus)) {
900             String[] itemStatusArray = holdDeliveryItemStatus.split(";");
901             for(String itemStatus : itemStatusArray){
902                 if(itemStatus.trim().equalsIgnoreCase(olePlaceRequestForm.getItemStatus())){
903                     valid = true;
904                     return valid;
905                 }
906             }
907         }
908         String holdHoldItemStatus = getLoanProcessor().getParameter(OLEConstants.HOLD_HOLD_ITEM_STATUS);
909         if (StringUtils.isNotBlank(holdHoldItemStatus)) {
910             String[] itemStatusArray = holdHoldItemStatus.split(";");
911             for(String itemStatus : itemStatusArray){
912                 if(itemStatus.trim().equalsIgnoreCase(olePlaceRequestForm.getItemStatus())){
913                     valid = true;
914                     return valid;
915                 }
916             }
917         }
918         String pageDeliveryItemStatus = getLoanProcessor().getParameter(OLEConstants.PAGE_DELIVERY_ITEM_STATUS);
919         if (StringUtils.isNotBlank(pageDeliveryItemStatus)) {
920             String[] itemStatusArray = pageDeliveryItemStatus.split(";");
921             for(String itemStatus : itemStatusArray){
922                 if(itemStatus.trim().equalsIgnoreCase(olePlaceRequestForm.getItemStatus())){
923                     valid = true;
924                     return valid;
925                 }
926             }
927         }
928         String pageHoldItemStatus = getLoanProcessor().getParameter(OLEConstants.PAGE_HOLD_ITEM_STATUS);
929         if (StringUtils.isNotBlank(pageHoldItemStatus)) {
930             String[] itemStatusArray = pageHoldItemStatus.split(";");
931             for(String itemStatus : itemStatusArray){
932                 if(itemStatus.trim().equalsIgnoreCase(olePlaceRequestForm.getItemStatus())){
933                     valid = true;
934                     return valid;
935                 }
936             }
937         }
938         String recallDeliveryItemStatus = getLoanProcessor().getParameter(OLEConstants.RECALL_DELIVERY_ITEM_STATUS);
939         if (StringUtils.isNotBlank(recallDeliveryItemStatus)) {
940             String[] itemStatusArray = recallDeliveryItemStatus.split(";");
941             for(String itemStatus : itemStatusArray){
942                 if(itemStatus.trim().equalsIgnoreCase(olePlaceRequestForm.getItemStatus())){
943                     valid = true;
944                     return valid;
945                 }
946             }
947         }
948         String recallHoldItemStatus = getLoanProcessor().getParameter(OLEConstants.RECALL_HOLD_ITEM_STATUS);
949         if (StringUtils.isNotBlank(recallHoldItemStatus)) {
950             String[] itemStatusArray = recallHoldItemStatus.split(";");
951             for(String itemStatus : itemStatusArray){
952                 if(itemStatus.trim().equalsIgnoreCase(olePlaceRequestForm.getItemStatus())){
953                     valid = true;
954                     return valid;
955                 }
956             }
957         }
958         return valid;
959     }
960 
961     public boolean isRequestAlreadyRaisedByPatron(String patronId,String itemId){
962       boolean requestExist = false;
963         List<OleDeliverRequestBo> oleDeliverRequestBoList ;
964         Map<String,String> requestMap =new HashMap<String,String>();
965         requestMap.put("borrowerId",patronId);
966         requestMap.put("itemId",itemId);
967         oleDeliverRequestBoList = (List<OleDeliverRequestBo>)getBusinessObjectService().findMatching(OleDeliverRequestBo.class,requestMap);
968               if(oleDeliverRequestBoList.size()>0){
969                   requestExist = true;
970               }
971                 return requestExist;
972     }
973 
974 
975 }
976