View Javadoc

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