1 package org.kuali.ole.deliver.rule;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.deliver.bo.OleDeliverRequestBo;
5 import org.kuali.ole.deliver.bo.OlePatronDocument;
6 import org.kuali.ole.deliver.service.OleDeliverRequestDocumentHelperServiceImpl;
7 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
8 import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
9 import org.kuali.rice.krad.service.BusinessObjectService;
10 import org.kuali.rice.krad.service.KRADServiceLocator;
11 import org.kuali.rice.krad.util.GlobalVariables;
12
13 import java.sql.Date;
14 import java.util.HashMap;
15 import java.util.List;
16 import java.util.Map;
17
18
19
20
21
22
23
24
25 public class OleDeliverRequestDocumentRule extends MaintenanceDocumentRuleBase {
26
27
28 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
29 OleDeliverRequestBo oleDeliverRequestBo = (OleDeliverRequestBo) document.getNewMaintainableObject().getDataObject();
30 boolean processed = super.processCustomSaveDocumentBusinessRules(document);
31 Map<String, String> patronMap = new HashMap<String, String>();
32 BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
33 patronMap.put(OLEConstants.OleDeliverRequest.PATRON_BARCODE, oleDeliverRequestBo.getBorrowerBarcode());
34 List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) businessObjectService.findMatching(OlePatronDocument.class, patronMap);
35 if(olePatronDocumentList==null || olePatronDocumentList.size()==0){
36 GlobalVariables.getMessageMap().putError(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, OLEConstants.OleDeliverRequest.INVALID_PATRON_BARCODE);
37 return false;
38 }
39 else{
40 oleDeliverRequestBo.setOlePatron(olePatronDocumentList.get(0));
41 }
42 OleDeliverRequestDocumentHelperServiceImpl service = new OleDeliverRequestDocumentHelperServiceImpl();
43 if (processed) {
44 if (oleDeliverRequestBo.getRequestTypeId().equals("1") || oleDeliverRequestBo.getRequestTypeId().equals("3") || oleDeliverRequestBo.getRequestTypeId().equals("5")) {
45 if (!oleDeliverRequestBo.getOlePatron().isDeliveryPrivilege()) {
46 if (oleDeliverRequestBo.getPickUpLocationId() != null) {
47 if (oleDeliverRequestBo.getRequestTypeId().equals("1")) {
48 oleDeliverRequestBo.setRequestTypeId("2");
49 } else if (oleDeliverRequestBo.getRequestTypeId().equals("3")) {
50 oleDeliverRequestBo.setRequestTypeId("4");
51 } else if (oleDeliverRequestBo.getRequestTypeId().equals("5")) {
52 oleDeliverRequestBo.setRequestTypeId("6");
53 }
54 }
55 }
56 } else if (oleDeliverRequestBo.getRequestTypeId().equals("2") || oleDeliverRequestBo.getRequestTypeId().equals("4") || oleDeliverRequestBo.getRequestTypeId().equals("6")) {
57
58 if (oleDeliverRequestBo.getOlePatron().isDeliveryPrivilege() && oleDeliverRequestBo.getPickUpLocationId() == null) {
59 if (oleDeliverRequestBo.getRequestTypeId().equals("2")) {
60 oleDeliverRequestBo.setRequestTypeId("1");
61 } else if (oleDeliverRequestBo.getRequestTypeId().equals("4")) {
62 oleDeliverRequestBo.setRequestTypeId("3");
63 } else if (oleDeliverRequestBo.getRequestTypeId().equals("6")) {
64 oleDeliverRequestBo.setRequestTypeId("5");
65 }
66 }
67 }
68 if (oleDeliverRequestBo.getOperatorModifiedId() == null) {
69 service.reOrderQueuePosition(oleDeliverRequestBo);
70 if (oleDeliverRequestBo.getNoticeType() != null && oleDeliverRequestBo.getNoticeType().equalsIgnoreCase(OLEConstants.NOTICE_RECALL)) {
71 try {
72 oleDeliverRequestBo = service.generateRecallNotice(oleDeliverRequestBo);
73 oleDeliverRequestBo.setRecallNoticeSentDate(new Date(System.currentTimeMillis()));
74 } catch (Exception e) {
75 LOG.error("Error occured while generating the notices " + e, e);
76 }
77 }
78 if (!oleDeliverRequestBo.getRequestTypeId().equals("8")) {
79 oleDeliverRequestBo = service.updateLoanDocument(oleDeliverRequestBo);
80 oleDeliverRequestBo.setOlePatron(null);
81 oleDeliverRequestBo.setOleProxyPatron(null);
82 }
83 } else {
84 service.processRequestType(oleDeliverRequestBo);
85 }
86 }
87 return processed;
88 }
89 }