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.OLENCIPConstants;
8 import org.kuali.ole.ncip.bo.OLEPlaceRequest;
9 import org.kuali.ole.ncip.converter.OLEPlaceRequestConverter;
10 import org.kuali.ole.ncip.service.OLECirculationService;
11 import org.kuali.ole.ncip.service.OLERequestItemService;
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.math.BigDecimal;
17 import java.util.ArrayList;
18 import java.util.GregorianCalendar;
19 import java.util.HashMap;
20 import java.util.List;
21
22
23
24
25
26
27
28
29 public class OLERequestItemServiceImpl implements OLERequestItemService {
30 private static final Logger LOG = Logger.getLogger(OLERequestItemServiceImpl.class);
31 private OLECirculationService oleCirculationService;
32 private OLECirculationHelperServiceImpl oleCirculationHelperService;
33 private OLEPlaceRequestConverter olePlaceRequestConverter = new OLEPlaceRequestConverter();
34 private LoanProcessor loanProcessor;
35
36 public LoanProcessor getLoanProcessor() {
37 if (loanProcessor == null) {
38 loanProcessor = SpringContext.getBean(LoanProcessor.class);
39 }
40 return loanProcessor;
41 }
42
43 public OLECirculationService getOleCirculationService() {
44 if (null == oleCirculationService) {
45 oleCirculationService = GlobalResourceLoader.getService(OLENCIPConstants.CIRCULATION_SERVICE);
46 }
47 return oleCirculationService;
48 }
49
50 public void setOleCirculationService(OLECirculationService oleCirculationService) {
51 this.oleCirculationService = oleCirculationService;
52 }
53
54 public OLECirculationHelperServiceImpl getOleCirculationHelperService() {
55 if (null == oleCirculationHelperService) {
56 oleCirculationHelperService = GlobalResourceLoader.getService(OLENCIPConstants.CIRCULATION_HELPER_SERVICE);
57 }
58 return oleCirculationHelperService;
59 }
60
61 public void setOleCirculationHelperService(OLECirculationHelperServiceImpl oleCirculationHelperService) {
62 this.oleCirculationHelperService = oleCirculationHelperService;
63 }
64
65 public OLEPlaceRequestConverter getOlePlaceRequestConverter() {
66 return olePlaceRequestConverter;
67 }
68
69 public void setOlePlaceRequestConverter(OLEPlaceRequestConverter olePlaceRequestConverter) {
70 this.olePlaceRequestConverter = olePlaceRequestConverter;
71 }
72
73 @Override
74 public RequestItemResponseData performService(RequestItemInitiationData requestItemInitiationData, ServiceContext serviceContext, RemoteServiceManager remoteServiceManager) throws ServiceException {
75 RequestItemResponseData requestItemResponseData = new RequestItemResponseData();
76
77 oleCirculationService = getOleCirculationService();
78 oleCirculationHelperService = getOleCirculationHelperService();
79 List<Problem> problems = new ArrayList<Problem>();
80 String responseString = null;
81 AgencyId agencyId = null;
82 RequestId requestId = new RequestId();
83 String operatorId, itemType, itemLocation = "";
84 Problem problem = new Problem();
85 ProblemType problemType = new ProblemType("");
86 if (requestItemInitiationData.getInitiationHeader() != null && requestItemInitiationData.getInitiationHeader().getFromAgencyId() != null && requestItemInitiationData.getInitiationHeader().getFromAgencyId().getAgencyId() != null && requestItemInitiationData.getInitiationHeader().getFromAgencyId().getAgencyId().getValue() != null && !requestItemInitiationData.getInitiationHeader().getFromAgencyId().getAgencyId().getValue().trim().isEmpty()) {
87 agencyId = new AgencyId(requestItemInitiationData.getInitiationHeader().getFromAgencyId().getAgencyId().getValue());
88 } else if (requestItemInitiationData.getInitiationHeader() != null && requestItemInitiationData.getInitiationHeader().getApplicationProfileType() != null && requestItemInitiationData.getInitiationHeader().getApplicationProfileType().getValue() != null && !requestItemInitiationData.getInitiationHeader().getApplicationProfileType().getValue().trim().isEmpty()) {
89 agencyId = new AgencyId(requestItemInitiationData.getInitiationHeader().getApplicationProfileType().getValue());
90 } else {
91 agencyId = new AgencyId(getLoanProcessor().getParameter(OLENCIPConstants.AGENCY_ID_PARAMETER));
92 }
93 String patronId = requestItemInitiationData.getUserId().getUserIdentifierValue();
94 ItemId itemId = requestItemInitiationData.getItemId(0);
95 String itemBarcode = itemId.getItemIdentifierValue();
96 String requestType = requestItemInitiationData.getRequestType().getValue();
97 String location = null;
98 if (requestItemInitiationData.getPickupLocation() != null) {
99 if (requestItemInitiationData.getPickupLocation().getValue() != null && !requestItemInitiationData.getPickupLocation().getValue().isEmpty()) {
100 location = requestItemInitiationData.getPickupLocation().getValue();
101 }
102 }
103 HashMap<String, String> agencyPropertyMap = oleCirculationHelperService.getAgencyPropertyMap(agencyId.getValue());
104 if (agencyPropertyMap.size() > 0) {
105 operatorId = agencyPropertyMap.get(OLENCIPConstants.OPERATOR_ID);
106 LOG.info("Inside Request Item Service . Patron Barcode : "+patronId + " Operator Id : " + operatorId + "Item Barcode : " + itemBarcode + " Request Type : " + requestType + " Pick-up Location : "+ location);
107 String response = oleCirculationService.placeRequest(patronId, operatorId, itemBarcode, requestType, location, null,null,null,null);
108 OLEPlaceRequest olePlaceRequest = (OLEPlaceRequest) olePlaceRequestConverter.generatePlaceRequestObject(response);
109 if (olePlaceRequest != null && olePlaceRequest.getMessage() != null && olePlaceRequest.getMessage().contains(OLEConstants.RQST_SUCCESS)) {
110 String reqId = olePlaceRequest.getRequestId();
111 requestId.setRequestIdentifierValue(reqId);
112 requestItemResponseData.setRequestId(requestId);
113 requestItemResponseData.setItemId(itemId);
114 requestItemResponseData.setHoldQueuePosition(new BigDecimal(olePlaceRequest.getQueuePosition()));
115 requestItemResponseData.setDateAvailable(oleCirculationHelperService.getGregorianCalendarDate(olePlaceRequest.getAvailableDate()));
116 requestItemResponseData.setUserId(requestItemInitiationData.getUserId());
117 requestItemResponseData.setRequestType(requestItemInitiationData.getRequestType());
118 requestItemResponseData.setRequestScopeType(requestItemInitiationData.getRequestScopeType());
119 } else {
120 if (olePlaceRequest != null) {
121 problem.setProblemDetail(olePlaceRequest.getMessage());
122 } else {
123 problem.setProblemDetail(ConfigContext.getCurrentContextConfig().getProperty(OLENCIPConstants.REQUEST_FAIL));
124 }
125 problem.setProblemElement(OLEConstants.ITEM);
126 problem.setProblemType(problemType);
127 problem.setProblemValue(itemBarcode);
128 problems.add(problem);
129 requestItemResponseData.setProblems(problems);
130 }
131 } else {
132 problem.setProblemDetail(ConfigContext.getCurrentContextConfig().getProperty(OLENCIPConstants.INVALID_AGENCY_ID));
133 problem.setProblemElement(OLENCIPConstants.AGENCY_ID);
134 problem.setProblemType(problemType);
135 problem.setProblemValue(agencyId.getValue());
136 problems.add(problem);
137 requestItemResponseData.setProblems(problems);
138 }
139
140 return requestItemResponseData;
141 }
142
143 }