View Javadoc
1   package org.kuali.ole.deliver.rule;
2   
3   import org.kuali.asr.ASRConstants;
4   import org.kuali.asr.service.ASRHelperServiceImpl;
5   import org.kuali.ole.OLEConstants;
6   import org.kuali.ole.deliver.bo.ASRTypeRequest;
7   import org.kuali.ole.deliver.bo.OleDeliverRequestBo;
8   import org.kuali.ole.deliver.bo.OlePatronDocument;
9   import org.kuali.ole.deliver.processor.LoanProcessor;
10  import org.kuali.ole.deliver.service.OleDeliverRequestDocumentHelperServiceImpl;
11  import org.kuali.rice.krad.maintenance.MaintenanceDocument;
12  import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
13  import org.kuali.rice.krad.service.BusinessObjectService;
14  import org.kuali.rice.krad.service.KRADServiceLocator;
15  import org.kuali.rice.krad.util.GlobalVariables;
16  
17  import java.sql.Date;
18  import java.util.HashMap;
19  import java.util.List;
20  import java.util.Map;
21  
22  /**
23   * Created with IntelliJ IDEA.
24   * User: ?
25   * Date: 10/26/12
26   * Time: 9:54 AM
27   * To change this template use File | Settings | File Templates.
28   */
29  public class OleDeliverRequestDocumentRule extends MaintenanceDocumentRuleBase {
30  
31        private ASRHelperServiceImpl asrHelperService = getAsrHelperService();
32        private LoanProcessor loanProcessor =getLoanProcessor();
33  
34      public ASRHelperServiceImpl getAsrHelperService(){
35          if(asrHelperService == null ){
36              asrHelperService = new ASRHelperServiceImpl();
37          }
38          return asrHelperService;
39      }
40  
41      public LoanProcessor getLoanProcessor(){
42          if(loanProcessor == null){
43              loanProcessor = new LoanProcessor();
44          }
45          return loanProcessor;
46      }
47  
48      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
49          OleDeliverRequestBo oleDeliverRequestBo = (OleDeliverRequestBo) document.getNewMaintainableObject().getDataObject();
50          boolean processed = super.processCustomSaveDocumentBusinessRules(document);
51          Map<String, String> patronMap = new HashMap<String, String>();
52          BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
53          patronMap.put(OLEConstants.OleDeliverRequest.PATRON_BARCODE, oleDeliverRequestBo.getBorrowerBarcode());
54          List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) businessObjectService.findMatching(OlePatronDocument.class, patronMap);
55          if(olePatronDocumentList==null || olePatronDocumentList.size()==0){
56              GlobalVariables.getMessageMap().putError(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, OLEConstants.OleDeliverRequest.INVALID_PATRON_BARCODE);
57              return false;
58          }
59          else{
60              oleDeliverRequestBo.setOlePatron(olePatronDocumentList.get(0));
61          }
62          OleDeliverRequestDocumentHelperServiceImpl service = new OleDeliverRequestDocumentHelperServiceImpl();
63          if (processed) {
64              if (oleDeliverRequestBo.getRequestTypeId().equals("1") || oleDeliverRequestBo.getRequestTypeId().equals("3") || oleDeliverRequestBo.getRequestTypeId().equals("5")) {
65                  if (!oleDeliverRequestBo.getOlePatron().isDeliveryPrivilege()) {
66                      if (oleDeliverRequestBo.getPickUpLocationId() != null) {
67                          if (oleDeliverRequestBo.getRequestTypeId().equals("1")) {
68                              oleDeliverRequestBo.setRequestTypeId("2");
69                          } else if (oleDeliverRequestBo.getRequestTypeId().equals("3")) {
70                              oleDeliverRequestBo.setRequestTypeId("4");
71                          } else if (oleDeliverRequestBo.getRequestTypeId().equals("5")) {
72                              oleDeliverRequestBo.setRequestTypeId("6");
73                          }
74                      }
75                  }
76              } else if (oleDeliverRequestBo.getRequestTypeId().equals("2") || oleDeliverRequestBo.getRequestTypeId().equals("4") || oleDeliverRequestBo.getRequestTypeId().equals("6")) {
77  
78                  if (oleDeliverRequestBo.getOlePatron().isDeliveryPrivilege() && oleDeliverRequestBo.getPickUpLocationId() == null) {
79                      if (oleDeliverRequestBo.getRequestTypeId().equals("2")) {
80                          oleDeliverRequestBo.setRequestTypeId("1");
81                      } else if (oleDeliverRequestBo.getRequestTypeId().equals("4")) {
82                          oleDeliverRequestBo.setRequestTypeId("3");
83                      } else if (oleDeliverRequestBo.getRequestTypeId().equals("6")) {
84                          oleDeliverRequestBo.setRequestTypeId("5");
85                      }
86                  }
87              }
88              if (oleDeliverRequestBo.getOperatorModifiedId() == null) {
89                 service.reOrderQueuePosition(oleDeliverRequestBo);
90                  String itemId=oleDeliverRequestBo.getItemId();
91                  Map<String,String> map=new HashMap<String,String>();
92                  map.put(OLEConstants.OleDeliverRequest.ITEM_ID,itemId);
93                  map.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID,OLEConstants.REQUEST_RECAL_DELIVERY);
94                  List<OleDeliverRequestBo> oleDeliverRequestBoList1=(List<OleDeliverRequestBo>)businessObjectService.findMatching(OleDeliverRequestBo.class,map);
95                  map.clear();
96                  map.put(OLEConstants.OleDeliverRequest.ITEM_ID,itemId);
97                  map.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID,OLEConstants.REQUEST_RECAL_HOLD);
98                  List<OleDeliverRequestBo> oleDeliverRequestBoList2=(List<OleDeliverRequestBo>)businessObjectService.findMatching(OleDeliverRequestBo.class,map);
99                  if (oleDeliverRequestBo.getNoticeType() != null && oleDeliverRequestBo.getNoticeType().equalsIgnoreCase(OLEConstants.NOTICE_RECALL)&&oleDeliverRequestBoList1.size()==0 && oleDeliverRequestBoList2.size()==0) {
100                     try {
101                         oleDeliverRequestBo = service.generateRecallNotice(oleDeliverRequestBo);
102                         oleDeliverRequestBo.setRecallNoticeSentDate(new Date(System.currentTimeMillis()));
103                     } catch (Exception e) {
104                         LOG.error("Error occured while generating the notices " + e, e);  //To change body of catch statement use File | Settings | File Templates.
105                     }
106                 }
107                 if (!oleDeliverRequestBo.getRequestTypeId().equals("8")) {
108                     oleDeliverRequestBo = service.updateLoanDocument(oleDeliverRequestBo);
109                     oleDeliverRequestBo.setOlePatron(null);
110                     oleDeliverRequestBo.setOleProxyPatron(null);
111                 }
112             } else {
113                 service.processRequestType(oleDeliverRequestBo);
114             }
115 
116             if(asrHelperService.isAnASRItem(oleDeliverRequestBo.getItemLocation()) && oleDeliverRequestBo.getItemStatus().equals(loanProcessor.getParameter(ASRConstants.ASR_REQUEST_ITEM_STATUS))){
117 
118                 oleDeliverRequestBo.setAsrFlag(true);
119                 oleDeliverRequestBo.setRequestStatus("1");
120                 ASRTypeRequest asrTypeRequest = new ASRTypeRequest();
121             //    asrTypeRequest.setPatronName(oleDeliverRequestBo.getBorrowerName());
122                 asrTypeRequest.setPatronId(oleDeliverRequestBo.getBorrowerId());
123                 asrTypeRequest.setPickUpLocation(oleDeliverRequestBo.getPickUpLocationCode());
124                 asrTypeRequest.setItemId(oleDeliverRequestBo.getItemId());
125                 asrTypeRequest.setRequestStatus("1");
126                 asrTypeRequest.setRequestId(oleDeliverRequestBo.getRequestId());
127                 businessObjectService.save(asrTypeRequest);
128             }
129 
130         }
131         return processed;
132     }
133 }