View Javadoc
1   package org.kuali.ole.ncip.service.impl;
2   
3   import org.apache.log4j.Logger;
4   import org.extensiblecatalog.ncip.v2.service.*;
5   import org.kuali.ole.OLEConstants;
6   import org.kuali.ole.deliver.processor.LoanProcessor;
7   import org.kuali.ole.ncip.bo.OLECancelRequest;
8   import org.kuali.ole.ncip.bo.OLENCIPConstants;
9   import org.kuali.ole.ncip.converter.OLECancelRequestConverter;
10  import org.kuali.ole.ncip.service.OLECancelRequestItemService;
11  import org.kuali.ole.ncip.service.OLECirculationService;
12  import org.kuali.ole.sys.context.SpringContext;
13  import org.kuali.rice.core.api.config.property.ConfigContext;
14  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
15  
16  import java.util.ArrayList;
17  import java.util.HashMap;
18  import java.util.List;
19  
20  /**
21   * Created with IntelliJ IDEA.
22   * User: maheswarang
23   * Date: 2/19/14
24   * Time: 4:08 PM
25   * To change this template use File | Settings | File Templates.
26   */
27  public class OLECancelRequestItemServiceImpl implements OLECancelRequestItemService {
28      private static final Logger LOG = Logger.getLogger(OLECancelRequestItemServiceImpl.class);
29      private OLECirculationService oleCirculationService;
30      private OLECirculationHelperServiceImpl oleCirculationHelperService;
31      private OLECancelRequestConverter oleCancelRequestConverter = new OLECancelRequestConverter();
32      private LoanProcessor loanProcessor;
33  
34      public LoanProcessor getLoanProcessor() {
35          if (loanProcessor == null) {
36              loanProcessor = SpringContext.getBean(LoanProcessor.class);
37          }
38          return loanProcessor;
39      }
40  
41      public OLECirculationService getOleCirculationService() {
42          if (null == oleCirculationService) {
43              oleCirculationService = GlobalResourceLoader.getService(OLENCIPConstants.CIRCULATION_SERVICE);
44          }
45          return oleCirculationService;
46      }
47  
48      public void setOleCirculationService(OLECirculationService oleCirculationService) {
49          this.oleCirculationService = oleCirculationService;
50      }
51  
52      public OLECirculationHelperServiceImpl getOleCirculationHelperService() {
53          if (null == oleCirculationHelperService) {
54              oleCirculationHelperService = GlobalResourceLoader.getService(OLENCIPConstants.CIRCULATION_HELPER_SERVICE);
55          }
56          return oleCirculationHelperService;
57      }
58  
59      public void setOleCirculationHelperService(OLECirculationHelperServiceImpl oleCirculationHelperService) {
60          this.oleCirculationHelperService = oleCirculationHelperService;
61      }
62  
63      public OLECancelRequestConverter getOleCancelRequestConverter() {
64          return oleCancelRequestConverter;
65      }
66  
67      public void setOleCancelRequestConverter(OLECancelRequestConverter oleCancelRequestConverter) {
68          this.oleCancelRequestConverter = oleCancelRequestConverter;
69      }
70  
71      @Override
72      public CancelRequestItemResponseData performService(CancelRequestItemInitiationData cancelRequestItemInitiationData, ServiceContext serviceContext, RemoteServiceManager remoteServiceManager) throws ServiceException {
73          CancelRequestItemResponseData cancelRequestItemResponseData = new CancelRequestItemResponseData();
74          oleCirculationService = getOleCirculationService();
75          oleCirculationHelperService = getOleCirculationHelperService();
76          List<Problem> problems = new ArrayList<Problem>();
77          AgencyId agencyId = null;
78          Problem problem = new Problem();
79          ProblemType problemType = new ProblemType("");
80          if (cancelRequestItemInitiationData.getInitiationHeader() != null && cancelRequestItemInitiationData.getInitiationHeader().getFromAgencyId() != null && cancelRequestItemInitiationData.getInitiationHeader().getFromAgencyId().getAgencyId() != null && cancelRequestItemInitiationData.getInitiationHeader().getFromAgencyId().getAgencyId().getValue() != null && !cancelRequestItemInitiationData.getInitiationHeader().getFromAgencyId().getAgencyId().getValue().trim().isEmpty()) {
81              agencyId = new AgencyId(cancelRequestItemInitiationData.getInitiationHeader().getFromAgencyId().getAgencyId().getValue());
82          } else if (cancelRequestItemInitiationData.getInitiationHeader() != null && cancelRequestItemInitiationData.getInitiationHeader().getApplicationProfileType() != null && cancelRequestItemInitiationData.getInitiationHeader().getApplicationProfileType().getValue() != null && !cancelRequestItemInitiationData.getInitiationHeader().getApplicationProfileType().getValue().trim().isEmpty()) {
83              agencyId = new AgencyId(cancelRequestItemInitiationData.getInitiationHeader().getApplicationProfileType().getValue());
84          } else {
85              agencyId = new AgencyId(getLoanProcessor().getParameter(OLENCIPConstants.AGENCY_ID_PARAMETER));
86          }
87          HashMap<String, String> agencyPropertyMap = oleCirculationHelperService.getAgencyPropertyMap(agencyId.getValue());
88          if (agencyPropertyMap.size() > 0) {
89              String operatorId = agencyPropertyMap.get(OLENCIPConstants.OPERATOR_ID);
90              String patronId = cancelRequestItemInitiationData.getUserId().getUserIdentifierValue();
91              String itemBarcode = cancelRequestItemInitiationData.getItemId().getItemIdentifierValue();
92              LOG.info("Inside Cancel Request . Patron Barcode : " + patronId + " Operator Id : " + operatorId + " Item Barcode : " + itemBarcode);
93              String response = oleCirculationService.cancelRequest(operatorId, patronId, itemBarcode);
94              LOG.info(response);
95              OLECancelRequest oleCancelRequest = (OLECancelRequest) oleCancelRequestConverter.generateCancelRequestObject(response);
96  
97              if (oleCancelRequest != null && oleCancelRequest.getMessage() != null && oleCancelRequest.getMessage().contains(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.REQUEST_SUCCESSFULLEY_CANCELLED))) {
98                  cancelRequestItemResponseData.setUserId(cancelRequestItemInitiationData.getUserId());
99                  cancelRequestItemResponseData.setItemId(cancelRequestItemInitiationData.getItemId());
100                 cancelRequestItemResponseData.setRequestId(cancelRequestItemInitiationData.getRequestId());
101             } else {
102                 if (oleCancelRequest != null) {
103                     problem.setProblemDetail(oleCancelRequest.getMessage());
104                 } else {
105                     problem.setProblemDetail(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RQST_FAIL));
106                 }
107                 problem.setProblemElement(OLENCIPConstants.ITEM);
108                 problem.setProblemType(problemType);
109                 problem.setProblemValue(itemBarcode);
110                 problems.add(problem);
111                 cancelRequestItemResponseData.setProblems(problems);
112             }
113         } else {
114             problem.setProblemDetail(ConfigContext.getCurrentContextConfig().getProperty(OLENCIPConstants.INVALID_AGENCY_ID));
115             problem.setProblemElement(OLENCIPConstants.AGENCY_ID);
116             problem.setProblemType(problemType);
117             problem.setProblemValue(agencyId.getValue());
118             problems.add(problem);
119             cancelRequestItemResponseData.setProblems(problems);
120         }
121 
122         return cancelRequestItemResponseData;  //To change body of implemented methods use File | Settings | File Templates.
123     }
124 }