View Javadoc

1   /**
2    * Copyright 2005-2015 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.rice.krad.document;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.coreservice.framework.CoreFrameworkServiceLocator;
20  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
21  import org.kuali.rice.kew.api.WorkflowDocument;
22  import org.kuali.rice.krad.util.GlobalVariables;
23  import org.kuali.rice.krad.util.KRADConstants;
24  
25  import java.io.Serializable;
26  
27  /**
28   * @author Kuali Rice Team (rice.collab@kuali.org)
29   */
30  public class DocumentPresentationControllerBase implements DocumentPresentationController, Serializable {
31      private static final long serialVersionUID = -9181864754090276024L;
32  
33      private static transient ParameterService parameterService;
34  
35      public boolean canInitiate(String documentTypeName) {
36          return true;
37      }
38  
39      public boolean canEdit(Document document) {
40          boolean canEdit = false;
41          WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
42          if (workflowDocument.isInitiated()
43                  || workflowDocument.isSaved()
44                  || workflowDocument.isEnroute()
45                  || workflowDocument.isException()) {
46              canEdit = true;
47          }
48  
49          return canEdit;
50      }
51  
52      public boolean canAnnotate(Document document) {
53          return canEdit(document);
54      }
55  
56      public boolean canReload(Document document) {
57          WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
58          return (canEdit(document) && !workflowDocument.isInitiated());
59  
60      }
61  
62      public boolean canClose(Document document) {
63          return true;
64      }
65  
66      public boolean canSave(Document document) {
67          return canEdit(document);
68      }
69  
70      public boolean canRoute(Document document) {
71          boolean canRoute = false;
72          WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
73          if (workflowDocument.isInitiated() || workflowDocument.isSaved()) {
74              canRoute = true;
75          }
76          return canRoute;
77      }
78  
79      public boolean canCancel(Document document) {
80          return canEdit(document);
81      }
82  
83      public boolean canRecall(Document document) {
84          // Enroute - the most liberal approximation of recallability
85          // DocumentAuthorizer will perform finer-grained authorization
86          return document.getDocumentHeader().getWorkflowDocument().isEnroute();
87      }
88  
89      public boolean canCopy(Document document) {
90          boolean canCopy = false;
91          if (document.getAllowsCopy()) {
92              canCopy = true;
93          }
94          return canCopy;
95      }
96  
97      @Override
98      public boolean canPerformRouteReport(Document document) {
99          return getParameterService().getParameterValueAsBoolean(KRADConstants.KNS_NAMESPACE,
100                 KRADConstants.DetailTypes.DOCUMENT_DETAIL_TYPE,
101                 KRADConstants.SystemGroupParameterNames.DEFAULT_CAN_PERFORM_ROUTE_REPORT_IND);
102     }
103 
104     public boolean canAddAdhocRequests(Document document) {
105         return true;
106     }
107 
108     public boolean canBlanketApprove(Document document) {
109         // check system parameter - if Y, use default workflow behavior: allow a user with the permission
110         // to perform the blanket approve action at any time
111         Boolean allowBlanketApproveNoRequest = getParameterService().getParameterValueAsBoolean(
112                 KRADConstants.KNS_NAMESPACE, KRADConstants.DetailTypes.DOCUMENT_DETAIL_TYPE,
113                 KRADConstants.SystemGroupParameterNames.ALLOW_ENROUTE_BLANKET_APPROVE_WITHOUT_APPROVAL_REQUEST_IND);
114         if (allowBlanketApproveNoRequest != null && allowBlanketApproveNoRequest.booleanValue()) {
115             return canEdit(document);
116         }
117 
118         // otherwise, limit the display of the blanket approve button to only the initiator of the document
119         // (prior to routing)
120         WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
121         if (canRoute(document) && StringUtils.equals(workflowDocument.getInitiatorPrincipalId(),
122                 GlobalVariables.getUserSession().getPrincipalId())) {
123             return true;
124         }
125 
126         // or to a user with an approval action request
127         if (workflowDocument.isApprovalRequested()) {
128             return true;
129         }
130 
131         return false;
132     }
133 
134     public boolean canApprove(Document document) {
135         return !canComplete(document);
136     }
137 
138     public boolean canDisapprove(Document document) {
139         // most of the time, a person who can approve can disapprove
140         return canApprove(document);
141     }
142 
143     public boolean canSendAdhocRequests(Document document) {
144         WorkflowDocument kualiWorkflowDocument = document.getDocumentHeader().getWorkflowDocument();
145         return !(kualiWorkflowDocument.isInitiated() || kualiWorkflowDocument.isSaved());
146     }
147 
148     public boolean canSendNoteFyi(Document document) {
149         return true;
150     }
151 
152     public boolean canEditDocumentOverview(Document document) {
153         WorkflowDocument kualiWorkflowDocument = document.getDocumentHeader().getWorkflowDocument();
154         return (kualiWorkflowDocument.isInitiated() || kualiWorkflowDocument.isSaved());
155     }
156 
157     public boolean canFyi(Document document) {
158         return true;
159     }
160 
161     public boolean canAcknowledge(Document document) {
162         return true;
163     }
164 
165     public boolean canComplete(Document document) {
166         boolean docInInit = document.getDocumentHeader().getWorkflowDocument().isInitiated() || document.getDocumentHeader().getWorkflowDocument().isSaved();
167         boolean completionRequested = document.getDocumentHeader().getWorkflowDocument().isCompletionRequested();
168         if (completionRequested && !docInInit) {
169             return true;
170         }
171         return false;
172     }
173 
174     protected ParameterService getParameterService() {
175         if (parameterService == null) {
176             parameterService = CoreFrameworkServiceLocator.getParameterService();
177         }
178         return parameterService;
179     }
180 }