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.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
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 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
58
59
60 protected boolean canAnnotate(Document document){
61 return canEdit(document);
62 }
63
64
65
66
67
68
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
80
81
82 protected boolean canClose(Document document){
83 return true;
84 }
85
86
87
88
89
90
91
92
93 protected boolean canSave(Document document){
94 return canEdit(document);
95 }
96
97
98
99
100
101
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
116
117
118 protected boolean canCancel(Document document){
119 return canEdit(document);
120 }
121
122
123
124
125
126
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
141
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
151
152
153 protected boolean canAddAdhocRequests(Document document){
154 return true;
155 }
156
157
158
159
160
161
162
163
164 protected boolean canBlanketApprove(Document document){
165
166
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
173 }
174
175
176 KualiWorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
177 if ( canRoute(document) && StringUtils.equals( workflowDocument.getInitiatorPrincipalId(), GlobalVariables.getUserSession().getPrincipalId() ) ) {
178 return true;
179 }
180
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
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
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 }