View Javadoc

1   /*
2    * Copyright 2007-2008 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.kns.document.Document;
23  import org.kuali.rice.kns.service.KNSServiceLocator;
24  import org.kuali.rice.kns.service.ParameterService;
25  import org.kuali.rice.kns.util.GlobalVariables;
26  import org.kuali.rice.kns.util.KNSConstants;
27  import org.kuali.rice.kns.workflow.service.KualiWorkflowDocument;
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      protected boolean canEdit(Document document){
45      	boolean canEdit = false;
46      	KualiWorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
47          if (workflowDocument.stateIsInitiated() || workflowDocument.stateIsSaved() || workflowDocument.stateIsEnroute() || workflowDocument.stateIsException()) {
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      protected 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      protected boolean canReload(Document document){
71      	KualiWorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
72      	return (canEdit(document) && !workflowDocument.stateIsInitiated()) ;
73               
74      }
75      
76      
77      /**
78       * 
79       * @param document
80       * @return boolean (true if can close the document)
81       */
82      protected 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      protected 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     protected boolean canRoute(Document document){
104     	boolean canRoute = false;
105     	KualiWorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
106     	if (workflowDocument.stateIsInitiated() || workflowDocument.stateIsSaved()){
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     protected 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     protected 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     protected boolean canPerformRouteReport(Document document){
144         return getParameterService().getIndicatorParameter( KNSConstants.KNS_NAMESPACE, KNSConstants.DetailTypes.DOCUMENT_DETAIL_TYPE, KNSConstants.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     protected 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     protected 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     	try {
168 	    	if ( getParameterService().getIndicatorParameter(KNSConstants.KNS_NAMESPACE, KNSConstants.DetailTypes.DOCUMENT_DETAIL_TYPE, KNSConstants.SystemGroupParameterNames.ALLOW_ENROUTE_BLANKET_APPROVE_WITHOUT_APPROVAL_REQUEST_IND) ) {
169 	    		return canEdit(document);
170 	    	}
171     	} catch ( IllegalArgumentException ex ) {
172     		// do nothing, the parameter does not exist and defaults to "N"
173     	}
174     	// otherwise, limit the display of the blanket approve button to only the initiator of the document
175     	// (prior to routing)
176     	KualiWorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
177     	if ( canRoute(document) && StringUtils.equals( workflowDocument.getInitiatorPrincipalId(), GlobalVariables.getUserSession().getPrincipalId() ) ) {
178     		return true;
179     	}
180     	// or to a user with an approval action request
181     	if ( workflowDocument.isApprovalRequested() ) {
182     		return true;
183     	}
184     	
185     	return false;
186     }
187     
188     protected boolean canApprove(Document document) {
189     	return true;
190     }
191 
192     protected boolean canDisapprove(Document document) {
193     	// most of the time, a person who can approve can disapprove
194     	return canApprove(document);
195     }
196     
197     protected boolean canSendAdhocRequests(Document document) {
198     	KualiWorkflowDocument kualiWorkflowDocument = document.getDocumentHeader().getWorkflowDocument();
199     	return !(kualiWorkflowDocument.stateIsInitiated() || kualiWorkflowDocument.stateIsSaved());
200     }
201     
202     protected boolean canSendNoteFyi(Document document) {
203     	return true;
204     }
205     
206     protected boolean canEditDocumentOverview(Document document){
207     	KualiWorkflowDocument kualiWorkflowDocument = document.getDocumentHeader().getWorkflowDocument();
208     	return (kualiWorkflowDocument.stateIsInitiated() || kualiWorkflowDocument.stateIsSaved());
209     }
210 
211     protected boolean canFyi(Document document) {
212     	return true;
213     }
214     
215     protected boolean canAcknowledge(Document document) {
216     	return true;
217     }
218     
219     /**
220      * @see org.kuali.rice.kns.document.authorization.DocumentPresentationController#getDocumentActions(org.kuali.rice.kns.document.Document)
221      */
222     public Set<String> getDocumentActions(Document document){
223     	Set<String> documentActions = new HashSet<String>();
224     	if (canEdit(document)){
225     		documentActions.add(KNSConstants.KUALI_ACTION_CAN_EDIT);
226     	}
227     	
228     	if(canAnnotate(document)){
229     		documentActions.add(KNSConstants.KUALI_ACTION_CAN_ANNOTATE);
230     	}
231     	 
232     	if(canClose(document)){
233     		documentActions.add(KNSConstants.KUALI_ACTION_CAN_CLOSE);
234     	}
235     	 
236     	if(canSave(document)){
237     		documentActions.add(KNSConstants.KUALI_ACTION_CAN_SAVE);
238     	}
239     	if(canRoute(document)){
240     		documentActions.add(KNSConstants.KUALI_ACTION_CAN_ROUTE);
241     	}
242     	 
243     	if(canCancel(document)){
244     		documentActions.add(KNSConstants.KUALI_ACTION_CAN_CANCEL);
245     	}
246     	 
247     	if(canReload(document)){
248     		documentActions.add(KNSConstants.KUALI_ACTION_CAN_RELOAD);
249     	}
250     	if(canCopy(document)){
251     		documentActions.add(KNSConstants.KUALI_ACTION_CAN_COPY);
252     	}
253     	if(canPerformRouteReport(document)){
254     		documentActions.add(KNSConstants.KUALI_ACTION_PERFORM_ROUTE_REPORT);
255     	}
256     	
257     	if(canAddAdhocRequests(document)){
258     		documentActions.add(KNSConstants.KUALI_ACTION_CAN_ADD_ADHOC_REQUESTS);
259     	}
260     	
261     	if(canBlanketApprove(document)){
262     		documentActions.add(KNSConstants.KUALI_ACTION_CAN_BLANKET_APPROVE);
263     	}
264     	if (canApprove(document)) {
265     		documentActions.add(KNSConstants.KUALI_ACTION_CAN_APPROVE);
266     	}
267     	if (canDisapprove(document)) {
268     		documentActions.add(KNSConstants.KUALI_ACTION_CAN_DISAPPROVE);
269     	}
270     	if (canSendAdhocRequests(document)) {
271     		documentActions.add(KNSConstants.KUALI_ACTION_CAN_SEND_ADHOC_REQUESTS);
272     	}
273     	if(canSendNoteFyi(document)){
274     		documentActions.add(KNSConstants.KUALI_ACTION_CAN_SEND_NOTE_FYI);
275     	}
276     	if(this.canEditDocumentOverview(document)){
277     		documentActions.add(KNSConstants.KUALI_ACTION_CAN_EDIT__DOCUMENT_OVERVIEW);
278     	}
279     	if (canFyi(document)) {
280     		documentActions.add(KNSConstants.KUALI_ACTION_CAN_FYI);
281     	}
282     	if (canAcknowledge(document)) {
283     		documentActions.add(KNSConstants.KUALI_ACTION_CAN_ACKNOWLEDGE);
284     	}
285     	return documentActions;
286     }
287 
288 	protected ParameterService getParameterService() {
289 		if ( parameterService == null ) {
290 			parameterService = KNSServiceLocator.getParameterService();
291 		}
292 		return parameterService;
293 	}
294     
295         
296 }