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