1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
125
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
140
141
142 protected boolean canAnnotate(Document document) {
143 return canEdit(document);
144 }
145
146
147
148
149
150 protected boolean canReload(Document document) {
151 WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
152 return (canEdit(document) && !workflowDocument.isInitiated());
153
154 }
155
156
157
158
159
160 protected boolean canClose(Document document) {
161 return true;
162 }
163
164
165
166
167
168 protected boolean canSave(Document document) {
169 return canEdit(document);
170 }
171
172
173
174
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
187
188
189 protected boolean canCancel(Document document) {
190 return canEdit(document);
191 }
192
193
194
195
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
207
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
217
218
219 protected boolean canAddAdhocRequests(Document document) {
220 return true;
221 }
222
223
224
225
226
227
228
229 protected boolean canBlanketApprove(Document document) {
230
231
232
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
242 }
243
244
245
246 WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
247 if (canRoute(document)
248 && StringUtils.equals(workflowDocument.getInitiatorPrincipalId(), GlobalVariables.getUserSession()
249 .getPrincipalId())) {
250 return true;
251 }
252
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
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 }