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