1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
32
33 private static transient ParameterService parameterService;
34
35 public boolean canInitiate(String documentTypeName) {
36 return true;
37 }
38
39
40
41
42
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
58
59
60 public boolean canAnnotate(Document document){
61 return canEdit(document);
62 }
63
64
65
66
67
68
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
80
81
82 public boolean canClose(Document document){
83 return true;
84 }
85
86
87
88
89
90
91
92
93 public boolean canSave(Document document){
94 return canEdit(document);
95 }
96
97
98
99
100
101
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
116
117
118 public boolean canCancel(Document document){
119 return canEdit(document);
120 }
121
122
123
124
125
126
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
141
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
151
152
153 public boolean canAddAdhocRequests(Document document){
154 return true;
155 }
156
157
158
159
160
161
162
163
164 public boolean canBlanketApprove(Document document){
165
166
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
172
173 WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
174 if ( canRoute(document) && StringUtils.equals( workflowDocument.getInitiatorPrincipalId(), GlobalVariables.getUserSession().getPrincipalId() ) ) {
175 return true;
176 }
177
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
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
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 }