1 package org.kuali.ole.service.impl;
2
3
4 import org.kuali.ole.DataCarrierService;
5 import org.kuali.ole.OLEConstants;
6 import org.kuali.ole.OLEParameterConstants;
7 import org.kuali.ole.OLESruItemHandler;
8 import org.kuali.ole.deliver.bo.FeeType;
9 import org.kuali.ole.deliver.bo.OleDeliverRequestBo;
10 import org.kuali.ole.deliver.bo.OleLoanDocument;
11 import org.kuali.ole.deliver.bo.OlePatronDocument;
12 import org.kuali.ole.deliver.processor.LoanProcessor;
13 import org.kuali.ole.deliver.service.CircDeskLocationResolver;
14 import org.kuali.ole.deliver.service.OleDeliverRequestDocumentHelperServiceImpl;
15 import org.kuali.ole.describe.bo.OleLocation;
16 import org.kuali.ole.docstore.common.document.content.instance.OleHoldings;
17 import org.kuali.ole.pojo.OLESruItem;
18 import org.kuali.ole.service.OleCirculationPolicyService;
19 import org.kuali.ole.service.OleCirculationPolicyServiceImpl;
20 import org.kuali.ole.service.OleLoanDocumentWebService;
21 import org.kuali.ole.sys.context.SpringContext;
22 import org.kuali.ole.util.DocstoreUtil;
23 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
24 import org.kuali.rice.krad.service.BusinessObjectService;
25 import org.kuali.rice.krad.service.KRADServiceLocator;
26 import org.kuali.rice.krms.api.engine.EngineResults;
27
28 import java.text.DateFormat;
29 import java.text.SimpleDateFormat;
30 import java.util.Date;
31 import java.util.HashMap;
32 import java.util.List;
33 import java.util.Map;
34
35
36
37
38
39
40
41
42
43 public class OleLoanDocumentWebServiceImpl implements OleLoanDocumentWebService {
44
45 private BusinessObjectService businessObjectService;
46 private OLESruItemHandler oleSruItemHandler;
47 private DocstoreUtil docstoreUtil;
48 private OleDeliverRequestDocumentHelperServiceImpl oleDeliverRequestDocumentHelperService;
49 private LoanProcessor loanProcessor;
50 private OleCirculationPolicyService oleCirculationPolicyService;
51 private CircDeskLocationResolver circDeskLocationResolver;
52
53 private CircDeskLocationResolver getCircDeskLocationResolver() {
54 if (circDeskLocationResolver == null) {
55 circDeskLocationResolver = new CircDeskLocationResolver();
56 }
57 return circDeskLocationResolver;
58 }
59
60 public BusinessObjectService getBusinessObjectService(){
61 if(businessObjectService==null){
62 businessObjectService = KRADServiceLocator.getBusinessObjectService();
63 }
64 return businessObjectService;
65 }
66
67 public OLESruItemHandler getOleSruItemHandler(){
68 if(oleSruItemHandler==null){
69 oleSruItemHandler = new OLESruItemHandler();
70 }
71 return oleSruItemHandler;
72 }
73
74 public OleDeliverRequestDocumentHelperServiceImpl getOleDeliverRequestDocumentHelperServiceImpl(){
75 if(oleDeliverRequestDocumentHelperService==null){
76 oleDeliverRequestDocumentHelperService = new OleDeliverRequestDocumentHelperServiceImpl();
77 }
78 return oleDeliverRequestDocumentHelperService;
79 }
80 public LoanProcessor getLoanProcessor(){
81 if(loanProcessor==null){
82 loanProcessor = new LoanProcessor();
83 }
84 return loanProcessor;
85 }
86
87 public DocstoreUtil getDocstoreUtil() {
88 if(docstoreUtil == null){
89 docstoreUtil = new DocstoreUtil();
90 }
91 return docstoreUtil;
92 }
93
94 public OleCirculationPolicyService getOleCirculationPolicyService() {
95 if (null == oleCirculationPolicyService) {
96 oleCirculationPolicyService = SpringContext.getBean(OleCirculationPolicyServiceImpl.class);
97 }
98 return oleCirculationPolicyService;
99 }
100
101 public String getItemDueDate(String itemUuId) {
102 String dueDate = "";
103 try {
104 HashMap<String, String> loanMap = new HashMap<String, String>();
105 loanMap.put(OLEConstants.ITEM_UUID, itemUuId);
106 List<OleLoanDocument> oleLoanDocument = (List<OleLoanDocument>) KRADServiceLocator.getBusinessObjectService().findMatching(OleLoanDocument.class, loanMap);
107 if (oleLoanDocument != null && oleLoanDocument.size() > 0) {
108 if (oleLoanDocument.get(0).getLoanDueDate() != null) {
109 dueDate = oleLoanDocument.get(0).getLoanDueDate().toString();
110 }
111 }
112 } catch (Exception e) {
113 e.printStackTrace();
114 }
115 return dueDate;
116 }
117
118 public boolean getItemRenewable(String itemUuId, String itemType, String location) {
119 DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
120 boolean errorMessage = false;
121 try {
122 OleDeliverRequestBo oleDeliverRequestBo = getLoanProcessor().getPrioritizedRequest(itemUuId);
123 if (oleDeliverRequestBo != null) {
124 errorMessage = false;
125 return errorMessage;
126 } else {
127 HashMap<String, String> loanMap = new HashMap<String, String>();
128 loanMap.put(OLEConstants.ITEM_UUID, itemUuId);
129 List<OleLoanDocument> oleLoanDocuments = (List<OleLoanDocument>) KRADServiceLocator.getBusinessObjectService().findMatching(OleLoanDocument.class, loanMap);
130 loanMap.put(OLEConstants.ITEM_UUID, itemUuId);
131 if (oleLoanDocuments != null && oleLoanDocuments.size() > 0) {
132 HashMap<String, String> patronMap = new HashMap<String, String>();
133 String patronId = oleLoanDocuments.get(0).getPatronId();
134 String itemId = oleLoanDocuments.get(0).getItemId();
135 patronMap.put(OLEConstants.OleDeliverRequest.PATRON_ID, patronId);
136 List<OlePatronDocument> olePatronDocuments = (List<OlePatronDocument>) KRADServiceLocator.getBusinessObjectService().findMatching(OlePatronDocument.class, patronMap);
137 if (olePatronDocuments != null && olePatronDocuments.size() > 0) {
138 Map<String, Object> detailMap = getOleDeliverRequestDocumentHelperServiceImpl().retrieveBIbItemHoldingData(oleLoanDocuments.get(0).getItemUuid());
139 OleHoldings oleHoldings = (OleHoldings) detailMap.get(OLEConstants.HOLDING);
140 org.kuali.ole.docstore.common.document.Item item = (org.kuali.ole.docstore.common.document.Item) detailMap.get(OLEConstants.DOCUMENT_ITEM);
141 String itemLocation = null;
142 if (item.getLocation() == null || (item.getLocation() != null && item.getLocation().trim().isEmpty())) {
143 itemLocation = getDocstoreUtil().getLocation(oleHoldings.getLocation(), new StringBuffer(""));
144 } else {
145 itemLocation = item.getLocation();
146 }
147 Map<String, String> locationMap = getCircDeskLocationResolver().getLocationMap(itemLocation);
148 String borrowerType = olePatronDocuments.get(0).getOleBorrowerType().getBorrowerTypeCode();
149 String numberOfClaimsReturned = String.valueOf(olePatronDocuments.get(0).getNumberOfClaimsReturned());
150 String numberOfRenewals = oleLoanDocuments.get(0).getNumberOfRenewals();
151 Integer noOfRenewals = Integer.parseInt(numberOfRenewals);
152 String digitRoutine = getLoanProcessor().getParameter(OLEParameterConstants.ITEM_DIGIT_ROUTINE);
153 Integer overdueFineAmt = 0;
154 Integer replacementFeeAmt = 0;
155 Integer serviceFeeAmt = 0;
156 DateFormat formatter = new SimpleDateFormat(OLEConstants.DDMMYYYYHHMMSS);
157 Date loanDueDate = oleLoanDocuments.get(0).getLoanDueDate() != null ? new Date(oleLoanDocuments.get(0).getLoanDueDate().getTime()) : null;
158 String dateToString = oleLoanDocuments.get(0).getLoanDueDate() != null ? formatter.format(oleLoanDocuments.get(0).getLoanDueDate()) : "null";
159 List<FeeType> feeTypeList = getOleCirculationPolicyService().getPatronBillPayment(oleLoanDocuments.get(0).getPatronId());
160 if (feeTypeList != null & feeTypeList.size() > 0) {
161 for (FeeType feeType : feeTypeList) {
162 Integer fineAmount = feeType.getFeeAmount().subtract(feeType.getPaidAmount()).intValue();
163 overdueFineAmt += feeType.getOleFeeType().getFeeTypeName().equalsIgnoreCase(OLEConstants.OVERDUE_FINE) ? fineAmount : 0;
164 replacementFeeAmt += feeType.getOleFeeType().getFeeTypeName().equalsIgnoreCase(OLEConstants.REPLACEMENT_FEE) ? fineAmount : 0;
165 serviceFeeAmt += feeType.getOleFeeType().getFeeTypeName().equalsIgnoreCase(OLEConstants.SERVICE_FEE) ? fineAmount : 0;
166 }
167 }
168 dataCarrierService.addData(OLEConstants.GROUP_ID, OLEConstants.HUNDRED);
169 dataCarrierService.removeData(patronId+itemId);
170 HashMap keyLoanMap=new HashMap();
171 keyLoanMap=oleCirculationPolicyService.getLoanedKeyMap(patronId,false);
172 List<Integer> listOfOverDueDays = (List<Integer>)keyLoanMap.get(OLEConstants.LIST_OF_OVERDUE_DAYS);
173 dataCarrierService.addData(OLEConstants.LIST_OVERDUE_DAYS, listOfOverDueDays);
174 dataCarrierService.addData(OLEConstants.LIST_RECALLED_OVERDUE_DAYS, (List<Integer>) keyLoanMap.get(OLEConstants.LIST_RECALLED_OVERDUE_DAYS));
175 HashMap<String, Object> termValues = new HashMap<String, Object>();
176 termValues.put(OLEConstants.BORROWER_TYPE, borrowerType);
177 termValues.put(OLEConstants.ITEM_TYPE, itemType);
178 termValues.put(OLEConstants.ITEM_SHELVING, locationMap.get(OLEConstants.ITEM_SHELVING));
179 termValues.put(OLEConstants.ITEM_COLLECTION, locationMap.get(OLEConstants.ITEM_COLLECTION));
180 termValues.put(OLEConstants.ITEM_LIBRARY, locationMap.get(OLEConstants.ITEM_LIBRARY));
181 termValues.put(OLEConstants.ITEM_CAMPUS, locationMap.get(OLEConstants.ITEM_CAMPUS));
182 termValues.put(OLEConstants.ITEM_INSTITUTION, locationMap.get(OLEConstants.ITEM_INSTITUTION));
183 termValues.put(OLEConstants.DIGIT_ROUTINE, digitRoutine);
184 termValues.put(OLEConstants.ITEMS_DUE_DATE_STRING, dateToString);
185 termValues.put(OLEConstants.NUM_CLAIMS_RETURNED, numberOfClaimsReturned);
186 termValues.put(OLEConstants.OVERDUE_FINE_AMT, overdueFineAmt);
187 termValues.put(OLEConstants.REPLACEMENT_FEE_AMT, replacementFeeAmt);
188 termValues.put(OLEConstants.ALL_CHARGES, overdueFineAmt + replacementFeeAmt + serviceFeeAmt);
189 termValues.put(OLEConstants.NUM_RENEWALS, noOfRenewals);
190 termValues.put(OLEConstants.ITEMS_DUE_DATE, loanDueDate);
191 termValues.put(OLEConstants.PATRON_ID_POLICY, patronId);
192 termValues.put(OLEConstants.ITEM_ID_POLICY, itemId);
193 EngineResults engineResults = getLoanProcessor().getEngineResults(OLEConstants.RENEWAL_AGENDA_NM, termValues);
194 dataCarrierService.removeData(patronId+itemId);
195 List<String> errorMessages = (List<String>) engineResults.getAttribute(OLEConstants.ERROR_ACTION);
196 HashMap<String, String> errorsAndPermission = (HashMap<String, String>) engineResults.getAttribute(OLEConstants.ERRORS_AND_PERMISSION);
197 dataCarrierService.addData(OLEConstants.ERROR_ACTION, null);
198 dataCarrierService.addData(OLEConstants.ERRORS_AND_PERMISSION, null);
199 if ((errorMessages != null && errorMessages.size() > 0) || (errorsAndPermission != null && errorsAndPermission.size() > 0)) {
200 errorMessage = false;
201 }else{
202 errorMessage=true;
203 }
204 }
205 }
206 }
207 } catch (Exception e) {
208 e.printStackTrace();
209 }
210 return errorMessage;
211 }
212
213 @Override
214 public String getItemInformation(String itemUUID, String itemType, String itemShelvingLocation ,String shelvingLocation, String localLocation) {
215 OLESruItem oleSruItem = new OLESruItem();
216
217
218 if(shelvingLocation!=null){
219 oleSruItem.setShelvingLocation(getLocationName(shelvingLocation));
220 }
221 if(localLocation !=null){
222 oleSruItem.setLocalLocation(getLocationName(localLocation));
223 }
224 return getOleSruItemHandler().generateXmlFromObject(oleSruItem);
225 }
226
227 public String getLocationName(String locationCode) {
228 String locationName = "";
229 Map<String, String> locationMap = new HashMap<String, String>();
230 locationMap.put(OLEConstants.LOC_CD, locationCode);
231 List<OleLocation> oleLocationList = (List<OleLocation>) getBusinessObjectService().findMatching(OleLocation.class, locationMap);
232 if (oleLocationList.size() > 0) {
233 locationName = oleLocationList.get(0).getLocationName();
234 }
235 return locationName;
236 }
237
238
239 }