Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
DocumentPresentationControllerBase |
|
| 2.761904761904762;2.762 |
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 | 0 | 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 | 0 | 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 | 0 | boolean canEdit = false; |
46 | 0 | KualiWorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument(); |
47 | 0 | if (workflowDocument.stateIsInitiated() || workflowDocument.stateIsSaved() || workflowDocument.stateIsEnroute() || workflowDocument.stateIsException()) { |
48 | 0 | canEdit = true; |
49 | } | |
50 | ||
51 | 0 | 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 | 0 | 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 | 0 | KualiWorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument(); |
72 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | boolean canRoute = false; |
105 | 0 | KualiWorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument(); |
106 | 0 | if (workflowDocument.stateIsInitiated() || workflowDocument.stateIsSaved()){ |
107 | 0 | canRoute = true; |
108 | } | |
109 | 0 | 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 | 0 | 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 | 0 | boolean canCopy = false; |
130 | 0 | if(document.getAllowsCopy()){ |
131 | 0 | canCopy = true; |
132 | } | |
133 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | if ( getParameterService().getIndicatorParameter(KNSConstants.KNS_NAMESPACE, KNSConstants.DetailTypes.DOCUMENT_DETAIL_TYPE, KNSConstants.SystemGroupParameterNames.ALLOW_ENROUTE_BLANKET_APPROVE_WITHOUT_APPROVAL_REQUEST_IND) ) { |
169 | 0 | return canEdit(document); |
170 | } | |
171 | 0 | } catch ( IllegalArgumentException ex ) { |
172 | // do nothing, the parameter does not exist and defaults to "N" | |
173 | 0 | } |
174 | // otherwise, limit the display of the blanket approve button to only the initiator of the document | |
175 | // (prior to routing) | |
176 | 0 | KualiWorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument(); |
177 | 0 | if ( canRoute(document) && StringUtils.equals( workflowDocument.getInitiatorPrincipalId(), GlobalVariables.getUserSession().getPrincipalId() ) ) { |
178 | 0 | return true; |
179 | } | |
180 | // or to a user with an approval action request | |
181 | 0 | if ( workflowDocument.isApprovalRequested() ) { |
182 | 0 | return true; |
183 | } | |
184 | ||
185 | 0 | return false; |
186 | } | |
187 | ||
188 | protected boolean canApprove(Document document) { | |
189 | 0 | return true; |
190 | } | |
191 | ||
192 | protected boolean canDisapprove(Document document) { | |
193 | // most of the time, a person who can approve can disapprove | |
194 | 0 | return canApprove(document); |
195 | } | |
196 | ||
197 | protected boolean canSendAdhocRequests(Document document) { | |
198 | 0 | KualiWorkflowDocument kualiWorkflowDocument = document.getDocumentHeader().getWorkflowDocument(); |
199 | 0 | return !(kualiWorkflowDocument.stateIsInitiated() || kualiWorkflowDocument.stateIsSaved()); |
200 | } | |
201 | ||
202 | protected boolean canSendNoteFyi(Document document) { | |
203 | 0 | return true; |
204 | } | |
205 | ||
206 | protected boolean canEditDocumentOverview(Document document){ | |
207 | 0 | KualiWorkflowDocument kualiWorkflowDocument = document.getDocumentHeader().getWorkflowDocument(); |
208 | 0 | return (kualiWorkflowDocument.stateIsInitiated() || kualiWorkflowDocument.stateIsSaved()); |
209 | } | |
210 | ||
211 | protected boolean canFyi(Document document) { | |
212 | 0 | return true; |
213 | } | |
214 | ||
215 | protected boolean canAcknowledge(Document document) { | |
216 | 0 | 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 | 0 | Set<String> documentActions = new HashSet<String>(); |
224 | 0 | if (canEdit(document)){ |
225 | 0 | documentActions.add(KNSConstants.KUALI_ACTION_CAN_EDIT); |
226 | } | |
227 | ||
228 | 0 | if(canAnnotate(document)){ |
229 | 0 | documentActions.add(KNSConstants.KUALI_ACTION_CAN_ANNOTATE); |
230 | } | |
231 | ||
232 | 0 | if(canClose(document)){ |
233 | 0 | documentActions.add(KNSConstants.KUALI_ACTION_CAN_CLOSE); |
234 | } | |
235 | ||
236 | 0 | if(canSave(document)){ |
237 | 0 | documentActions.add(KNSConstants.KUALI_ACTION_CAN_SAVE); |
238 | } | |
239 | 0 | if(canRoute(document)){ |
240 | 0 | documentActions.add(KNSConstants.KUALI_ACTION_CAN_ROUTE); |
241 | } | |
242 | ||
243 | 0 | if(canCancel(document)){ |
244 | 0 | documentActions.add(KNSConstants.KUALI_ACTION_CAN_CANCEL); |
245 | } | |
246 | ||
247 | 0 | if(canReload(document)){ |
248 | 0 | documentActions.add(KNSConstants.KUALI_ACTION_CAN_RELOAD); |
249 | } | |
250 | 0 | if(canCopy(document)){ |
251 | 0 | documentActions.add(KNSConstants.KUALI_ACTION_CAN_COPY); |
252 | } | |
253 | 0 | if(canPerformRouteReport(document)){ |
254 | 0 | documentActions.add(KNSConstants.KUALI_ACTION_PERFORM_ROUTE_REPORT); |
255 | } | |
256 | ||
257 | 0 | if(canAddAdhocRequests(document)){ |
258 | 0 | documentActions.add(KNSConstants.KUALI_ACTION_CAN_ADD_ADHOC_REQUESTS); |
259 | } | |
260 | ||
261 | 0 | if(canBlanketApprove(document)){ |
262 | 0 | documentActions.add(KNSConstants.KUALI_ACTION_CAN_BLANKET_APPROVE); |
263 | } | |
264 | 0 | if (canApprove(document)) { |
265 | 0 | documentActions.add(KNSConstants.KUALI_ACTION_CAN_APPROVE); |
266 | } | |
267 | 0 | if (canDisapprove(document)) { |
268 | 0 | documentActions.add(KNSConstants.KUALI_ACTION_CAN_DISAPPROVE); |
269 | } | |
270 | 0 | if (canSendAdhocRequests(document)) { |
271 | 0 | documentActions.add(KNSConstants.KUALI_ACTION_CAN_SEND_ADHOC_REQUESTS); |
272 | } | |
273 | 0 | if(canSendNoteFyi(document)){ |
274 | 0 | documentActions.add(KNSConstants.KUALI_ACTION_CAN_SEND_NOTE_FYI); |
275 | } | |
276 | 0 | if(this.canEditDocumentOverview(document)){ |
277 | 0 | documentActions.add(KNSConstants.KUALI_ACTION_CAN_EDIT__DOCUMENT_OVERVIEW); |
278 | } | |
279 | 0 | if (canFyi(document)) { |
280 | 0 | documentActions.add(KNSConstants.KUALI_ACTION_CAN_FYI); |
281 | } | |
282 | 0 | if (canAcknowledge(document)) { |
283 | 0 | documentActions.add(KNSConstants.KUALI_ACTION_CAN_ACKNOWLEDGE); |
284 | } | |
285 | 0 | return documentActions; |
286 | } | |
287 | ||
288 | protected ParameterService getParameterService() { | |
289 | 0 | if ( parameterService == null ) { |
290 | 0 | parameterService = KNSServiceLocator.getParameterService(); |
291 | } | |
292 | 0 | return parameterService; |
293 | } | |
294 | ||
295 | ||
296 | } |