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.bo.OLERenewItem;
9 import org.kuali.ole.ncip.converter.OLERenewItemConverter;
10 import org.kuali.ole.ncip.service.OLECirculationService;
11 import org.kuali.ole.ncip.service.OLERenewItemService;
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.HashMap;
19 import java.util.List;
20
21
22
23
24
25
26
27
28 public class OLERenewItemServiceImpl implements OLERenewItemService {
29 private static final Logger LOG = Logger.getLogger(OLERequestItemServiceImpl.class);
30 private OLECirculationService oleCirculationService;
31 private OLECirculationHelperServiceImpl oleCirculationHelperService;
32 private OLERenewItemConverter oleRenewItemConverter = new OLERenewItemConverter();
33 private LoanProcessor loanProcessor;
34
35 public LoanProcessor getLoanProcessor() {
36 if (loanProcessor == null) {
37 loanProcessor = SpringContext.getBean(LoanProcessor.class);
38 }
39 return loanProcessor;
40 }
41
42 public OLECirculationService getOleCirculationService() {
43 if (null == oleCirculationService) {
44 oleCirculationService = GlobalResourceLoader.getService(OLENCIPConstants.CIRCULATION_SERVICE);
45 }
46 return oleCirculationService;
47 }
48
49 public void setOleCirculationService(OLECirculationService oleCirculationService) {
50 this.oleCirculationService = oleCirculationService;
51 }
52
53 public OLECirculationHelperServiceImpl getOleCirculationHelperService() {
54 if (null == oleCirculationHelperService) {
55 oleCirculationHelperService = GlobalResourceLoader.getService(OLENCIPConstants.CIRCULATION_HELPER_SERVICE);
56 }
57 return oleCirculationHelperService;
58 }
59
60 public void setOleCirculationHelperService(OLECirculationHelperServiceImpl oleCirculationHelperService) {
61 this.oleCirculationHelperService = oleCirculationHelperService;
62 }
63
64 public OLERenewItemConverter getOleRenewItemConverter() {
65 return oleRenewItemConverter;
66 }
67
68 public void setOleRenewItemConverter(OLERenewItemConverter oleRenewItemConverter) {
69 this.oleRenewItemConverter = oleRenewItemConverter;
70 }
71
72 @Override
73 public RenewItemResponseData performService(RenewItemInitiationData renewItemInitiationData, ServiceContext serviceContext, RemoteServiceManager remoteServiceManager) throws ServiceException {
74
75 RenewItemResponseData renewItemResponseData = new RenewItemResponseData();
76 oleCirculationService = getOleCirculationService();
77 oleCirculationHelperService = getOleCirculationHelperService();
78 List<Problem> problems = new ArrayList<Problem>();
79 String responseString = null;
80 AgencyId agencyId = null;
81 Problem problem = new Problem();
82 ProblemType problemType = new ProblemType("");
83 if (renewItemInitiationData.getInitiationHeader() != null && renewItemInitiationData.getInitiationHeader().getFromAgencyId() != null && renewItemInitiationData.getInitiationHeader().getFromAgencyId().getAgencyId() != null && renewItemInitiationData.getInitiationHeader().getFromAgencyId().getAgencyId().getValue() != null && !renewItemInitiationData.getInitiationHeader().getFromAgencyId().getAgencyId().getValue().trim().isEmpty()) {
84 agencyId = new AgencyId(renewItemInitiationData.getInitiationHeader().getFromAgencyId().getAgencyId().getValue());
85 } else if (renewItemInitiationData.getInitiationHeader() != null && renewItemInitiationData.getInitiationHeader().getApplicationProfileType() != null && renewItemInitiationData.getInitiationHeader().getApplicationProfileType().getValue() != null && !renewItemInitiationData.getInitiationHeader().getApplicationProfileType().getValue().trim().isEmpty()) {
86 agencyId = new AgencyId(renewItemInitiationData.getInitiationHeader().getApplicationProfileType().getValue());
87 } else {
88 agencyId = new AgencyId(getLoanProcessor().getParameter(OLENCIPConstants.AGENCY_ID_PARAMETER));
89 }
90 HashMap<String, String> agencyPropertyMap = oleCirculationHelperService.getAgencyPropertyMap(agencyId.getValue());
91 if (agencyPropertyMap.size() > 0) {
92 String operatorId = agencyPropertyMap.get(OLENCIPConstants.OPERATOR_ID);
93 String patronId = renewItemInitiationData.getUserId().getUserIdentifierValue();
94 String itemBarcode = renewItemInitiationData.getItemId().getItemIdentifierValue();
95 LOG.info("Inside Renew Item Service . Patron Barcode : " + patronId + " Operator Id : " +operatorId + "Item Barcode : " + itemBarcode);
96 String response = oleCirculationService.renewItem(patronId, operatorId, itemBarcode,false);
97 LOG.info(response);
98 OLERenewItem oleRenewItem = (OLERenewItem) oleRenewItemConverter.generateRenewItemObject(response);
99 if (oleRenewItem != null && oleRenewItem.getMessage().contains(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RENEW_SUCCESS))) {
100 renewItemResponseData.setItemId(renewItemInitiationData.getItemId());
101 renewItemResponseData.setUserId(renewItemInitiationData.getUserId());
102 renewItemResponseData.setDateDue(oleCirculationHelperService.getGregorianCalendarDate(oleRenewItem.getPastDueDate()));
103 renewItemResponseData.setDateForReturn(oleCirculationHelperService.getGregorianCalendarDate(oleRenewItem.getNewDueDate()));
104 renewItemResponseData.setRenewalCount(new BigDecimal(oleRenewItem.getRenewalCount()));
105 } else {
106 if (oleRenewItem != null) {
107 problem.setProblemDetail(oleRenewItem.getMessage());
108 } else {
109 problem.setProblemDetail(ConfigContext.getCurrentContextConfig().getProperty(OLENCIPConstants.RENEW_FAIL));
110 }
111 problem.setProblemElement(OLENCIPConstants.ITEM);
112 problem.setProblemType(problemType);
113 problem.setProblemValue(itemBarcode);
114 problems.add(problem);
115 renewItemResponseData.setProblems(problems);
116 }
117 } else {
118 problem.setProblemDetail(ConfigContext.getCurrentContextConfig().getProperty(OLENCIPConstants.INVALID_AGENCY_ID));
119 problem.setProblemElement(OLENCIPConstants.AGENCY_ID);
120 problem.setProblemType(problemType);
121 problem.setProblemValue(agencyId.getValue());
122 problems.add(problem);
123 renewItemResponseData.setProblems(problems);
124 }
125
126 return renewItemResponseData;
127 }
128
129
130 }