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