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