001package org.kuali.asr.service.impl; 002 003 004import org.apache.log4j.Logger; 005import org.kuali.ole.DataCarrierService; 006import org.kuali.ole.LoanUtil; 007import org.kuali.ole.OLEConstants; 008import org.kuali.ole.OLEParameterConstants; 009import org.kuali.ole.deliver.batch.OleDeliverBatchServiceImpl; 010import org.kuali.ole.deliver.batch.OleMailer; 011import org.kuali.ole.deliver.batch.OleNoticeBo; 012import org.kuali.ole.deliver.batch.OleSms; 013import org.kuali.ole.deliver.bo.*; 014import org.kuali.ole.deliver.processor.LoanProcessor; 015import org.kuali.ole.describe.bo.OleInstanceItemType; 016import org.kuali.ole.docstore.common.client.DocstoreClientLocator; 017import org.kuali.ole.docstore.common.document.ItemOleml; 018import org.kuali.ole.docstore.common.document.content.enums.DocType; 019import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor; 020import org.kuali.ole.docstore.common.search.SearchResponse; 021import org.kuali.ole.docstore.common.search.SearchResult; 022import org.kuali.ole.docstore.common.search.SearchResultField; 023import org.kuali.ole.ingest.pojo.MatchBo; 024import org.kuali.ole.sys.context.SpringContext; 025import org.kuali.ole.util.DocstoreUtil; 026import org.kuali.rice.core.api.config.property.ConfigContext; 027import org.kuali.rice.core.api.mail.EmailBody; 028import org.kuali.rice.core.api.mail.EmailFrom; 029import org.kuali.rice.core.api.mail.EmailSubject; 030import org.kuali.rice.core.api.mail.EmailTo; 031import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; 032import org.kuali.rice.coreservice.impl.parameter.ParameterBo; 033import org.kuali.rice.kim.api.permission.PermissionService; 034import org.kuali.rice.kim.api.role.RoleService; 035import org.kuali.rice.kim.api.services.KimApiServiceLocator; 036import org.kuali.rice.kim.impl.identity.type.EntityTypeContactInfoBo; 037import org.kuali.rice.krad.service.BusinessObjectService; 038import org.kuali.rice.krad.service.KRADServiceLocator; 039import org.kuali.rice.krad.util.GlobalVariables; 040import org.kuali.rice.krad.util.ObjectUtils; 041import org.kuali.rice.krms.api.KrmsApiServiceLocator; 042import org.kuali.rice.krms.api.engine.*; 043import org.kuali.rice.krms.impl.repository.AgendaBo; 044 045import java.math.BigDecimal; 046import java.sql.Timestamp; 047import java.text.DateFormat; 048import java.text.SimpleDateFormat; 049import java.util.*; 050 051/** 052 * Created with IntelliJ IDEA. 053 * User: sheiksalahudeenm 054 * Date: 1/15/14 055 * Time: 11:45 AM 056 * To change this template use File | Settings | File Templates. 057 */ 058public class OLEASRPlaceRequestHelperServiceImpl { 059 private static final Logger LOG = Logger.getLogger(OLEASRPlaceRequestHelperServiceImpl.class); 060 private static final String NAMESPACE_CODE_SELECTOR = "namespaceCode"; 061 private static final String NAME_SELECTOR = "name"; 062 private final static String RULE_EVALUATED = "Rule Evaluated"; 063 private final static String ROUTED_EXTERNAL = "Routed External"; 064 private BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService(); 065 private int queuePosition = 0; 066 private LoanProcessor loanProcessor = new LoanProcessor(); 067 private DocstoreUtil docstoreUtil = new DocstoreUtil(); 068 069 private PermissionService getPermissionService() { 070 PermissionService service = KimApiServiceLocator.getPermissionService(); 071 return service; 072 } 073 074 private DocstoreClientLocator docstoreClientLocator; 075 076 public DocstoreClientLocator getDocstoreClientLocator() { 077 078 if (docstoreClientLocator == null) { 079 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class); 080 081 } 082 return docstoreClientLocator; 083 } 084 085 /** 086 * Gets the businessObjectService attribute. 087 * 088 * @return Returns the businessObjectService 089 */ 090 private BusinessObjectService getBusinessObjectService() { 091 if (null == businessObjectService) { 092 businessObjectService = KRADServiceLocator.getBusinessObjectService(); 093 } 094 return businessObjectService; 095 } 096 097 public void setbusinessObjectService(BusinessObjectService businessObjectService) { 098 this.businessObjectService = businessObjectService; 099 } 100 101 public LoanProcessor getLoanProcessor() { 102 return loanProcessor; 103 } 104 105 public void setLoanProcessor(LoanProcessor loanProcessor) { 106 this.loanProcessor = loanProcessor; 107 } 108 109 /** 110 * This method is used to change the request type based on selection of pick up location 111 * 112 * @param oleDeliverRequestBo 113 * @return oleDeliverRequestBo 114 */ 115 public OleDeliverRequestBo processRequestType(OleDeliverRequestBo oleDeliverRequestBo) { 116 117 LOG.debug("Inside processRequestType for the Request id :" + oleDeliverRequestBo.getRequestId()); 118 oleDeliverRequestBo = processPatron(oleDeliverRequestBo); 119 oleDeliverRequestBo = processItem(oleDeliverRequestBo); 120 if (oleDeliverRequestBo.getRequestTypeId() != null) { 121 if (oleDeliverRequestBo.getRequestTypeId().equals("3") && oleDeliverRequestBo.getPickUpLocationId() != null && !oleDeliverRequestBo.getPickUpLocationId().isEmpty()) { 122 oleDeliverRequestBo.setRequestTypeId("4"); 123 } else if (oleDeliverRequestBo.getRequestTypeId().equals("5") && oleDeliverRequestBo.getPickUpLocationId() != null && !oleDeliverRequestBo.getPickUpLocationId().isEmpty()) { 124 oleDeliverRequestBo.setRequestTypeId("6"); 125 } else if (oleDeliverRequestBo.getRequestTypeId().equals("1") && oleDeliverRequestBo.getPickUpLocationId() != null && !oleDeliverRequestBo.getPickUpLocationId().isEmpty()) { 126 oleDeliverRequestBo.setRequestTypeId("2"); 127 } 128 } 129 return oleDeliverRequestBo; 130 } 131 132 133 /** 134 * This is to create a new patron object if the user enters the operator Id manually 135 * 136 * @param oleDeliverRequestBo 137 * @return deliver 138 */ 139 public OleDeliverRequestBo processPatron(OleDeliverRequestBo oleDeliverRequestBo) { 140 LOG.debug("Inside processPatron"); 141 OleDeliverRequestBo deliver = oleDeliverRequestBo; 142 143 if (oleDeliverRequestBo.getBorrowerBarcode() != null || oleDeliverRequestBo.getProxyBorrowerBarcode() != null) { 144 Map<String, String> patronMap = new HashMap<String, String>(); 145 patronMap.put(OLEConstants.OleDeliverRequest.PATRON_BARCODE, oleDeliverRequestBo.getBorrowerBarcode()); 146 List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) businessObjectService.findMatching(OlePatronDocument.class, patronMap); 147 if (olePatronDocumentList != null && olePatronDocumentList.size() > 0) { 148 deliver.setOlePatron(olePatronDocumentList.get(0)); 149 deliver.setBorrowerName(olePatronDocumentList.get(0).getPatronName()); 150 deliver.setBorrowerId(olePatronDocumentList.get(0).getOlePatronId()); 151 } else if (olePatronDocumentList != null && olePatronDocumentList.size() == 0) { 152 deliver.setBorrowerId(null); 153 deliver.setFirstName(null); 154 deliver.setLastName(null); 155 deliver.setOlePatron(null); 156 deliver.setBorrowerName(null); 157 deliver.setBorrowerBarcode(null); 158 } 159 if (oleDeliverRequestBo.getRequestCreator().equals(OLEConstants.OleDeliverRequest.REQUESTER_PROXY_PATRON)) { 160 Map<String, String> proxyPatronMap = new HashMap<String, String>(); 161 proxyPatronMap.put(OLEConstants.OleDeliverRequest.PATRON_BARCODE, oleDeliverRequestBo.getProxyBorrowerBarcode()); 162 List<OlePatronDocument> oleProxyPatronDocumentList = (List<OlePatronDocument>) businessObjectService.findMatching(OlePatronDocument.class, proxyPatronMap); 163 if (oleProxyPatronDocumentList != null && oleProxyPatronDocumentList.size() > 0) { 164 deliver.setOleProxyPatron(oleProxyPatronDocumentList.get(0)); 165 deliver.setProxyBorrowerName(oleProxyPatronDocumentList.get(0).getPatronName()); 166 deliver.setProxyBorrowerId(oleProxyPatronDocumentList.get(0).getOlePatronId()); 167 } else if (oleProxyPatronDocumentList != null && oleProxyPatronDocumentList.size() == 0) { 168 deliver.setProxyBorrowerId(null); 169 deliver.setProxyBorrowerName(null); 170 deliver.setOleProxyPatron(null); 171 } 172 } 173 174 } 175 176 return deliver; 177 } 178 179 public boolean processOperator(String principalId) { 180 /*if (getPermissionService().hasPermission(oleDeliverRequestBo.getOperatorCreateId(), OLEConstants.OlePatron.PATRON_NAMESPACE, OLEConstants.CAN_LOAN)) { 181 return true; 182 }*/ 183 // Modified as per comments in Jira OLE-4901 184 boolean isOperator = true; 185 Collection<String> roles = getRoleService().getRoleMemberPrincipalIds(OLEConstants.OlePatron.PATRON_NAMESPACE, OLEConstants.OleDeliverRequest.REQUESTER_OPERATOR, null); 186 if (roles != null) { 187 isOperator = roles.contains(principalId); 188 } 189 return isOperator; 190 } 191 192 /** 193 * This is to check whether the pick up location is selected for the hold type of Request 194 * 195 * @param oleDeliverRequestBo 196 * @return validRequest 197 */ 198 public boolean validateRequestType(OleDeliverRequestBo oleDeliverRequestBo) { 199 LOG.debug("Inside validateRequestType"); 200 boolean validRequest = true; 201 if ((oleDeliverRequestBo.getRequestTypeId().equals("2") || oleDeliverRequestBo.getRequestTypeId().equals("4") || oleDeliverRequestBo.getRequestTypeId().equals("6")) && (oleDeliverRequestBo.getPickUpLocationId() == null) || (oleDeliverRequestBo.getPickUpLocationId() != null && oleDeliverRequestBo.getPickUpLocationId().isEmpty())) { 202 validRequest = false; 203 } 204 return validRequest; 205 } 206 207 208 /** 209 * This is to check whether the patron is having delivery privilege or not 210 * 211 * @param oleDeliverRequestBo 212 * @return hasDeliveryPrivilege 213 */ 214 public boolean validateDeliveryPrivilege(OleDeliverRequestBo oleDeliverRequestBo) { 215 LOG.debug("Inside validateDeliveryPrivilege"); 216 boolean hasDeliveryPrivilege = true; 217 if (oleDeliverRequestBo.getRequestTypeId().equals("1") || oleDeliverRequestBo.getRequestTypeId().equals("3") || oleDeliverRequestBo.getRequestTypeId().equals("5")) { 218 if (oleDeliverRequestBo.getOlePatron() != null && !oleDeliverRequestBo.getOlePatron().isDeliveryPrivilege()) { 219 hasDeliveryPrivilege = false; 220 } 221 } else if (oleDeliverRequestBo.getRequestTypeId().equals("2") || oleDeliverRequestBo.getRequestTypeId().equals("4") || oleDeliverRequestBo.getRequestTypeId().equals("6")) { 222 if (oleDeliverRequestBo.getOlePatron() != null && !oleDeliverRequestBo.getOlePatron().isDeliveryPrivilege() && oleDeliverRequestBo.getPickUpLocationId() == null) { 223 hasDeliveryPrivilege = false; 224 } 225 } 226 return hasDeliveryPrivilege; 227 } 228 229 230 /** 231 * This is to check whether the patron is having paging privilege or not 232 * 233 * @param oleDeliverRequestBo 234 * @return hasPagePrivilege 235 */ 236 public boolean validatePagingPrivilege(OleDeliverRequestBo oleDeliverRequestBo) { 237 LOG.debug("Inside validatePagingPrivilege"); 238 boolean hasPagePrivilege = true; 239 if (oleDeliverRequestBo.getRequestTypeId().equals("5") || oleDeliverRequestBo.getRequestTypeId().equals("6")) { 240 if (!oleDeliverRequestBo.getOlePatron().isPagingPrivilege()) { 241 hasPagePrivilege = false; 242 } 243 } 244 return hasPagePrivilege; 245 } 246 247 248 /** 249 * This for setting the null values for the unselected requester 250 * 251 * @param oleDeliverRequestBo 252 * @return oleDeliverRequestBo 253 */ 254 public OleDeliverRequestBo processRequester(OleDeliverRequestBo oleDeliverRequestBo) { 255 LOG.debug("Inside processRequester"); 256 if (oleDeliverRequestBo.getRequestCreator().equals(OLEConstants.OleDeliverRequest.REQUESTER_PATRON)) { 257 oleDeliverRequestBo.setProxyBorrowerId(null); 258 oleDeliverRequestBo.setOleProxyPatron(null); 259 oleDeliverRequestBo.setOperatorCreateId(null); 260 oleDeliverRequestBo.setOperatorCreator(null); 261 } else if (oleDeliverRequestBo.getRequestCreator().equals(OLEConstants.OleDeliverRequest.REQUESTER_PROXY_PATRON)) { 262 oleDeliverRequestBo.setOperatorCreateId(null); 263 oleDeliverRequestBo.setOperatorCreator(null); 264 } else if (oleDeliverRequestBo.getRequestCreator().equals(OLEConstants.OleDeliverRequest.REQUESTER_OPERATOR)) { 265 oleDeliverRequestBo.setProxyBorrowerId(null); 266 oleDeliverRequestBo.setOleProxyPatron(null); 267 } 268 return oleDeliverRequestBo; 269 } 270 271 272 /** 273 * This is to check whether the login patron is the proxy patron for the real patron 274 * 275 * @param oleDeliverRequestBo 276 * @return validProxy 277 */ 278 public boolean isValidProxyPatron(OleDeliverRequestBo oleDeliverRequestBo) { 279 LOG.debug("Inside isValidProxyPatron"); 280 boolean validProxy = true; 281 Map<String, String> proxyMap = new HashMap<String, String>(); 282 proxyMap.put(OLEConstants.OleDeliverRequest.PATRON_ID, oleDeliverRequestBo.getBorrowerId()); 283 proxyMap.put(OLEConstants.OleDeliverRequest.PROXY_PATRON_ID, oleDeliverRequestBo.getProxyBorrowerId()); 284 if (oleDeliverRequestBo.getProxyBorrowerId() != null && !oleDeliverRequestBo.getProxyBorrowerId().isEmpty()) { 285 List<OleProxyPatronDocument> proxyPatronDocuments = (List<OleProxyPatronDocument>) businessObjectService.findMatching(OleProxyPatronDocument.class, proxyMap); 286 if (proxyPatronDocuments.size() == 0) { 287 validProxy = false; 288 } 289 } 290 return validProxy; 291 } 292 293 294 /** 295 * This is to check whether the request is already raised by the patron for this item 296 * 297 * @param oleDeliverRequestBo 298 * @return alreadyExist 299 */ 300 public boolean isRequestAlreadyRaisedByPatron(OleDeliverRequestBo oleDeliverRequestBo) { 301 LOG.debug("Inside isRequestAlreadyRaised"); 302 boolean alreadyExist = false; 303 Map<String, String> requestMap = new HashMap<String, String>(); 304 requestMap.put(OLEConstants.OleDeliverRequest.BORROWER_ID, oleDeliverRequestBo.getBorrowerId()); 305 requestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid()); 306 List<OleDeliverRequestBo> deliverRequestBos = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class, requestMap); 307 if (deliverRequestBos != null && deliverRequestBos.size() > 0) { 308 alreadyExist = true; 309 } 310 return alreadyExist; 311 } 312 313 314 /** 315 * This is to check whether the requested item is currently in loan to the requesting patron 316 * 317 * @param oleDeliverRequestBo 318 * @return alreadyLoaned 319 */ 320 public boolean isAlreadyLoaned(OleDeliverRequestBo oleDeliverRequestBo) { 321 LOG.debug("Inside isAlreadyLoaned"); 322 boolean alreadyLoaned = false; 323 Map<String, String> loanMap = new HashMap<String, String>(); 324 loanMap.put(OLEConstants.OleDeliverRequest.LOAN_PATRON_ID, oleDeliverRequestBo.getBorrowerId()); 325 loanMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid()); 326 List<OleLoanDocument> loanDocuments = (List<OleLoanDocument>) businessObjectService.findMatching(OleLoanDocument.class, loanMap); 327 if (loanDocuments != null && loanDocuments.size() > 0) { 328 alreadyLoaned = true; 329 } 330 return alreadyLoaned; 331 } 332 333 334 /** 335 * This is to check whether the item is available in the desk or not 336 * 337 * @param oleDeliverRequestBo 338 * @return itemAvailable 339 */ 340 public boolean isItemAvailable(OleDeliverRequestBo oleDeliverRequestBo) { 341 LOG.debug("Inside isItemAvailable"); 342 boolean itemAvailable = true; 343 344 String itemStatuslist = null; 345 String requestTypeCode = oleDeliverRequestBo.getRequestTypeCode(); 346 if (requestTypeCode.equals("Recall/Delivery Request")) { 347 itemStatuslist = loanProcessor.getParameter(OLEConstants.RECALL_DELIVERY_ITEM_STATUS); 348 } else if (requestTypeCode.equals("Recall/Hold Request")) { 349 itemStatuslist = loanProcessor.getParameter(OLEConstants.RECALL_HOLD_ITEM_STATUS); 350 } else if (requestTypeCode.equals("Hold/Delivery Request")) { 351 itemStatuslist = loanProcessor.getParameter(OLEConstants.HOLD_DELIVERY_ITEM_STATUS); 352 } else if (requestTypeCode.equals("Hold/Hold Request")) { 353 itemStatuslist = loanProcessor.getParameter(OLEConstants.HOLD_HOLD_ITEM_STATUS); 354 } else if (requestTypeCode.equals("Page/Delivery Request")) { 355 itemStatuslist = loanProcessor.getParameter(OLEConstants.PAGE_DELIVERY_ITEM_STATUS); 356 } else if (requestTypeCode.equals("Page/Hold Request")) { 357 itemStatuslist = loanProcessor.getParameter(OLEConstants.PAGE_HOLD_ITEM_STATUS); 358 } else if (requestTypeCode.equals("Copy Request")) { 359 itemStatuslist = loanProcessor.getParameter(OLEConstants.COPY_REQUEST_ITEM_STATUS); 360 } else { 361 GlobalVariables.getMessageMap().putError(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, OLEConstants.OleDeliverRequest.REQUEST_ID_INVALID); 362 } 363 String[] str = itemStatuslist.split(";"); 364 for (String itemStatus : str) { 365 if ((itemStatus != null) && (!itemStatus.isEmpty()) && (itemStatus.equals(oleDeliverRequestBo.getItemStatus()))) { 366 itemAvailable = false; 367 } 368 } 369 return itemAvailable; 370 } 371 372 373 /** 374 * This is to check whether the item is available in the desk or not 375 * 376 * @param oleDeliverRequestBo 377 * @return itemAvailable 378 */ 379 public boolean isItemAvailableForLoan(OleDeliverRequestBo oleDeliverRequestBo) { 380 LOG.debug("Inside isItemAvailable"); 381 boolean itemAvailable = false; 382 Map<String, String> loanItemMap = new HashMap<String, String>(); 383 loanItemMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid()); 384 List<OleLoanDocument> loanItemDocuments = (List<OleLoanDocument>) businessObjectService.findMatching(OleLoanDocument.class, loanItemMap); 385 if (loanItemDocuments.size() == 0) { 386 itemAvailable = true; 387 } 388 return itemAvailable; 389 } 390 391 392 /** 393 * This is to check whether the item is eligible to loan 394 * 395 * @param oleDeliverRequestBo 396 * @return itemEligible 397 */ 398 public boolean isItemEligible(OleDeliverRequestBo oleDeliverRequestBo) { 399 LOG.debug("Inside isItemEligible"); 400 boolean itemEligible = true; 401 Map<String, String> statusMap = new HashMap<String, String>(); 402 statusMap.put(OLEConstants.OleDeliverRequest.LOSTBILLREPLACEMENT, OLEConstants.OleDeliverRequest.LOSTBILLREPLACEMENT); 403 statusMap.put(OLEConstants.OleDeliverRequest.MISSINGFINALOVERDUE, OLEConstants.OleDeliverRequest.MISSINGFINALOVERDUE); 404 statusMap.put(OLEConstants.OleDeliverRequest.WITHDRAWNCLIAMSRETURN, OLEConstants.OleDeliverRequest.WITHDRAWNCLIAMSRETURN); 405 406 if (statusMap.containsKey(oleDeliverRequestBo.getItemStatus())) { 407 itemEligible = false; 408 } 409 return itemEligible; 410 } 411 412 /** 413 * This is to check whether the patron record is alive or expired 414 * 415 * @param oleDeliverRequestBo 416 * @return expired 417 */ 418 public String patronRecordExpired(OleDeliverRequestBo oleDeliverRequestBo) { 419 LOG.debug("Inside patronRecordExpired"); 420 String expired = null; 421 Map<String, String> patronMap = new HashMap<String, String>(); 422 patronMap.put(OLEConstants.OleDeliverRequest.PATRON_ID, oleDeliverRequestBo.getBorrowerId()); 423 List<OlePatronDocument> olePatronDocuments = (List<OlePatronDocument>) businessObjectService.findMatching(OlePatronDocument.class, patronMap); 424 if (olePatronDocuments != null && olePatronDocuments.size() > 0) { 425 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OleDeliverRequest.DATE_FORMAT); 426 Date expirationDate = olePatronDocuments.get(0).getExpirationDate(); 427 Date activationDate = olePatronDocuments.get(0).getActivationDate(); 428 if ((fmt.format(activationDate)).compareTo(fmt.format(new Date(System.currentTimeMillis()))) <= 0) { 429 if (expirationDate != null) { 430 if ((fmt.format(expirationDate)).compareTo(fmt.format(new Date(System.currentTimeMillis()))) < 0) { 431 expired = OLEConstants.OleDeliverRequest.PATRON_RECORD_EXPIRE; 432 } 433 } 434 } else { 435 expired = OLEConstants.OleDeliverRequest.PATRON_RECORD_FUTURE; 436 } 437 } 438 return expired; 439 } 440 441 442 /** 443 * This is for retrieving the request raised by the patron 444 * 445 * @param olePatronId 446 * @return deliverRequestBos 447 */ 448 public List<OleDeliverRequestBo> getRequestedItems(String olePatronId) { 449 LOG.debug("Inside getRequestedItems"); 450 Map<String, String> requestMap = new HashMap<String, String>(); 451 requestMap.put(OLEConstants.OleDeliverRequest.BORROWER_ID, olePatronId); 452 List<OleDeliverRequestBo> deliverRequestBos = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class, requestMap); 453 for (int i = 0; i < deliverRequestBos.size(); i++) { 454 processItem(deliverRequestBos.get(i)); 455 } 456 return deliverRequestBos; 457 458 } 459 460 461 /** 462 * This is to check the duplicate in the queue Position while re -ordering 463 * 464 * @param itemList 465 * @return exist 466 */ 467 public String validateQueuePosition(List<OleDeliverRequestBo> itemList) { 468 LOG.debug("Inside validateQueuePosition"); 469 String message = OLEConstants.OleDeliverRequest.REORDER_SUCCESS; 470 List<Integer> queuePositionList = new ArrayList<Integer>(); 471 if (itemList.get(0).getBorrowerQueuePosition() < 1) { 472 return OLEConstants.OleDeliverRequest.POSITIVE_QUEUE_POSITION; 473 } 474 queuePositionList.add(itemList.get(0).getBorrowerQueuePosition()); 475 476 for (int i = 1; i < itemList.size(); i++) { 477 for (int j = 0; j < queuePositionList.size(); j++) { 478 if (itemList.get(i).getBorrowerQueuePosition() != null) { 479 if ((itemList.get(i).getBorrowerQueuePosition() >= 1) && (itemList.get(i).getBorrowerQueuePosition() == queuePositionList.get(j))) { 480 return OLEConstants.OleDeliverRequest.QUEUE_DUPLICATE; 481 } else if ((itemList.get(i).getBorrowerQueuePosition() <= 0)) { 482 return OLEConstants.OleDeliverRequest.POSITIVE_QUEUE_POSITION; 483 } 484 } 485 } 486 queuePositionList.add(itemList.get(i).getBorrowerQueuePosition()); 487 } 488 return message; 489 } 490 491 // 492 493 /** 494 * This is to check whether any request raised for the item 495 * 496 * @param oleDeliverRequestBo 497 * @return exist 498 */ 499 public boolean isRequestRaised(OleDeliverRequestBo oleDeliverRequestBo) { 500 LOG.debug("Inside isRequestRaised"); 501 boolean exist = false; 502 Map<String, String> requestMap = new HashMap<String, String>(); 503 requestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid()); 504 List<OleDeliverRequestBo> deliverRequestBos = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class, requestMap); 505 if (deliverRequestBos.size() > 0) { 506 exist = true; 507 } 508 return exist; 509 } 510 511 512 /** 513 * This method is used to cancel the request document 514 * 515 * @param oleDeliverRequestBo 516 */ 517 public void cancelDocument(OleDeliverRequestBo oleDeliverRequestBo) { 518 LOG.debug("Inside cancelDocument"); 519 Map<String, String> itemMap = new HashMap<String, String>(); 520 itemMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid()); 521 Map<String, String> requestMap = new HashMap<String, String>(); 522 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_ID, oleDeliverRequestBo.getRequestId()); 523 businessObjectService.deleteMatching(OleDeliverRequestBo.class, requestMap); 524 List<OleDeliverRequestBo> oleDeliverRequestDocumentsList = (List<OleDeliverRequestBo>) businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class, itemMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true); 525 businessObjectService.delete(oleDeliverRequestDocumentsList); 526 int queuePosition = 1; 527 for (int i = 0; i < oleDeliverRequestDocumentsList.size(); i++) { 528 oleDeliverRequestDocumentsList.get(i).setBorrowerQueuePosition(queuePosition); 529 queuePosition = queuePosition + 1; 530 } 531 businessObjectService.save(oleDeliverRequestDocumentsList); 532 } 533 534 public void cancelPendingRequestForClaimsReturnedItem(String itemUuid) throws Exception { 535 Map<String, String> requestMap = new HashMap<String, String>(); 536 requestMap.put("itemUuid", itemUuid); 537 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl(); 538 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class, requestMap); 539 for (OleDeliverRequestBo oleDeliverRequestBo : oleDeliverRequestBoList) { 540 cancelDocument(oleDeliverRequestBo); 541 OleItemSearch itemSearch = docstoreUtil.getOleItemSearchList(itemUuid); 542 EntityTypeContactInfoBo entityTypeContactInfoBo = oleDeliverRequestBo.getOlePatron().getEntity().getEntityTypeContactInfos().get(0); 543 List<OleNoticeBo> oleNoticeBos = new ArrayList<OleNoticeBo>(); 544 OleNoticeBo oleNoticeBo = new OleNoticeBo(); 545 oleNoticeBo.setNoticeName(OLEConstants.CANCELLATION_NOTICE); 546 oleNoticeBo.setAuthor(itemSearch.getAuthor() != null ? itemSearch.getAuthor() : ""); 547 oleNoticeBo.setItemCallNumber(itemSearch.getCallNumber() != null ? itemSearch.getCallNumber() : ""); 548 oleNoticeBo.setItemShelvingLocation(itemSearch.getShelvingLocation() != null ? itemSearch.getShelvingLocation() : ""); 549 oleNoticeBo.setItemId(itemSearch.getItemUUID() != null ? itemSearch.getItemUUID() : ""); 550 oleNoticeBo.setTitle(itemSearch.getTitle() != null ? itemSearch.getTitle() : ""); 551 oleNoticeBo.setOleItem(getItem(oleDeliverRequestBo.getItemUuid())); 552 oleNoticeBo.setPatronEmailAddress(getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getPatronHomeEmailId(entityTypeContactInfoBo) : ""); 553 String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL); 554 if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) { 555 fromAddress = OLEConstants.KUALI_MAIL; 556 } 557 if (oleNoticeBo.getPatronEmailAddress() != null && !oleNoticeBo.getPatronEmailAddress().isEmpty()) { 558 oleNoticeBos.add(oleNoticeBo); 559 List list = oleDeliverBatchService.getNoticeForPatron(oleNoticeBos); 560 String content = list.toString(); 561 content = content.replace('[', ' '); 562 content = content.replace(']', ' '); 563 if (!content.trim().equals("")) { 564 OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer"); 565 oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.CANCELLATION_NOTICE), new EmailBody(content), true); 566 } 567 } 568 } 569 } 570 571 /** 572 * This method is to set the item values from docstore 573 * 574 * @param oleDeliverRequestBo 575 * @return oleDeliverRequestBo 576 */ 577 public OleDeliverRequestBo processItem(OleDeliverRequestBo oleDeliverRequestBo) { 578 LOG.debug("Inside processItem"); 579 OleItemSearch oleItemSearch = null; 580 if (oleDeliverRequestBo.getItemType() == null) { 581 // Map<String, String> itemMap = new HashMap<String, String>(); 582 //itemMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid()); 583 OleItemSearch itemSearchList = docstoreUtil.getOleItemSearchList(oleDeliverRequestBo.getItemUuid()); 584 try { 585 //org.kuali.ole.docstore.common.document.Item item=getDocstoreClientLocator().getDocstoreClient().retrieveItem( oleDeliverRequestBo.getItemUuid()); 586 587 588 if (itemSearchList != null) { 589 oleItemSearch = itemSearchList; 590 oleDeliverRequestBo.setTitle(itemSearchList.getTitle()); 591 oleDeliverRequestBo.setAuthor(itemSearchList.getAuthor()); 592 oleDeliverRequestBo.setCallNumber(itemSearchList.getCallNumber()); 593 oleDeliverRequestBo.setItemType(itemSearchList.getItemType()); 594 oleDeliverRequestBo.setItemLocation(itemSearchList.getShelvingLocation()); 595 } 596 } catch (Exception ex) { 597 ex.printStackTrace(); 598 } 599 try { 600 if (oleItemSearch == null) { 601 oleItemSearch = new OleItemSearch(); 602 } 603 // Map docStoreDetails = loanProcessor.getItemDetails(oleDeliverRequestBo.getItemId()); 604 String itemXml = loanProcessor.getItemXML(oleDeliverRequestBo.getItemUuid()); 605 org.kuali.ole.docstore.common.document.content.instance.Item oleItem = loanProcessor.getItemPojo(itemXml); 606 oleItemSearch.setCopyNumber(oleItem.getCopyNumber()); 607 if (oleItem.getItemStatus() != null) { 608 oleItemSearch.setItemStatus(oleItem.getItemStatus().getCodeValue()); 609 } 610 oleItemSearch.setShelvingLocation(getShelvingLocation(oleItem.getLocation())); 611 oleDeliverRequestBo.setCopyNumber(oleItem.getCopyNumber()); 612 if (oleItem.getItemStatus() != null) { 613 oleDeliverRequestBo.setItemStatus(oleItem.getItemStatus().getCodeValue()); 614 } 615 oleDeliverRequestBo.setShelvingLocation(getShelvingLocation(oleItem.getLocation())); 616 if (oleDeliverRequestBo.getRequestTypeId().equals("8")) { 617 oleDeliverRequestBo.setInTransitCheckInNote(oleItem.getCheckinNote()); 618 } 619 } catch (Exception e) { 620 LOG.error(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVAL_LOC), e); //To change body of catch statement use File | Settings | File Templates. 621 } 622 } 623 oleDeliverRequestBo.setOleItemSearch(oleItemSearch); 624 oleDeliverRequestBo = processItemType(oleDeliverRequestBo); 625 return oleDeliverRequestBo; 626 } 627 628 /** 629 * This method is to set the item type name based on the item type code 630 * 631 * @param oleDeliverRequestBo 632 * @return 633 */ 634 public OleDeliverRequestBo processItemType(OleDeliverRequestBo oleDeliverRequestBo) { 635 LOG.debug("Inside process Item Type"); 636 Map<String, String> itemMap = new HashMap<String, String>(); 637 itemMap = new HashMap<String, String>(); 638 itemMap.put(OLEConstants.OleDeliverRequest.ITEM_TYPE_CODE, oleDeliverRequestBo.getItemType()); 639 List<OleInstanceItemType> oleInstanceItemTypeList = (List<OleInstanceItemType>) businessObjectService.findMatching(OleInstanceItemType.class, itemMap); 640 if (oleInstanceItemTypeList != null && oleInstanceItemTypeList.size() > 0) { 641 OleInstanceItemType oleInstanceItemType = oleInstanceItemTypeList.get(0); 642 oleDeliverRequestBo.setItemTypeName(oleInstanceItemType.getInstanceItemTypeName()); 643 } 644 645 return oleDeliverRequestBo; 646 } 647 648 /** 649 * This method is to retrieve the shelving location from item 650 * 651 * @param oleLocation 652 * @return locationLevelName 653 */ 654 private String getShelvingLocation(org.kuali.ole.docstore.common.document.content.instance.Location oleLocation) { 655 656 LOG.debug("Inside getShelvingLocation"); 657 String locationLevelName = ""; 658 if (oleLocation != null) { 659 org.kuali.ole.docstore.common.document.content.instance.LocationLevel locationLevel = 660 oleLocation.getLocationLevel(); 661 if (locationLevel != null) { 662 while (locationLevel.getLocationLevel() != null && !locationLevel.getLevel().equalsIgnoreCase(OLEConstants.OleDeliverRequest.SHELVING)) { 663 locationLevel = locationLevel.getLocationLevel(); 664 } 665 locationLevelName = locationLevel.getName(); 666 } 667 } 668 return locationLevelName; 669 } 670 671 672 /** 673 * This method is to check whether the selected request can be raised for the item 674 * 675 * @param oleDeliverRequestBo 676 * @return canRaiseRequest 677 */ 678 public boolean canRaiseRequest(OleDeliverRequestBo oleDeliverRequestBo) { 679 LOG.debug("Inside canRaiseRequest"); 680 boolean canRaiseRequest = true; 681 682 if (isItemAvailable(oleDeliverRequestBo)) { 683 canRaiseRequest = false; 684 685 686 } 687 return canRaiseRequest; 688 } 689 690 691 /** 692 * racle 693 * This method is to update the request id in the loan document 694 * 695 * @param oleDeliverRequestBo 696 */ 697 public OleDeliverRequestBo updateLoanDocument(OleDeliverRequestBo oleDeliverRequestBo) { 698 LOG.debug("Inside updateLoanDocument"); 699 Map<String, String> loanMap = new HashMap<String, String>(); 700 loanMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid()); 701 List<OleLoanDocument> oleLoanDocumentList = (List<OleLoanDocument>) businessObjectService.findMatching(OleLoanDocument.class, loanMap); 702 if (oleLoanDocumentList != null && oleLoanDocumentList.size() > 0 && oleLoanDocumentList.get(0) != null && oleLoanDocumentList.get(0).getOleRequestId() == null) { 703 if (oleLoanDocumentList.get(0).getLoanId() != null) { 704 // oleLoanDocumentList.get(0).setOleRequestId(oleDeliverRequestBo.getRequestId()); 705 oleDeliverRequestBo.setLoanTransactionRecordNumber(oleLoanDocumentList.get(0).getLoanId()); 706 } 707 // businessObjectService.save(oleLoanDocumentList.get(0)); 708 709 } 710 return oleDeliverRequestBo; 711 } 712 713 /** 714 * @param requestId 715 * @param itemUUID 716 * @param operatorId 717 * @param loanTransactionNumber 718 */ 719 public void deleteRequest(String requestId, String itemUUID, String operatorId, String loanTransactionNumber) { 720 LOG.debug("Inside deleteRequest"); 721 Map<String, String> requestMap = new HashMap<String, String>(); 722 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_ID, requestId); 723 createRequestHistoryRecord(requestId, operatorId, loanTransactionNumber); 724 Map<String, String> itemMap = new HashMap<String, String>(); 725 itemMap.put(OLEConstants.ITEM_UUID, itemUUID); 726 List<OleDeliverRequestBo> oleDeliverRequestDocumentsList = (List<OleDeliverRequestBo>) businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class, itemMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true); 727 businessObjectService.delete(oleDeliverRequestDocumentsList); 728 int queuePosition = 1; 729 for (int i = 0; i < oleDeliverRequestDocumentsList.size(); i++) { 730 oleDeliverRequestDocumentsList.get(i).setBorrowerQueuePosition(queuePosition); 731 queuePosition = queuePosition + 1; 732 } 733 businessObjectService.save(oleDeliverRequestDocumentsList); 734 735 } 736 737 /** 738 * This for retrieving the item Details from docstore 739 * 740 * @param itemUUID 741 * @return oleItemSearch 742 */ 743 public OleItemSearch getItemDetails(String itemUUID) { 744 LOG.debug("Inside getItemDetails"); 745 OleItemSearch oleItemSearch = getItemDetailsForPatron(itemUUID); 746 try { 747 // Map docStoreDetails= loanProcessor.getItemDetails(itemBarCode); 748 String itemXml = loanProcessor.getItemXML(itemUUID); 749 org.kuali.ole.docstore.common.document.content.instance.Item oleItem = loanProcessor.getItemPojo(itemXml); 750 if (oleItem != null && oleItem.getItemType() != null) { 751 oleItemSearch.setItemType(processItemType(oleItem.getItemType().getCodeValue())); 752 } 753 oleItemSearch.setCopyNumber(oleItem.getCopyNumber()); 754 if (oleItem.getItemStatus() != null) { 755 oleItemSearch.setItemStatus(oleItem.getItemStatus().getCodeValue()); 756 } 757 oleItemSearch.setShelvingLocation(getShelvingLocation(oleItem.getLocation())); 758 oleItemSearch.setVolumeNumber(oleItem.getVolumeNumber()); 759 } catch (Exception e) { 760 LOG.error("Not able to retrieve information from the docstore for the Item Barcode : " + itemUUID, e); //To change body of catch statement use File | Settings | File Templates. 761 } 762 return oleItemSearch; 763 } 764 765 /** 766 * This method is for retrieving the item details for displaying in the patron screen 767 * 768 * @param itemUUID 769 * @return OleItemSearch 770 */ 771 public OleItemSearch getItemDetailsForPatron(String itemUUID) { 772 LOG.debug("Inside getItemDetailsForPatron"); 773 OleItemSearch oleItemSearch; 774 try { 775 776 Map<String, String> itemMap = new HashMap<String, String>(); 777 // itemMap.put(OLEConstants.OleDeliverRequest.ITEM_UUID, itemUUID); 778 OleItemSearch itemSearchList = docstoreUtil.getOleItemSearchList(itemUUID); 779 if (itemSearchList != null) { 780 return oleItemSearch = itemSearchList; 781 } 782 } catch (NullPointerException e) { 783 LOG.error("No item details available for the Item Barcode : " + itemUUID, e); 784 } 785 786 return new OleItemSearch(); 787 788 } 789 790 /** 791 * This method is to re-order the queuePosition based on the priority while creating the request 792 * 793 * @param oleDeliverRequestBo 794 * @return OleDeliverRequestBo 795 */ 796 public OleDeliverRequestBo reOrderQueuePosition(OleDeliverRequestBo oleDeliverRequestBo) { 797 LOG.debug("Inside reOrderQueuePosition"); 798 List<OleDeliverRequestBo> existingRequest = new ArrayList<OleDeliverRequestBo>(); 799 String queue = getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.REQUEST_QUEUE); 800 List<String> orderQueue = new ArrayList<String>(); 801 String[] queueArray = queue.split(";"); 802 for (int i = 0; i < queueArray.length; i++) { 803 orderQueue.add(queueArray[i]); 804 } 805 List<OleDeliverRequestBo> finalList = new ArrayList<OleDeliverRequestBo>(); 806 Map<String, String> recallRequestMap = new HashMap<String, String>(); 807 recallRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid()); 808 recallRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "1"); 809 Map<String, String> recallHoldRequestMap = new HashMap<String, String>(); 810 recallHoldRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid()); 811 recallHoldRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "2"); 812 Map<String, String> holdRequestMap = new HashMap<String, String>(); 813 holdRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid()); 814 holdRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "3"); 815 Map<String, String> holdHoldRequestMap = new HashMap<String, String>(); 816 holdHoldRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid()); 817 holdHoldRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "4"); 818 Map<String, String> pageRequestMap = new HashMap<String, String>(); 819 pageRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid()); 820 pageRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "5"); 821 Map<String, String> pageHoldRequestMap = new HashMap<String, String>(); 822 pageHoldRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid()); 823 pageHoldRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "6"); 824 Map<String, String> copyRequestMap = new HashMap<String, String>(); 825 copyRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid()); 826 copyRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "7"); 827 Map<String, String> inTransitRequestMap = new HashMap<String, String>(); 828 inTransitRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid()); 829 inTransitRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "8"); 830 List<OleDeliverRequestBo> recallList = (List<OleDeliverRequestBo>) businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class, recallRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true); 831 List<OleDeliverRequestBo> recallHoldList = (List<OleDeliverRequestBo>) businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class, recallHoldRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true); 832 List<OleDeliverRequestBo> holdList = (List<OleDeliverRequestBo>) businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class, holdRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true); 833 List<OleDeliverRequestBo> holdHoldList = (List<OleDeliverRequestBo>) businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class, holdHoldRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true); 834 List<OleDeliverRequestBo> pageList = (List<OleDeliverRequestBo>) businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class, pageRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true); 835 List<OleDeliverRequestBo> pageHoldList = (List<OleDeliverRequestBo>) businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class, pageHoldRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true); 836 List<OleDeliverRequestBo> copyList = (List<OleDeliverRequestBo>) businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class, copyRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true); 837 List<OleDeliverRequestBo> inTransitList = (List<OleDeliverRequestBo>) businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class, inTransitRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true); 838 if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.RECALL_DELIVERY)) { 839 recallList.add(oleDeliverRequestBo); 840 } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.HOLD_DELIVERY)) { 841 holdList.add(oleDeliverRequestBo); 842 } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.PAGE_DELIVERY)) { 843 pageList.add(oleDeliverRequestBo); 844 } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.COPY)) { 845 copyList.add(oleDeliverRequestBo); 846 } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.INTRANSIT)) { 847 inTransitList.add(oleDeliverRequestBo); 848 } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.RECALL_HOLD)) { 849 recallHoldList.add(oleDeliverRequestBo); 850 } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.HOLD_HOLD)) { 851 holdHoldList.add(oleDeliverRequestBo); 852 } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.PAGE_HOLD)) { 853 pageHoldList.add(oleDeliverRequestBo); 854 } 855 OleDeliverRequestBo oleDeliverRequestBo1; 856 for (int i = 0; i < orderQueue.size(); i++) { 857 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.RECALL) && recallList.size() > 0) { 858 for (int x = 0; x < recallList.size(); x++) { 859 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(recallList.get(x)); 860 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1); 861 this.queuePosition = this.queuePosition + 1; 862 finalList.add(oleDeliverRequestBo1); 863 864 } 865 } 866 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.HOLD) && holdList.size() > 0) { 867 for (int x = 0; x < holdList.size(); x++) { 868 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(holdList.get(x)); 869 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1); 870 this.queuePosition = this.queuePosition + 1; 871 finalList.add(oleDeliverRequestBo1); 872 873 } 874 } 875 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.PAGE) && pageList.size() > 0) { 876 for (int x = 0; x < pageList.size(); x++) { 877 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(pageList.get(x)); 878 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1); 879 this.queuePosition = this.queuePosition + 1; 880 finalList.add(oleDeliverRequestBo1); 881 } 882 } 883 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.RECALL) && recallHoldList.size() > 0) { 884 for (int x = 0; x < recallHoldList.size(); x++) { 885 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(recallHoldList.get(x)); 886 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1); 887 this.queuePosition = this.queuePosition + 1; 888 finalList.add(oleDeliverRequestBo1); 889 890 } 891 } 892 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.HOLD) && holdHoldList.size() > 0) { 893 for (int x = 0; x < holdHoldList.size(); x++) { 894 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(holdHoldList.get(x)); 895 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1); 896 this.queuePosition = this.queuePosition + 1; 897 finalList.add(oleDeliverRequestBo1); 898 899 } 900 } 901 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.PAGE) && pageHoldList.size() > 0) { 902 for (int x = 0; x < pageHoldList.size(); x++) { 903 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(pageHoldList.get(x)); 904 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1); 905 this.queuePosition = this.queuePosition + 1; 906 finalList.add(oleDeliverRequestBo1); 907 } 908 } 909 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.COPY) && copyList.size() > 0) { 910 for (int x = 0; x < copyList.size(); x++) { 911 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(copyList.get(x)); 912 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1); 913 this.queuePosition = this.queuePosition + 1; 914 finalList.add(oleDeliverRequestBo1); 915 916 } 917 } 918 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.INTRANSIT) && inTransitList.size() > 0) { 919 for (int x = 0; x < inTransitList.size(); x++) { 920 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(inTransitList.get(x)); 921 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1); 922 this.queuePosition = this.queuePosition + 1; 923 finalList.add(oleDeliverRequestBo1); 924 925 } 926 } 927 } 928 for (int i = 0; i < finalList.size(); i++) { 929 if (finalList.get(i).getRequestId() == null) { 930 oleDeliverRequestBo.setBorrowerQueuePosition(finalList.get(i).getBorrowerQueuePosition()); 931 finalList.remove(finalList.get(i)); 932 } 933 } 934 businessObjectService.save(finalList); 935 this.queuePosition = 0; 936 return oleDeliverRequestBo; 937 } 938 939 /** 940 * Thsi method is to check whether the item is available in doc store or not 941 * 942 * @param oleDeliverRequestBo 943 * @return boolean 944 */ 945 public boolean isItemAvailbleInDocstore(OleDeliverRequestBo oleDeliverRequestBo) { 946 LOG.debug("Inside isItemAvailbleInDocstore"); 947 boolean available = false; 948 Map<String, String> itemMap = new HashMap<String, String>(); 949 try { 950 String itemUUID = ""; 951 org.kuali.ole.docstore.common.document.Item item = new ItemOleml(); 952 org.kuali.ole.docstore.common.search.SearchParams search_Params = new org.kuali.ole.docstore.common.search.SearchParams(); 953 SearchResponse searchResponse = null; 954 search_Params.getSearchConditions().add(search_Params.buildSearchCondition("", search_Params.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), item.ITEM_BARCODE, oleDeliverRequestBo.getItemId()), "")); 955 956 957 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), "id")); 958 ; 959 960 /* Map<String,String> map=new HashMap<>(); 961 map.put(item.BARCODE, itemBarcode); 962 item=getDocstoreClientLocator().getDocstoreClient().findItem(map);*/ 963 964 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(search_Params); 965 for (SearchResult searchResult : searchResponse.getSearchResults()) { 966 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) { 967 String fieldName = searchResultField.getFieldName(); 968 String fieldValue = searchResultField.getFieldValue() != null ? searchResultField.getFieldValue() : ""; 969 970 if (fieldName.equalsIgnoreCase("id") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) { 971 itemUUID = fieldValue; 972 } 973 974 } 975 } 976 977 978 oleDeliverRequestBo.setItemUuid(itemUUID); 979 } catch (Exception e) { 980 LOG.error(e, e); 981 //To change body of catch statement use File | Settings | File Templates. 982 } 983 // itemMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid()); 984 OleItemSearch itemSearchList = docstoreUtil.getOleItemSearchList(oleDeliverRequestBo.getItemUuid()); 985 if (itemSearchList != null) { 986 oleDeliverRequestBo.setTitle(itemSearchList.getTitle()); 987 oleDeliverRequestBo.setAuthor(itemSearchList.getAuthor()); 988 oleDeliverRequestBo.setCallNumber(itemSearchList.getCallNumber()); 989 oleDeliverRequestBo.setItemType(itemSearchList.getItemType()); 990 } 991 try { 992 // Map docStoreDetails = loanProcessor.getItemDetailsByUUID(oleDeliverRequestBo.getItemId()); 993 String itemXml = loanProcessor.getItemXML(oleDeliverRequestBo.getItemUuid()); 994 org.kuali.ole.docstore.common.document.content.instance.Item oleItem = loanProcessor.getItemPojo(itemXml); 995 996 oleDeliverRequestBo.setCopyNumber(oleItem.getCopyNumber()); 997 if (oleItem.getItemStatus() != null) { 998 oleDeliverRequestBo.setItemStatus(oleItem.getItemStatus().getCodeValue()); 999 } 1000 oleDeliverRequestBo.setShelvingLocation(getShelvingLocation(oleItem.getLocation())); 1001 available = true; 1002 } catch (Exception e) { 1003 LOG.error(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVAL_LOC), e); //To change body of catch statement use File | Settings | File Templates. 1004 } 1005 return available; 1006 } 1007 1008 public OleDeliverRequestBo populateItemDetailsToRequest(OleDeliverRequestBo oleDeliverRequestBo, OleItemSearch oleItemSearch) { 1009 LOG.debug("Inside populateItemDetailsToRequest"); 1010 if (oleDeliverRequestBo != null && oleItemSearch != null) { 1011 oleDeliverRequestBo.setAuthor(oleItemSearch.getAuthor()); 1012 oleDeliverRequestBo.setTitle(oleItemSearch.getTitle()); 1013 oleDeliverRequestBo.setCallNumber(oleItemSearch.getCallNumber()); 1014 oleDeliverRequestBo.setCopyNumber(oleItemSearch.getCopyNumber()); 1015 oleDeliverRequestBo.setItemType(oleItemSearch.getItemType()); 1016 oleDeliverRequestBo.setItemStatus(oleItemSearch.getItemStatus()); 1017 oleItemSearch.setShelvingLocation(oleDeliverRequestBo.getShelvingLocation()); 1018 } 1019 return oleDeliverRequestBo; 1020 } 1021 1022 1023 public OleDeliverRequestBo generateRecallNotice(OleDeliverRequestBo oleDeliverRequestBo) throws Exception { 1024 Map<String, String> loanMap = new HashMap<String, String>(); 1025 loanMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid()); 1026 List<OleLoanDocument> loanDocuments = (List<OleLoanDocument>) businessObjectService.findMatching(OleLoanDocument.class, loanMap); 1027 OleLoanDocument oleLoanDocument = loanDocuments.get(0); 1028 Map<String, String> patronMap = new HashMap<String, String>(); 1029 patronMap.put(OLEConstants.OleDeliverRequest.PATRON_ID, oleLoanDocument.getPatronId()); 1030 List<OlePatronDocument> patronDocumentList = (List<OlePatronDocument>) businessObjectService.findMatching(OlePatronDocument.class, patronMap); 1031 OleNoticeBo oleNoticeBo = new OleNoticeBo(); 1032 org.kuali.ole.docstore.common.document.content.instance.Item item; 1033 if (patronDocumentList.size() > 0) { 1034 OlePatronDocument olePatronDocument = patronDocumentList.get(0); 1035 EntityTypeContactInfoBo entityTypeContactInfoBo = olePatronDocument.getEntity().getEntityTypeContactInfos().get(0); 1036 oleNoticeBo.setPatronName(olePatronDocument.getEntity().getNames().get(0).getFirstName() + " " + oleDeliverRequestBo.getOlePatron().getEntity().getNames().get(0).getLastName()); 1037 oleNoticeBo.setPatronAddress(getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getPatronPreferredAddress(entityTypeContactInfoBo) : ""); 1038 oleNoticeBo.setPatronEmailAddress(getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getPatronHomeEmailId(entityTypeContactInfoBo) : ""); 1039 oleNoticeBo.setPatronPhoneNumber(getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getPatronHomePhoneNumber(entityTypeContactInfoBo) : ""); 1040 } 1041 oleNoticeBo.setAuthor(oleDeliverRequestBo.getAuthor() != null ? oleDeliverRequestBo.getAuthor() : ""); 1042 oleNoticeBo.setCirculationDeskAddress(""); 1043 oleNoticeBo.setCirculationDeskName(""); 1044 oleNoticeBo.setCirculationDeskEmailAddress(""); 1045 oleNoticeBo.setCirculationDeskPhoneNumber(""); 1046 oleNoticeBo.setItemCallNumber(oleDeliverRequestBo.getCallNumber() != null ? oleDeliverRequestBo.getCallNumber() : ""); 1047 oleNoticeBo.setItemShelvingLocation(oleDeliverRequestBo.getShelvingLocation() != null ? oleDeliverRequestBo.getShelvingLocation() : ""); 1048 oleNoticeBo.setItemId(oleDeliverRequestBo.getItemId() != null ? oleDeliverRequestBo.getItemId() : ""); 1049 oleNoticeBo.setTitle(oleDeliverRequestBo.getTitle() != null ? oleDeliverRequestBo.getTitle() : ""); 1050 oleNoticeBo.setOleItem(getItem(oleDeliverRequestBo.getItemUuid())); 1051 oleNoticeBo.setOlePatron(oleDeliverRequestBo.getOlePatron()); 1052 oleNoticeBo.setVolumeNumber(oleNoticeBo.getOleItem().getVolumeNumber() != null ? oleNoticeBo.getOleItem().getVolumeNumber() : ""); 1053 oleNoticeBo.setOriginalDueDate(oleLoanDocument.getLoanDueDate()); 1054 oleNoticeBo.setNewDueDate(oleDeliverRequestBo.getNewDueDate()); 1055 oleNoticeBo.setOriginalDueDate(oleDeliverRequestBo.getOriginalDueDate()); 1056 /*if (oleDeliverRequestBo.getRecallDueDate() != null) { 1057 oleNoticeBo.setNewDueDate(oleDeliverRequestBo.getRecallDueDate()); 1058 } else { 1059 oleNoticeBo.setNewDueDate(oleLoanDocument.getLoanDueDate()); 1060 }*/ 1061 oleNoticeBo.setNoticeName(OLEConstants.NOTICE_RECALL); 1062 String noticeContent = getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.RECALL_BODY); 1063 oleNoticeBo.setNoticeSpecificContent(noticeContent); 1064 // oleNoticeBo = setPatronDetailsForNotice(oleNoticeBo,oleDeliverRequestBo.getOlePatron()); 1065 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl(); 1066 List<OleNoticeBo> oleNoticeBos = new ArrayList<OleNoticeBo>(); 1067 String noticeType = getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.RECALL_NOTICE_TYPE); 1068 oleNoticeBos.add(oleNoticeBo); 1069 if (noticeType.equalsIgnoreCase(OLEConstants.EMAIL)) { 1070 String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL); 1071 if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) { 1072 fromAddress = OLEConstants.KUALI_MAIL; 1073 } 1074 if (oleNoticeBo.getPatronEmailAddress() != null && !oleNoticeBo.getPatronEmailAddress().isEmpty()) { 1075 List list = oleDeliverBatchService.getNoticeForPatron(oleNoticeBos); 1076 String content = list.toString(); 1077 content = content.replace('[', ' '); 1078 content = content.replace(']', ' '); 1079 if (!content.trim().equals("")) { 1080 OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer"); 1081 oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(content), true); 1082 } else { 1083 for (OleNoticeBo oleNoticeBo1 : oleNoticeBos) { 1084 LOG.info("Notice Type :" + oleNoticeBo1.getNoticeName() + " " + "Item Barcode : " + oleNoticeBo1.getItemId() + " " + "Patron Name :" + oleNoticeBo1.getPatronName()); 1085 } 1086 } 1087 LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress()); 1088/* 1089 Mailer mailer = CoreApiServiceLocator.getMailer(); 1090 mailer.sendEmail(new EmailFrom(OLEConstants.KUALI_MAIL), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(list.toString()), true); 1091 */ 1092 } 1093 } else if (noticeType.equalsIgnoreCase(OLEConstants.SMS)) { 1094 //oleNoticeBos.add(oleNoticeBo); 1095 Map map = oleDeliverBatchService.getSMSForPatron(oleNoticeBos); 1096 HashMap sms = (HashMap) map.get(OLEConstants.OleDeliverRequest.RECALL); 1097 Iterator it = sms.entrySet().iterator(); 1098 while (it.hasNext()) { 1099 Map.Entry pairs = (Map.Entry) it.next(); 1100 String patronPhoneNumber = oleNoticeBo.getPatronPhoneNumber(); 1101 OleSms oleSms = new OleSms(); 1102 oleSms.sendSms("", patronPhoneNumber, (String) pairs.getValue()); 1103 } 1104 1105 } 1106 if (noticeType.equalsIgnoreCase(OLEConstants.MAIL) || noticeType.equalsIgnoreCase(OLEConstants.EMAIL)) { 1107 //oleNoticeBos.add(oleNoticeBo); 1108 oleDeliverBatchService.getPdfNoticeForPatron(oleNoticeBos); 1109 LOG.info("Recall Notice Pdf generated for item Id" + oleNoticeBo.getItemId()); 1110 } 1111 oleDeliverRequestBo = (OleDeliverRequestBo) ObjectUtils.deepCopy(oleDeliverRequestBo); 1112 oleDeliverRequestBo.setRecallNoticeSentDate(new java.sql.Date(System.currentTimeMillis())); 1113 return oleDeliverRequestBo; 1114 } 1115 1116 1117 public void generateOnHoldNotice() throws Exception { 1118 1119 List<OleDeliverRequestBo> finalDeliverRequestBoList = new ArrayList<OleDeliverRequestBo>(); 1120 Map<String, String> onHoldNoticeMap = new HashMap<String, String>(); 1121 onHoldNoticeMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "2"); 1122 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class, onHoldNoticeMap); 1123 Map<String, String> onHoldHoldNoticeMap = new HashMap<String, String>(); 1124 onHoldHoldNoticeMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "4"); 1125 List<OleDeliverRequestBo> oleDeliverRequestBoList1 = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class, onHoldHoldNoticeMap); 1126 oleDeliverRequestBoList.addAll(oleDeliverRequestBoList1); 1127 OleDeliverRequestBo oleDeliverRequestBo; 1128 List<OleNoticeBo> noticesList = new ArrayList<OleNoticeBo>(); 1129 EntityTypeContactInfoBo entityTypeContactInfoBo; 1130 OleNoticeBo oleNoticeBo; 1131 org.kuali.ole.docstore.common.document.content.instance.Item item; 1132 for (int i = 0; i < oleDeliverRequestBoList.size(); i++) { 1133 if (docstoreUtil.isItemAvailableInDocStore(oleDeliverRequestBoList.get(i))) { 1134 item = oleDeliverRequestBoList.get(i).getOleItem(); 1135 if (item != null && item.getItemStatus() != null && item.getItemStatus().getCodeValue() != null && item.getItemStatus().getCodeValue().equals(OLEConstants.ITEM_STATUS_ON_HOLD) && oleDeliverRequestBoList.get(i).getOnHoldNoticeSentDate() == null) { 1136 entityTypeContactInfoBo = oleDeliverRequestBoList.get(i).getOlePatron().getEntity().getEntityTypeContactInfos().get(0); 1137 oleNoticeBo = new OleNoticeBo(); 1138 oleNoticeBo.setAuthor(oleDeliverRequestBoList.get(i).getAuthor()); 1139 oleNoticeBo.setCirculationDeskAddress(""); 1140 oleNoticeBo.setCirculationDeskName(""); 1141 oleNoticeBo.setCirculationDeskEmailAddress(""); 1142 oleNoticeBo.setCirculationDeskPhoneNumber(""); 1143 oleNoticeBo.setPatronName(oleDeliverRequestBoList.get(i).getOlePatron().getEntity().getNames().get(0).getFirstName() + " " + oleDeliverRequestBoList.get(i).getOlePatron().getEntity().getNames().get(0).getLastName()); 1144 oleNoticeBo.setPatronAddress(getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getPatronPreferredAddress(entityTypeContactInfoBo) : ""); 1145 oleNoticeBo.setPatronEmailAddress(getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getPatronHomeEmailId(entityTypeContactInfoBo) : ""); 1146 oleNoticeBo.setPatronPhoneNumber(getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getPatronHomePhoneNumber(entityTypeContactInfoBo) : ""); 1147 oleNoticeBo.setItemCallNumber(oleDeliverRequestBoList.get(i).getCallNumber() != null ? oleDeliverRequestBoList.get(i).getCallNumber() : ""); 1148 oleNoticeBo.setItemShelvingLocation(oleDeliverRequestBoList.get(i).getShelvingLocation() != null ? oleDeliverRequestBoList.get(i).getShelvingLocation() : ""); 1149 oleNoticeBo.setItemId(oleDeliverRequestBoList.get(i).getItemId() != null ? oleDeliverRequestBoList.get(i).getItemId() : ""); 1150 oleNoticeBo.setTitle(oleDeliverRequestBoList.get(i).getTitle() != null ? oleDeliverRequestBoList.get(i).getTitle() : ""); 1151 oleNoticeBo.setOleItem(item); 1152 oleNoticeBo.setOlePatron(oleDeliverRequestBoList.get(i).getOlePatron()); 1153 oleNoticeBo.setVolumeNumber(item.getVolumeNumber() != null ? item.getVolumeNumber() : ""); 1154 oleNoticeBo.setNewDueDate(new Date()); 1155 oleNoticeBo.setOriginalDueDate(new Date()); 1156 oleNoticeBo.setNoticeName(OLEConstants.NOTICE_ONHOLD); 1157 oleNoticeBo.setCirculationDeskName(oleDeliverRequestBoList.get(i).getOlePickUpLocation().getCirculationDeskPublicName()); 1158 String circulationDeskId = oleDeliverRequestBoList.get(i).getPickUpLocationId(); 1159 int noDays = 0; 1160 Map<String, String> mapCirculationDesk = new HashMap<String, String>(); 1161 mapCirculationDesk.put("circulationDeskId", circulationDeskId); 1162 List<OleCirculationDesk> oleCirculationDesks = (List<OleCirculationDesk>) KRADServiceLocator.getBusinessObjectService().findMatching(OleCirculationDesk.class, mapCirculationDesk); 1163 if (oleCirculationDesks.size() > 0) { 1164 OleCirculationDesk oleCirculationDesk = oleCirculationDesks.get(0); 1165 noDays = Integer.parseInt(oleCirculationDesk.getOnHoldDays()); 1166 } 1167 Calendar calendar = Calendar.getInstance(); 1168 calendar.add(Calendar.DATE, noDays); 1169 Date date = calendar.getTime(); 1170 oleNoticeBo.setExpiredOnHoldDate(date); 1171 String maxNumOfDays = oleDeliverRequestBoList.get(i).getOlePickUpLocation().getOnHoldDays() != null ? oleDeliverRequestBoList.get(i).getOlePickUpLocation().getOnHoldDays() : loanProcessor.getParameter(OLEConstants.MAX_NO_OF_DAYS_ON_HOLD); 1172 Integer maxNumberOfDaysOnHold = new Integer(maxNumOfDays); 1173 oleNoticeBo.setOnHoldDueDate(dateAdd(oleDeliverRequestBoList.get(i).getCreateDate(), maxNumberOfDaysOnHold)); 1174 String noticeContent = getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.ONHOLD_BODY); 1175 oleNoticeBo.setNoticeSpecificContent(noticeContent); 1176 noticesList.add(oleNoticeBo); 1177 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl(); 1178 String agendaName = OLEConstants.BATCH_PROGRAM_AGENDA; 1179 HashMap<String, Object> termValues = new HashMap<String, Object>(); 1180 OleCirculationDesk oleCirculationDesk = oleDeliverRequestBoList.get(i).getOlePickUpLocation(); 1181 OlePatronDocument olePatronDocument = oleDeliverRequestBoList.get(i).getOlePatron(); 1182 String deskLocation = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskCode() : ""; 1183 String deskLocationName = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskPublicName() : ""; 1184 termValues.put(OLEConstants.BORROWER_TYPE, olePatronDocument.getOleBorrowerType().getBorrowerTypeCode()); 1185 termValues.put(OLEConstants.DESK_LOCATION, deskLocation); 1186 termValues.put(OLEConstants.NOTICE, OLEConstants.NOTICE_ONHOLD); 1187 LOG.info("termValues.toString()" + termValues.toString()); 1188 EngineResults engineResults = loanProcessor.getEngineResults(agendaName, termValues); 1189 String noticeType = (String) engineResults.getAttribute(OLEConstants.NOTICE_TYPE); 1190 LOG.info("**************" + noticeType); 1191 noticeType = noticeType != null ? noticeType : getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.ONHOLD_NOTICE_TYPE); 1192 if (noticeType != null && (noticeType.equalsIgnoreCase(OLEConstants.EMAIL) || noticeType.equalsIgnoreCase(OLEConstants.MAIL))) { 1193 LOG.info("noticesList.size()" + noticesList.size()); 1194 oleDeliverBatchService.getPdfNoticeForPatron(noticesList); 1195 LOG.info("OnHold Notice Pdf generated for item Id" + oleNoticeBo.getItemId()); 1196 } 1197 if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.EMAIL)) { 1198 String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL); 1199 if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) { 1200 fromAddress = OLEConstants.KUALI_MAIL; 1201 } 1202 if (oleNoticeBo.getPatronEmailAddress() != null && !oleNoticeBo.getPatronEmailAddress().isEmpty()) { 1203 List list = oleDeliverBatchService.getNoticeForPatron(noticesList); 1204 String content = list.toString(); 1205 content = content.replace('[', ' '); 1206 content = content.replace(']', ' '); 1207 if (!content.trim().equals("")) { 1208 OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer"); 1209 oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(content), true); 1210 } else { 1211 for (OleNoticeBo oleNoticeBo1 : noticesList) { 1212 LOG.info("Notice Type :" + oleNoticeBo1.getNoticeName() + " " + "Item Barcode : " + oleNoticeBo1.getItemId() + " " + "Patron Name :" + oleNoticeBo1.getPatronName()); 1213 } 1214 } 1215 LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress()); 1216 /* Mailer mailer = CoreApiServiceLocator.getMailer(); 1217 mailer.sendEmail(new EmailFrom(OLEConstants.KUALI_MAIL), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(list.toString()), true); 1218 */ 1219 } 1220 } else if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.SMS)) { 1221 Map map = oleDeliverBatchService.getSMSForPatron(noticesList); 1222 HashMap sms = (HashMap) map.get(OLEConstants.NOTICE_ONHOLD); 1223 Iterator it = sms.entrySet().iterator(); 1224 while (it.hasNext()) { 1225 Map.Entry pairs = (Map.Entry) it.next(); 1226 String patronPhoneNumber = oleNoticeBo.getPatronPhoneNumber(); 1227 OleSms oleSms = new OleSms(); 1228 oleSms.sendSms("", patronPhoneNumber, (String) pairs.getValue()); 1229 } 1230 } 1231 // To do send Notice 1232 oleDeliverRequestBoList.get(i).setOleItem(null); 1233 oleDeliverRequestBo = (OleDeliverRequestBo) ObjectUtils.deepCopy(oleDeliverRequestBoList.get(i)); 1234 oleDeliverRequestBo.setOnHoldNoticeSentDate(new java.sql.Date(System.currentTimeMillis())); 1235 finalDeliverRequestBoList.add(oleDeliverRequestBo); 1236 } 1237 } 1238 businessObjectService.save(finalDeliverRequestBoList); 1239 } 1240 } 1241 1242 public void generateRequestExpirationNotice() throws Exception { 1243 List<OleDeliverRequestBo> oleDeliverRequestBoList = new ArrayList<OleDeliverRequestBo>(); 1244 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl(); 1245 oleDeliverRequestBoList = (List<OleDeliverRequestBo>) businessObjectService.findAll(OleDeliverRequestBo.class); 1246 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OleDeliverRequest.DATE_FORMAT); 1247 EntityTypeContactInfoBo entityTypeContactInfoBo; 1248 List<OleNoticeBo> noticesList = new ArrayList<OleNoticeBo>(); 1249 org.kuali.ole.docstore.common.document.content.instance.Item item; 1250 String noticeType = null; 1251 OleNoticeBo oleNoticeBo = new OleNoticeBo(); 1252 if (oleDeliverRequestBoList.size() > 0) { 1253 for (int i = 0; i < oleDeliverRequestBoList.size(); i++) { 1254 if (docstoreUtil.isItemAvailableInDocStore(oleDeliverRequestBoList.get(i))) { 1255 // processItem(oleDeliverRequestBoList.get(i)); 1256 item = oleDeliverRequestBoList.get(i).getOleItem(); 1257 LOG.info("Expiration Date :" + oleDeliverRequestBoList.get(i).getRequestExpiryDate()); 1258 if (oleDeliverRequestBoList.get(i).getOlePatron().isCourtesyNotice() && (fmt.format(oleDeliverRequestBoList.get(i).getRequestExpiryDate())).compareTo(fmt.format(new Date(System.currentTimeMillis()))) <= 0) { 1259 LOG.info("Inside Expiration Date :" + oleDeliverRequestBoList.get(i).getRequestExpiryDate()); 1260 entityTypeContactInfoBo = oleDeliverRequestBoList.get(i).getOlePatron().getEntity().getEntityTypeContactInfos().get(0); 1261 oleNoticeBo = new OleNoticeBo(); 1262 oleNoticeBo.setAuthor(oleDeliverRequestBoList.get(i).getAuthor()); 1263 oleNoticeBo.setCirculationDeskAddress(""); 1264 oleNoticeBo.setCirculationDeskName(""); 1265 oleNoticeBo.setCirculationDeskEmailAddress(""); 1266 oleNoticeBo.setCirculationDeskPhoneNumber(""); 1267 oleNoticeBo.setPatronName(oleDeliverRequestBoList.get(i).getOlePatron().getEntity().getNames().get(0).getFirstName() + " " + oleDeliverRequestBoList.get(i).getOlePatron().getEntity().getNames().get(0).getLastName()); 1268 oleNoticeBo.setPatronAddress(getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getPatronPreferredAddress(entityTypeContactInfoBo) : ""); 1269 oleNoticeBo.setPatronEmailAddress(getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getPatronHomeEmailId(entityTypeContactInfoBo) : ""); 1270 oleNoticeBo.setPatronPhoneNumber(getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getPatronHomePhoneNumber(entityTypeContactInfoBo) : ""); 1271 oleNoticeBo.setItemCallNumber(oleDeliverRequestBoList.get(i).getCallNumber() != null ? oleDeliverRequestBoList.get(i).getCallNumber() : ""); 1272 oleNoticeBo.setItemShelvingLocation(oleDeliverRequestBoList.get(i).getShelvingLocation() != null ? oleDeliverRequestBoList.get(i).getShelvingLocation() : ""); 1273 oleNoticeBo.setItemId(oleDeliverRequestBoList.get(i).getItemId() != null ? oleDeliverRequestBoList.get(i).getItemId() : ""); 1274 oleNoticeBo.setTitle(oleDeliverRequestBoList.get(i).getTitle() != null ? oleDeliverRequestBoList.get(i).getTitle() : ""); 1275 oleNoticeBo.setOleItem(item); 1276 oleNoticeBo.setOlePatron(oleDeliverRequestBoList.get(i).getOlePatron()); 1277 oleNoticeBo.setVolumeNumber(item.getVolumeNumber() != null ? item.getVolumeNumber() : ""); 1278 oleNoticeBo.setNewDueDate(new Date()); 1279 oleNoticeBo.setOriginalDueDate(new Date()); 1280 oleNoticeBo.setNoticeName(OLEConstants.OleDeliverRequest.EXPIRED_REQUEST); 1281 String noticeContent = getLoanProcessor().getParameter(OLEParameterConstants.EXPIRED_BODY); 1282 oleNoticeBo.setNoticeSpecificContent(noticeContent); 1283 noticesList.add(oleNoticeBo); 1284 String agendaName = OLEConstants.BATCH_PROGRAM_AGENDA; 1285 HashMap<String, Object> termValues = new HashMap<String, Object>(); 1286 OleCirculationDesk oleCirculationDesk = oleDeliverRequestBoList.get(i).getOlePickUpLocation(); 1287 OlePatronDocument olePatronDocument = oleDeliverRequestBoList.get(i).getOlePatron(); 1288 String deskLocation = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskCode() : ""; 1289 String deskLocationName = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskPublicName() : ""; 1290 termValues.put(OLEConstants.BORROWER_TYPE, olePatronDocument.getOleBorrowerType().getBorrowerTypeCode()); 1291 termValues.put(OLEConstants.DESK_LOCATION, deskLocation); 1292 termValues.put(OLEConstants.NOTICE, OLEConstants.OleDeliverRequest.EXPIRED_REQUEST); 1293 LOG.info("termValues.toString()" + termValues.toString()); 1294 EngineResults engineResults = loanProcessor.getEngineResults(agendaName, termValues); 1295 noticeType = (String) engineResults.getAttribute(OLEConstants.NOTICE_TYPE); 1296 LOG.info("**************" + noticeType); 1297 noticeType = noticeType != null ? noticeType : getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.RQST_EXPR_NOTICE_TYPE); 1298 if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.SMS)) { 1299 // noticesList.add(oleNoticeBo); 1300 Map map = oleDeliverBatchService.getSMSForPatron(noticesList); 1301 HashMap sms = (HashMap) map.get(OLEConstants.OleDeliverRequest.EXPIRED_REQUEST); 1302 Iterator it = sms.entrySet().iterator(); 1303 while (it.hasNext()) { 1304 Map.Entry pairs = (Map.Entry) it.next(); 1305 1306 String patronPhoneNumber = oleNoticeBo.getPatronPhoneNumber(); 1307 OleSms oleSms = new OleSms(); 1308 oleSms.sendSms("", patronPhoneNumber, (String) pairs.getValue()); 1309 } 1310 } 1311 } 1312 } 1313 if (noticeType != null && (noticeType.equalsIgnoreCase(OLEConstants.EMAIL) || noticeType.equalsIgnoreCase(OLEConstants.MAIL))) { 1314 oleDeliverBatchService.getPdfNoticeForPatron(noticesList); 1315 LOG.info("Request Expiration Notice Pdf generated for item Id"); 1316 } 1317 if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.EMAIL)) { 1318 String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL); 1319 if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) { 1320 fromAddress = OLEConstants.KUALI_MAIL; 1321 } 1322 // noticesList.add(oleNoticeBo); 1323 List list = (List) oleDeliverBatchService.getNoticeForPatron(noticesList); 1324 String noticeContent = list.toString(); 1325 noticeContent = noticeContent.replace('[', ' '); 1326 noticeContent = noticeContent.replace(']', ' '); 1327 if (!noticeContent.trim().equals("")) { 1328 OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer"); 1329 oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(noticeContent), true); 1330 } else { 1331 for (OleNoticeBo oleNoticeBo1 : noticesList) { 1332 LOG.info("Notice Type :" + oleNoticeBo1.getNoticeName() + " " + "Item Barcode : " + oleNoticeBo1.getItemId() + " " + "Patron Name :" + oleNoticeBo1.getPatronName()); 1333 } 1334 } 1335 LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress()); 1336 1337 } 1338 } 1339 } 1340 } 1341 1342 private java.sql.Date dateAdd(java.sql.Date in, int daysToAdd) { 1343 if (in == null) { 1344 return null; 1345 } 1346 GregorianCalendar cal = new GregorianCalendar(); 1347 cal.setTime(in); 1348 cal.add(Calendar.DAY_OF_MONTH, daysToAdd); 1349 return new java.sql.Date(cal.getTime().getTime()); 1350 } 1351 1352 public void deletingExpiredRequests() { 1353 LOG.info("Inside deletingExpiredRequests"); 1354 List<OleDeliverRequestBo> oleDeliverRequestBoList = new ArrayList<OleDeliverRequestBo>(); 1355 List<OleDeliverRequestBo> newOleDeliverRequestBoList = new ArrayList<OleDeliverRequestBo>(); 1356 try { 1357 oleDeliverRequestBoList = (List<OleDeliverRequestBo>) businessObjectService.findAll(OleDeliverRequestBo.class); 1358 businessObjectService.delete(oleDeliverRequestBoList); 1359 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OleDeliverRequest.DATE_FORMAT); 1360 for (int i = 0; i < oleDeliverRequestBoList.size(); i++) { 1361 if ((fmt.format(oleDeliverRequestBoList.get(i).getRequestExpiryDate())).compareTo(fmt.format(new Date(System.currentTimeMillis()))) > 0) { 1362 newOleDeliverRequestBoList.add(oleDeliverRequestBoList.get(i)); 1363 } 1364 } 1365 businessObjectService.save(newOleDeliverRequestBoList); 1366 } catch (Exception e) { 1367 businessObjectService.save(oleDeliverRequestBoList); 1368 LOG.error(e, e); 1369 } 1370 } 1371 1372 private org.kuali.ole.docstore.common.document.content.instance.Item getItem(String itemUUID) { 1373 LOG.debug("Inside getItem"); 1374 try { 1375 // Map docStoreDetails= loanProcessor.getItemDetails(itemBarCode); 1376 String itemXml = loanProcessor.getItemXML(itemUUID); 1377 org.kuali.ole.docstore.common.document.content.instance.Item oleItem = loanProcessor.getItemPojo(itemXml); 1378 return oleItem; 1379 } catch (Exception e) { 1380 LOG.error("Item not available in doc store", e); 1381 } 1382 return null; 1383 } 1384 1385 1386 private OleNoticeBo setPatronDetailsForNotice(OleNoticeBo oleNoticeBo, OlePatronDocument olePatronDocument) { 1387 LOG.debug("Inside setPatronDetailsForNotice"); 1388 if (oleNoticeBo.getAuthor() != null && olePatronDocument.getOlePatronId() != null) { 1389 oleNoticeBo.setPatronName(olePatronDocument.getName().getFirstName()); 1390 if (olePatronDocument.getAddresses().size() > 0) { 1391 oleNoticeBo.setPatronAddress(olePatronDocument.getAddresses().get(0).getLine1() + "/n" + olePatronDocument.getAddresses().get(0).getLine2() + "/n" + olePatronDocument.getAddresses().get(0).getCity()); 1392 } 1393 oleNoticeBo.setPatronEmailAddress(olePatronDocument.getEmailAddress()); 1394 oleNoticeBo.setPatronPhoneNumber(olePatronDocument.getPhoneNumber()); 1395 } 1396 return oleNoticeBo; 1397 } 1398 1399 1400 private void createRequestHistoryRecord(String requestId, String OperatorId, String loanTransactionNumber) { 1401 LOG.debug("Inside createRequestHistoryRecord"); 1402 Map<String, String> requestMap = new HashMap<String, String>(); 1403 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_ID, requestId); 1404 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class, requestMap); 1405 if (oleDeliverRequestBoList.size() > 0) { 1406 OleDeliverRequestBo oleDeliverRequestBo = oleDeliverRequestBoList.get(0); 1407 OleDeliverRequestHistoryRecord oleDeliverRequestHistoryRecord = new OleDeliverRequestHistoryRecord(); 1408 oleDeliverRequestHistoryRecord.setRequestId(oleDeliverRequestBo.getRequestId()); 1409 oleDeliverRequestHistoryRecord.setItemId(oleDeliverRequestBo.getItemId()); 1410 oleDeliverRequestHistoryRecord.setArchiveDate(new java.sql.Date(System.currentTimeMillis())); 1411 oleDeliverRequestHistoryRecord.setPickUpLocationCode(oleDeliverRequestBo.getPickUpLocationCode()); 1412 oleDeliverRequestHistoryRecord.setOperatorId(OperatorId); 1413 oleDeliverRequestHistoryRecord.setDeliverRequestTypeCode(oleDeliverRequestBo.getRequestTypeCode()); 1414 oleDeliverRequestHistoryRecord.setPoLineItemNumber(""); 1415 oleDeliverRequestHistoryRecord.setLoanTransactionId(loanTransactionNumber); 1416 //oleDeliverRequestHistoryRecord.setMachineId(""); //commented for jira OLE-5675 1417 businessObjectService.save(oleDeliverRequestHistoryRecord); 1418 } 1419 businessObjectService.delete(oleDeliverRequestBoList); 1420 } 1421 1422 public OleDeliverRequestBo getOleDeliverRequestBo(String itemUUID) { 1423 1424 LOG.debug("Inside getOleDeliverRequestBo method"); 1425 Map<String, String> requestMap = new HashMap<String, String>(); 1426 requestMap.put(OLEConstants.ITEM_UUID, itemUUID); 1427 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class, requestMap); 1428 if (oleDeliverRequestBoList.size() > 0) 1429 return oleDeliverRequestBoList.get(0); 1430 return null; 1431 } 1432 1433 public String getPatronPreferredAddress(EntityTypeContactInfoBo entityTypeContactInfoBo) throws Exception { 1434 LOG.debug("Inside the getPatronPreferredAddress method"); 1435 String address = ""; 1436 if (entityTypeContactInfoBo.getAddresses() != null) { 1437 for (int i = 0; i < entityTypeContactInfoBo.getAddresses().size(); i++) { 1438 if (entityTypeContactInfoBo.getAddresses().get(i).isDefaultValue()) { 1439 if (entityTypeContactInfoBo.getAddresses().get(i).getLine1() != null) 1440 if (!entityTypeContactInfoBo.getAddresses().get(i).getLine1().isEmpty()) 1441 address += entityTypeContactInfoBo.getAddresses().get(i).getLine1() + ","; 1442 1443 if (entityTypeContactInfoBo.getAddresses().get(i).getLine2() != null) 1444 if (!entityTypeContactInfoBo.getAddresses().get(i).getLine2().isEmpty()) 1445 address += entityTypeContactInfoBo.getAddresses().get(i).getLine2() + ","; 1446 1447 if (entityTypeContactInfoBo.getAddresses().get(i).getLine3() != null) 1448 if (!entityTypeContactInfoBo.getAddresses().get(i).getLine3().isEmpty()) 1449 address += entityTypeContactInfoBo.getAddresses().get(i).getLine3() + ","; 1450 1451 if (entityTypeContactInfoBo.getAddresses().get(i).getCity() != null) 1452 if (!entityTypeContactInfoBo.getAddresses().get(i).getCity().isEmpty()) 1453 address += entityTypeContactInfoBo.getAddresses().get(i).getCity() + ","; 1454 1455 if (entityTypeContactInfoBo.getAddresses().get(i).getStateProvinceCode() != null) 1456 if (!entityTypeContactInfoBo.getAddresses().get(i).getStateProvinceCode().isEmpty()) 1457 address += entityTypeContactInfoBo.getAddresses().get(i).getStateProvinceCode() + ","; 1458 1459 if (entityTypeContactInfoBo.getAddresses().get(i).getCountryCode() != null) 1460 if (!entityTypeContactInfoBo.getAddresses().get(i).getCountryCode().isEmpty()) 1461 address += entityTypeContactInfoBo.getAddresses().get(i).getCountryCode() + ","; 1462 1463 if (entityTypeContactInfoBo.getAddresses().get(i).getPostalCode() != null) 1464 if (!entityTypeContactInfoBo.getAddresses().get(i).getPostalCode().isEmpty()) 1465 address += entityTypeContactInfoBo.getAddresses().get(i).getPostalCode(); 1466 } 1467 } 1468 } 1469 1470 return address; 1471 } 1472 1473 public String getPatronHomePhoneNumber(EntityTypeContactInfoBo entityTypeContactInfoBo) throws Exception { 1474 LOG.debug("Inside the getPatronHomePhoneNumber method"); 1475 String phoneNumber = ""; 1476 if (entityTypeContactInfoBo.getPhoneNumbers() != null) { 1477 for (int j = 0; j < entityTypeContactInfoBo.getPhoneNumbers().size(); j++) { 1478 if (entityTypeContactInfoBo.getPhoneNumbers().get(j).getPhoneTypeCode().equalsIgnoreCase("HM")) { 1479 phoneNumber = (entityTypeContactInfoBo.getPhoneNumbers().get(j).getPhoneNumber()); 1480 } 1481 } 1482 } 1483 return phoneNumber; 1484 } 1485 1486 public String getPatronHomeEmailId(EntityTypeContactInfoBo entityTypeContactInfoBo) throws Exception { 1487 LOG.debug("Inside the getPatronHomeEmailId method"); 1488 String emailId = ""; 1489 if (entityTypeContactInfoBo.getEmailAddresses() != null) { 1490 for (int j = 0; j < entityTypeContactInfoBo.getEmailAddresses().size(); j++) { 1491 if (entityTypeContactInfoBo.getEmailAddresses().get(j).getEmailTypeCode().equalsIgnoreCase("HM")) { 1492 emailId = (entityTypeContactInfoBo.getEmailAddresses().get(j).getEmailAddress()); 1493 } 1494 } 1495 } 1496 return emailId; 1497 } 1498 1499 private static int determineDifferenceInDays(Date currentDate, Date dueDate) { 1500 Calendar calendar1 = Calendar.getInstance(); 1501 calendar1.setTime(dueDate); 1502 Calendar calendar2 = Calendar.getInstance(); 1503 calendar2.setTime(currentDate); 1504 long diffInMillis = calendar2.getTimeInMillis() - calendar1.getTimeInMillis(); 1505 return (int) (diffInMillis / (24 * 1000 * 60 * 60)); 1506 } 1507 1508 1509 public void generateNotices() throws Exception { 1510 DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE); 1511 List<OlePatronDocument> patronDocumentList = (List<OlePatronDocument>) KRADServiceLocator.getBusinessObjectService().findAll(OlePatronDocument.class); 1512 for (OlePatronDocument olePatronDocument : patronDocumentList) { 1513 Map<String, String> requestMap = new HashMap<String, String>(); 1514 requestMap.put(OLEConstants.OleDeliverRequest.LOAN_PATRON_ID, olePatronDocument.getOlePatronId()); 1515 List<OleLoanDocument> oleLoanDocumentList = (List<OleLoanDocument>) KRADServiceLocator.getBusinessObjectService().findMatching(OleLoanDocument.class, requestMap); 1516 for (OleLoanDocument oleLoanDocument : oleLoanDocumentList) { 1517 try { 1518 List<OleNoticeBo> oleNoticeBos = new ArrayList<OleNoticeBo>(); 1519 org.kuali.ole.docstore.common.document.Item item = new ItemOleml(); 1520 org.kuali.ole.docstore.common.search.SearchParams search_Params = new org.kuali.ole.docstore.common.search.SearchParams(); 1521 SearchResponse searchResponse = null; 1522 search_Params.getSearchConditions().add(search_Params.buildSearchCondition("", search_Params.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), item.ITEM_BARCODE, oleLoanDocument.getItemId()), "")); 1523 //search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), "id")); 1524 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.HOLDINGS.getCode(), "id")); 1525 // search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), "id")); 1526 /* Map<String,String> map=new HashMap<>(); 1527 map.put(item.BARCODE, itemBarcode); 1528 item=getDocstoreClientLocator().getDocstoreClient().findItem(map);*/ 1529 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(search_Params); 1530 for (SearchResult searchResult : searchResponse.getSearchResults()) { 1531 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) { 1532 String fieldName = searchResultField.getFieldName(); 1533 String fieldValue = searchResultField.getFieldValue() != null ? searchResultField.getFieldValue() : ""; 1534 1535 if (fieldName.equalsIgnoreCase("id") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("holdings")) { 1536 oleLoanDocument.setInstanceUuid(fieldValue); 1537 } 1538 1539 } 1540 } 1541 String itemXml = loanProcessor.getItemXML(oleLoanDocument.getItemUuid()); 1542 org.kuali.ole.docstore.common.document.content.instance.Item oleItem = loanProcessor.getItemPojo(itemXml); 1543 oleLoanDocument.setOleItem(oleItem); 1544 oleLoanDocument.setOlePatron(olePatronDocument); 1545 OleNoticeBo oleNoticeBo = new OleNoticeBo(); 1546 Date dueDate = oleLoanDocument.getLoanDueDate(); 1547 Date currentDate = new Date(); 1548 Integer dueDateDiffInterval = dueDate!=null ? determineDifferenceInDays(dueDate, currentDate) : 0; 1549 DateFormat formatter = new SimpleDateFormat(OLEConstants.DAT_FORMAT_EFFECTIVE_NOTICE); 1550 LOG.info("oleItem.getItemStatusEffectiveDate()" + oleItem.getItemStatusEffectiveDate()); 1551 Date itemStatusEffectiveDate = (Date) formatter.parse(oleItem.getItemStatusEffectiveDate()); 1552 Integer numberOfDaysOnHold = determineDifferenceInDays(itemStatusEffectiveDate, currentDate); 1553 Integer dueDateSumInterval = dueDate!=null ? determineDifferenceInDays(currentDate, dueDate) : 0; 1554 Integer overdueNoticeInterval = Integer.parseInt(getIntervalForOverdueNotice()); 1555 Integer intervalWithNoticeCount = 0; 1556 Integer loanNoOfOverdueNoticeSent = oleLoanDocument.getNumberOfOverdueNoticesSent() != null ? Integer.parseInt(oleLoanDocument.getNumberOfOverdueNoticesSent()) : 0; 1557 if (oleLoanDocument.getNumberOfOverdueNoticesSent() != null) { 1558 intervalWithNoticeCount = Integer.parseInt(oleLoanDocument.getNumberOfOverdueNoticesSent()) + 1; 1559 } else { 1560 intervalWithNoticeCount = intervalWithNoticeCount + 1; 1561 } 1562 // intervalWithNoticeCount = intervalWithNoticeCount * overdueNoticeInterval; 1563 dueDateSumInterval = dueDateSumInterval / intervalWithNoticeCount; 1564 if (dueDateSumInterval < 0) { 1565 dueDateSumInterval = 0; 1566 } 1567 if (dueDateDiffInterval < 0) { 1568 dueDateDiffInterval = 0; 1569 } 1570 Integer maxNumberOfDaysOnHold = 0; 1571 OleCirculationDesk oleCirculationDesk = null; 1572 if (oleLoanDocument.getCirculationLocationId() != null) { 1573 oleCirculationDesk = loanProcessor.getOleCirculationDesk(oleLoanDocument.getCirculationLocationId()); 1574 String maxNumOfDays = oleCirculationDesk.getOnHoldDays() != null ? oleCirculationDesk.getOnHoldDays() : loanProcessor.getParameter(OLEConstants.MAX_NO_OF_DAYS_ON_HOLD); 1575 maxNumberOfDaysOnHold = new Integer(maxNumOfDays); 1576 } 1577 if (oleItem.getTemporaryItemType() != null && oleItem.getTemporaryItemType().getCodeValue() != "") { 1578 OleInstanceItemType oleInstanceItemType = loanProcessor.getItemTypeIdByItemType(oleItem.getTemporaryItemType().getCodeValue()); 1579 oleLoanDocument.setItemTypeName(oleInstanceItemType.getInstanceItemTypeCode()); 1580 } 1581 else if (oleItem.getItemType() != null && oleItem.getItemType().getCodeValue() != "") { 1582 OleInstanceItemType oleInstanceItemType = loanProcessor.getItemTypeIdByItemType(oleItem.getItemType().getCodeValue()); 1583 oleLoanDocument.setItemTypeName(oleInstanceItemType.getInstanceItemTypeCode()); 1584 } 1585 oleLoanDocument.setInstanceUuid(oleLoanDocument.getInstanceUuid()); 1586 loanProcessor.getLocation(oleItem, oleLoanDocument); 1587 String agendaName = OLEConstants.NOTICE_AGENDA_NM; 1588 dataCarrierService.addData(OLEConstants.CIRC_POLICY_FOUND, null); 1589 HashMap<String, Object> termValues = new HashMap<String, Object>(); 1590 termValues.put(OLEConstants.BORROWER_TYPE, olePatronDocument.getOleBorrowerType().getBorrowerTypeCode()); 1591 termValues.put(OLEConstants.ITEM_TYPE, oleLoanDocument.getItemTypeName()); 1592 termValues.put(OLEConstants.OVERLAY_ITEM_LOCATION, oleLoanDocument.getItemLocation()); 1593 termValues.put(OLEConstants.DUE_DATE_DIFF_INTERVAL, dueDateDiffInterval); 1594 if (oleItem.getItemStatus() != null) 1595 termValues.put(OLEConstants.ITEM_STATUS, oleItem.getItemStatus().getCodeValue()); 1596 termValues.put(OLEConstants.NO_OF_DAYS_ON_HOLD, numberOfDaysOnHold); 1597 termValues.put(OLEConstants.MAX_NO_OF_DAYS_ONHOLD, maxNumberOfDaysOnHold); 1598 termValues.put(OLEConstants.OleDeliverRequest.CLAIM_RETURNED, oleItem.isClaimsReturnedFlag() ? "true" : "false"); 1599 termValues.put(OLEConstants.OleDeliverRequest.REPLACEMENT_FEE_PATRON_BILL, oleLoanDocument.getRepaymentFeePatronBillId() != null ? "true" : "false"); 1600 termValues.put(OLEConstants.OleDeliverRequest.NUBER_OF_OVER_DUE_SENT, loanNoOfOverdueNoticeSent); 1601 termValues.put(OLEConstants.OleDeliverRequest.DUE_DATE_SUM_INTERVAL, dueDateSumInterval); 1602 termValues.put(OLEConstants.OleDeliverRequest.CONFIGURABLE_INTERVAL, Integer.parseInt(getIntervalForCourtesyNotice())); 1603 termValues.put(OLEConstants.OleDeliverRequest.INTERVAL_WITH_NOTICE_COUNT, intervalWithNoticeCount); 1604 termValues.put(OLEConstants.ITEM_SHELVING, oleLoanDocument.getItemLocation()); 1605 termValues.put(OLEConstants.ITEM_COLLECTION, oleLoanDocument.getItemCollection()); 1606 termValues.put(OLEConstants.ITEM_LIBRARY, oleLoanDocument.getItemLibrary()); 1607 termValues.put(OLEConstants.ITEM_CAMPUS, oleLoanDocument.getItemCampus()); 1608 termValues.put(OLEConstants.ITEM_INSTITUTION, oleLoanDocument.getItemInstitution()); 1609 LOG.info("termValues.toString()" + termValues.toString()); 1610 EngineResults engineResults = loanProcessor.getEngineResults(agendaName, termValues); 1611 String notice = (String) engineResults.getAttribute(OLEConstants.NOTICE); 1612 String itemStatus = (String) engineResults.getAttribute(OLEConstants.ITEM_STATUS); 1613 BigDecimal replacementBill = (BigDecimal) engineResults.getAttribute(OLEConstants.REPLACEMENT_BILL); 1614 List<String> errorMessage = (List<String>) engineResults.getAttribute(OLEConstants.ERROR_ACTION); 1615 if (errorMessage != null) { 1616 LOG.info("errorMessage" + errorMessage.toString()); 1617 } 1618 LOG.info("notice" + notice); 1619 agendaName = OLEConstants.BATCH_PROGRAM_AGENDA; 1620 termValues = new HashMap<String, Object>(); 1621 String deskLocation = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskCode() : ""; 1622 String deskLocationName = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskPublicName() : ""; 1623 termValues.put(OLEConstants.BORROWER_TYPE, olePatronDocument.getOleBorrowerType().getBorrowerTypeCode()); 1624 termValues.put(OLEConstants.DESK_LOCATION, deskLocation); 1625 termValues.put(OLEConstants.NOTICE, notice); 1626 engineResults = loanProcessor.getEngineResults(agendaName, termValues); 1627 String noticeType = (String) engineResults.getAttribute(OLEConstants.NOTICE_TYPE); 1628 errorMessage = (List<String>) engineResults.getAttribute(OLEConstants.ERROR_ACTION); 1629 if (errorMessage != null) { 1630 LOG.info("errorMessage" + errorMessage); 1631 } 1632 LOG.info("noticeType" + noticeType); 1633 if (itemStatus != null) { 1634 int noOfOverdueNoticeSent = Integer.parseInt(oleLoanDocument.getNumberOfOverdueNoticesSent() != null ? oleLoanDocument.getNumberOfOverdueNoticesSent() : "0"); 1635 noOfOverdueNoticeSent = noOfOverdueNoticeSent + 1; 1636 oleLoanDocument.setNumberOfOverdueNoticesSent(Integer.toString(noOfOverdueNoticeSent)); 1637 oleLoanDocument.setOverDueNoticeDate(new java.sql.Date(System.currentTimeMillis())); 1638 String billNumber = loanProcessor.generatePatronBillPayment(oleLoanDocument, OLEConstants.REPLACEMENT_FEE, replacementBill); 1639 oleLoanDocument.setRepaymentFeePatronBillId(billNumber); 1640 getBusinessObjectService().save(oleLoanDocument); 1641 loanProcessor.updateItemStatus(oleItem, itemStatus); 1642 } 1643 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl(); 1644 if (notice != null) { 1645 oleNoticeBo.setNoticeName(notice); 1646 /*if(notice.equalsIgnoreCase(OLEConstants.NOTICE_HOLD_COURTESY)){ 1647 oleNoticeBo = getExpiredHoldNotice(oleLoanDocument); 1648 } else */ 1649 if (notice.equalsIgnoreCase(OLEConstants.NOTICE_OVERDUE)) { 1650 oleNoticeBo = getOverdueNotice(oleLoanDocument); 1651 noticeType = noticeType == null ? loanProcessor.getParameter(OLEParameterConstants.OVERDUE_NOTICE_TYPE) : noticeType; 1652 } else if (notice.equalsIgnoreCase(OLEConstants.NOTICE_COURTESY) && olePatronDocument.isCourtesyNotice() && !oleLoanDocument.isCourtesyNoticeFlag()) { 1653 oleNoticeBo = getCourtesyNotice(oleLoanDocument); 1654 noticeType = noticeType == null ? loanProcessor.getParameter(OLEParameterConstants.COURTESY_NOTICE_TYPE) : noticeType; 1655 } 1656 oleNoticeBo.setCirculationDeskName(deskLocationName); 1657 if (!olePatronDocument.isCourtesyNotice()) { 1658 oleNoticeBo = null; 1659 } 1660 if (oleNoticeBo != null) { 1661 oleNoticeBos.add(oleNoticeBo); 1662 } 1663 if (oleNoticeBos != null && oleNoticeBos.size() > 0 && noticeType != null && (noticeType.equalsIgnoreCase(OLEConstants.EMAIL) || noticeType.equalsIgnoreCase(OLEConstants.MAIL))) { 1664 oleDeliverBatchService.getPdfNoticeForPatron(oleNoticeBos); 1665 } 1666 } 1667 olePatronDocument = oleLoanDocument.getOlePatron(); 1668 if (oleNoticeBos != null && oleNoticeBos.size() > 0 && oleNoticeBos != null && oleNoticeBos.size() > 0 && noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.EMAIL)) { 1669 String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL); 1670 if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) { 1671 fromAddress = OLEConstants.KUALI_MAIL; 1672 } 1673 if (olePatronDocument.getEmailAddress() != null && !olePatronDocument.getEmailAddress().isEmpty()) { 1674 List list = oleDeliverBatchService.getNoticeForPatron(oleNoticeBos); 1675 String noticeContent = list.toString(); 1676 noticeContent = noticeContent.replace('[', ' '); 1677 noticeContent = noticeContent.replace(']', ' '); 1678 if (!noticeContent.trim().equals("")) { 1679 OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer"); 1680 oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(noticeContent), true); 1681 } else { 1682 for (OleNoticeBo oleNoticeBo1 : oleNoticeBos) { 1683 LOG.info("Notice Type :" + oleNoticeBo1.getNoticeName() + " " + "Item Barcode : " + oleNoticeBo1.getItemId() + " " + "Patron Name :" + oleNoticeBo1.getPatronName()); 1684 } 1685 } 1686 LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress()); 1687 /* Mailer mailer =CoreApiServiceLocator.getMailer(); 1688 mailer.sendEmail(new EmailFrom(OLEConstants.KUALI_MAIL), new EmailTo(olePatronDocument.getEmailAddress()), new EmailSubject("Notice Mail"), new EmailBody(list.toString()), true); 1689 */ 1690 LOG.info("olePatronDocument.getEmailAddress()" + olePatronDocument.getEmailAddress()); 1691 } 1692 } else if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.SMS)) { 1693 //TODO : sms in progress. 1694 } 1695 } catch (Exception e) { 1696 LOG.error("Exception in generateNotices()" + e.getMessage(), e); 1697 } 1698 } 1699 } 1700 } 1701 1702 public void generateHoldCourtesyNotice() throws Exception { 1703 List<OleDeliverRequestBo> oleDeliverRequestBos = (List<OleDeliverRequestBo>) KRADServiceLocator.getBusinessObjectService().findAll(OleDeliverRequestBo.class); 1704 for (OleDeliverRequestBo oleDeliverRequestBo : oleDeliverRequestBos) { 1705 List<OleNoticeBo> oleNoticeBos = new ArrayList<OleNoticeBo>(); 1706 DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE); 1707 if (docstoreUtil.isItemAvailableInDocStore(oleDeliverRequestBo)) { 1708 org.kuali.ole.docstore.common.document.content.instance.Item oleItem = oleDeliverRequestBo.getOleItem(); 1709 OleNoticeBo oleNoticeBo = new OleNoticeBo(); 1710 Date currentDate = new Date(); 1711 DateFormat formatter = new SimpleDateFormat(OLEConstants.DAT_FORMAT_EFFECTIVE_NOTICE); 1712 Date itemStatusEffectiveDate = (Date) formatter.parse(oleItem.getItemStatusEffectiveDate()); 1713 Integer numberOfDaysOnHold = determineDifferenceInDays(currentDate, itemStatusEffectiveDate); 1714 Integer maxNumberOfDaysOnHold = 0; 1715 OleCirculationDesk oleCirculationDesk = null; 1716 if (oleDeliverRequestBo.getPickUpLocationId() != null) { 1717 oleCirculationDesk = loanProcessor.getOleCirculationDesk(oleDeliverRequestBo.getPickUpLocationId()); 1718 String maxNumOfDays = oleCirculationDesk.getOnHoldDays() != null ? oleCirculationDesk.getOnHoldDays() : loanProcessor.getParameter(OLEConstants.MAX_NO_OF_DAYS_ON_HOLD); 1719 maxNumberOfDaysOnHold = new Integer(maxNumOfDays); 1720 } 1721 String itemTypeName = null; 1722 if (oleItem.getTemporaryItemType() != null && oleItem.getTemporaryItemType().getCodeValue() != "") { 1723 OleInstanceItemType oleInstanceItemType = loanProcessor.getItemTypeIdByItemType(oleItem.getTemporaryItemType().getCodeValue()); 1724 itemTypeName = oleInstanceItemType.getInstanceItemTypeCode(); 1725 }else if (oleItem.getItemType() != null && oleItem.getItemType().getCodeValue() != "") { 1726 OleInstanceItemType oleInstanceItemType = loanProcessor.getItemTypeIdByItemType(oleItem.getItemType().getCodeValue()); 1727 itemTypeName = oleInstanceItemType.getInstanceItemTypeCode(); 1728 } 1729 OlePatronDocument olePatronDocument = oleDeliverRequestBo.getOlePatron(); 1730 String agendaName = "Notice Validation"; 1731 dataCarrierService.addData(OLEConstants.CIRC_POLICY_FOUND, null); 1732 HashMap<String, Object> termValues = new HashMap<String, Object>(); 1733 termValues.put(OLEConstants.BORROWER_TYPE, olePatronDocument.getOleBorrowerType().getBorrowerTypeCode()); 1734 termValues.put(OLEConstants.ITEM_TYPE, itemTypeName); 1735 termValues.put(OLEConstants.OVERLAY_ITEM_LOCATION, oleDeliverRequestBo.getShelvingLocation()); 1736 termValues.put(OLEConstants.NO_OF_DAYS_ON_HOLD, numberOfDaysOnHold); 1737 termValues.put(OLEConstants.MAX_NO_OF_DAYS_ONHOLD, maxNumberOfDaysOnHold); 1738 termValues.put(OLEConstants.ITEM_SHELVING, oleDeliverRequestBo.getShelvingLocation()); 1739 termValues.put(OLEConstants.ITEM_COLLECTION, oleDeliverRequestBo.getItemCollection()); 1740 termValues.put(OLEConstants.ITEM_LIBRARY, oleDeliverRequestBo.getItemLibrary()); 1741 termValues.put(OLEConstants.ITEM_CAMPUS, oleDeliverRequestBo.getItemCampus()); 1742 termValues.put(OLEConstants.ITEM_INSTITUTION, oleDeliverRequestBo.getItemInstitution()); 1743 if (oleItem.getItemStatus() != null) 1744 termValues.put(OLEConstants.ITEM_STATUS, oleItem.getItemStatus().getCodeValue()); 1745 LOG.info("termValues.toString()" + termValues.toString()); 1746 EngineResults engineResults = loanProcessor.getEngineResults(agendaName, termValues); 1747 String notice = (String) engineResults.getAttribute(OLEConstants.NOTICE); 1748 LOG.info("notice" + notice); 1749 agendaName = OLEConstants.BATCH_PROGRAM_AGENDA; 1750 termValues = new HashMap<String, Object>(); 1751 String deskLocation = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskCode() : ""; 1752 String deskLocationName = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskPublicName() : ""; 1753 termValues.put(OLEConstants.BORROWER_TYPE, olePatronDocument.getOleBorrowerType().getBorrowerTypeCode()); 1754 termValues.put(OLEConstants.DESK_LOCATION, deskLocation); 1755 termValues.put(OLEConstants.NOTICE, notice); 1756 LOG.info("termValues.toString()" + termValues.toString()); 1757 engineResults = loanProcessor.getEngineResults(agendaName, termValues); 1758 String noticeType = (String) engineResults.getAttribute(OLEConstants.NOTICE_TYPE); 1759 LOG.info("**************" + noticeType); 1760 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl(); 1761 if (notice != null) { 1762 oleNoticeBo.setNoticeName(notice); 1763 if (notice.equalsIgnoreCase(OLEConstants.NOTICE_HOLD_COURTESY)) { 1764 oleNoticeBo = getExpiredHoldNotice(oleDeliverRequestBo); 1765 oleNoticeBo.setCirculationDeskName(deskLocationName); 1766 oleNoticeBos.add(oleNoticeBo); 1767 noticeType = noticeType == null ? loanProcessor.getParameter("HOLDCOURTESY_NOTICE_TYPE") : noticeType; 1768 } 1769 if (oleNoticeBos.size() > 0 && noticeType != null && (noticeType.equalsIgnoreCase(OLEConstants.EMAIL) || noticeType.equalsIgnoreCase(OLEConstants.MAIL))) { 1770 oleDeliverBatchService.getPdfNoticeForPatron(oleNoticeBos); 1771 } 1772 1773 } 1774 olePatronDocument = oleDeliverRequestBo.getOlePatron(); 1775 if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.EMAIL)) { 1776 String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL); 1777 if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) { 1778 fromAddress = OLEConstants.KUALI_MAIL; 1779 } 1780 if (olePatronDocument.getEmailAddress() != null && !olePatronDocument.getEmailAddress().isEmpty()) { 1781 List list = oleDeliverBatchService.getNoticeForPatron(oleNoticeBos); 1782 String noticeContent = list.toString(); 1783 noticeContent = noticeContent.replace('[', ' '); 1784 noticeContent = noticeContent.replace(']', ' '); 1785 if (!noticeContent.trim().equals("")) { 1786 OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer"); 1787 oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(noticeContent), true); 1788 } else { 1789 for (OleNoticeBo oleNoticeBo1 : oleNoticeBos) { 1790 LOG.info("Notice Type :" + oleNoticeBo1.getNoticeName() + " " + "Item Barcode : " + oleNoticeBo1.getItemId() + " " + "Patron Name :" + oleNoticeBo1.getPatronName()); 1791 } 1792 } 1793/* 1794 Mailer mailer =CoreApiServiceLocator.getMailer(); 1795 mailer.sendEmail(new EmailFrom(OLEConstants.KUALI_MAIL), new EmailTo(olePatronDocument.getEmailAddress()), new EmailSubject("Notice Mail"), new EmailBody(list.toString()), true); 1796 */ 1797 LOG.info("olePatronDocument.getEmailAddress()" + olePatronDocument.getEmailAddress()); 1798 } 1799 } else if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.SMS)) { 1800 //TODO : sms in progress. 1801 } 1802 } 1803 } 1804 } 1805 1806 public void deleteTemporaryHistoryRecord() throws Exception { 1807 List<OlePatronDocument> patronDocumentList = (List<OlePatronDocument>) KRADServiceLocator.getBusinessObjectService().findAll(OlePatronDocument.class); 1808 for (OlePatronDocument olePatronDocument : patronDocumentList) { 1809 Map<String, String> requestMap = new HashMap<String, String>(); 1810 requestMap.put(OLEConstants.OlePatron.PATRON_ID, olePatronDocument.getOlePatronId()); 1811 List<OleTemporaryCirculationHistory> oleTemporaryCirculationHistoryList = (List<OleTemporaryCirculationHistory>) KRADServiceLocator.getBusinessObjectService().findMatching(OleTemporaryCirculationHistory.class, requestMap); 1812 List<OleTemporaryCirculationHistory> deleteRecords = new ArrayList<OleTemporaryCirculationHistory>(); 1813 for (OleTemporaryCirculationHistory oleTemporaryCirculationHistory : oleTemporaryCirculationHistoryList) { 1814 String agendaName = OLEConstants.BATCH_PROGRAM_AGENDA; 1815 HashMap<String, Object> termValues = new HashMap<String, Object>(); 1816 termValues.put(OLEConstants.OleDeliverRequest.IS_TEMPORARY_HISTORY_RECORD, "true"); 1817 DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE); 1818 dataCarrierService.addData(OLEConstants.DATE_CHECK_IN, oleTemporaryCirculationHistory.getCheckInDate()); 1819 EngineResults engineResults = loanProcessor.getEngineResults(agendaName, termValues); 1820 Boolean deleteRecord = (Boolean) engineResults.getAttribute(OLEConstants.OVERLAY_OPTION_DELETE); 1821 if (deleteRecord != null && deleteRecord) { 1822 deleteRecords.add(oleTemporaryCirculationHistory); 1823 } 1824 } 1825 getBusinessObjectService().delete(deleteRecords); 1826 } 1827 } 1828 1829 private OleNoticeBo getExpiredHoldNotice(OleDeliverRequestBo oleDeliverRequestBo) throws Exception { 1830 LOG.debug("Expired Hold Notice"); 1831 org.kuali.ole.docstore.common.document.content.instance.Item oleItem = oleDeliverRequestBo.getOleItem(); 1832 EntityTypeContactInfoBo entityTypeContactInfoBo = oleDeliverRequestBo.getOlePatron().getEntity().getEntityTypeContactInfos().get(0); 1833 OleNoticeBo oleNoticeBo = new OleNoticeBo(); 1834 org.kuali.ole.docstore.common.document.Item item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(oleDeliverRequestBo.getItemUuid()); 1835 String shelvingLocation = oleDeliverRequestBo.getShelvingLocation(); 1836 OleCirculationDesk oleCirculationDesk = getOleCirculationDesk(oleDeliverRequestBo.getPickUpLocationId()); 1837 if (oleCirculationDesk != null) 1838 oleNoticeBo.setCirculationDeskName(oleCirculationDesk.getCirculationDeskPublicName()); 1839 else 1840 oleNoticeBo.setCirculationDeskName(""); 1841 oleNoticeBo.setCirculationDeskAddress(""); 1842 oleNoticeBo.setCirculationDeskEmailAddress(""); 1843 oleNoticeBo.setCirculationDeskPhoneNumber(""); 1844 oleNoticeBo.setCirculationDeskPhoneNumber(""); 1845 oleNoticeBo.setPatronName(oleDeliverRequestBo.getOlePatron().getEntity().getNames().get(0).getFirstName() + " " + oleDeliverRequestBo.getOlePatron().getEntity().getNames().get(0).getLastName()); 1846 oleNoticeBo.setPatronAddress(getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getPatronPreferredAddress(entityTypeContactInfoBo) : ""); 1847 oleNoticeBo.setPatronEmailAddress(getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getPatronHomeEmailId(entityTypeContactInfoBo) : ""); 1848 oleNoticeBo.setPatronPhoneNumber(getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getPatronHomePhoneNumber(entityTypeContactInfoBo) : ""); 1849 oleNoticeBo.setNoticeName(OLEConstants.NOTICE_HOLD_COURTESY); 1850 oleNoticeBo.setNoticeSpecificContent(LoanUtil.getLoanUtil().getProperty(OLEConstants.OleDeliverRequest.EXP_HOLD_NOTICE_CONTENT)); 1851 oleNoticeBo.setTitle(item.getHolding().getBib().getTitle()); 1852 oleNoticeBo.setAuthor(item.getHolding().getBib().getAuthor()); 1853 /*oleNoticeBo.setTitle((String) bibInformation.get(OLEConstants.TITLE) != null ? (String) bibInformation.get(OLEConstants.TITLE) : ""); 1854 oleNoticeBo.setAuthor((String) bibInformation.get(OLEConstants.AUTHOR) != null ? (String) bibInformation.get(OLEConstants.AUTHOR) : "");*/ 1855 oleNoticeBo.setVolumeNumber(item.getVolumeNumber()); 1856 oleNoticeBo.setItemShelvingLocation(shelvingLocation != null ? shelvingLocation : ""); 1857 //oleNoticeBo.setItemCallNumber((String) docStoreDetails.get(OLEConstants.CALL_NUM) != null ? (String) docStoreDetails.get(OLEConstants.CALL_NUM) : ""); 1858 oleNoticeBo.setItemCallNumber((String) oleItem.getCallNumber().getNumber() != null && !oleItem.getCallNumber().getNumber().equals("") ? oleItem.getCallNumber().getNumber() : ""); 1859 oleNoticeBo.setItemId(oleDeliverRequestBo.getItemId() != null ? oleDeliverRequestBo.getItemId() : ""); 1860 oleNoticeBo.setOleItem(oleItem); 1861 oleNoticeBo.setOlePatron(oleDeliverRequestBo.getOlePatron()); 1862 oleNoticeBo = setPatronDetailsForNotice(oleNoticeBo, oleDeliverRequestBo.getOlePatron()); 1863 oleDeliverRequestBo.getOlePatron().setEmailAddress(oleNoticeBo.getPatronEmailAddress()); 1864 return oleNoticeBo; 1865 } 1866 1867 private OleNoticeBo getCourtesyNotice(OleLoanDocument oleLoanDocument) throws Exception { 1868 LOG.debug("Courtesy Notice"); 1869 oleLoanDocument.setCourtesyNoticeFlag(true); 1870 Map<String, String> map = new HashMap<String, String>(); 1871 map.put("loanId", oleLoanDocument.getLoanId()); 1872 KRADServiceLocator.getBusinessObjectService().save(oleLoanDocument); 1873 EntityTypeContactInfoBo entityTypeContactInfoBo = oleLoanDocument.getOlePatron().getEntity().getEntityTypeContactInfos().get(0); 1874 OleNoticeBo oleNoticeBo = new OleNoticeBo(); 1875 //String itemId = oleLoanDocument.getItemId(); 1876 org.kuali.ole.docstore.common.document.content.instance.Item oleItem = oleLoanDocument.getOleItem(); 1877 org.kuali.ole.docstore.common.document.Item item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(oleLoanDocument.getItemUuid()); 1878 ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor(); 1879 org.kuali.ole.docstore.common.document.content.instance.Item itemContent = itemOlemlRecordProcessor.fromXML(item.getContent()); 1880 String shelvingLocation = oleLoanDocument.getItemLocation(); 1881 OleCirculationDesk oleCirculationDesk = getOleCirculationDesk(oleLoanDocument.getCirculationLocationId()); 1882 if (oleCirculationDesk != null) 1883 oleNoticeBo.setCirculationDeskName(oleCirculationDesk.getCirculationDeskPublicName()); 1884 else 1885 oleNoticeBo.setCirculationDeskName(""); 1886 oleNoticeBo.setCirculationDeskAddress(""); 1887 oleNoticeBo.setCirculationDeskEmailAddress(""); 1888 oleNoticeBo.setCirculationDeskPhoneNumber(""); 1889 oleNoticeBo.setPatronName(oleLoanDocument.getOlePatron().getEntity().getNames().get(0).getFirstName() + " " + oleLoanDocument.getOlePatron().getEntity().getNames().get(0).getLastName()); 1890 oleNoticeBo.setPatronAddress(getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getPatronPreferredAddress(entityTypeContactInfoBo) : ""); 1891 oleNoticeBo.setPatronEmailAddress(getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getPatronHomeEmailId(entityTypeContactInfoBo) : ""); 1892 oleNoticeBo.setPatronPhoneNumber(getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getPatronHomePhoneNumber(entityTypeContactInfoBo) : ""); 1893 oleNoticeBo.setNoticeName(OLEConstants.NOTICE_COURTESY); 1894 oleNoticeBo.setNoticeSpecificContent(LoanUtil.getLoanUtil().getProperty(OLEConstants.OleDeliverRequest.COURTESY_NOTICE_CONTENT)); 1895 /* oleNoticeBo.setTitle((String) bibInformation.get(OLEConstants.TITLE) != null ? (String) bibInformation.get(OLEConstants.TITLE) : ""); 1896 oleNoticeBo.setAuthor((String) bibInformation.get(OLEConstants.AUTHOR) != null ? (String) bibInformation.get(OLEConstants.AUTHOR) : "");*/ 1897 oleNoticeBo.setTitle(item.getHolding().getBib().getTitle()); 1898 oleNoticeBo.setAuthor(item.getHolding().getBib().getAuthor()); 1899 oleNoticeBo.setVolumeNumber(item.getVolumeNumber()); 1900 oleNoticeBo.setItemShelvingLocation(shelvingLocation != null ? shelvingLocation : ""); 1901 // oleNoticeBo.setItemCallNumber((String) docStoreDetails.get(OLEConstants.CALL_NUM) != null ? (String) docStoreDetails.get(OLEConstants.CALL_NUM) : ""); 1902 oleNoticeBo.setItemCallNumber((String) oleItem.getCallNumber().getNumber() != null && !oleItem.getCallNumber().getNumber().equals("") ? oleItem.getCallNumber().getNumber() : loanProcessor.getItemCallNumber(itemContent, item.getHolding().getId())); 1903 oleNoticeBo.setItemId(oleLoanDocument.getItemId()); 1904 oleLoanDocument.getOlePatron().setEmailAddress(oleNoticeBo.getPatronEmailAddress()); 1905 LOG.info("oleNoticeBo.getPatronEmailAddress()" + oleNoticeBo.getPatronEmailAddress()); 1906 return oleNoticeBo; 1907 } 1908 1909 private OleNoticeBo getOverdueNotice(OleLoanDocument oleLoanDocument) throws Exception { 1910 LOG.debug("Overdue Notice"); 1911 EntityTypeContactInfoBo entityTypeContactInfoBo = oleLoanDocument.getOlePatron().getEntity().getEntityTypeContactInfos().get(0); 1912 OleNoticeBo oleNoticeBo = new OleNoticeBo(); 1913 // String itemId = oleLoanDocument.getItemId(); 1914 org.kuali.ole.docstore.common.document.content.instance.Item oleItem = oleLoanDocument.getOleItem(); 1915 // String itemUuid = oleItem.getItemIdentifier(); 1916 //String shelvingLocation = oleLoanDocument.getItemLocation(); 1917 org.kuali.ole.docstore.common.document.Item item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(oleLoanDocument.getItemUuid()); 1918 OleCirculationDesk oleCirculationDesk = getOleCirculationDesk(oleLoanDocument.getCirculationLocationId()); 1919 if (oleCirculationDesk != null) 1920 oleNoticeBo.setCirculationDeskName(oleCirculationDesk.getCirculationDeskPublicName()); 1921 else 1922 oleNoticeBo.setCirculationDeskName(""); 1923 oleNoticeBo.setCirculationDeskAddress(""); 1924 oleNoticeBo.setCirculationDeskEmailAddress(""); 1925 oleNoticeBo.setCirculationDeskPhoneNumber(""); 1926 oleNoticeBo.setPatronName(oleLoanDocument.getOlePatron().getEntity().getNames().get(0).getFirstName() + " " + oleLoanDocument.getOlePatron().getEntity().getNames().get(0).getLastName()); 1927 oleNoticeBo.setPatronAddress(getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getPatronPreferredAddress(entityTypeContactInfoBo) : ""); 1928 oleNoticeBo.setPatronEmailAddress(getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getPatronHomeEmailId(entityTypeContactInfoBo) : ""); 1929 oleNoticeBo.setPatronPhoneNumber(getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getPatronHomePhoneNumber(entityTypeContactInfoBo) : ""); 1930 oleNoticeBo.setNoticeName(OLEConstants.NOTICE_OVERDUE); 1931 oleNoticeBo.setNoticeSpecificContent(LoanUtil.getLoanUtil().getProperty(OLEConstants.OleDeliverRequest.OVERDUE_NOTICE_CONTENT)); 1932 oleNoticeBo.setTitle(item.getHolding().getBib().getTitle()); 1933 oleNoticeBo.setAuthor(item.getHolding().getBib().getAuthor()); 1934 /*oleNoticeBo.setTitle((String) bibInformation.get(OLEConstants.TITLE) != null ? (String) bibInformation.get(OLEConstants.TITLE) : ""); 1935 oleNoticeBo.setAuthor((String) bibInformation.get(OLEConstants.AUTHOR) != null ? (String) bibInformation.get(OLEConstants.AUTHOR) : "");*/ 1936 1937 //oleNoticeBo.setVolumeNumber((String) docStoreDetails.get(OLEConstants.VOL_NUM) != null ? (String) docStoreDetails.get(OLEConstants.VOL_NUM) : ""); 1938 String volume = (String) oleItem.getEnumeration() != null && !oleItem.getEnumeration().equals("") ? oleItem.getEnumeration() : ""; 1939 String issue = new String(" "); 1940 String copyNumber = (String) oleItem.getCopyNumber() != null && !oleItem.getCopyNumber().equals("") ? oleItem.getCopyNumber() : ""; 1941 oleNoticeBo.setVolumeIssueCopyNumber(volume + "/" + issue + "/" + copyNumber); 1942 oleNoticeBo.setItemShelvingLocation(item.getLocationName()); 1943 if (oleItem.getCallNumber().getNumber() != null && !oleItem.getCallNumber().getNumber().equals("")) { 1944 oleNoticeBo.setItemCallNumber((String) oleItem.getCallNumber().getNumber() != null && !oleItem.getCallNumber().getNumber().equals("") ? oleItem.getCallNumber().getNumber() : ""); 1945 } else { 1946 oleNoticeBo.setItemCallNumber(getLoanProcessor().getItemCallNumber(oleItem, oleLoanDocument.getInstanceUuid())); 1947 } 1948 //oleNoticeBo.setItemCallNumber((String) docStoreDetails.get(OLEConstants.CALL_NUM) != null ? (String) docStoreDetails.get(OLEConstants.CALL_NUM) : ""); 1949 oleNoticeBo.setItemId(oleLoanDocument.getItemId()); 1950 //oleNoticeBo.setDueDate(oleLoanDocument.getLoanDueDate()!=null ? oleLoanDocument.getLoanDueDate().toString().substring(0, 10) : null); 1951 oleNoticeBo.setDueDate(oleLoanDocument.getLoanDueDate()!=null ? oleLoanDocument.getLoanDueDate() :null); 1952 oleLoanDocument.getOlePatron().setEmailAddress(oleNoticeBo.getPatronEmailAddress()); 1953 LOG.info("oleNoticeBo.getPatronEmailAddress()" + oleNoticeBo.getPatronEmailAddress()); 1954 int noOfOverdueNoticeSent = Integer.parseInt(oleLoanDocument.getNumberOfOverdueNoticesSent() != null ? oleLoanDocument.getNumberOfOverdueNoticesSent() : "0"); 1955 noOfOverdueNoticeSent = noOfOverdueNoticeSent + 1; 1956 LOG.debug("Updated Loan Record : " + oleLoanDocument); 1957 oleLoanDocument.setNumberOfOverdueNoticesSent(Integer.toString(noOfOverdueNoticeSent)); 1958 oleLoanDocument.setOverDueNoticeDate(new java.sql.Date(System.currentTimeMillis())); 1959 getBusinessObjectService().save(oleLoanDocument); 1960 return oleNoticeBo; 1961 } 1962 1963 public void updateItem(org.kuali.ole.docstore.common.document.content.instance.Item oleItem, String itemUuid) throws Exception { 1964 org.kuali.ole.docstore.common.document.content.instance.ItemStatus itemStatus = new org.kuali.ole.docstore.common.document.content.instance.ItemStatus(); 1965 itemStatus.setCodeValue(OLEConstants.OleDeliverRequest.MISSING); 1966 itemStatus.setFullValue(OLEConstants.OleDeliverRequest.MISSING); 1967 oleItem.setItemStatus(itemStatus); 1968 oleItem.setStaffOnlyFlag(true); 1969 String itemContent = new ItemOlemlRecordProcessor().toXML(oleItem); 1970 org.kuali.ole.docstore.common.document.Item item = new ItemOleml(); 1971 item.setId(itemUuid); 1972 item.setContent(itemContent); 1973 item.setCategory(OLEConstants.WORK_CATEGORY); 1974 item.setType(DocType.ITEM.getCode()); 1975 item.setFormat(OLEConstants.OLEML_FORMAT); 1976 getDocstoreClientLocator().getDocstoreClient().updateItem(item); 1977 } 1978 1979 public String getShelvingLocation(org.kuali.ole.docstore.common.document.content.instance.LocationLevel oleLocationLevel) { 1980 String location = null; 1981 if (oleLocationLevel != null) { 1982 if (OLEConstants.LOCATION_LEVEL_SHELVING.equalsIgnoreCase(oleLocationLevel.getLevel())) 1983 location = oleLocationLevel.getName(); 1984 else 1985 location = getShelvingLocation(oleLocationLevel.getLocationLevel()); 1986 } 1987 if ("".equals(location) || location == null) 1988 return null; 1989 return location; 1990 } 1991 1992 1993 public String getIntervalForCourtesyNotice() { 1994 BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService(); 1995 Map<String, String> criteriaMap = new HashMap<String, String>(); 1996 criteriaMap.put(OLEConstants.NAMESPACE_CODE, OLEConstants.DLVR_NMSPC); 1997 criteriaMap.put(OLEConstants.COMPONENT_CODE, OLEConstants.DLVR_CMPNT); 1998 criteriaMap.put(OLEConstants.NAME, OLEParameterConstants.COURTESY_NOTICE_INTER); 1999 List<ParameterBo> parametersList = (List<ParameterBo>) businessObjectService.findMatching(ParameterBo.class, criteriaMap); 2000 return parametersList.get(0).getValue(); 2001 } 2002 2003 public String getIntervalForOverdueNotice() { 2004 BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService(); 2005 Map<String, String> criteriaMap = new HashMap<String, String>(); 2006 criteriaMap.put(OLEConstants.NAMESPACE_CODE, OLEConstants.DLVR_NMSPC); 2007 criteriaMap.put(OLEConstants.COMPONENT_CODE, OLEConstants.DLVR_CMPNT); 2008 criteriaMap.put(OLEConstants.NAME, OLEConstants.OVERDUE_NOTICE_INTER); 2009 List<ParameterBo> parametersList = (List<ParameterBo>) businessObjectService.findMatching(ParameterBo.class, criteriaMap); 2010 return parametersList.get(0).getValue(); 2011 } 2012 2013 2014 private PatronBillPayment getPatronBillPayment(String patronId) { 2015 LOG.debug("Inside the getPatronBillPayment method"); 2016 Map billMap = new HashMap(); 2017 billMap.put(OLEConstants.OleDeliverRequest.LOAN_PATRON_ID, patronId); 2018 List<PatronBillPayment> patronBillPaymentList = (List<PatronBillPayment>) getBusinessObjectService().findMatching(PatronBillPayment.class, billMap); 2019 return patronBillPaymentList != null && patronBillPaymentList.size() > 0 ? patronBillPaymentList.get(0) : null; 2020 } 2021 2022 private OlePaymentStatus getPaymentStatus() { 2023 LOG.debug("Inside the getPaymentStatus method"); 2024 Map statusMap = new HashMap(); 2025 statusMap.put(OLEConstants.OleDeliverRequest.PAYMENT_STATUS_NAME, OLEConstants.PAYMENT_STATUS_OUTSTANDING); 2026 List<OlePaymentStatus> olePaymentStatusList = (List<OlePaymentStatus>) getBusinessObjectService().findMatching(OlePaymentStatus.class, statusMap); 2027 return olePaymentStatusList != null && olePaymentStatusList.size() > 0 ? olePaymentStatusList.get(0) : null; 2028 } 2029 2030 private String getFeeTypeId(String feeTypeName) { 2031 LOG.debug("Inside the getOverdueFeeTypeId method"); 2032 Map feeMap = new HashMap(); 2033 feeMap.put(OLEConstants.FEE_TYPE_NAME, feeTypeName); 2034 List<OleFeeType> oleFeeTypes = (List<OleFeeType>) getBusinessObjectService().findMatching(OleFeeType.class, feeMap); 2035 return oleFeeTypes != null && oleFeeTypes.size() > 0 ? oleFeeTypes.get(0).getFeeTypeId() : null; 2036 } 2037 2038 public String processItemType(String itemType) { 2039 2040 LOG.debug("Inside process Item Type"); 2041 Map<String, String> itemMap = new HashMap<String, String>(); 2042 itemMap.put(OLEConstants.OleDeliverRequest.ITEM_TYPE_CODE, itemType); 2043 List<OleInstanceItemType> oleInstanceItemTypeList = (List<OleInstanceItemType>) businessObjectService.findMatching(OleInstanceItemType.class, itemMap); 2044 if (oleInstanceItemTypeList != null && oleInstanceItemTypeList.size() > 0) { 2045 OleInstanceItemType oleInstanceItemType = oleInstanceItemTypeList.get(0); 2046 return oleInstanceItemType.getInstanceItemTypeName(); 2047 } 2048 return null; 2049 } 2050 2051 public String placeRequest(String patronId, String operatorId, String itemBarcode, String requestType, String pickUpLocation, String itemIdentifier) { 2052 OleDeliverRequestBo oleDeliverRequestBo = new OleDeliverRequestBo(); 2053 oleDeliverRequestBo.setCreateDate(new java.sql.Date(System.currentTimeMillis())); 2054 OlePatronDocument olePatronDocument = null; 2055 Map<String, String> patronMap = new HashMap<String, String>(); 2056 patronMap.put("olePatronId", patronId); 2057 OleNoticeBo oleNoticeBo = new OleNoticeBo(); 2058 List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) businessObjectService.findMatching(OlePatronDocument.class, patronMap); 2059 if (olePatronDocumentList.size() > 0) { 2060 olePatronDocument = olePatronDocumentList.get(0); 2061 oleDeliverRequestBo.setBorrowerId(patronId); 2062 oleDeliverRequestBo.setBorrowerBarcode(olePatronDocument.getBarcode()); 2063 oleDeliverRequestBo.setOlePatron(olePatronDocument); 2064 EntityTypeContactInfoBo entityTypeContactInfoBo = olePatronDocument.getEntity().getEntityTypeContactInfos().get(0); 2065 try { 2066 oleNoticeBo.setPatronName(olePatronDocument.getEntity().getNames().get(0).getFirstName() + " " + oleDeliverRequestBo.getOlePatron().getEntity().getNames().get(0).getLastName()); 2067 oleNoticeBo.setPatronAddress(getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getPatronPreferredAddress(entityTypeContactInfoBo) : ""); 2068 oleNoticeBo.setPatronEmailAddress(getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getPatronHomeEmailId(entityTypeContactInfoBo) : ""); 2069 oleNoticeBo.setPatronPhoneNumber(getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getPatronHomePhoneNumber(entityTypeContactInfoBo) : ""); 2070 } catch (Exception e) { 2071 LOG.error(e, e); 2072 LOG.info("Exception Occured while setting the patron information for the patron . Patron Barcode : " + oleDeliverRequestBo.getBorrowerBarcode()); 2073 } 2074 } else { 2075 return "No patron information"; 2076 } 2077 if (requestType != null) { 2078 Map<String, String> requestTypeMap = new HashMap<String, String>(); 2079 requestTypeMap.put("requestTypeCode", requestType); 2080 List<OleDeliverRequestType> oleDeliverRequestTypeList = (List<OleDeliverRequestType>) businessObjectService.findMatching(OleDeliverRequestType.class, requestTypeMap); 2081 if (oleDeliverRequestTypeList != null && (oleDeliverRequestTypeList.size() > 0)) { 2082 oleDeliverRequestBo.setRequestTypeId(oleDeliverRequestTypeList.get(0).getRequestTypeId()); 2083 oleDeliverRequestBo.setOleDeliverRequestType(oleDeliverRequestTypeList.get(0)); 2084 } else 2085 return "Invalid Request Type Code"; 2086 2087 } 2088 if (pickUpLocation != null) { 2089 Map<String, String> circulationDeskMap = new HashMap<String, String>(); 2090 circulationDeskMap.put("circulationDeskCode", pickUpLocation); 2091 List<OleCirculationDesk> oleCirculationDeskList = (List<OleCirculationDesk>) businessObjectService.findMatching(OleCirculationDesk.class, circulationDeskMap); 2092 if (oleCirculationDeskList != null && oleCirculationDeskList.size() > 0) { 2093 oleDeliverRequestBo.setPickUpLocationId(oleCirculationDeskList.get(0).getCirculationDeskId()); 2094 oleDeliverRequestBo.setPickUpLocationCode(oleCirculationDeskList.get(0).getCirculationDeskCode()); 2095 oleDeliverRequestBo.setOlePickUpLocation(oleCirculationDeskList.get(0)); 2096 } else { 2097 return "Invalid Pick Up Location"; 2098 } 2099 2100 } 2101 try { 2102 if (itemBarcode == null || (itemBarcode != null && itemBarcode.isEmpty())) { 2103 return "invalid barcode"; 2104 } 2105 oleDeliverRequestBo.setItemId(itemBarcode); 2106 oleDeliverRequestBo.setItemUuid(itemIdentifier); 2107 Thread.sleep(2000); 2108 docstoreUtil.isItemAvailableInDocStore(oleDeliverRequestBo); 2109 if (oleDeliverRequestBo.getItemUuid() == null || (oleDeliverRequestBo.getItemUuid() != null && oleDeliverRequestBo.getItemUuid().trim().isEmpty())) { 2110 return "invalid barcode"; 2111 } else { 2112 oleDeliverRequestBo.setRequestCreator("Operator"); 2113 oleDeliverRequestBo.setOperatorCreateId(operatorId); 2114 oleDeliverRequestBo.setBorrowerId(patronId); 2115 oleDeliverRequestBo.setItemId(itemBarcode); 2116 oleDeliverRequestBo.setRequestStatus("1"); 2117 if (!processOperator(operatorId)) { 2118 return OLEConstants.INVALID_OPERATOR; 2119 } 2120 processRequestType(oleDeliverRequestBo); 2121 String message = this.patronRecordExpired(oleDeliverRequestBo); 2122 if (message != null) 2123 return message; 2124 boolean requestRaised = this.isRequestAlreadyRaisedByPatron(oleDeliverRequestBo); 2125 if (requestRaised) 2126 return "Request Already Raised For This Item By The Patron "; 2127 boolean itemEligible = this.isItemEligible(oleDeliverRequestBo); 2128 if (!itemEligible) 2129 return "Item is not eligible for circulation"; 2130 boolean alreadyLoaned = this.isAlreadyLoaned(oleDeliverRequestBo); 2131 if (alreadyLoaned) 2132 return "Item is currently in loan with the requested borrower"; 2133 2134 boolean valid = false; 2135 EngineResults engineResult = this.executeEngineResults(oleDeliverRequestBo); 2136 if (engineResult != null) { 2137 List<ResultEvent> allResults = engineResult.getAllResults(); 2138 if (allResults.size() > 0) { 2139 for (Iterator<ResultEvent> resultEventIterator = allResults.iterator(); resultEventIterator.hasNext(); ) { 2140 ResultEvent resultEvent = resultEventIterator.next(); 2141 if (resultEvent.getType().equals(RULE_EVALUATED)) 2142 valid |= resultEvent.getResult(); 2143 } 2144 if ((oleDeliverRequestBo.getMessage() != null && !oleDeliverRequestBo.getMessage().isEmpty())) 2145 return oleDeliverRequestBo.getMessage(); 2146 } 2147 } 2148 OleDeliverRequestBo oleDeliverRequestBo1 = oleDeliverRequestBo; 2149 if (oleDeliverRequestBo.getRequestTypeId().equals("1") || oleDeliverRequestBo.getRequestTypeId().equals("2") || oleDeliverRequestBo.getRequestTypeId().equals("3") || oleDeliverRequestBo.getRequestTypeId().equals("4")) { 2150 if (oleDeliverRequestBo.getRequestTypeId().equals("1") || oleDeliverRequestBo.getRequestTypeId().equals("2")) 2151 oleDeliverRequestBo1 = this.updateLoanDocument(oleDeliverRequestBo); 2152 if (isItemAvailable(oleDeliverRequestBo1)) { 2153 return "Recall / Hold type of request can be raised only for the item which is currently in circulation"; 2154 } 2155 } 2156 oleDeliverRequestBo.setOleItem(null); 2157 this.reOrderQueuePosition(oleDeliverRequestBo1); 2158 getBusinessObjectService().save(oleDeliverRequestBo1); 2159 Map<String, String> requestMap = new HashMap<String, String>(); 2160 requestMap.put("borrowerId", patronId); 2161 requestMap.put("itemId", itemBarcode); 2162 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class, requestMap); 2163 String requestId = ""; 2164 if (oleDeliverRequestBoList.size() > 0) { 2165 requestId = ":Request Id :" + oleDeliverRequestBoList.get(0).getRequestId(); 2166 } 2167 LOG.info("Request Raised Succesfully" + requestId); 2168 String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL); 2169 if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) { 2170 fromAddress = OLEConstants.KUALI_MAIL; 2171 } 2172 oleNoticeBo.setNoticeName(OLEConstants.PICKUP_NOTICE); 2173 Date pickupDate = addDate(new java.sql.Date(System.currentTimeMillis()), new Integer(oleDeliverRequestBo.getOlePickUpLocation().getOnHoldDays())); 2174 oleNoticeBo.setNoticeSpecificContent(OLEConstants.PICKUP_NOTICE_START_CONTENT + oleDeliverRequestBo.getOlePickUpLocation().getCirculationDeskPublicName() + OLEConstants.PICKUP_NOTICE_MIDDLE_CONTENT + pickupDate + OLEConstants.PICKUP_NOTICE_FINAL_CONTENT); 2175 oleNoticeBo.setAuthor(oleDeliverRequestBo.getAuthor() != null ? oleDeliverRequestBo.getAuthor() : ""); 2176 oleNoticeBo.setItemCallNumber(oleDeliverRequestBo.getCallNumber() != null ? oleDeliverRequestBo.getCallNumber() : ""); 2177 oleNoticeBo.setItemId(oleDeliverRequestBo.getItemId() != null ? oleDeliverRequestBo.getItemId() : ""); 2178 oleNoticeBo.setTitle(oleDeliverRequestBo.getTitle() != null ? oleDeliverRequestBo.getTitle() : ""); 2179 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl(); 2180 String content = oleDeliverBatchService.getEmailPickUpNotice(oleNoticeBo); 2181 try { 2182 if (!content.trim().equals("")) { 2183 OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer"); 2184 oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(content), true); 2185 LOG.info("Mail send Successfully to " + oleNoticeBo.getPatronEmailAddress()); 2186 oleDeliverBatchService.getPdfPickUpNotice(oleNoticeBo); 2187 } else { 2188 LOG.info("Notice Type :" + oleNoticeBo.getNoticeName() + " " + "Item Barcode : " + oleNoticeBo.getItemId() + " " + "Patron Name :" + oleNoticeBo.getPatronName()); 2189 } 2190 } catch (Exception e) { 2191 LOG.error(e, e); 2192 return "Request Raised Succesfully" + requestId + ".Problem occured while sending notice."; 2193 } 2194 return "Request Raised Succesfully" + requestId; 2195 } 2196 } catch (Exception e) { 2197 LOG.error(e, e); 2198 if (e.getMessage().equalsIgnoreCase("Item barcode does not exist.")) { 2199 return "Item barcode does not exist."; 2200 } 2201 return "Request failed"; 2202 } 2203 } 2204 2205 private java.sql.Date addDate(java.sql.Date in, int daysToAdd) { 2206 if (in == null) { 2207 return null; 2208 } 2209 GregorianCalendar cal = new GregorianCalendar(); 2210 cal.setTime(in); 2211 cal.add(Calendar.DAY_OF_MONTH, daysToAdd); 2212 return new java.sql.Date(cal.getTime().getTime()); 2213 } 2214 2215 public EngineResults executeEngineResults(OleDeliverRequestBo oleDeliverRequestBo) { 2216 List<OleDeliverRequestBo> recallList = new ArrayList<OleDeliverRequestBo>(); 2217 List<OleDeliverRequestBo> holdList = new ArrayList<OleDeliverRequestBo>(); 2218 List<OleDeliverRequestBo> pageList = new ArrayList<OleDeliverRequestBo>(); 2219 List<OleDeliverRequestBo> requestsByBorrower = new ArrayList<OleDeliverRequestBo>(); 2220 Engine engine = KrmsApiServiceLocator.getEngine(); 2221 EngineResults engineResult = null; 2222 HashMap<String, Object> agendaValue = new HashMap<String, Object>(); 2223 agendaValue.put(OLEConstants.NAME_NM, OLEConstants.REQUEST_AGENDA_NM); 2224 List<AgendaBo> agendaBos = (List<AgendaBo>) KRADServiceLocator.getBusinessObjectService().findMatching(AgendaBo.class, agendaValue); 2225 if (agendaBos != null && agendaBos.size() > 0) { 2226 AgendaBo agendaBo = agendaBos.get(0); 2227 HashMap<String, String> map = new HashMap<String, String>(); 2228 map.put(OLEConstants.AGENDA_NAME, agendaBo.getName()); 2229 List<MatchBo> matchBos = (List<MatchBo>) KRADServiceLocator.getBusinessObjectService().findMatching(MatchBo.class, map); 2230 2231 SelectionCriteria selectionCriteria = 2232 SelectionCriteria.createCriteria(null, getSelectionContext(agendaBo.getContext().getName()), 2233 getAgendaContext(OLEConstants.REQUEST_AGENDA_NM)); 2234 2235 ExecutionOptions executionOptions = new ExecutionOptions(); 2236 executionOptions.setFlag(ExecutionFlag.LOG_EXECUTION, true); 2237 2238 Facts.Builder factBuilder = Facts.Builder.create(); 2239 2240 String borrowerType = ""; 2241 if (oleDeliverRequestBo.getOlePatron() != null && oleDeliverRequestBo.getOlePatron().getOleBorrowerType() != null) { 2242 borrowerType = oleDeliverRequestBo.getOlePatron().getOleBorrowerType().getBorrowerTypeCode(); 2243 } 2244 String itemType = oleDeliverRequestBo.getItemType(); 2245 2246 String requestTypeId = oleDeliverRequestBo.getRequestTypeId(); 2247 2248 String requestType = oleDeliverRequestBo.getRequestTypeCode(); 2249 2250 String location = oleDeliverRequestBo.getShelvingLocation(); 2251 LoanProcessor loanProcessor = getLoanProcessor(); 2252 OleLoanDocument oleLoanDocument = loanProcessor.getOleLoanDocumentUsingItemUUID(oleDeliverRequestBo.getItemUuid()); 2253 DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE); 2254 dataCarrierService.addData(OLEConstants.LOANED_DATE, oleLoanDocument != null ? oleLoanDocument.getCreateDate() : null); 2255 dataCarrierService.addData(OLEConstants.CIRC_POLICY_FOUND, null); 2256 String borrowerId = oleDeliverRequestBo.getBorrowerId(); 2257 Map<String, String> requestMap = new HashMap<String, String>(); 2258 requestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid()); 2259 if (requestTypeId != null && (requestTypeId.equals("1") || requestTypeId.equals("2"))) { 2260 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "1"); 2261 recallList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap); 2262 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "2"); 2263 recallList.addAll((List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap)); 2264 } else if (requestTypeId != null && (requestTypeId.equals("3") || requestTypeId.equals("4"))) { 2265 // holdList = (List<OleDeliverRequestBo>)getBusinessObjectService().findMatching(OleDeliverRequestBo.class,requestMap); 2266 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "3"); 2267 holdList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap); 2268 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "4"); 2269 holdList.addAll((List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap)); 2270 } else if (requestTypeId != null && (requestTypeId.equals("5") || requestTypeId.equals("6"))) { 2271 // pageList = (List<OleDeliverRequestBo>)getBusinessObjectService().findMatching(OleDeliverRequestBo.class,requestMap); 2272 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "5"); 2273 pageList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap); 2274 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "6"); 2275 pageList.addAll((List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap)); 2276 } 2277 Map<String, String> requestByBorrower = new HashMap<String, String>(); 2278 requestByBorrower.put(OLEConstants.OleDeliverRequest.BORROWER_ID, borrowerId); 2279 requestsByBorrower = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestByBorrower); 2280 HashMap<String, Object> termValues = new HashMap<String, Object>(); 2281 termValues.put(OLEConstants.BORROWER_TYPE, borrowerType); 2282 termValues.put(OLEConstants.ITEM_TYPE, itemType); 2283 termValues.put(OLEConstants.LOCATION, location); 2284 termValues.put(OLEConstants.ITEM_SHELVING, oleDeliverRequestBo.getShelvingLocation()); 2285 termValues.put(OLEConstants.ITEM_COLLECTION, oleDeliverRequestBo.getItemCollection()); 2286 termValues.put(OLEConstants.ITEM_LIBRARY, oleDeliverRequestBo.getItemLibrary()); 2287 termValues.put(OLEConstants.ITEM_CAMPUS, oleDeliverRequestBo.getItemCampus()); 2288 termValues.put(OLEConstants.ITEM_INSTITUTION, oleDeliverRequestBo.getItemInstitution()); 2289 termValues.put(OLEConstants.MAX_NO_OF_RECALL_REQUEST, new Integer(recallList.size()) + 1); 2290 termValues.put(OLEConstants.MAX_NO_OF_HOLD_REQUEST, new Integer(holdList.size()) + 1); 2291 termValues.put(OLEConstants.MAX_NO_OF_PAGE_REQUEST, new Integer(pageList.size()) + 1); 2292 // termValues.put("maxNumberOfRequestByBorrower",requestsByBorrower.size()); 2293 termValues.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, requestTypeId); 2294 termValues.put(OLEConstants.REQUEST_TYPE, requestType); 2295 2296 2297 for (Iterator<MatchBo> matchBoIterator = matchBos.iterator(); matchBoIterator.hasNext(); ) { 2298 MatchBo matchBo = matchBoIterator.next(); 2299 factBuilder.addFact(matchBo.getTermName(), termValues.get((matchBo.getTermName()))); 2300 } 2301 LOG.info("termValues.toString()" + termValues.toString()); 2302 engineResult = engine.execute(selectionCriteria, factBuilder.build(), executionOptions); 2303 List<String> errorMessage = (List<String>) engineResult.getAttribute(OLEConstants.ERROR_ACTION); 2304 java.sql.Date d = (java.sql.Date) engineResult.getAttribute(OLEConstants.REQ_EXPIRATION_DATE); 2305 Timestamp recallDueDate = (Timestamp) engineResult.getAttribute(OLEConstants.RECALL_DUE_DATE); 2306 String notice = (String) engineResult.getAttribute(OLEConstants.NOTICE); 2307 oleDeliverRequestBo.setNoticeType(notice); 2308 if (recallDueDate != null && oleLoanDocument.getLoanDueDate()!=null && oleLoanDocument.getLoanDueDate().compareTo(recallDueDate) > 0) { 2309 oleLoanDocument.setLoanDueDate(recallDueDate); 2310 oleDeliverRequestBo.setRecallDueDate(recallDueDate); 2311 getBusinessObjectService().save(oleLoanDocument); 2312 } 2313 oleDeliverRequestBo.setRequestExpiryDate(d); 2314 StringBuffer failures = new StringBuffer(); 2315 if (errorMessage != null && errorMessage.size() > 0) { 2316 int i = 1; 2317 for (String errMsg : errorMessage) { 2318 failures.append(i++ + ". " + errMsg + OLEConstants.BREAK); 2319 } 2320 } 2321 if (!failures.toString().isEmpty()) { 2322 oleDeliverRequestBo.setMessage(failures.toString()); 2323 } 2324 dataCarrierService.addData(OLEConstants.ERROR_ACTION, null); 2325 } 2326 return engineResult; 2327 } 2328 2329 /** 2330 * This method returns SelectionContext using contextName. 2331 * 2332 * @param contextName 2333 * @return Map 2334 */ 2335 protected Map<String, String> getSelectionContext(String contextName) { 2336 Map<String, String> selector = new HashMap<String, String>(); 2337 selector.put(NAMESPACE_CODE_SELECTOR, OLEConstants.OLE_NAMESPACE); 2338 selector.put(NAME_SELECTOR, contextName); 2339 return selector; 2340 } 2341 2342 /** 2343 * This method returns AgendaContext using agendaName.. 2344 * 2345 * @param agendaName 2346 * @return Map 2347 */ 2348 protected Map<String, String> getAgendaContext(String agendaName) { 2349 Map<String, String> selector = new HashMap<String, String>(); 2350 selector.put(NAME_SELECTOR, agendaName); 2351 return selector; 2352 } 2353 2354 private OleCirculationDesk getOleCirculationDesk(String circulationDeskId) { 2355 Map<String, String> circulationDeskMap = new HashMap<String, String>(); 2356 circulationDeskMap.put("circulationDeskId", circulationDeskId); 2357 List<OleCirculationDesk> oleCirculationDeskList = (List<OleCirculationDesk>) businessObjectService.findMatching(OleCirculationDesk.class, circulationDeskMap); 2358 if (oleCirculationDeskList != null && oleCirculationDeskList.size() > 0) { 2359 return oleCirculationDeskList.get(0); 2360 } else 2361 return null; 2362 } 2363 2364 private RoleService getRoleService() { 2365 RoleService service = KimApiServiceLocator.getRoleService(); 2366 return service; 2367 } 2368 2369 2370} 2371 2372 2373 2374 2375 2376