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.exception.WorkflowException;
22 import org.kuali.rice.kew.postprocessor.ActionTakenEvent;
23 import org.kuali.rice.kew.postprocessor.AfterProcessEvent;
24 import org.kuali.rice.kew.postprocessor.BeforeProcessEvent;
25 import org.kuali.rice.kew.postprocessor.DeleteEvent;
26 import org.kuali.rice.kew.postprocessor.DocumentLockingEvent;
27 import org.kuali.rice.kew.postprocessor.DocumentRouteLevelChange;
28 import org.kuali.rice.kew.postprocessor.DocumentRouteStatusChange;
29 import org.kuali.rice.kew.postprocessor.PostProcessor;
30 import org.kuali.rice.kew.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(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 doDeleteRouteHeader(DeleteEvent 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 doRouteLevelChange(DocumentRouteLevelChange levelChangeEvent) throws Exception {
73 if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), levelChangeEvent.getDocumentId()))) {
74 return new ProcessDocReport(true, "");
75 }
76 if ("WorkflowDocument2".equals(levelChangeEvent.getNewNodeName())) {
77 return new ProcessDocReport(true, "");
78 }
79 throw new WorkflowRuntimeException("Post Processor should never be called in this instance");
80 }
81
82
83
84
85 public ProcessDocReport doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) throws Exception {
86 if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), statusChangeEvent.getDocumentId()))) {
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 beforeProcess(BeforeProcessEvent beforeProcessEvent) throws Exception {
96 if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), beforeProcessEvent.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 afterProcess(AfterProcessEvent afterProcessEvent) throws Exception {
106 if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), afterProcessEvent.getDocumentId()), Arrays.asList(new String[]{"WorkflowDocument2"}))) {
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 List<String> getDocumentIdsToLock(DocumentLockingEvent lockingEvent) throws Exception {
116 return null;
117 }
118
119 private boolean isDocumentPostProcessable(WorkflowDocument doc) throws WorkflowException {
120 return isDocumentPostProcessable(doc, new ArrayList<String>());
121 }
122
123 private boolean isDocumentPostProcessable(WorkflowDocument doc, List<String> validNodeNames) throws WorkflowException {
124 Set<String> nodeNames = doc.getNodeNames();
125 if (nodeNames != null && nodeNames.size() > 0) {
126 String nodeName = nodeNames.iterator().next();
127 return validNodeNames.contains(nodeName) || (nodeName.equals("AdHoc")) || (nodeName.equals("WorkflowDocument"));
128 }
129 return false;
130 }
131
132 private String getPrincipalId(String principalName) {
133 return KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(principalName).getPrincipalId();
134 }
135 }