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