001 package org.kuali.ole.deliver.request.service; 002 003 import org.apache.log4j.Logger; 004 import org.kuali.ole.OLEConstants; 005 import org.kuali.ole.catalog.bo.OleInstanceItemType; 006 import org.kuali.ole.deliver.batch.OleDeliverNoticeService; 007 import org.kuali.ole.deliver.batch.OleNoticeBo; 008 import org.kuali.ole.deliver.loan.LoanProcessor; 009 import org.kuali.ole.deliver.loan.bo.OleItemSearch; 010 import org.kuali.ole.deliver.loan.bo.OleLoanDocument; 011 import org.kuali.ole.deliver.request.bo.OleDeliverRequestBo; 012 import org.kuali.ole.deliver.request.bo.OleDeliverRequestHistoryRecord; 013 import org.kuali.ole.docstore.model.xmlpojo.work.instance.oleml.Item; 014 import org.kuali.ole.docstore.model.xmlpojo.work.instance.oleml.Location; 015 import org.kuali.ole.docstore.model.xmlpojo.work.instance.oleml.LocationLevel; 016 import org.kuali.ole.location.bo.OleLocation; 017 import org.kuali.ole.patron.bo.OlePatronDocument; 018 import org.kuali.ole.patron.bo.OleProxyPatronDocument; 019 import org.kuali.ole.service.OleDeliveryDocstoreService; 020 import org.kuali.ole.service.impl.OleDeliveryDocstoreServiceImpl; 021 import org.kuali.rice.coreservice.impl.parameter.ParameterBo; 022 import org.kuali.rice.krad.maintenance.MaintenanceDocument; 023 import org.kuali.rice.krad.service.BusinessObjectService; 024 import org.kuali.rice.krad.service.KRADServiceLocator; 025 import org.kuali.rice.krad.util.ObjectUtils; 026 import org.kuali.rice.krad.web.form.MaintenanceForm; 027 028 029 030 import java.sql.*; 031 import java.text.SimpleDateFormat; 032 import java.util.*; 033 import java.util.Date; 034 035 /** 036 * Created with IntelliJ IDEA. 037 * User: ? 038 * Date: 10/24/12 039 * Time: 10:27 AM 040 * To change this template use File | Settings | File Templates. 041 */ 042 public class OleDeliverRequestDocumentHelperServiceImpl { 043 private static final Logger LOG = Logger.getLogger(OleDeliverRequestDocumentHelperServiceImpl.class); 044 private BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService(); 045 private int queuePosition=0; 046 private LoanProcessor loanProcessor = new LoanProcessor(); 047 private OleDeliveryDocstoreService docStoreService = new OleDeliveryDocstoreServiceImpl(); 048 049 050 051 052 053 public BusinessObjectService getbusinessObjectService() { 054 return businessObjectService; 055 } 056 057 public void setbusinessObjectService(BusinessObjectService businessObjectService) { 058 this.businessObjectService = businessObjectService; 059 } 060 061 public LoanProcessor getLoanProcessor() { 062 return loanProcessor; 063 } 064 065 public void setLoanProcessor(LoanProcessor loanProcessor) { 066 this.loanProcessor = loanProcessor; 067 } 068 069 public OleDeliveryDocstoreService getDocStoreService() { 070 return docStoreService; 071 } 072 073 public void setDocStoreService(OleDeliveryDocstoreService docStoreService) { 074 this.docStoreService = docStoreService; 075 } 076 077 078 /** 079 * This method is used to change the request type based on selection of pick up location 080 * @param oleDeliverRequestBo 081 * @return oleDeliverRequestBo 082 */ 083 public OleDeliverRequestBo processRequestType(OleDeliverRequestBo oleDeliverRequestBo) { 084 085 LOG.debug("Inside processRequestType for the Request id :" + oleDeliverRequestBo.getRequestId()); 086 087 if (oleDeliverRequestBo.getRequestTypeId().equals(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID_3) && oleDeliverRequestBo.getPickUpLocationCode() != null && !oleDeliverRequestBo.getPickUpLocationCode().isEmpty() ) { 088 oleDeliverRequestBo.setRequestTypeId(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID_4); 089 } else if (oleDeliverRequestBo.getRequestTypeId().equals(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID_5) && oleDeliverRequestBo.getPickUpLocationCode() != null && !oleDeliverRequestBo.getPickUpLocationCode().isEmpty()) { 090 oleDeliverRequestBo.setRequestTypeId(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID_6); 091 } else if (oleDeliverRequestBo.getRequestTypeId().equals(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID_1) && oleDeliverRequestBo.getPickUpLocationCode() != null && !oleDeliverRequestBo.getPickUpLocationCode().isEmpty()) { 092 oleDeliverRequestBo.setRequestTypeId(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID_2); 093 094 } 095 oleDeliverRequestBo = processPatron(oleDeliverRequestBo); 096 oleDeliverRequestBo = processItem(oleDeliverRequestBo); 097 return oleDeliverRequestBo; 098 } 099 100 101 102 /** 103 * This is to create a new patron object if the user enters the operator Id manually 104 * @param oleDeliverRequestBo 105 * @return deliver 106 */ 107 public OleDeliverRequestBo processPatron(OleDeliverRequestBo oleDeliverRequestBo) { 108 LOG.debug("Inside processPatron"); 109 OleDeliverRequestBo deliver = oleDeliverRequestBo; 110 if (oleDeliverRequestBo.getBorrowerId() != null || oleDeliverRequestBo.getProxyBorrowerId() != null) { 111 Map<String, String> patronMap = new HashMap<String, String>(); 112 patronMap.put(OLEConstants.OleDeliverRequest.PATRON_ID, oleDeliverRequestBo.getBorrowerId()); 113 List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>)businessObjectService.findMatching(OlePatronDocument.class, patronMap); 114 if (olePatronDocumentList != null && olePatronDocumentList.size()>0) { 115 deliver.setOlePatron(olePatronDocumentList.get(0)); 116 } 117 if(oleDeliverRequestBo.getRequestCreator().equals(OLEConstants.OleDeliverRequest.REQUESTER_PROXY_PATRON)){ 118 Map<String, String> proxyPatronMap = new HashMap<String, String>(); 119 proxyPatronMap.put(OLEConstants.OleDeliverRequest.PATRON_ID, oleDeliverRequestBo.getBorrowerId()); 120 List<OlePatronDocument> oleProxyPatronDocumentList = (List<OlePatronDocument>)businessObjectService.findMatching(OlePatronDocument.class, proxyPatronMap); 121 if (oleProxyPatronDocumentList != null && oleProxyPatronDocumentList.size()>0) { 122 deliver.setOleProxyPatron(oleProxyPatronDocumentList.get(0)); 123 } 124 } 125 126 } 127 128 return deliver; 129 } 130 131 132 133 /** 134 * This is to check whether the pick up location is selected for the hold type of Request 135 * @param oleDeliverRequestBo 136 * @return validRequest 137 */ 138 public boolean validateRequestType(OleDeliverRequestBo oleDeliverRequestBo) { 139 LOG.debug("Inside validateRequestType"); 140 boolean validRequest = true; 141 if ((oleDeliverRequestBo.getRequestTypeId().equals(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID_2) || oleDeliverRequestBo.getRequestTypeId().equals(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID_4) || oleDeliverRequestBo.getRequestTypeId().equals(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID_6)) && (oleDeliverRequestBo.getPickUpLocationId() == null) || (oleDeliverRequestBo.getPickUpLocationId()!=null && oleDeliverRequestBo.getPickUpLocationId().isEmpty() )) { 142 validRequest = false; 143 } 144 return validRequest; 145 } 146 147 148 149 /** 150 * This is to check whether the patron is having delivery privilege or not 151 * @param oleDeliverRequestBo 152 * @return hasDeliveryPrivilege 153 */ 154 public boolean validateDeliveryPrivilege(OleDeliverRequestBo oleDeliverRequestBo) { 155 LOG.debug("Inside validateDeliveryPrivilege"); 156 boolean hasDeliveryPrivilege = true; 157 if (oleDeliverRequestBo.getRequestTypeId().equals(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID_1) || oleDeliverRequestBo.getRequestTypeId().equals(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID_3) || oleDeliverRequestBo.getRequestTypeId().equals(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID_5)) { 158 if (!oleDeliverRequestBo.getOlePatron().isDeliveryPrivilege()) { 159 hasDeliveryPrivilege = false; 160 } 161 } 162 return hasDeliveryPrivilege; 163 } 164 165 166 167 /** 168 * This is to check whether the patron is having paging privilege or not 169 * @param oleDeliverRequestBo 170 * @return hasPagePrivilege 171 */ 172 public boolean validatePagingPrivilege(OleDeliverRequestBo oleDeliverRequestBo) { 173 LOG.debug("Inside validatePagingPrivilege"); 174 boolean hasPagePrivilege = true; 175 if (oleDeliverRequestBo.getRequestTypeId().equals(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID_5) || oleDeliverRequestBo.getRequestTypeId().equals(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID_6)) { 176 if (!oleDeliverRequestBo.getOlePatron().isPagingPrivilege()) { 177 hasPagePrivilege = false; 178 } 179 } 180 return hasPagePrivilege; 181 } 182 183 184 185 /** 186 * This for setting the null values for the unselected requester 187 * @param oleDeliverRequestBo 188 * @return oleDeliverRequestBo 189 */ 190 public OleDeliverRequestBo processRequester(OleDeliverRequestBo oleDeliverRequestBo) { 191 LOG.debug("Inside processRequester"); 192 if (oleDeliverRequestBo.getRequestCreator().equals(OLEConstants.OleDeliverRequest.REQUESTER_PATRON)) { 193 oleDeliverRequestBo.setProxyBorrowerId(null); 194 oleDeliverRequestBo.setOleProxyPatron(null); 195 oleDeliverRequestBo.setOperatorCreateId(null); 196 oleDeliverRequestBo.setOperatorCreator(null); 197 } else if (oleDeliverRequestBo.getRequestCreator().equals(OLEConstants.OleDeliverRequest.REQUESTER_PROXY_PATRON)) { 198 oleDeliverRequestBo.setOperatorCreateId(null); 199 oleDeliverRequestBo.setOperatorCreator(null); 200 } else if (oleDeliverRequestBo.getRequestCreator().equals(OLEConstants.OleDeliverRequest.REQUESTER_OPERATOR)) { 201 oleDeliverRequestBo.setProxyBorrowerId(null); 202 oleDeliverRequestBo.setOleProxyPatron(null); 203 } 204 return oleDeliverRequestBo; 205 } 206 207 208 209 /** 210 * This is to check whether the login patron is the proxy patron for the real patron 211 * @param oleDeliverRequestBo 212 * @return validProxy 213 */ 214 public boolean isValidProxyPatron(OleDeliverRequestBo oleDeliverRequestBo) { 215 LOG.debug("Inside isValidProxyPatron"); 216 boolean validProxy = true; 217 Map<String, String> proxyMap = new HashMap<String, String>(); 218 proxyMap.put(OLEConstants.OleDeliverRequest.PATRON_ID, oleDeliverRequestBo.getBorrowerId()); 219 proxyMap.put(OLEConstants.OleDeliverRequest.PROXY_PATRON_ID, oleDeliverRequestBo.getProxyBorrowerId()); 220 if (oleDeliverRequestBo.getProxyBorrowerId() != null && !oleDeliverRequestBo.getProxyBorrowerId().isEmpty()) { 221 List<OleProxyPatronDocument> proxyPatronDocuments = (List<OleProxyPatronDocument>)businessObjectService.findMatching(OleProxyPatronDocument.class, proxyMap); 222 if (proxyPatronDocuments.size() == 0) { 223 validProxy = false; 224 } 225 } 226 return validProxy; 227 } 228 229 230 231 /** 232 * This is to check whether the request is already raised by the patron for this item 233 * @param oleDeliverRequestBo 234 * @return alreadyExist 235 */ 236 public boolean isRequestAlreadyRaisedByPatron(OleDeliverRequestBo oleDeliverRequestBo) { 237 LOG.debug("Inside isRequestAlreadyRaised"); 238 boolean alreadyExist = false; 239 Map<String, String> requestMap = new HashMap<String, String>(); 240 requestMap.put(OLEConstants.OleDeliverRequest.BORROWER_ID, oleDeliverRequestBo.getBorrowerId()); 241 requestMap.put(OLEConstants.OleDeliverRequest.ITEM_ID, oleDeliverRequestBo.getItemId()); 242 List<OleDeliverRequestBo> deliverRequestBos = (List<OleDeliverRequestBo>)businessObjectService.findMatching(OleDeliverRequestBo.class, requestMap); 243 if (deliverRequestBos != null && deliverRequestBos.size() > 0) { 244 alreadyExist = true; 245 } 246 return alreadyExist; 247 } 248 249 250 251 /** 252 * This is to check whether the requested item is currently in loan to the requesting patron 253 * @param oleDeliverRequestBo 254 * @return alreadyLoaned 255 */ 256 public boolean isAlreadyLoaned(OleDeliverRequestBo oleDeliverRequestBo) { 257 LOG.debug("Inside isAlreadyLoaned"); 258 boolean alreadyLoaned = false; 259 Map<String, String> loanMap = new HashMap<String, String>(); 260 loanMap.put(OLEConstants.OleDeliverRequest.LOAN_PATRON_ID, oleDeliverRequestBo.getBorrowerId()); 261 loanMap.put(OLEConstants.OleDeliverRequest.ITEM_ID, oleDeliverRequestBo.getItemId()); 262 List<OleLoanDocument> loanDocuments = (List<OleLoanDocument>)businessObjectService.findMatching(OleLoanDocument.class, loanMap); 263 if (loanDocuments != null && loanDocuments.size() > 0) { 264 alreadyLoaned = true; 265 } 266 return alreadyLoaned; 267 } 268 269 270 271 /** 272 * This is to check whether the item is available in the desk or not 273 * @param oleDeliverRequestBo 274 * @return itemAvailable 275 */ 276 public boolean isItemAvailable(OleDeliverRequestBo oleDeliverRequestBo) { 277 LOG.debug("Inside isItemAvailable"); 278 boolean itemAvailable = false; 279 Map<String, String> loanItemMap = new HashMap<String, String>(); 280 loanItemMap.put(OLEConstants.OleDeliverRequest.ITEM_ID, oleDeliverRequestBo.getItemId()); 281 List<OleLoanDocument> loanItemDocuments = (List<OleLoanDocument>)businessObjectService.findMatching(OleLoanDocument.class, loanItemMap); 282 if (loanItemDocuments.size() == 0) { 283 itemAvailable = true; 284 } 285 286 return itemAvailable; 287 } 288 289 290 291 /** 292 * This is to check whether the item is eligible to loan 293 * @param oleDeliverRequestBo 294 * @return itemEligible 295 */ 296 public boolean isItemEligible(OleDeliverRequestBo oleDeliverRequestBo) { 297 LOG.debug("Inside isItemEligible"); 298 boolean itemEligible = true; 299 Map<String, String> statusMap = new HashMap<String, String>(); 300 statusMap.put("lost/billed for replacement", "lost/billed for replacement"); 301 statusMap.put("missing/final overdue notice sent", "missing/final overdue notice sent"); 302 statusMap.put("withdrawn or claims returned", "withdrawn or claims returned"); 303 304 if (statusMap.containsKey(oleDeliverRequestBo.getItemType())) { 305 itemEligible = false; 306 } 307 return itemEligible; 308 } 309 310 /** 311 * This is to check whether the patron record is alive or expired 312 * @param oleDeliverRequestBo 313 * @return expired 314 */ 315 public boolean isPatronRecordExpired(OleDeliverRequestBo oleDeliverRequestBo) { 316 LOG.debug("Inside isPatronExpired"); 317 boolean expired = true; 318 Map<String, String> patronMap = new HashMap<String, String>(); 319 patronMap.put(OLEConstants.OleDeliverRequest.PATRON_ID, oleDeliverRequestBo.getBorrowerId()); 320 List<OlePatronDocument> olePatronDocuments = (List<OlePatronDocument>)businessObjectService.findMatching(OlePatronDocument.class, patronMap); 321 if (olePatronDocuments != null && olePatronDocuments.size() > 0) { 322 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OleDeliverRequest.DATE_FORMAT); 323 if ((fmt.format(olePatronDocuments.get(0).getExpirationDate())).compareTo(fmt.format(new Date(System.currentTimeMillis()))) > 0) { 324 expired = false; 325 } else { 326 expired = true; 327 } 328 } 329 return expired; 330 } 331 332 333 334 /** 335 * This is for retrieving the request raised by the patron 336 * @param olePatronId 337 * @return deliverRequestBos 338 */ 339 public List<OleDeliverRequestBo> getRequestedItems(String olePatronId) { 340 LOG.debug("Inside getRequestedItems"); 341 Map<String, String> requestMap = new HashMap<String, String>(); 342 requestMap.put(OLEConstants.OleDeliverRequest.BORROWER_ID, olePatronId); 343 List<OleDeliverRequestBo> deliverRequestBos = (List<OleDeliverRequestBo>)businessObjectService.findMatching(OleDeliverRequestBo.class, requestMap); 344 for(int i=0;i<deliverRequestBos.size();i++){ 345 deliverRequestBos.get(i).setOleItemSearch( getItemDetailsForPatron(deliverRequestBos.get(i).getItemId())); 346 } 347 return deliverRequestBos; 348 349 } 350 351 352 353 /** 354 * This is to check the duplicate in the queue Position while re -ordering 355 * @param itemList 356 * @return exist 357 */ 358 public String validateQueuePosition(List<OleDeliverRequestBo> itemList) { 359 LOG.debug("Inside validateQueuePosition"); 360 String message =OLEConstants.OleDeliverRequest.REORDER_SUCCESS; 361 List<Integer> queuePositionList = new ArrayList<Integer>(); 362 if(itemList.get(0).getBorrowerQueuePosition()<1){ 363 return OLEConstants.OleDeliverRequest.POSITIVE_QUEUE_POSITION; 364 } 365 queuePositionList.add(itemList.get(0).getBorrowerQueuePosition()); 366 367 for(int i=1;i<itemList.size();i++){ 368 for(int j=0;j<queuePositionList.size();j++){ 369 if(itemList.get(i).getBorrowerQueuePosition()!=null){ 370 if((itemList.get(i).getBorrowerQueuePosition()>=1) && (itemList.get(i).getBorrowerQueuePosition() == queuePositionList.get(j))){ 371 return OLEConstants.OleDeliverRequest.QUEUE_DUPLICATE; 372 } 373 else if((itemList.get(i).getBorrowerQueuePosition()<=0)){ 374 return OLEConstants.OleDeliverRequest.POSITIVE_QUEUE_POSITION; 375 } 376 } 377 } 378 queuePositionList.add(itemList.get(i).getBorrowerQueuePosition()); 379 } 380 return message; 381 } 382 383 // 384 385 /** 386 * This is to check whether any request raised for the item 387 * @param oleDeliverRequestBo 388 * @return exist 389 */ 390 public boolean isRequestRaised(OleDeliverRequestBo oleDeliverRequestBo) { 391 LOG.debug("Inside isRequestRaised"); 392 boolean exist = false; 393 Map<String, String> requestMap = new HashMap<String, String>(); 394 requestMap.put(OLEConstants.OleDeliverRequest.ITEM_ID, oleDeliverRequestBo.getItemId()); 395 List<OleDeliverRequestBo> deliverRequestBos = (List<OleDeliverRequestBo>)businessObjectService.findMatching(OleDeliverRequestBo.class, requestMap); 396 if (deliverRequestBos.size() > 0) { 397 exist = true; 398 } 399 return exist; 400 } 401 402 403 404 /** 405 * This method is used to cancel the request document 406 * @param oleDeliverRequestBo 407 */ 408 public void cancelDocument(OleDeliverRequestBo oleDeliverRequestBo) { 409 LOG.debug("Inside cancelDocument"); 410 Map<String, String> itemMap = new HashMap<String, String>(); 411 itemMap.put(OLEConstants.OleDeliverRequest.ITEM_ID, oleDeliverRequestBo.getItemId()); 412 Map<String, String> requestMap = new HashMap<String, String>(); 413 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_ID, oleDeliverRequestBo.getRequestId()); 414 businessObjectService.deleteMatching(OleDeliverRequestBo.class, requestMap); 415 List<OleDeliverRequestBo> oleDeliverRequestDocumentsList = (List<OleDeliverRequestBo>)businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class, itemMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true); 416 businessObjectService.delete(oleDeliverRequestDocumentsList); 417 int queuePosition = 1; 418 for (int i = 0; i < oleDeliverRequestDocumentsList.size(); i++) { 419 oleDeliverRequestDocumentsList.get(i).setBorrowerQueuePosition(queuePosition); 420 queuePosition = queuePosition + 1; 421 } 422 businessObjectService.save(oleDeliverRequestDocumentsList); 423 } 424 425 426 427 /** 428 * This method is to set the item values from docstore 429 * @param oleDeliverRequestBo 430 * @return oleDeliverRequestBo 431 */ 432 public OleDeliverRequestBo processItem(OleDeliverRequestBo oleDeliverRequestBo) { 433 LOG.debug("Inside processItem"); 434 if(oleDeliverRequestBo.getItemType()==null){ 435 Map<String, String> itemMap = new HashMap<String, String>(); 436 itemMap.put(OLEConstants.OleDeliverRequest.ITEM_BARCODE, oleDeliverRequestBo.getItemId()); 437 List<OleItemSearch> itemSearchList = docStoreService.getOleItemSearchList(itemMap); 438 if (itemSearchList != null && itemSearchList.size() > 0) { 439 oleDeliverRequestBo.setTitle(itemSearchList.get(0).getTitle()); 440 oleDeliverRequestBo.setAuthor(itemSearchList.get(0).getAuthor()); 441 oleDeliverRequestBo.setCallNumber(itemSearchList.get(0).getCallNumber()); 442 oleDeliverRequestBo.setItemType(itemSearchList.get(0).getItemType()); 443 } 444 445 446 try { 447 Map docStoreDetails = loanProcessor.getItemDetails(oleDeliverRequestBo.getItemId()); 448 String itemXml = loanProcessor.getItemXML((String) docStoreDetails.get("itemUuid")); 449 Item oleItem = loanProcessor.getItemPojo(itemXml); 450 451 oleDeliverRequestBo.setCopyNumber(oleItem.getCopyNumber()); 452 oleDeliverRequestBo.setItemStatus(oleItem.getItemStatus()); 453 oleDeliverRequestBo.setShelvingLocation(getShelvingLocation(oleItem.getLocation())); 454 if(oleDeliverRequestBo.getRequestTypeId().equals(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID_8)){ 455 oleDeliverRequestBo.setInTransitCheckInNote(oleItem.getCheckinNote()); 456 } 457 } catch (Exception e) { 458 LOG.error("Item Barcode not available in doc store"); //To change body of catch statement use File | Settings | File Templates. 459 } 460 } 461 oleDeliverRequestBo=processItemType(oleDeliverRequestBo); 462 return oleDeliverRequestBo; 463 } 464 465 /** 466 * This method is to set the item type name based on the item type code 467 * @param oleDeliverRequestBo 468 * @return 469 */ 470 public OleDeliverRequestBo processItemType(OleDeliverRequestBo oleDeliverRequestBo){ 471 LOG.debug("Inside process Item Type"); 472 Map<String, String> itemMap = new HashMap<String, String>(); 473 itemMap = new HashMap<String, String>(); 474 itemMap.put(OLEConstants.OleDeliverRequest.ITEM_TYPE_CODE, oleDeliverRequestBo.getItemType()); 475 List<OleInstanceItemType> oleInstanceItemTypeList =(List<OleInstanceItemType>)businessObjectService.findMatching(OleInstanceItemType.class, itemMap); 476 if(oleInstanceItemTypeList!=null && oleInstanceItemTypeList.size()>0){ 477 OleInstanceItemType oleInstanceItemType = oleInstanceItemTypeList.get(0); 478 oleDeliverRequestBo.setItemTypeName(oleInstanceItemType.getInstanceItemTypeName()); 479 } 480 481 return oleDeliverRequestBo; 482 } 483 /** 484 * This method is to retrieve the shelving location from item 485 * @param oleLocation 486 * @return locationLevelName 487 */ 488 private String getShelvingLocation(Location oleLocation) { 489 LOG.debug("Inside getShelvingLocation"); 490 LocationLevel locationLevel = 491 oleLocation.getLocationLevel(); 492 while (locationLevel.getLocationLevel() != null && !locationLevel.getLevel().equalsIgnoreCase(OLEConstants.OleDeliverRequest.SHELVING)) { 493 locationLevel = locationLevel.getLocationLevel(); 494 } 495 String locationLevelName= locationLevel.getName(); 496 return locationLevelName; 497 } 498 499 500 /** 501 * This method is to check whether the selected request can be raised for the item 502 * @param oleDeliverRequestBo 503 * @return canRaiseRequest 504 */ 505 public boolean canRaiseRequest(OleDeliverRequestBo oleDeliverRequestBo){ 506 LOG.debug("Inside canRaiseRequest"); 507 boolean canRaiseRequest = true; 508 if(oleDeliverRequestBo.getRequestTypeId().equals(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID_1) || oleDeliverRequestBo.getRequestTypeId().equals(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID_2 ) || oleDeliverRequestBo.getRequestTypeId().equals(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID_3) || oleDeliverRequestBo.getRequestTypeId().equals(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID_4 )){ 509 if(isItemAvailable(oleDeliverRequestBo)) { 510 canRaiseRequest = false; 511 } 512 } else if(oleDeliverRequestBo.getRequestTypeId().equals(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID_5) || oleDeliverRequestBo.getRequestTypeId().equals(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID_6)) { 513 if(!isItemAvailable(oleDeliverRequestBo)){ 514 canRaiseRequest=false; 515 } 516 } 517 return canRaiseRequest; 518 } 519 520 521 /** 522 * This method is to update the request id in the loan document 523 * @param oleDeliverRequestBo 524 */ 525 public void updateLoanDocument(OleDeliverRequestBo oleDeliverRequestBo){ 526 LOG.debug("Inside updateLoanDocument"); 527 Map<String,String> loanMap = new HashMap<String,String>(); 528 loanMap.put("itemId",oleDeliverRequestBo.getItemId()); 529 List<OleLoanDocument> oleLoanDocumentList = (List<OleLoanDocument>)businessObjectService.findMatching(OleLoanDocument.class, loanMap); 530 if(oleLoanDocumentList!=null && oleLoanDocumentList.size()>0 && oleLoanDocumentList.get(0)!=null && oleLoanDocumentList.get(0).getOleRequestId()==null){ 531 oleLoanDocumentList.get(0).setOleRequestId(oleDeliverRequestBo.getRequestId()); 532 businessObjectService.save(oleLoanDocumentList.get(0)); 533 534 } 535 } 536 537 /** 538 * This method is to delete the request 539 * @param requestId 540 * @param itemId 541 */ 542 public void deleteRequest(String requestId,String itemId,String operatorId,String loanTransactionNumber){ 543 LOG.debug("Inside deleteRequest"); 544 Map<String, String> requestMap = new HashMap<String, String>(); 545 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_ID, requestId); 546 createRequestHistoryRecord(requestId,operatorId,loanTransactionNumber); 547 Map<String, String> itemMap = new HashMap<String, String>(); 548 itemMap.put(OLEConstants.OleDeliverRequest.ITEM_ID,itemId); 549 List<OleDeliverRequestBo> oleDeliverRequestDocumentsList = (List<OleDeliverRequestBo>)businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class, itemMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true); 550 businessObjectService.delete(oleDeliverRequestDocumentsList); 551 int queuePosition = 1; 552 for (int i = 0; i < oleDeliverRequestDocumentsList.size(); i++) { 553 oleDeliverRequestDocumentsList.get(i).setBorrowerQueuePosition(queuePosition); 554 queuePosition = queuePosition + 1; 555 } 556 businessObjectService.save(oleDeliverRequestDocumentsList); 557 558 } 559 560 /** 561 * This for retrieving the item Details from docstore 562 * @param itemBarCode 563 * @return oleItemSearch 564 */ 565 public OleItemSearch getItemDetails(String itemBarCode){ 566 LOG.debug("Inside getItemDetails"); 567 OleItemSearch oleItemSearch = getItemDetailsForPatron(itemBarCode); 568 try{ 569 Map docStoreDetails= loanProcessor.getItemDetails(itemBarCode); 570 String itemXml = loanProcessor.getItemXML((String) docStoreDetails.get("itemUuid")); 571 Item oleItem = loanProcessor.getItemPojo(itemXml); 572 oleItemSearch.setCopyNumber(oleItem.getCopyNumber()); 573 oleItemSearch.setItemStatus(oleItem.getItemStatus()); 574 oleItemSearch.setShelvingLocation(getShelvingLocation(oleItem.getLocation())); 575 oleItemSearch.setVolumeNumber(oleItem.getVolumeNumber()); 576 } catch (Exception e) { 577 LOG.error("Not able to retrieve information from the docstore for the Item Barcode : "+itemBarCode); //To change body of catch statement use File | Settings | File Templates. 578 } 579 return oleItemSearch; 580 } 581 582 /** 583 * This method is for retrieving the item details for displaying in the patron screen 584 * @param itemBarCode 585 * @return OleItemSearch 586 */ 587 public OleItemSearch getItemDetailsForPatron(String itemBarCode){ 588 LOG.debug("Inside getItemDetailsForPatron"); 589 OleItemSearch oleItemSearch; 590 try{ 591 592 Map<String, String> itemMap = new HashMap<String, String>(); 593 itemMap.put(OLEConstants.OleDeliverRequest.ITEM_BARCODE, itemBarCode); 594 List<OleItemSearch> itemSearchList = docStoreService.getOleItemSearchList(itemMap); 595 if(itemSearchList.size()>0){ 596 return oleItemSearch= itemSearchList.get(0); 597 } 598 } catch(NullPointerException e){ 599 LOG.error("No item details available for the Item Barcode : "+itemBarCode ); 600 } 601 602 return new OleItemSearch(); 603 604 } 605 606 /** 607 * This method is to re-order the queuePosition based on the priority while creating the request 608 * @param oleDeliverRequestBo 609 * @return OleDeliverRequestBo 610 */ 611 public OleDeliverRequestBo reOrderQueuePosition( OleDeliverRequestBo oleDeliverRequestBo){ 612 LOG.debug("Inside reOrderQueuePosition"); 613 List<OleDeliverRequestBo> existingRequest = new ArrayList<OleDeliverRequestBo>(); 614 String queue = getLoanProcessor().getParameter("REQUEST QUEUE"); 615 List<String> orderQueue= new ArrayList<String>(); 616 String[] queueArray = queue.split(";"); 617 for(int i=0;i<queueArray.length;i++){ 618 orderQueue.add(queueArray[i]); 619 } 620 List<OleDeliverRequestBo> finalList = new ArrayList<OleDeliverRequestBo>(); 621 Map<String,String> recallRequestMap = new HashMap<String,String>(); 622 recallRequestMap.put("itemId",oleDeliverRequestBo.getItemId()); 623 recallRequestMap.put("requestTypeId","1"); 624 Map<String,String> recallHoldRequestMap = new HashMap<String,String>(); 625 recallHoldRequestMap.put("itemId",oleDeliverRequestBo.getItemId()); 626 recallHoldRequestMap.put("requestTypeId","2"); 627 Map<String,String> holdRequestMap = new HashMap<String,String>(); 628 holdRequestMap.put("itemId",oleDeliverRequestBo.getItemId()); 629 holdRequestMap.put("requestTypeId","3"); 630 Map<String,String> holdHoldRequestMap = new HashMap<String,String>(); 631 holdHoldRequestMap.put("itemId",oleDeliverRequestBo.getItemId()); 632 holdHoldRequestMap.put("requestTypeId","4"); 633 Map<String,String> pageRequestMap = new HashMap<String,String>(); 634 pageRequestMap.put("itemId",oleDeliverRequestBo.getItemId()); 635 pageRequestMap.put("requestTypeId","5"); 636 Map<String,String> pageHoldRequestMap = new HashMap<String,String>(); 637 pageHoldRequestMap.put("itemId",oleDeliverRequestBo.getItemId()); 638 pageHoldRequestMap.put("requestTypeId","6"); 639 Map<String,String> copyRequestMap = new HashMap<String,String>(); 640 copyRequestMap.put("itemId",oleDeliverRequestBo.getItemId()); 641 copyRequestMap.put("requestTypeId","7"); 642 Map<String,String> inTransitRequestMap = new HashMap<String,String>(); 643 inTransitRequestMap.put("itemId",oleDeliverRequestBo.getItemId()); 644 inTransitRequestMap.put("requestTypeId","8"); 645 List<OleDeliverRequestBo> recallList =(List<OleDeliverRequestBo>)businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class,recallRequestMap,"borrowerQueuePosition",true); 646 List<OleDeliverRequestBo> recallHoldList = (List<OleDeliverRequestBo>) businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class, recallHoldRequestMap, "borrowerQueuePosition", true); 647 List<OleDeliverRequestBo> holdList =(List<OleDeliverRequestBo>)businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class,holdRequestMap,"borrowerQueuePosition",true); 648 List<OleDeliverRequestBo> holdHoldList = (List<OleDeliverRequestBo>) businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class, holdHoldRequestMap, "borrowerQueuePosition", true); 649 List<OleDeliverRequestBo> pageList =(List<OleDeliverRequestBo>)businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class,pageRequestMap,"borrowerQueuePosition",true); 650 List<OleDeliverRequestBo> pageHoldList = (List<OleDeliverRequestBo>) businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class, pageHoldRequestMap, "borrowerQueuePosition", true); 651 List<OleDeliverRequestBo> copyList =(List<OleDeliverRequestBo>)businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class,copyRequestMap,"borrowerQueuePosition",true); 652 List<OleDeliverRequestBo> inTransitList =(List<OleDeliverRequestBo>)businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class,inTransitRequestMap,"borrowerQueuePosition",true); 653 if(oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains("Recall/Delivery")){ 654 recallList.add(oleDeliverRequestBo); 655 } else if(oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains("Hold/Delivery")){ 656 holdList.add(oleDeliverRequestBo); 657 } else if(oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains("Page/Delivery")){ 658 pageList.add(oleDeliverRequestBo); 659 } else if(oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains("Copy")){ 660 copyList.add(oleDeliverRequestBo); 661 } else if(oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains("In Transit")){ 662 inTransitList.add(oleDeliverRequestBo); 663 }else if(oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains("Recall/Hold")){ 664 recallHoldList.add(oleDeliverRequestBo); 665 } else if(oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains("Hold/Hold")){ 666 holdHoldList.add(oleDeliverRequestBo); 667 } else if(oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains("Page/Hold")){ 668 pageHoldList.add(oleDeliverRequestBo); 669 } 670 OleDeliverRequestBo oleDeliverRequestBo1; 671 for(int i=0;i<orderQueue.size();i++){ 672 if(orderQueue.get(i).equals("Recall") && recallList.size()>0 ){ 673 for(int x=0;x<recallList.size();x++){ 674 oleDeliverRequestBo1 = (OleDeliverRequestBo)ObjectUtils.deepCopy(recallList.get(x)); 675 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition+1); 676 this.queuePosition=this.queuePosition+1; 677 finalList.add(oleDeliverRequestBo1); 678 679 } 680 } 681 if(orderQueue.get(i).equals("Hold") && holdList.size()>0){ 682 for(int x=0;x<holdList.size();x++){ 683 oleDeliverRequestBo1 = (OleDeliverRequestBo)ObjectUtils.deepCopy(holdList.get(x)); 684 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition+1); 685 this.queuePosition=this.queuePosition+1; 686 finalList.add(oleDeliverRequestBo1); 687 688 } 689 } 690 if(orderQueue.get(i).equals("Page") && pageList.size()>0){ 691 for(int x=0;x<pageList.size();x++){ 692 oleDeliverRequestBo1 = (OleDeliverRequestBo)ObjectUtils.deepCopy(pageList.get(x)); 693 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition+1); 694 this.queuePosition=this.queuePosition+1; 695 finalList.add(oleDeliverRequestBo1); 696 } 697 } 698 if(orderQueue.get(i).equals("Recall") && recallHoldList.size()>0 ){ 699 for(int x=0;x<recallHoldList.size();x++){ 700 oleDeliverRequestBo1 = (OleDeliverRequestBo)ObjectUtils.deepCopy(recallHoldList.get(x)); 701 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition+1); 702 this.queuePosition=this.queuePosition+1; 703 finalList.add(oleDeliverRequestBo1); 704 705 } 706 } 707 if(orderQueue.get(i).equals("Hold") && holdHoldList.size()>0){ 708 for(int x=0;x<holdHoldList.size();x++){ 709 oleDeliverRequestBo1 = (OleDeliverRequestBo)ObjectUtils.deepCopy(holdHoldList.get(x)); 710 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition+1); 711 this.queuePosition=this.queuePosition+1; 712 finalList.add(oleDeliverRequestBo1); 713 714 } 715 } 716 if(orderQueue.get(i).equals("Page") && pageHoldList.size()>0){ 717 for(int x=0;x<pageHoldList.size();x++){ 718 oleDeliverRequestBo1 = (OleDeliverRequestBo)ObjectUtils.deepCopy(pageHoldList.get(x)); 719 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition+1); 720 this.queuePosition=this.queuePosition+1; 721 finalList.add(oleDeliverRequestBo1); System.out.println("in page" + this.queuePosition); 722 } 723 } 724 if(orderQueue.get(i).equals("Copy") && copyList.size()>0){ 725 for(int x=0;x<copyList.size();x++){ 726 oleDeliverRequestBo1 = (OleDeliverRequestBo)ObjectUtils.deepCopy(copyList.get(x)); 727 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition+1); 728 this.queuePosition=this.queuePosition+1; 729 finalList.add(oleDeliverRequestBo1); 730 731 } 732 } if(orderQueue.get(i).equals("In Transit") && inTransitList.size()>0){ 733 for(int x=0;x<inTransitList.size();x++){ 734 oleDeliverRequestBo1 = (OleDeliverRequestBo)ObjectUtils.deepCopy(inTransitList.get(x)); 735 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition+1); 736 this.queuePosition=this.queuePosition+1; 737 finalList.add(oleDeliverRequestBo1); 738 739 } 740 } 741 } 742 for(int i=0;i<finalList.size();i++){ 743 if(finalList.get(i).getRequestId()==null){ 744 oleDeliverRequestBo.setBorrowerQueuePosition(finalList.get(i).getBorrowerQueuePosition()); 745 finalList.remove(finalList.get(i)); 746 } 747 } 748 businessObjectService.save(finalList); 749 return oleDeliverRequestBo; 750 } 751 752 /** 753 * Thsi method is to check whether the item is available in doc store or not 754 * @param oleDeliverRequestBo 755 * @return boolean 756 */ 757 public boolean isItemAvailbleInDocstore(OleDeliverRequestBo oleDeliverRequestBo) { 758 LOG.debug("Inside isItemAvailbleInDocstore"); 759 boolean available=false; 760 Map<String, String> itemMap = new HashMap<String, String>(); 761 itemMap.put(OLEConstants.OleDeliverRequest.ITEM_BARCODE, oleDeliverRequestBo.getItemId()); 762 List<OleItemSearch> itemSearchList = docStoreService.getOleItemSearchList(itemMap); 763 if (itemSearchList != null && itemSearchList.size() > 0) { 764 oleDeliverRequestBo.setTitle(itemSearchList.get(0).getTitle()); 765 oleDeliverRequestBo.setAuthor(itemSearchList.get(0).getAuthor()); 766 oleDeliverRequestBo.setCallNumber(itemSearchList.get(0).getCallNumber()); 767 oleDeliverRequestBo.setItemType(itemSearchList.get(0).getItemType()); 768 } 769 try { 770 Map docStoreDetails = loanProcessor.getItemDetails(oleDeliverRequestBo.getItemId()); 771 String itemXml = loanProcessor.getItemXML((String) docStoreDetails.get("itemUuid")); 772 Item oleItem = loanProcessor.getItemPojo(itemXml); 773 774 oleDeliverRequestBo.setCopyNumber(oleItem.getCopyNumber()); 775 oleDeliverRequestBo.setItemStatus(oleItem.getItemStatus()); 776 oleDeliverRequestBo.setShelvingLocation(getShelvingLocation(oleItem.getLocation())); 777 available=true; 778 } catch (Exception e) { 779 LOG.error("Item Barcode not available in doc store"); //To change body of catch statement use File | Settings | File Templates. 780 } 781 782 783 return available; 784 } 785 786 public OleDeliverRequestBo populateItemDetailsToRequest(OleDeliverRequestBo oleDeliverRequestBo,OleItemSearch oleItemSearch){ 787 LOG.debug("Inside populateItemDetailsToRequest"); 788 if(oleDeliverRequestBo!=null && oleItemSearch!=null){ 789 oleDeliverRequestBo.setAuthor(oleItemSearch.getAuthor()); 790 oleDeliverRequestBo.setTitle(oleItemSearch.getTitle()); 791 oleDeliverRequestBo.setCallNumber(oleItemSearch.getCallNumber()); 792 oleDeliverRequestBo.setCopyNumber(oleItemSearch.getCopyNumber()); 793 oleDeliverRequestBo.setItemType(oleItemSearch.getItemType()); 794 oleDeliverRequestBo.setItemStatus(oleItemSearch.getItemStatus()); 795 oleItemSearch.setShelvingLocation(oleDeliverRequestBo.getShelvingLocation()); 796 797 } 798 return oleDeliverRequestBo; 799 } 800 801 802 public void generateRecallNotice(){ 803 List<OleDeliverRequestBo> finalDeliverRequestBoList = new ArrayList<OleDeliverRequestBo>(); 804 Map<String,String> recallNoticeMap = new HashMap<String,String>(); 805 recallNoticeMap.put("requestTypeId","1"); 806 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>)businessObjectService.findMatching(OleDeliverRequestBo.class,recallNoticeMap); 807 Map<String,String> recallHoldNoticeMap = new HashMap<String, String>(); 808 recallHoldNoticeMap.put("requestTypeId","2"); 809 List<OleDeliverRequestBo> oleDeliverRequestBoList1 = (List<OleDeliverRequestBo>)businessObjectService.findMatching(OleDeliverRequestBo.class,recallHoldNoticeMap); 810 oleDeliverRequestBoList.addAll(oleDeliverRequestBoList1); 811 OleDeliverRequestBo oleDeliverRequestBo ; 812 813 for(int i=0;i<oleDeliverRequestBoList.size();i++){ 814 if(oleDeliverRequestBoList.get(i).getRecallNoticeSentDate()==null){ 815 // To do send Notice 816 OleNoticeBo oleNoticeBo = new OleNoticeBo(); 817 oleNoticeBo.setAuthor(oleDeliverRequestBoList.get(i).getAuthor()); 818 oleNoticeBo.setCirculationDeskAddress(""); 819 oleNoticeBo.setCirculationDeskName(""); 820 oleNoticeBo.setCirculationDeskEmailAddress(""); 821 oleNoticeBo.setCirculationDeskPhoneNumber(""); 822 oleNoticeBo.setItemCallNumber(oleDeliverRequestBoList.get(i).getCallNumber()); 823 oleNoticeBo.setItemShelvingLocation(oleDeliverRequestBoList.get(i).getShelvingLocation()); 824 oleNoticeBo.setItemId(oleDeliverRequestBoList.get(i).getItemId()); 825 oleNoticeBo.setTitle(oleDeliverRequestBoList.get(i).getTitle()); 826 oleNoticeBo.setOleItem(getItem(oleDeliverRequestBoList.get(i).getItemId())); 827 oleNoticeBo.setOlePatron(oleDeliverRequestBoList.get(i).getOlePatron()); 828 oleNoticeBo.setVolumeNumber(getItem(oleDeliverRequestBoList.get(i).getItemId()).getVolumeNumber()); 829 oleNoticeBo.setNewDueDate(new Date()); 830 oleNoticeBo.setOriginalDueDate(new Date()); 831 oleNoticeBo.setNoticeName("Recall Notice"); 832 oleNoticeBo.setNoticeSpecificContent("The following item is requested by another user.Please return by or before the NEW due date shown below in order to avoid any penalties"); 833 oleNoticeBo = setPatronDetailsForNotice(oleNoticeBo,oleDeliverRequestBoList.get(i).getOlePatron()); 834 OleDeliverNoticeService oleDeliverNoticeService = new OleDeliverNoticeService(); 835 oleDeliverNoticeService.createPdf(oleNoticeBo); 836 oleDeliverRequestBo =(OleDeliverRequestBo)ObjectUtils.deepCopy(oleDeliverRequestBoList.get(i)); 837 oleDeliverRequestBo.setRecallNoticeSentDate(new java.sql.Date(System.currentTimeMillis())); 838 finalDeliverRequestBoList.add(oleDeliverRequestBo); 839 } 840 } 841 businessObjectService.save(finalDeliverRequestBoList); 842 843 } 844 845 846 public void generateOnHoldNotice(){ 847 List<OleDeliverRequestBo> finalDeliverRequestBoList = new ArrayList<OleDeliverRequestBo>(); 848 Map<String,String> onHoldNoticeMap = new HashMap<String,String>(); 849 onHoldNoticeMap.put("requestTypeId","3"); 850 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>)businessObjectService.findMatching(OleDeliverRequestBo.class,onHoldNoticeMap); 851 Map<String,String> onHoldHoldNoticeMap = new HashMap<String, String>(); 852 onHoldHoldNoticeMap.put("requestTypeId","4"); 853 List<OleDeliverRequestBo> oleDeliverRequestBoList1 = (List<OleDeliverRequestBo>)businessObjectService.findMatching(OleDeliverRequestBo.class,onHoldHoldNoticeMap); 854 oleDeliverRequestBoList.addAll(oleDeliverRequestBoList1); 855 OleDeliverRequestBo oleDeliverRequestBo ; 856 857 for(int i=0;i<oleDeliverRequestBoList.size();i++){ 858 if(oleDeliverRequestBoList.get(i).getOnHoldNoticeSentDate()==null){ 859 OleNoticeBo oleNoticeBo = new OleNoticeBo(); 860 oleNoticeBo.setAuthor(oleDeliverRequestBoList.get(i).getAuthor()); 861 oleNoticeBo.setCirculationDeskAddress(""); 862 oleNoticeBo.setCirculationDeskName(""); 863 oleNoticeBo.setCirculationDeskEmailAddress(""); 864 oleNoticeBo.setCirculationDeskPhoneNumber(""); 865 oleNoticeBo.setItemCallNumber(oleDeliverRequestBoList.get(i).getCallNumber()); 866 oleNoticeBo.setItemShelvingLocation(oleDeliverRequestBoList.get(i).getShelvingLocation()); 867 oleNoticeBo.setItemId(oleDeliverRequestBoList.get(i).getItemId()); 868 oleNoticeBo.setTitle(oleDeliverRequestBoList.get(i).getTitle()); 869 oleNoticeBo.setOleItem(getItem(oleDeliverRequestBoList.get(i).getItemId())); 870 oleNoticeBo.setOlePatron(oleDeliverRequestBoList.get(i).getOlePatron()); 871 oleNoticeBo.setVolumeNumber(getItem(oleDeliverRequestBoList.get(i).getItemId()).getVolumeNumber()); 872 oleNoticeBo.setNewDueDate(new Date()); 873 oleNoticeBo.setOriginalDueDate(new Date()); 874 oleNoticeBo.setNoticeName("On Hold Notice"); 875 oleNoticeBo.setNoticeSpecificContent("The following requested item is ready for pick up and will be held until the expiration date at the location shown below"); 876 oleNoticeBo = setPatronDetailsForNotice(oleNoticeBo,oleDeliverRequestBoList.get(i).getOlePatron()); 877 OleDeliverNoticeService oleDeliverNoticeService = new OleDeliverNoticeService(); 878 oleDeliverNoticeService.createPdf(oleNoticeBo); 879 // To do send Notice 880 oleDeliverRequestBo =(OleDeliverRequestBo)ObjectUtils.deepCopy(oleDeliverRequestBoList.get(i)); 881 oleDeliverRequestBo.setOnHoldNoticeSentDate(new java.sql.Date(System.currentTimeMillis())); 882 finalDeliverRequestBoList.add(oleDeliverRequestBo); 883 } 884 } 885 businessObjectService.save(finalDeliverRequestBoList); 886 887 888 } 889 890 891 public void generateRequestExpirationNotice(){ 892 List<OleDeliverRequestBo> oleDeliverRequestBoList = new ArrayList<OleDeliverRequestBo>(); 893 oleDeliverRequestBoList =(List<OleDeliverRequestBo>)businessObjectService.findAll(OleDeliverRequestBo.class); 894 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OleDeliverRequest.DATE_FORMAT); 895 if(oleDeliverRequestBoList.size()>0){ 896 for(int i=0;i<oleDeliverRequestBoList.size();i++){ 897 if (oleDeliverRequestBoList.get(0).getOlePatron().isCourtesyNotice() && (fmt.format(oleDeliverRequestBoList.get(0).getRequestExpiryDate())).compareTo(fmt.format(new Date(System.currentTimeMillis()))) < 0 ) { 898 OleNoticeBo oleNoticeBo = new OleNoticeBo(); 899 oleNoticeBo.setAuthor(oleDeliverRequestBoList.get(i).getAuthor()); 900 oleNoticeBo.setCirculationDeskAddress(""); 901 oleNoticeBo.setCirculationDeskName(""); 902 oleNoticeBo.setCirculationDeskEmailAddress(""); 903 oleNoticeBo.setCirculationDeskPhoneNumber(""); 904 oleNoticeBo.setItemCallNumber(oleDeliverRequestBoList.get(i).getCallNumber()); 905 oleNoticeBo.setItemShelvingLocation(oleDeliverRequestBoList.get(i).getShelvingLocation()); 906 oleNoticeBo.setItemId(oleDeliverRequestBoList.get(i).getItemId()); 907 oleNoticeBo.setTitle(oleDeliverRequestBoList.get(i).getTitle()); 908 oleNoticeBo.setOleItem(getItem(oleDeliverRequestBoList.get(i).getItemId())); 909 oleNoticeBo.setOlePatron(oleDeliverRequestBoList.get(i).getOlePatron()); 910 oleNoticeBo.setVolumeNumber(getItem(oleDeliverRequestBoList.get(i).getItemId()).getVolumeNumber()); 911 oleNoticeBo.setNewDueDate(new Date()); 912 oleNoticeBo.setOriginalDueDate(new Date()); 913 oleNoticeBo.setNoticeName("Expired Request Notice"); 914 oleNoticeBo.setNoticeSpecificContent("The library regrets that it was unable to fulfill your request for the following item(s).Please initiate an inter library loan request or contact the library shown above for other options"); 915 oleNoticeBo = setPatronDetailsForNotice(oleNoticeBo,oleDeliverRequestBoList.get(i).getOlePatron()); 916 OleDeliverNoticeService oleDeliverNoticeService = new OleDeliverNoticeService(); 917 oleDeliverNoticeService.createPdf(oleNoticeBo); 918 //do request expire notice 919 } 920 } 921 } 922 } 923 924 925 public void generateExpireHoldNotice(){ 926 List<OleDeliverRequestBo> oleDeliverRequestBoList = new ArrayList<OleDeliverRequestBo>(); 927 Map<String,String> requestMap = new HashMap<String,String>(); 928 requestMap.put("requestTypeId","2"); 929 oleDeliverRequestBoList = (List<OleDeliverRequestBo>)businessObjectService.findMatching(OleDeliverRequestBo.class,requestMap); 930 requestMap = new HashMap<String,String>(); 931 requestMap.put("requestTypeId","4"); 932 oleDeliverRequestBoList.addAll(businessObjectService.findMatching(OleDeliverRequestBo.class,requestMap)); 933 requestMap = new HashMap<String,String>(); 934 requestMap.put("requestTypeId","6"); 935 oleDeliverRequestBoList.addAll(businessObjectService.findMatching(OleDeliverRequestBo.class,requestMap)); 936 if(oleDeliverRequestBoList.size()>0){ 937 for(int i=0;i<oleDeliverRequestBoList.size();i++){ 938 Map docStoreDetails= null; 939 try { 940 docStoreDetails = loanProcessor.getItemDetails(oleDeliverRequestBoList.get(i).getItemId()); 941 String itemXml = loanProcessor.getItemXML((String) docStoreDetails.get("itemUuid")); 942 Item oleItem = loanProcessor.getItemPojo(itemXml); 943 if(oleItem.getItemStatus().equals("On-Hold")){ 944 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OleDeliverRequest.DATE_FORMAT); 945 if((fmt.format(oleItem.getItemStatusEffectiveDate()).compareTo(fmt.format(new Date(System.currentTimeMillis()))) > 0 )){ 946 //to do 947 OleNoticeBo oleNoticeBo = new OleNoticeBo(); 948 oleNoticeBo.setAuthor(oleDeliverRequestBoList.get(i).getAuthor()); 949 oleNoticeBo.setCirculationDeskAddress(""); 950 oleNoticeBo.setCirculationDeskName(""); 951 oleNoticeBo.setCirculationDeskEmailAddress(""); 952 oleNoticeBo.setCirculationDeskPhoneNumber(""); 953 oleNoticeBo.setItemCallNumber(oleDeliverRequestBoList.get(i).getCallNumber()); 954 oleNoticeBo.setItemShelvingLocation(oleDeliverRequestBoList.get(i).getShelvingLocation()); 955 oleNoticeBo.setItemId(oleDeliverRequestBoList.get(i).getItemId()); 956 oleNoticeBo.setTitle(oleDeliverRequestBoList.get(i).getTitle()); 957 oleNoticeBo.setOleItem(getItem(oleDeliverRequestBoList.get(i).getItemId())); 958 oleNoticeBo.setOlePatron(oleDeliverRequestBoList.get(i).getOlePatron()); 959 oleNoticeBo.setVolumeNumber(getItem(oleDeliverRequestBoList.get(i).getItemId()).getVolumeNumber()); 960 oleNoticeBo.setNewDueDate(new Date()); 961 oleNoticeBo.setOriginalDueDate(new Date()); 962 oleNoticeBo.setNoticeName("Expired Hold Notice"); 963 oleNoticeBo.setNoticeSpecificContent("The following item(s),previously on hold at your request, have been returned to the shelf or loaned to the another user.If you would still like to see this material,please make another request."); 964 oleNoticeBo = setPatronDetailsForNotice(oleNoticeBo,oleDeliverRequestBoList.get(i).getOlePatron()); 965 OleDeliverNoticeService oleDeliverNoticeService = new OleDeliverNoticeService(); 966 oleDeliverNoticeService.createPdf(oleNoticeBo); 967 //sending notices 968 }}} 969 970 971 catch (Exception e) { 972 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. 973 } 974 975 976 } 977 } 978 } 979 980 private java.sql.Date dateAdd(java.sql.Date in, int daysToAdd) { 981 if (in == null) { 982 return null; 983 } 984 GregorianCalendar cal = new GregorianCalendar(); 985 cal.setTime(in); 986 cal.add(Calendar.DAY_OF_MONTH, daysToAdd); 987 return new java.sql.Date(cal.getTime().getTime()); 988 } 989 990 public void deletingExpiredRequests(){ 991 LOG.debug("Inside deletingExpiredRequests"); 992 List<OleDeliverRequestBo> oleDeliverRequestBoList = new ArrayList<OleDeliverRequestBo>(); 993 List<OleDeliverRequestBo> newOleDeliverRequestBoList = new ArrayList<OleDeliverRequestBo>(); 994 oleDeliverRequestBoList = (List<OleDeliverRequestBo>)businessObjectService.findAll(OleDeliverRequestBo.class); 995 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OleDeliverRequest.DATE_FORMAT); 996 for(int i=0;i<oleDeliverRequestBoList.size();i++){ 997 if((fmt.format(oleDeliverRequestBoList.get(0).getRequestExpiryDate())).compareTo(fmt.format(new Date(System.currentTimeMillis()))) > 0 ){ 998 newOleDeliverRequestBoList.add(oleDeliverRequestBoList.get(i)); 999 } 1000 } 1001 businessObjectService.save(newOleDeliverRequestBoList); 1002 1003 } 1004 1005 private Item getItem(String itemBarCode){ 1006 LOG.debug("Inside getItem"); 1007 try{ 1008 Map docStoreDetails= loanProcessor.getItemDetails(itemBarCode); 1009 String itemXml = loanProcessor.getItemXML((String) docStoreDetails.get("itemUuid")); 1010 Item oleItem = loanProcessor.getItemPojo(itemXml); 1011 return oleItem; 1012 }catch(Exception e){ 1013 LOG.error("Item not available in doc store"); 1014 } 1015 1016 return null; 1017 } 1018 1019 1020 private OleNoticeBo setPatronDetailsForNotice(OleNoticeBo oleNoticeBo,OlePatronDocument olePatronDocument){ 1021 LOG.debug("Inside setPatronDetailsForNotice"); 1022 if(oleNoticeBo.getAuthor()!=null && olePatronDocument.getOlePatronId()!=null){ 1023 oleNoticeBo.setPatronName(olePatronDocument.getName().getFirstName()); 1024 if(olePatronDocument.getAddresses().size()>0){ 1025 oleNoticeBo.setPatronAddress(olePatronDocument.getAddresses().get(0).getLine1()+"/n"+olePatronDocument.getAddresses().get(0).getLine2()+"/n"+olePatronDocument.getAddresses().get(0).getCity()); 1026 } 1027 oleNoticeBo.setPatronEmailAddress(olePatronDocument.getEmailAddress()); 1028 oleNoticeBo.setPatronPhoneNumber(olePatronDocument.getPhoneNumber()); 1029 } 1030 1031 return oleNoticeBo; 1032 } 1033 1034 1035 private void createRequestHistoryRecord(String requestId,String OperatorId,String loanTransactionNumber){ 1036 LOG.debug("Inside createRequestHistoryRecord"); 1037 Map<String,String> requestMap =new HashMap<String,String>(); 1038 requestMap.put("requestId",requestId); 1039 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>)businessObjectService.findMatching(OleDeliverRequestBo.class,requestMap); 1040 if(oleDeliverRequestBoList.size()>0){ 1041 OleDeliverRequestBo oleDeliverRequestBo = oleDeliverRequestBoList.get(0); 1042 OleDeliverRequestHistoryRecord oleDeliverRequestHistoryRecord = new OleDeliverRequestHistoryRecord(); 1043 oleDeliverRequestHistoryRecord.setRequestId(oleDeliverRequestBo.getRequestId()); 1044 oleDeliverRequestHistoryRecord.setItemId(oleDeliverRequestBo.getItemId()); 1045 oleDeliverRequestHistoryRecord.setArchiveDate(new java.sql.Date(System.currentTimeMillis())); 1046 oleDeliverRequestHistoryRecord.setPickUpLocationCode(oleDeliverRequestBo.getPickUpLocationCode()); 1047 oleDeliverRequestHistoryRecord.setOperatorId(OperatorId); 1048 oleDeliverRequestHistoryRecord.setDeliverRequestTypeCode(oleDeliverRequestBo.getRequestTypeCode()); 1049 oleDeliverRequestHistoryRecord.setPoLineItemNumber(""); 1050 oleDeliverRequestHistoryRecord.setLoanTransactionId(loanTransactionNumber); 1051 oleDeliverRequestHistoryRecord.setMachineId(""); 1052 businessObjectService.save(oleDeliverRequestHistoryRecord); 1053 } 1054 businessObjectService.delete(oleDeliverRequestBoList); 1055 1056 1057 } 1058 1059 public OleDeliverRequestBo getOleDeliverRequestBo(String itemBarcode){ 1060 1061 LOG.debug("Inside getOleDeliverRequestBo method"); 1062 Map<String,String> requestMap =new HashMap<String,String>(); 1063 requestMap.put("itemId",itemBarcode); 1064 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>)businessObjectService.findMatching(OleDeliverRequestBo.class,requestMap); 1065 if(oleDeliverRequestBoList.size()>0) 1066 return oleDeliverRequestBoList.get(0); 1067 return null; 1068 } 1069 } 1070 1071 1072 1073 1074