1 package org.kuali.ole.sip2.service.impl;
2
3 import org.apache.commons.collections.CollectionUtils;
4 import org.apache.log4j.Logger;
5 import org.kuali.ole.OLEConstants;
6 import org.kuali.ole.deliver.bo.OleItemSearch;
7 import org.kuali.ole.deliver.bo.OleLoanDocument;
8 import org.kuali.ole.deliver.bo.OlePatronDocument;
9 import org.kuali.ole.deliver.processor.LoanProcessor;
10 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
11 import org.kuali.ole.docstore.common.document.Item;
12 import org.kuali.ole.docstore.common.document.content.enums.DocType;
13 import org.kuali.ole.docstore.common.search.SearchParams;
14 import org.kuali.ole.docstore.common.search.SearchResponse;
15 import org.kuali.ole.ncip.bo.*;
16 import org.kuali.ole.ncip.converter.*;
17 import org.kuali.ole.ncip.service.OLECirculationService;
18 import org.kuali.ole.ncip.service.impl.OLECirculationHelperServiceImpl;
19 import org.kuali.ole.ncip.service.impl.OLECirculationServiceImpl;
20 import org.kuali.ole.olekrad.filter.OLELoginFilter;
21 import org.kuali.ole.service.OlePatronService;
22 import org.kuali.ole.service.OlePatronServiceImpl;
23 import org.kuali.ole.sip2.common.OLESIP2Util;
24 import org.kuali.ole.sip2.constants.OLESIP2Constants;
25 import org.kuali.ole.sip2.requestParser.*;
26 import org.kuali.ole.sip2.service.OLESIP2HelperService;
27 import org.kuali.ole.sip2.service.OLESIP2Service;
28 import org.kuali.ole.sip2.sip2Response.*;
29 import org.kuali.ole.sys.context.SpringContext;
30 import org.kuali.ole.util.DocstoreUtil;
31 import org.kuali.rice.core.api.util.type.KualiDecimal;
32 import org.kuali.rice.krad.service.BusinessObjectService;
33 import org.kuali.rice.krad.service.KRADServiceLocator;
34
35 import java.util.ArrayList;
36 import java.util.HashMap;
37 import java.util.List;
38 import java.util.Map;
39
40
41
42
43 public class OLESIP2ServiceImpl implements OLESIP2Service {
44
45 private static final Logger LOG = Logger.getLogger(OLESIP2ServiceImpl.class);
46
47 private DocstoreClientLocator docstoreClientLocator;
48 private DocstoreUtil docstoreUtil;
49 private int totalRecCount;
50 private OlePatronService olePatronService;
51
52 OLESIP2HelperService OLESIP2HelperService = new OLESIP2HelperServiceImpl();
53 OLECirculationService oleCirculationService = new OLECirculationServiceImpl();
54 private OLECirculationHelperServiceImpl oleCirculationHelperService = new OLECirculationHelperServiceImpl();
55
56 public OlePatronService getOlePatronService() {
57
58 if (olePatronService == null)
59 olePatronService = new OlePatronServiceImpl();
60 return olePatronService;
61 }
62
63
64 private BusinessObjectService businessObjectService;
65
66 protected BusinessObjectService getBusinessObjectService() {
67 if (businessObjectService == null) {
68 businessObjectService = KRADServiceLocator.getBusinessObjectService();
69 }
70 return businessObjectService;
71 }
72
73 public DocstoreUtil getDocstoreUtil() {
74 if (docstoreUtil == null) {
75 docstoreUtil = SpringContext.getBean(DocstoreUtil.class);
76 }
77 return docstoreUtil;
78 }
79
80 public DocstoreClientLocator getDocstoreClientLocator() {
81 if (docstoreClientLocator == null) {
82 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
83 }
84 return docstoreClientLocator;
85 }
86
87 @Override
88 public String feePaidService(OLESIP2FeePaidRequestParser sip2FeePaidRequestParser, String service, String operatorId) {
89
90 String responseString = "";
91 String message = "";
92 KualiDecimal feeAmount = new KualiDecimal(Double.parseDouble(sip2FeePaidRequestParser.getFeeAmount()));
93 if (sip2FeePaidRequestParser.getCurrencyType().equals(OLESIP2Util.getDefaultCurrency().getCurrencyCode())) {
94 message = OLESIP2HelperService.feePaid(sip2FeePaidRequestParser.getPatronIdentifier(), sip2FeePaidRequestParser.getFeeType(),
95 sip2FeePaidRequestParser.getFeeIdentifier(), sip2FeePaidRequestParser.getPaymentType(), feeAmount,
96 sip2FeePaidRequestParser.getTransactionId(), operatorId);
97 } else {
98 message = "Please Enter Valid Currency";
99 }
100
101
102 OLESIP2FeePaidResponse sip2FeePaidResponse = new OLESIP2FeePaidResponse();
103 responseString = sip2FeePaidResponse.getFeePaidResponse(message, sip2FeePaidRequestParser);
104
105 if (responseString == null || responseString.equalsIgnoreCase("")) {
106 OLENCIPErrorResponse olencipErrorResponse = new OLENCIPErrorResponse();
107 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE, sip2FeePaidRequestParser.getPatronIdentifier());
108 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID, operatorId);
109 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.MESSAGE, OLENCIPConstants.INVALID_INPUT);
110 responseString = olencipErrorResponse.getErrorXml(service);
111 }
112
113
114 return responseString;
115 }
116
117
118 @Override
119 public String processRequest(String requestData, String service, String operatorId) {
120 String responseString = "";
121
122 if (requestData.startsWith("99")) {
123
124 LOG.info("Request Type : SC Status Request");
125 OLESIP2SCStatusRequestParser sip2SCStatusRequestParser = new OLESIP2SCStatusRequestParser(requestData);
126 responseString = this.scStatusService(sip2SCStatusRequestParser, service, operatorId);
127
128 } else if (requestData.startsWith("93")) {
129 LOG.info("Request Type : Login Request");
130 OLESIP2LoginRequestParser loginRequestParser = new OLESIP2LoginRequestParser(requestData);
131 responseString = this.loginService(loginRequestParser, service, operatorId);
132
133
134 } else if (requestData.startsWith("11")) {
135 LOG.info("Request Type : Checkout Request");
136 OLESIP2CheckOutRequestParser sip2CheckOutRequestParser = new OLESIP2CheckOutRequestParser(requestData);
137 responseString = this.checkOutService(sip2CheckOutRequestParser, service, operatorId);
138
139 } else if (requestData.startsWith("09")) {
140 LOG.info("Request Type : Check-in Request");
141 OLESIP2CheckInRequestParser sip2CheckInRequestParser = new OLESIP2CheckInRequestParser(requestData);
142 responseString = this.checkInService(sip2CheckInRequestParser, service, operatorId);
143
144
145 } else if (requestData.startsWith("17")) {
146 LOG.info("Request Type : Item Information");
147 OLESIP2ItemInformationRequestParser sip2ItemInformationRequestParser = new OLESIP2ItemInformationRequestParser(requestData);
148 responseString = this.itemInformationService(sip2ItemInformationRequestParser, service, operatorId);
149
150 } else if (requestData.startsWith("23")) {
151 LOG.info("Request Type : Patron Status Request");
152 OLESIP2PatronStatusRequestParser sip2PatronStatusRequestParser = new OLESIP2PatronStatusRequestParser(requestData);
153 responseString = this.patronStatusService(sip2PatronStatusRequestParser, service, operatorId);
154
155 } else if (requestData.startsWith("63")) {
156 LOG.info("Request Type : Patron Information");
157 OLESIP2PatronInformationRequestParser sip2PatronInformationRequestParser = new OLESIP2PatronInformationRequestParser(requestData);
158 responseString = this.patronInformationService(sip2PatronInformationRequestParser, service, operatorId);
159
160 } else if (requestData.startsWith("01")) {
161 LOG.info("Request Type : Patron Block");
162
163 OLESIP2BlockPatronRequestParser sip2BlockPatronRequestParser = new OLESIP2BlockPatronRequestParser(requestData);
164 responseString = this.blockPatronService(sip2BlockPatronRequestParser, service, operatorId);
165
166 } else if (requestData.startsWith("25")) {
167 LOG.info("Request Type : Patron Enable");
168 OLESIP2PatronEnableRequestParser sip2PatronEnableRequestParser = new OLESIP2PatronEnableRequestParser(requestData);
169 responseString = this.patronEnableService(sip2PatronEnableRequestParser, service, operatorId);
170
171
172 } else if (requestData.startsWith("35")) {
173 LOG.info("Request Type : End Patron Session");
174 OLESIP2EndPatronSessionRequestParser sip2EndPatronSessionRequestParser = new OLESIP2EndPatronSessionRequestParser(requestData);
175 OLESIP2EndPatronSessionResponse olesip2EndPatronSessionResponse = new OLESIP2EndPatronSessionResponse();
176 responseString = olesip2EndPatronSessionResponse.getEndPatronSession(sip2EndPatronSessionRequestParser);
177
178
179 } else if (requestData.startsWith("29")) {
180 LOG.info("Request Type : Renew");
181 System.out.println(requestData);
182 OLESIP2RenewRequestParser sip2RenewRequestParser = new OLESIP2RenewRequestParser(requestData);
183 responseString = this.renewService(sip2RenewRequestParser, service, operatorId);
184
185 } else if (requestData.startsWith("15")) {
186 LOG.info("Request Type : Hold");
187 OLESIP2HoldRequestParser sip2HoldRequestParser = new OLESIP2HoldRequestParser(requestData);
188 responseString = this.holdService(sip2HoldRequestParser, service, operatorId);
189
190 } else if (requestData.startsWith("37")) {
191 LOG.info("Request Type : Fee Paid Message");
192 OLESIP2FeePaidRequestParser sip2FeePaidRequestParser = new OLESIP2FeePaidRequestParser(requestData);
193 responseString = this.feePaidService(sip2FeePaidRequestParser, service, operatorId);
194 } else if (requestData.startsWith("65")) {
195 LOG.info("Request Type : Renew All");
196 OLESIP2RenewAllRequestParser sip2RenewAllRequestParser = new OLESIP2RenewAllRequestParser(requestData);
197 responseString = this.renewAllService(sip2RenewAllRequestParser, service, operatorId);
198
199 } else if (requestData.startsWith("19")) {
200 LOG.info("Request Type : Item Status Update");
201 OLESIP2ItemStatusUpdateRequestParser sip2ItemStatusUpdateRequestParser = new OLESIP2ItemStatusUpdateRequestParser(requestData);
202
203 responseString = this.itemStatusUpdateService(requestData, sip2ItemStatusUpdateRequestParser, service, operatorId);
204 } else {
205 LOG.info("Request Type : *****Not a valid request");
206 responseString = "Not a valid SIP2 request";
207 new Throwable("Not a valid SIP2 request");
208
209 }
210 LOG.info("Exit SOASNettyServerHandler.analysisRequestType(String requestData)");
211 return responseString;
212 }
213
214
215 @Override
216 public String loginService(OLESIP2LoginRequestParser loginRequestParser, String service, String operatorId) {
217 OLELoginFilter oleLoginFilter = new OLELoginFilter();
218 String responseString = "";
219 Boolean validateUser = oleLoginFilter.checkValidUserNameAndPassword(loginRequestParser.getLoginUserId(),
220 loginRequestParser.getLoginPassword());
221
222 OLESIP2LoginResponse sip2LoginResponseParser = new OLESIP2LoginResponse();
223 responseString = sip2LoginResponseParser.getSIP2LoginResponse(validateUser, loginRequestParser);
224 if (responseString == null) {
225 OLENCIPErrorResponse olencipErrorResponse = new OLENCIPErrorResponse();
226 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE, loginRequestParser.getLoginUserId());
227 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID, loginRequestParser.getLoginPassword());
228 responseString = olencipErrorResponse.getErrorXml(service);
229 }
230 return responseString;
231 }
232
233 @Override
234 public String scStatusService(OLESIP2SCStatusRequestParser sip2SCStatusRequestParser, String service, String operatorId) {
235 String responseString = "";
236 OLESIP2ACSStatusResponse sip2ACSStatusResponseParser = new OLESIP2ACSStatusResponse();
237
238 responseString = sip2ACSStatusResponseParser.getSIP2ACSStatusResponse(sip2SCStatusRequestParser);
239
240 if (responseString == null) {
241 OLENCIPErrorResponse olencipErrorResponse = new OLENCIPErrorResponse();
242 responseString = olencipErrorResponse.getErrorXml(service);
243 }
244
245 return responseString;
246
247 }
248
249 @Override
250 public String checkOutService(OLESIP2CheckOutRequestParser sip2CheckOutRequestParser, String service, String operatorId) {
251 String responseString = null;
252 OLECirculationService oleCirculationService = new OLECirculationServiceImpl();
253
254
255 Map patronMap = new HashMap();
256 patronMap.put("barcode", sip2CheckOutRequestParser.getPatronIdentifier());
257 List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) getBusinessObjectService()
258 .findMatching(OlePatronDocument.class, patronMap);
259
260 if (olePatronDocumentList != null && olePatronDocumentList.size() > 0) {
261 Map barMap = new HashMap();
262 barMap.put("itemId", sip2CheckOutRequestParser.getItemIdentifier());
263 barMap.put("patronId", olePatronDocumentList.get(0).getOlePatronId());
264 List<OleLoanDocument> oleLoanDocuments = (List<OleLoanDocument>) getBusinessObjectService().findMatchingOrderBy(OleLoanDocument.class, barMap, "loanId", true);
265 if (oleLoanDocuments != null && oleLoanDocuments.size() > 0) {
266
267 responseString = oleCirculationService.renewItem(sip2CheckOutRequestParser.getPatronIdentifier(),
268 operatorId,
269 sip2CheckOutRequestParser.getItemIdentifier(), true);
270
271 if (responseString != null && !responseString.equalsIgnoreCase("")) {
272 OLERenewItem oleRenewItem = (OLERenewItem) new OLERenewItemConverter().generateRenewItemObject(responseString);
273 OLESIP2CheckOutResponse sip2CheckOutResponseParser = new OLESIP2CheckOutResponse();
274 responseString = sip2CheckOutResponseParser.getSIP2CheckOutResponse(oleRenewItem, sip2CheckOutRequestParser);
275 }
276 } else {
277 responseString = oleCirculationService.checkOutItem(sip2CheckOutRequestParser.getPatronIdentifier(),
278 operatorId,
279 sip2CheckOutRequestParser.getItemIdentifier(), true);
280
281 if (responseString != null && !responseString.equalsIgnoreCase("")) {
282 OLECheckOutItem oleCheckOutItem = (OLECheckOutItem) new OLECheckOutItemConverter().generateCheckoutItemObject(responseString);
283 OLESIP2CheckOutResponse sip2CheckOutResponseParser = new OLESIP2CheckOutResponse();
284 responseString = sip2CheckOutResponseParser.getSIP2CheckOutResponse(oleCheckOutItem, sip2CheckOutRequestParser);
285 }
286
287 }
288
289 }
290 if (responseString == null || responseString.equalsIgnoreCase("")) {
291 OLENCIPErrorResponse olencipErrorResponse = new OLENCIPErrorResponse();
292 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE, sip2CheckOutRequestParser.getPatronIdentifier());
293 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID, operatorId);
294 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.MESSAGE, OLENCIPConstants.INVALID_INPUT);
295 responseString = olencipErrorResponse.getErrorXml(service);
296 }
297
298
299 return responseString;
300
301 }
302
303 @Override
304 public String checkInService(OLESIP2CheckInRequestParser sip2CheckInRequestParser, String service, String operatorId) {
305 String responseString = "";
306 OLECirculationService oleCirculationService = new OLECirculationServiceImpl();
307 OLECheckInItem oleCheckInItem = new OLECheckInItem();
308
309
310 LoanProcessor loanProcessor = new LoanProcessor();
311
312 OleLoanDocument oleLoanDocument = loanProcessor.getOleLoanDocumentUsingItemBarcode(sip2CheckInRequestParser.getItemIdentifier());
313
314 if(oleLoanDocument != null){
315 responseString = oleCirculationService.checkInItem(oleLoanDocument.getPatronBarcode(),
316 operatorId,
317 sip2CheckInRequestParser.getItemIdentifier(),
318 "N", true);
319 if (responseString != null && !responseString.equalsIgnoreCase("")) {
320 oleCheckInItem = (OLECheckInItem) new OLECheckInItemConverter().generateCheckInItemObject(responseString);
321 OLESIP2CheckInResponse sip2CheckInResponseParser = new OLESIP2CheckInResponse();
322 responseString = sip2CheckInResponseParser.getSIP2CheckInResponse(oleCheckInItem, sip2CheckInRequestParser);
323 }
324 }else{
325 oleCheckInItem.setCode("500");
326 oleCheckInItem.setMessage("Item is not currently checked out.");
327 OLESIP2CheckInResponse sip2CheckInResponseParser = new OLESIP2CheckInResponse();
328 responseString = sip2CheckInResponseParser.getSIP2CheckInResponse(oleCheckInItem, sip2CheckInRequestParser);
329 }
330
331
332
333 if (responseString == null) {
334 OLENCIPErrorResponse olencipErrorResponse = new OLENCIPErrorResponse();
335 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE, oleLoanDocument.getPatronBarcode());
336 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID, operatorId);
337 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.MESSAGE, OLENCIPConstants.INVALID_INPUT);
338 responseString = olencipErrorResponse.getErrorXml(service);
339 }
340
341 return responseString;
342
343 }
344
345
346 @Override
347 public String patronStatusService(OLESIP2PatronStatusRequestParser sip2PatronStatusRequestParser, String service, String operatorId) {
348 String responseString = "";
349 OLECirculationService oleCirculationService = new OLECirculationServiceImpl();
350
351 responseString = oleCirculationService.lookupUser(sip2PatronStatusRequestParser.getPatronIdentifier(),
352 operatorId, null, true);
353
354 if (responseString != null && !responseString.equalsIgnoreCase("")) {
355 OLELookupUser oleLookupUser = (OLELookupUser) new OLELookupUserConverter().getLookupUser(responseString);
356 OLESIP2PatronStatusResponse sip2PatronStatusResponse = new OLESIP2PatronStatusResponse();
357
358 responseString = sip2PatronStatusResponse.getSIP2PatronStatusResponse(oleLookupUser,
359 sip2PatronStatusRequestParser);
360
361 }
362 if (responseString == null) {
363 OLENCIPErrorResponse olencipErrorResponse = new OLENCIPErrorResponse();
364 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE, sip2PatronStatusRequestParser.getPatronIdentifier());
365 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID, operatorId);
366 responseString = olencipErrorResponse.getErrorXml(service);
367 }
368
369
370 return responseString;
371 }
372
373 @Override
374 public String patronInformationService(OLESIP2PatronInformationRequestParser sip2PatronInformationRequestParser, String service, String operatorId) {
375 String responseString = "";
376
377 responseString = oleCirculationService.lookupUser(sip2PatronInformationRequestParser.getPatronIdentifier(),
378 operatorId, null, true);
379
380 if (responseString != null && !responseString.equalsIgnoreCase("")) {
381 OLELookupUser oleLookupUser = (OLELookupUser) new OLELookupUserConverter().getLookupUser(responseString);
382 OLESIP2PatronInformationResponse sip2PatronInformationResponse = new OLESIP2PatronInformationResponse();
383
384 responseString = sip2PatronInformationResponse.getSIP2PatronInfoResponse(oleLookupUser,
385 sip2PatronInformationRequestParser);
386
387 }
388 if (responseString == null) {
389 OLENCIPErrorResponse olencipErrorResponse = new OLENCIPErrorResponse();
390 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE, sip2PatronInformationRequestParser.getPatronIdentifier());
391 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID, operatorId);
392 responseString = olencipErrorResponse.getErrorXml(service);
393 }
394
395
396 return responseString;
397
398 }
399
400 @Override
401 public String itemInformationService(OLESIP2ItemInformationRequestParser sip2ItemInformationRequestParser, String service, String operatorId) {
402 String responseString = "";
403
404 OleItemSearch oleItemSearch = new OleItemSearch();
405 List<OleItemSearch> oleItemSearches = new ArrayList<>();
406 SearchParams item_search_Params = new SearchParams();
407 item_search_Params.getSearchConditions().add(item_search_Params.buildSearchCondition("phrase", item_search_Params.buildSearchField(DocType.ITEM.getCode(), Item.ITEM_BARCODE, sip2ItemInformationRequestParser.getItemIdentifier()), "AND"));
408 getDocstoreUtil().getSearchResultFields(item_search_Params);
409 SearchResponse searchResponse = null;
410
411
412 try {
413 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(item_search_Params);
414 this.totalRecCount = searchResponse.getTotalRecordCount();
415 oleItemSearches = getDocstoreUtil().getSearchResults(searchResponse);
416 if (CollectionUtils.isNotEmpty(oleItemSearches))
417 oleItemSearch = oleItemSearches.get(0);
418 } catch (Exception e) {
419 e.printStackTrace();
420 }
421
422 if (oleItemSearch != null) {
423
424 OLESIP2ItemInformationResponse sip2ItemInfoParser = new OLESIP2ItemInformationResponse();
425 responseString = sip2ItemInfoParser.getSIP2ItemInfoResponse(oleItemSearch, sip2ItemInformationRequestParser);
426
427 }
428 if (responseString == null) {
429 OLENCIPErrorResponse olencipErrorResponse = new OLENCIPErrorResponse();
430 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.ITEM_BARCODE, sip2ItemInformationRequestParser.getItemIdentifier());
431 responseString = olencipErrorResponse.getErrorXml(service);
432 }
433
434
435 return responseString;
436
437 }
438
439 @Override
440 public String blockPatronService(OLESIP2BlockPatronRequestParser sip2BlockPatronRequestParser, String service, String operatorId) {
441 String responseString = "";
442
443 Map<String, String> patronMap = new HashMap<String, String>();
444 patronMap.put(OLEConstants.OlePatron.BARCODE, sip2BlockPatronRequestParser.getPatronIdentifier());
445 OlePatronDocument patronDocument = (OlePatronDocument) KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, patronMap);
446 patronDocument.setGeneralBlock(true);
447 patronDocument.setGeneralBlockNotes(sip2BlockPatronRequestParser.getBlockedCardMessage());
448
449 KRADServiceLocator.getBusinessObjectService().save(patronDocument);
450 String lookupUserResponse = oleCirculationService.lookupUser(sip2BlockPatronRequestParser.getPatronIdentifier(),
451 OLESIP2Constants.OPERATOR_ID, null, true);
452 OLELookupUser oleLookupUser = new OLELookupUser();
453 if (lookupUserResponse != null && !lookupUserResponse.equalsIgnoreCase("")) {
454 oleLookupUser = (OLELookupUser) new OLELookupUserConverter().getLookupUser(lookupUserResponse);
455 }
456 OLESIP2PatronStatusResponse sip2PatronStatusResponse = new OLESIP2PatronStatusResponse();
457
458 responseString = sip2PatronStatusResponse.getSIP2PatronStatusResponse(oleLookupUser, sip2BlockPatronRequestParser);
459
460
461 if (responseString == null) {
462 OLENCIPErrorResponse olencipErrorResponse = new OLENCIPErrorResponse();
463 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE, sip2BlockPatronRequestParser.getPatronIdentifier());
464
465 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.MESSAGE, responseString);
466 responseString = olencipErrorResponse.getErrorXml(service);
467 }
468
469 return responseString;
470
471 }
472
473 @Override
474 public String patronEnableService(OLESIP2PatronEnableRequestParser sip2PatronEnableRequestParser, String service, String operatorId) {
475 String responseString = "";
476
477
478 Map<String, String> patronMap = new HashMap<String, String>();
479 patronMap.put(OLEConstants.OlePatron.BARCODE, sip2PatronEnableRequestParser.getPatronIdentifier());
480 OlePatronDocument patronDocument = (OlePatronDocument) KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, patronMap);
481 patronDocument.setGeneralBlock(false);
482
483
484 KRADServiceLocator.getBusinessObjectService().save(patronDocument);
485 OLESIP2PatronEnableResponse sip2PatronEnableResponse = new OLESIP2PatronEnableResponse();
486 boolean isValidPatron = false;
487 if (!(patronDocument.isGeneralBlock() || oleCirculationHelperService.isPatronExpired(patronDocument) || !patronDocument.isActiveIndicator() || oleCirculationHelperService.isPatronActivated(patronDocument))) {
488 isValidPatron = true;
489 }
490 responseString = sip2PatronEnableResponse.getSIP2PatronEnableResponse(patronDocument, sip2PatronEnableRequestParser, isValidPatron);
491 if (responseString == null) {
492 OLENCIPErrorResponse olencipErrorResponse = new OLENCIPErrorResponse();
493 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE, sip2PatronEnableRequestParser.getPatronIdentifier());
494
495 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.MESSAGE, responseString);
496 responseString = olencipErrorResponse.getErrorXml(service);
497 }
498
499
500 return responseString;
501
502 }
503
504 @Override
505 public String renewService(OLESIP2RenewRequestParser sip2RenewRequestParser, String service, String operatorId) {
506 String responseString = "";
507 OLECirculationService oleCirculationService = new OLECirculationServiceImpl();
508 responseString = oleCirculationService.renewItem(sip2RenewRequestParser.getPatronIdentifier(),
509 operatorId,
510 sip2RenewRequestParser.getItemIdentifier(), true);
511
512 if (responseString != null && !responseString.equalsIgnoreCase("")) {
513 OLERenewItem oleRenewItem = (OLERenewItem) new OLERenewItemConverter().generateRenewItemObject(responseString);
514 OLESIP2RenewResponse sip2RenewResponse = new OLESIP2RenewResponse();
515 responseString = sip2RenewResponse.getSIP2RenewResponse(oleRenewItem, sip2RenewRequestParser);
516 }
517
518 if (responseString == null) {
519 OLENCIPErrorResponse olencipErrorResponse = new OLENCIPErrorResponse();
520 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE, sip2RenewRequestParser.getPatronIdentifier());
521 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID, operatorId);
522 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.MESSAGE, responseString);
523 responseString = olencipErrorResponse.getErrorXml(service);
524 }
525
526
527 return responseString;
528
529 }
530
531 @Override
532 public String itemStatusUpdateService(String requestData, OLESIP2ItemStatusUpdateRequestParser oleSIP2ItemStatusUpdateRequestParser, String service, String operatorId) {
533 String responseString = "";
534 OLESIP2ItemStatusUpdateResponse olesip2ItemStatusUpdateResponse = new OLESIP2ItemStatusUpdateResponse();
535 responseString = olesip2ItemStatusUpdateResponse.getOLESIP2ItemStatusUpdateResponse(requestData, oleSIP2ItemStatusUpdateRequestParser);
536
537 if (responseString == null) {
538 OLENCIPErrorResponse olencipErrorResponse = new OLENCIPErrorResponse();
539 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE, oleSIP2ItemStatusUpdateRequestParser.getPatronIdentifier());
540 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID, operatorId);
541 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.MESSAGE, responseString);
542 responseString = olencipErrorResponse.getErrorXml(service);
543 }
544 return responseString;
545 }
546
547 @Override
548 public String holdService(OLESIP2HoldRequestParser sip2HoldRequestParser, String service, String operatorId) {
549 String responseString = "";
550 OLESIP2HoldResponse sip2HoldResponse = new OLESIP2HoldResponse();
551 String pickupLocation = null;
552 OLECirculationService oleCirculationService = new OLECirculationServiceImpl();
553 if (sip2HoldRequestParser.getHoldType().equalsIgnoreCase("add")) {
554 responseString = oleCirculationService.placeRequest(sip2HoldRequestParser.getPatronIdentifier(),
555 operatorId,
556 sip2HoldRequestParser.getItemIdentifier(),
557 OLESIP2Constants.REQUEST_TYPE,
558 (sip2HoldRequestParser.getPickupLocation() != null
559 && !sip2HoldRequestParser.getPickupLocation().equalsIgnoreCase("")) ?
560 sip2HoldRequestParser.getPickupLocation() : "",null,null,
561 null,null);
562 if (responseString != null && !responseString.equalsIgnoreCase("")) {
563 OLEPlaceRequest olePlaceRequest = (OLEPlaceRequest) new OLEPlaceRequestConverter().generatePlaceRequestObject(responseString);
564
565 responseString = sip2HoldResponse.getSIP2PlaceHoldRequestService(olePlaceRequest, sip2HoldRequestParser);
566
567 }
568 if (responseString == null) {
569 OLENCIPErrorResponse olencipErrorResponse = new OLENCIPErrorResponse();
570 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE, sip2HoldRequestParser.getPatronIdentifier());
571 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID, operatorId);
572 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.MESSAGE, OLENCIPConstants.INVALID_INPUT);
573 responseString = olencipErrorResponse.getErrorXml(service);
574 }
575 } else if (sip2HoldRequestParser.getHoldType().equals("delete")) {
576
577 responseString = oleCirculationService.cancelRequest(operatorId,
578 sip2HoldRequestParser.getPatronIdentifier(),
579 sip2HoldRequestParser.getItemIdentifier());
580
581 if (responseString != null && !responseString.equalsIgnoreCase("")) {
582 OLECancelRequest oleCancelRequest = (OLECancelRequest) new OLECancelRequestConverter().generateCancelRequestObject(responseString);
583 responseString = sip2HoldResponse.getSIP2CancelHoldRequestService(oleCancelRequest, sip2HoldRequestParser);
584
585 }
586 if (responseString == null) {
587 OLENCIPErrorResponse olencipErrorResponse = new OLENCIPErrorResponse();
588 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID, operatorId);
589 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_ID, sip2HoldRequestParser.getPatronIdentifier());
590 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.MESSAGE, OLENCIPConstants.INVALID_INPUT);
591 responseString = olencipErrorResponse.getErrorXml(service);
592 }
593
594 } else if (sip2HoldRequestParser.getHoldType().equals("updateHold")) {
595 responseString = sip2HoldResponse.getSIP2UpdateHoldRequestService(sip2HoldRequestParser);
596
597 }
598 return responseString;
599
600 }
601
602 @Override
603 public String getCirculationErrorMessage(String service, String message, String code, String requiredParameters, String outputFormat) {
604 OLECirculationErrorMessage oleCirculationErrorMessage = new OLECirculationErrorMessage();
605 OLECirculationErrorMessageConverter oleCirculationErrorMessageConverter = new OLECirculationErrorMessageConverter();
606 oleCirculationErrorMessage.setMessage(message);
607 oleCirculationErrorMessage.setCode(code);
608 oleCirculationErrorMessage.setService(service);
609 oleCirculationErrorMessage.setRequiredParameters(requiredParameters);
610 String errorMessage = "";
611 errorMessage = oleCirculationErrorMessageConverter.generateCirculationErrorXml(oleCirculationErrorMessage);
612 if (outputFormat.equalsIgnoreCase(OLENCIPConstants.JSON_FORMAT)) {
613 errorMessage = oleCirculationErrorMessageConverter.generateLookupUserJson(errorMessage);
614 }
615 return errorMessage;
616 }
617
618
619 @Override
620 public String renewAllService(OLESIP2RenewAllRequestParser sip2RenewAllRequestParser, String service, String operatorId) {
621 String responseString = "";
622 String itemBarcodes = "";
623 int count = 1;
624 OLECirculationService oleCirculationService = new OLECirculationServiceImpl();
625
626 Map<String, Object> parameterMap = new HashMap<>();
627 parameterMap.put("barcode", sip2RenewAllRequestParser.getPatronIdentifier());
628 List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) KRADServiceLocator.getBusinessObjectService().findMatching(OlePatronDocument.class, parameterMap);
629 if (olePatronDocumentList != null && olePatronDocumentList.size() > 0) {
630 OlePatronDocument olePatronDocument = olePatronDocumentList.get(0);
631 for (OleLoanDocument oleLoanDocument : olePatronDocument.getOleLoanDocuments()) {
632 if (count == 1) {
633 itemBarcodes = oleLoanDocument.getItemId();
634 count = count + 1;
635 } else {
636 itemBarcodes = itemBarcodes + "," + oleLoanDocument.getItemId();
637 }
638
639 }
640 }
641 if (org.apache.commons.lang3.StringUtils.isNotBlank(itemBarcodes)) {
642 responseString = oleCirculationService.renewItemList(sip2RenewAllRequestParser.getPatronIdentifier(),
643 operatorId,
644 itemBarcodes, true);
645 } else {
646 responseString = "Patron don't have loaned item to renew";
647 }
648
649 if (org.apache.commons.lang3.StringUtils.isNotBlank(responseString)) {
650 OLESIP2RenewAllResponse sip2RenewAllResponse = new OLESIP2RenewAllResponse();
651 if (responseString.equalsIgnoreCase("Patron don't have loaned item to renew")) {
652 responseString = sip2RenewAllResponse.getSIP2RenewAllResponse(responseString, sip2RenewAllRequestParser);
653 } else {
654 OLERenewItemList oleRenewItemList = (OLERenewItemList) new OLERenewItemConverter().generateRenewItemListObjectForSip2(responseString);
655 responseString = sip2RenewAllResponse.getSIP2RenewAllResponse(oleRenewItemList, sip2RenewAllRequestParser);
656 }
657 }
658 if (org.apache.commons.lang3.StringUtils.isBlank(responseString)) {
659 OLENCIPErrorResponse olencipErrorResponse = new OLENCIPErrorResponse();
660 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE, sip2RenewAllRequestParser.getPatronIdentifier());
661 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID, operatorId);
662 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.MESSAGE, OLENCIPConstants.INVALID_INPUT);
663 responseString = olencipErrorResponse.getErrorXml(service);
664 }
665 return responseString;
666
667 }
668
669 }