1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.actions;
17
18 import org.kuali.rice.kew.api.WorkflowDocument;
19 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
20 import org.kuali.rice.kew.api.WorkflowRuntimeException;
21 import org.kuali.rice.kew.api.action.ActionType;
22 import org.kuali.rice.kew.api.exception.WorkflowException;
23 import org.kuali.rice.kew.framework.postprocessor.*;
24 import org.kuali.rice.kew.framework.postprocessor.AfterProcessEvent;
25 import org.kuali.rice.kew.framework.postprocessor.BeforeProcessEvent;
26 import org.kuali.rice.kew.framework.postprocessor.DeleteEvent;
27 import org.kuali.rice.kew.framework.postprocessor.DocumentLockingEvent;
28 import org.kuali.rice.kew.framework.postprocessor.DocumentRouteLevelChange;
29 import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
30 import org.kuali.rice.kew.framework.postprocessor.ProcessDocReport;
31 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
32
33 import java.util.ArrayList;
34 import java.util.Arrays;
35 import java.util.List;
36 import java.util.Set;
37
38
39
40
41
42
43
44
45 public class SuperUserActionInvalidPostProcessor implements PostProcessor {
46
47 private static final String USER_AUTH_ID = "rkirkend";
48
49
50
51
52 public ProcessDocReport doActionTaken(org.kuali.rice.kew.framework.postprocessor.ActionTakenEvent event) throws Exception {
53 if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), event.getDocumentId()))) {
54 return new ProcessDocReport(true, "");
55 }
56 throw new WorkflowRuntimeException("Post Processor should never be called in this instance");
57 }
58
59
60
61
62 public ProcessDocReport afterActionTaken(ActionType performed, org.kuali.rice.kew.framework.postprocessor.ActionTakenEvent event) throws Exception {
63 if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), event.getDocumentId()))) {
64 return new ProcessDocReport(true, "");
65 }
66 throw new WorkflowRuntimeException("Post Processor should never be called in this instance");
67 }
68
69
70
71
72 public ProcessDocReport doDeleteRouteHeader(DeleteEvent event) throws Exception {
73 if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), event.getDocumentId()))) {
74 return new ProcessDocReport(true, "");
75 }
76 throw new WorkflowRuntimeException("Post Processor should never be called in this instance");
77 }
78
79
80
81
82 public ProcessDocReport doRouteLevelChange(DocumentRouteLevelChange levelChangeEvent) throws Exception {
83 if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), levelChangeEvent.getDocumentId()))) {
84 return new ProcessDocReport(true, "");
85 }
86 if ("WorkflowDocument2".equals(levelChangeEvent.getNewNodeName())) {
87 return new ProcessDocReport(true, "");
88 }
89 throw new WorkflowRuntimeException("Post Processor should never be called in this instance");
90 }
91
92
93
94
95 public ProcessDocReport doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) throws Exception {
96 if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), statusChangeEvent.getDocumentId()))) {
97 return new ProcessDocReport(true, "");
98 }
99 throw new WorkflowRuntimeException("Post Processor should never be called in this instance");
100 }
101
102
103
104
105 public ProcessDocReport beforeProcess(BeforeProcessEvent beforeProcessEvent) throws Exception {
106 if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), beforeProcessEvent.getDocumentId()))) {
107 return new ProcessDocReport(true, "");
108 }
109 throw new WorkflowRuntimeException("Post Processor should never be called in this instance");
110 }
111
112
113
114
115 public ProcessDocReport afterProcess(AfterProcessEvent afterProcessEvent) throws Exception {
116 if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), afterProcessEvent.getDocumentId()), Arrays.asList(new String[]{"WorkflowDocument2"}))) {
117 return new ProcessDocReport(true, "");
118 }
119 throw new WorkflowRuntimeException("Post Processor should never be called in this instance");
120 }
121
122
123
124
125 public List<String> getDocumentIdsToLock(DocumentLockingEvent lockingEvent) throws Exception {
126 return null;
127 }
128
129 private boolean isDocumentPostProcessable(WorkflowDocument doc) throws WorkflowException {
130 return isDocumentPostProcessable(doc, new ArrayList<String>());
131 }
132
133 private boolean isDocumentPostProcessable(WorkflowDocument doc, List<String> validNodeNames) throws WorkflowException {
134 Set<String> nodeNames = doc.getNodeNames();
135 if (nodeNames != null && nodeNames.size() > 0) {
136 String nodeName = nodeNames.iterator().next();
137 return validNodeNames.contains(nodeName) || (nodeName.equals("AdHoc")) || (nodeName.equals("WorkflowDocument"));
138 }
139 return false;
140 }
141
142 private String getPrincipalId(String principalName) {
143 return KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(principalName).getPrincipalId();
144 }
145 }