1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.engine;
17
18 import java.io.Serializable;
19 import java.util.HashMap;
20 import java.util.LinkedList;
21 import java.util.List;
22 import java.util.Map;
23
24 import org.apache.commons.lang3.StringUtils;
25 import org.kuali.rice.core.framework.util.ApplicationThreadLocal;
26 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
27 import org.kuali.rice.kew.api.WorkflowRuntimeException;
28 import org.kuali.rice.kew.engine.node.RouteNodeInstance;
29 import org.kuali.rice.kew.routeheader.DocumentContent;
30 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
31 import org.kuali.rice.kew.routeheader.StandardDocumentContent;
32
33
34
35
36
37
38
39 public class RouteContext implements Serializable {
40
41 private static final long serialVersionUID = -7125137491367944594L;
42
43 private String id;
44
45 private DocumentRouteHeaderValue routeHeader;
46
47 private DocumentContent documentContent;
48
49 private RouteNodeInstance nodeInstance;
50
51 private EngineState engineState;
52
53 private ActionRequestValue actionRequest;
54
55 private ActivationContext activationContext = new ActivationContext(!ActivationContext.CONTEXT_IS_SIMULATION);
56
57 private boolean doNotSendApproveNotificationEmails = false;
58
59 private Map parameters = new HashMap();
60
61 private boolean searchIndexingRequestedForContext = false;
62
63 public RouteContext() {
64 id = new String();
65 }
66
67 private static ThreadLocal<List<RouteContext>> ROUTE_CONTEXT_STACK = new ApplicationThreadLocal<List<RouteContext>>() {
68 protected List<RouteContext> initialValue() {
69 List<RouteContext> contextStack = new LinkedList<RouteContext>();
70 contextStack.add(0, new RouteContext());
71 return contextStack;
72 }
73 };
74
75 public static RouteContext getCurrentRouteContext() {
76 return ROUTE_CONTEXT_STACK.get().get(0);
77 }
78
79 public static void clearRouteContextByDocumentId(String documentId) {
80 if(StringUtils.isNotBlank(documentId)) {
81
82 for(int i = 0; i < ROUTE_CONTEXT_STACK.get().size(); i++) {
83 if(ROUTE_CONTEXT_STACK.get().get(i).routeHeader.getDocumentId().equals(documentId)) {
84 ROUTE_CONTEXT_STACK.get().remove(i);
85 ROUTE_CONTEXT_STACK.get().add(i, new RouteContext());
86 }
87 }
88 }
89
90 }
91
92 public static void clearCurrentRouteContext() {
93 ROUTE_CONTEXT_STACK.get().remove(0);
94 ROUTE_CONTEXT_STACK.get().add(0, new RouteContext());
95 }
96
97 public static RouteContext createNewRouteContext() {
98 ROUTE_CONTEXT_STACK.get().add(0, new RouteContext());
99 return getCurrentRouteContext();
100 }
101
102 public static RouteContext releaseCurrentRouteContext() {
103 return ROUTE_CONTEXT_STACK.get().remove(0);
104 }
105
106
107
108
109 public DocumentRouteHeaderValue getRouteHeader() {
110 return routeHeader;
111 }
112
113
114
115
116 public void setRouteHeader(DocumentRouteHeaderValue routeHeader) {
117 this.routeHeader = routeHeader;
118 }
119
120 public DocumentRouteHeaderValue getDocument() {
121 return routeHeader;
122 }
123
124 public void setDocument(DocumentRouteHeaderValue routeHeader) {
125 this.routeHeader = routeHeader;
126 try {
127 setDocumentContent(new StandardDocumentContent(routeHeader.getDocContent(), this));
128 } catch (Exception e) {
129 throw new WorkflowRuntimeException(e);
130 }
131 }
132
133 public DocumentContent getDocumentContent() {
134 return documentContent;
135 }
136
137 public void setDocumentContent(DocumentContent documentContent) {
138 this.documentContent = documentContent;
139 }
140
141 public RouteNodeInstance getNodeInstance() {
142 return nodeInstance;
143 }
144
145 public void setNodeInstance(RouteNodeInstance nodeInstance) {
146 this.nodeInstance = nodeInstance;
147 }
148
149 public EngineState getEngineState() {
150 return engineState;
151 }
152
153 public void setEngineState(EngineState engineState) {
154 this.engineState = engineState;
155 }
156
157 public ActionRequestValue getActionRequest() {
158 return actionRequest;
159 }
160
161 public void setActionRequest(ActionRequestValue actionRequest) {
162 this.actionRequest = actionRequest;
163 }
164
165 public boolean isSimulation() {
166 if (activationContext == null) {
167 return false;
168 }
169 return activationContext.isSimulation();
170 }
171
172 public ActivationContext getActivationContext() {
173 return activationContext;
174 }
175
176 public void setActivationContext(ActivationContext activationContext) {
177 this.activationContext = activationContext;
178 }
179
180 public boolean isDoNotSendApproveNotificationEmails() {
181 return doNotSendApproveNotificationEmails;
182 }
183
184 public void setDoNotSendApproveNotificationEmails(boolean sendNotificationEmails) {
185 this.doNotSendApproveNotificationEmails = sendNotificationEmails;
186 }
187
188 public Map getParameters() {
189 return parameters;
190 }
191
192 public void setParameters(Map parameters) {
193 this.parameters = parameters;
194 }
195
196
197
198
199
200 public boolean isSearchIndexingRequestedForContext() {
201 return this.searchIndexingRequestedForContext;
202 }
203
204
205
206
207 public void requestSearchIndexingForContext() {
208 this.searchIndexingRequestedForContext = true;
209 }
210
211 }