View Javadoc

1   /**
2    * Copyright 2005-2011 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.uif.authorization;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.core.framework.parameter.ParameterService;
20  import org.kuali.rice.core.framework.services.CoreFrameworkServiceLocator;
21  import org.kuali.rice.kew.api.WorkflowDocument;
22  import org.kuali.rice.krad.document.Document;
23  import org.kuali.rice.krad.util.GlobalVariables;
24  import org.kuali.rice.krad.util.KRADConstants;
25  import org.kuali.rice.krad.web.form.DocumentFormBase;
26  import org.kuali.rice.krad.web.form.UifFormBase;
27  
28  import java.util.HashSet;
29  import java.util.Set;
30  
31  /**
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  public class DocumentPresentationControllerBase extends PresentationControllerBase {
35  
36      private static transient ParameterService parameterService;
37  
38      @Override
39      public Set<String> getActionFlags(UifFormBase model) {
40          Set<String> documentActions = new HashSet<String>();
41        
42          Document document = ((DocumentFormBase) model).getDocument();
43  
44          if (canEdit(document)) {
45              documentActions.add(KRADConstants.KUALI_ACTION_CAN_EDIT);
46          }
47  
48          if (canAnnotate(document)) {
49              documentActions.add(KRADConstants.KUALI_ACTION_CAN_ANNOTATE);
50          }
51  
52          if (canClose(document)) {
53              documentActions.add(KRADConstants.KUALI_ACTION_CAN_CLOSE);
54          }
55  
56          if (canSave(document)) {
57              documentActions.add(KRADConstants.KUALI_ACTION_CAN_SAVE);
58          }
59  
60          if (canRoute(document)) {
61              documentActions.add(KRADConstants.KUALI_ACTION_CAN_ROUTE);
62          }
63  
64          if (canCancel(document)) {
65              documentActions.add(KRADConstants.KUALI_ACTION_CAN_CANCEL);
66          }
67  
68          if (canReload(document)) {
69              documentActions.add(KRADConstants.KUALI_ACTION_CAN_RELOAD);
70          }
71  
72          if (canCopy(document)) {
73              documentActions.add(KRADConstants.KUALI_ACTION_CAN_COPY);
74          }
75  
76          if (canPerformRouteReport(document)) {
77              documentActions.add(KRADConstants.KUALI_ACTION_PERFORM_ROUTE_REPORT);
78          }
79  
80          if (canAddAdhocRequests(document)) {
81              documentActions.add(KRADConstants.KUALI_ACTION_CAN_ADD_ADHOC_REQUESTS);
82          }
83  
84          if (canBlanketApprove(document)) {
85              documentActions.add(KRADConstants.KUALI_ACTION_CAN_BLANKET_APPROVE);
86          }
87  
88          if (canApprove(document)) {
89              documentActions.add(KRADConstants.KUALI_ACTION_CAN_APPROVE);
90          }
91  
92          if (canDisapprove(document)) {
93              documentActions.add(KRADConstants.KUALI_ACTION_CAN_DISAPPROVE);
94          }
95  
96          if (canSendAdhocRequests(document)) {
97              documentActions.add(KRADConstants.KUALI_ACTION_CAN_SEND_ADHOC_REQUESTS);
98          }
99  
100         if (canSendNoteFyi(document)) {
101             documentActions.add(KRADConstants.KUALI_ACTION_CAN_SEND_NOTE_FYI);
102         }
103 
104         if (this.canEditDocumentOverview(document)) {
105             documentActions.add(KRADConstants.KUALI_ACTION_CAN_EDIT__DOCUMENT_OVERVIEW);
106         }
107 
108         if (canFyi(document)) {
109             documentActions.add(KRADConstants.KUALI_ACTION_CAN_FYI);
110         }
111 
112         if (canAcknowledge(document)) {
113             documentActions.add(KRADConstants.KUALI_ACTION_CAN_ACKNOWLEDGE);
114         }
115 
116         return documentActions;
117     }
118 
119     public boolean canInitiate(String documentTypeName) {
120         return true;
121     }
122 
123     /**
124      * @param document
125      * @return boolean (true if can edit the document)
126      */
127     protected boolean canEdit(Document document) {
128         boolean canEdit = false;
129         WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
130         if (workflowDocument.isInitiated() || workflowDocument.isSaved() || workflowDocument.isEnroute()
131                 || workflowDocument.isException()) {
132             canEdit = true;
133         }
134 
135         return canEdit;
136     }
137 
138     /**
139      * @param document
140      * @return boolean (true if can add notes to the document)
141      */
142     protected boolean canAnnotate(Document document) {
143         return canEdit(document);
144     }
145 
146     /**
147      * @param document
148      * @return boolean (true if can reload the document)
149      */
150     protected boolean canReload(Document document) {
151         WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
152         return (canEdit(document) && !workflowDocument.isInitiated());
153 
154     }
155 
156     /**
157      * @param document
158      * @return boolean (true if can close the document)
159      */
160     protected boolean canClose(Document document) {
161         return true;
162     }
163 
164     /**
165      * @param document
166      * @return boolean (true if can save the document)
167      */
168     protected boolean canSave(Document document) {
169         return canEdit(document);
170     }
171 
172     /**
173      * @param document
174      * @return boolean (true if can route the document)
175      */
176     protected boolean canRoute(Document document) {
177         boolean canRoute = false;
178         WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
179         if (workflowDocument.isInitiated() || workflowDocument.isSaved()) {
180             canRoute = true;
181         }
182         return canRoute;
183     }
184 
185     /**
186      * @param document
187      * @return boolean (true if can cancel the document)
188      */
189     protected boolean canCancel(Document document) {
190         return canEdit(document);
191     }
192 
193     /**
194      * @param document
195      * @return boolean (true if can copy the document)
196      */
197     protected boolean canCopy(Document document) {
198         boolean canCopy = false;
199         if (document.getAllowsCopy()) {
200             canCopy = true;
201         }
202         return canCopy;
203     }
204 
205     /**
206      * @param document
207      * @return boolean (true if can perform route report)
208      */
209     protected boolean canPerformRouteReport(Document document) {
210         return getParameterService().getParameterValueAsBoolean(KRADConstants.KRAD_NAMESPACE,
211                 KRADConstants.DetailTypes.DOCUMENT_DETAIL_TYPE,
212                 KRADConstants.SystemGroupParameterNames.DEFAULT_CAN_PERFORM_ROUTE_REPORT_IND);
213     }
214 
215     /**
216      * @param document
217      * @return boolean (true if can do ad hoc route)
218      */
219     protected boolean canAddAdhocRequests(Document document) {
220         return true;
221     }
222 
223     /**
224      * This method ...
225      * 
226      * @param document
227      * @return boolean (true if can blanket approve the document)
228      */
229     protected boolean canBlanketApprove(Document document) {
230         // check system parameter - if Y, use default workflow behavior: allow a
231         // user with the permission
232         // to perform the blanket approve action at any time
233         try {
234             if (getParameterService().getParameterValueAsBoolean(KRADConstants.KRAD_NAMESPACE,
235                     KRADConstants.DetailTypes.DOCUMENT_DETAIL_TYPE,
236                     KRADConstants.SystemGroupParameterNames.ALLOW_ENROUTE_BLANKET_APPROVE_WITHOUT_APPROVAL_REQUEST_IND)) {
237                 return canEdit(document);
238             }
239         }
240         catch (IllegalArgumentException ex) {
241             // do nothing, the parameter does not exist and defaults to "N"
242         }
243         // otherwise, limit the display of the blanket approve button to only
244         // the initiator of the document
245         // (prior to routing)
246         WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
247         if (canRoute(document)
248                 && StringUtils.equals(workflowDocument.getInitiatorPrincipalId(), GlobalVariables.getUserSession()
249                         .getPrincipalId())) {
250             return true;
251         }
252         // or to a user with an approval action request
253         if (workflowDocument.isApprovalRequested()) {
254             return true;
255         }
256 
257         return false;
258     }
259 
260     protected boolean canApprove(Document document) {
261         return true;
262     }
263 
264     protected boolean canDisapprove(Document document) {
265         // most of the time, a person who can approve can disapprove
266         return canApprove(document);
267     }
268 
269     protected boolean canSendAdhocRequests(Document document) {
270         WorkflowDocument kualiWorkflowDocument = document.getDocumentHeader().getWorkflowDocument();
271         return !(kualiWorkflowDocument.isInitiated() || kualiWorkflowDocument.isSaved());
272     }
273 
274     protected boolean canSendNoteFyi(Document document) {
275         return true;
276     }
277 
278     protected boolean canEditDocumentOverview(Document document) {
279         WorkflowDocument kualiWorkflowDocument = document.getDocumentHeader().getWorkflowDocument();
280         return (kualiWorkflowDocument.isInitiated() || kualiWorkflowDocument.isSaved());
281     }
282 
283     protected boolean canFyi(Document document) {
284         return true;
285     }
286 
287     protected boolean canAcknowledge(Document document) {
288         return true;
289     }
290 
291     protected ParameterService getParameterService() {
292         if (parameterService == null) {
293             parameterService = CoreFrameworkServiceLocator.getParameterService();
294         }
295         return parameterService;
296     }
297 
298 }