View Javadoc
1   /*
2    * Copyright 2009 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.fp.document.authorization;
17  
18  import java.util.Set;
19  
20  import org.kuali.ole.fp.businessobject.CashDrawer;
21  import org.kuali.ole.fp.document.CashReceiptDocument;
22  import org.kuali.ole.fp.service.CashDrawerService;
23  import org.kuali.ole.sys.OLEConstants;
24  import org.kuali.ole.sys.OLEKeyConstants;
25  import org.kuali.ole.sys.OleAuthorizationConstants;
26  import org.kuali.ole.sys.context.SpringContext;
27  import org.kuali.ole.sys.document.authorization.LedgerPostingDocumentPresentationControllerBase;
28  import org.kuali.ole.sys.service.FinancialSystemWorkflowHelperService;
29  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
30  import org.kuali.rice.kew.api.WorkflowDocument;
31  import org.kuali.rice.krad.document.Document;
32  import org.kuali.rice.krad.util.GlobalVariables;
33  
34  public class CashReceiptDocumentPresentationController extends LedgerPostingDocumentPresentationControllerBase {
35      private static final String CASH_MANAGEMENT_NODE_NAME = "CashManagement";
36  
37      /**
38       * @see org.kuali.rice.krad.document.authorization.DocumentPresentationControllerBase#canApprove(org.kuali.rice.krad.document.Document)
39       */
40      @Override
41      public boolean canApprove(Document document) {
42          return this.canApproveOrBlanketApprove(document) ? super.canApprove(document) : false;
43      }
44  
45      /**
46       * @see org.kuali.rice.krad.document.authorization.DocumentPresentationControllerBase#canBlanketApprove(org.kuali.rice.krad.document.Document)
47       */
48      @Override
49      public boolean canBlanketApprove(Document document) {
50          // blanket approve only available for cash management confirm edit mode
51          if(!this.isInCashManageConfirmMode(document)){
52              return false;
53          }
54  
55          return this.canApproveOrBlanketApprove(document) ? super.canBlanketApprove(document) : false;
56      }
57  
58      protected boolean canApproveOrBlanketApprove(Document document) {
59          WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
60  
61          if (workflowDocument.isApprovalRequested() ) {
62              if (!SpringContext.getBean(FinancialSystemWorkflowHelperService.class).isAdhocApprovalRequestedForPrincipal(workflowDocument, GlobalVariables.getUserSession().getPrincipalId())) {
63              CashReceiptDocument cashReceiptDocument = (CashReceiptDocument) document;
64  
65              String campusCode = cashReceiptDocument.getCampusLocationCode();
66              CashDrawer cashDrawer = SpringContext.getBean(CashDrawerService.class).getByCampusCode(campusCode);
67              if (cashDrawer == null) {
68                  GlobalVariables.getMessageMap().putError(OLEConstants.GLOBAL_ERRORS, OLEKeyConstants.CashReceipt.ERROR_CASH_DRAWER_DOES_NOT_EXIST, campusCode);
69                  return false;
70              }
71              if (cashDrawer.isClosed()) {
72                  return false;
73              }
74          }
75          }
76          return true;
77      }
78  
79      /**
80       * Prevents editing of the document at the CashManagement node
81       * @see org.kuali.rice.kns.document.authorization.DocumentPresentationControllerBase#canEdit(org.kuali.rice.kns.document.Document)
82       */
83      @Override
84      public boolean canEdit(Document document) {
85          if (document.getDocumentHeader().getWorkflowDocument().getCurrentNodeNames().contains(CashReceiptDocumentPresentationController.CASH_MANAGEMENT_NODE_NAME)) {
86              return false;
87          }
88          return super.canEdit(document);
89      }
90  
91      /**
92       * @see org.kuali.ole.sys.document.authorization.FinancialSystemTransactionalDocumentPresentationControllerBase#getEditModes(org.kuali.rice.kns.document.Document)
93       */
94      @Override
95      public Set<String> getEditModes(Document document) {
96          Set<String> editModes = super.getEditModes(document);
97          addFullEntryEntryMode(document, editModes);
98          addChangeRequestMode(document, editModes);
99  
100         return editModes;
101     }
102 
103     protected void addFullEntryEntryMode(Document document, Set<String> editModes) {
104         if (this.isInCashManageConfirmMode(document)){
105             editModes.add(OleAuthorizationConstants.CashReceiptEditMode.CASH_MANAGER_CONFIRM_MODE);
106         }
107     }
108 
109     protected void addChangeRequestMode(Document document, Set<String> editModes) {
110         boolean IndValue = SpringContext.getBean(ParameterService.class).getParameterValueAsBoolean(CashReceiptDocument.class, "CHANGE_REQUEST_ENABLED_IND");
111         if(IndValue) {
112             editModes.add(OleAuthorizationConstants.CashReceiptEditMode.CHANGE_REQUEST_MODE);
113         }
114     }
115 
116     /**
117      * determine whether the given document is in cash management confirm edit mode
118      */
119     protected boolean isInCashManageConfirmMode(Document document){
120         WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
121 
122         if (workflowDocument.isEnroute()) {
123             Set<String> currentRouteLevels = workflowDocument.getCurrentNodeNames();
124             if(currentRouteLevels.contains(CASH_MANAGEMENT_NODE_NAME)) {
125                 return true;
126             }
127         }
128             return false;
129     }
130 
131 }