View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    *
4    *
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.opensource.org/licenses/ecl2.php
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.kuali.rice.kew.routeheader.service.impl;
18  
19  import org.kuali.rice.core.api.exception.RiceRuntimeException;
20  import org.kuali.rice.kew.actionitem.ActionItem;
21  import org.kuali.rice.kew.actionrequest.KimGroupRecipient;
22  import org.kuali.rice.kew.actionrequest.Recipient;
23  import org.kuali.rice.kew.actions.AcknowledgeAction;
24  import org.kuali.rice.kew.actions.ActionTakenEvent;
25  import org.kuali.rice.kew.actions.AdHocAction;
26  import org.kuali.rice.kew.actions.ApproveAction;
27  import org.kuali.rice.kew.actions.BlanketApproveAction;
28  import org.kuali.rice.kew.actions.CancelAction;
29  import org.kuali.rice.kew.actions.ClearFYIAction;
30  import org.kuali.rice.kew.actions.CompleteAction;
31  import org.kuali.rice.kew.actions.DisapproveAction;
32  import org.kuali.rice.kew.actions.LogDocumentActionAction;
33  import org.kuali.rice.kew.actions.MoveDocumentAction;
34  import org.kuali.rice.kew.actions.ReleaseWorkgroupAuthority;
35  import org.kuali.rice.kew.actions.ReturnToPreviousNodeAction;
36  import org.kuali.rice.kew.actions.RevokeAdHocAction;
37  import org.kuali.rice.kew.actions.RouteDocumentAction;
38  import org.kuali.rice.kew.actions.SaveActionEvent;
39  import org.kuali.rice.kew.actions.SuperUserActionRequestApproveEvent;
40  import org.kuali.rice.kew.actions.SuperUserApproveEvent;
41  import org.kuali.rice.kew.actions.SuperUserCancelEvent;
42  import org.kuali.rice.kew.actions.SuperUserDisapproveEvent;
43  import org.kuali.rice.kew.actions.SuperUserNodeApproveEvent;
44  import org.kuali.rice.kew.actions.SuperUserReturnToPreviousNodeAction;
45  import org.kuali.rice.kew.actions.TakeWorkgroupAuthority;
46  import org.kuali.rice.kew.actions.asyncservices.ActionInvocation;
47  import org.kuali.rice.kew.actions.asyncservices.ActionInvocationService;
48  import org.kuali.rice.kew.actiontaken.ActionTakenValue;
49  import org.kuali.rice.kew.api.KewApiConstants;
50  import org.kuali.rice.kew.api.WorkflowRuntimeException;
51  import org.kuali.rice.kew.api.action.AdHocRevoke;
52  import org.kuali.rice.kew.api.action.MovePoint;
53  import org.kuali.rice.kew.api.doctype.IllegalDocumentTypeException;
54  import org.kuali.rice.kew.docsearch.service.SearchableAttributeProcessingService;
55  import org.kuali.rice.kew.engine.CompatUtils;
56  import org.kuali.rice.kew.engine.RouteContext;
57  import org.kuali.rice.kew.engine.node.RouteNode;
58  import org.kuali.rice.kew.exception.InvalidActionTakenException;
59  import org.kuali.rice.kew.exception.WorkflowException;
60  import org.kuali.rice.kew.messaging.MessageServiceNames;
61  import org.kuali.rice.kew.postprocessor.PostProcessor;
62  import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
63  import org.kuali.rice.kew.routeheader.service.WorkflowDocumentService;
64  import org.kuali.rice.kew.service.KEWServiceLocator;
65  import org.kuali.rice.kew.util.KEWConstants;
66  import org.kuali.rice.kim.api.identity.principal.Principal;
67  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
68  
69  import java.sql.Timestamp;
70  import java.util.Collections;
71  import java.util.Date;
72  import java.util.HashSet;
73  import java.util.Iterator;
74  import java.util.List;
75  import java.util.Set;
76  
77  /**
78   * @author Kuali Rice Team (rice.collab@kuali.org)
79   *
80   * this class mainly interacts with ActionEvent 'action' classes and non-vo objects.
81   *
82   */
83  
84  public class WorkflowDocumentServiceImpl implements WorkflowDocumentService {
85  
86  	private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(WorkflowDocumentServiceImpl.class);
87  
88  	private void init(DocumentRouteHeaderValue routeHeader) {
89  		KEWServiceLocator.getRouteHeaderService().lockRouteHeader(routeHeader.getDocumentId(), true);
90  		KEWServiceLocator.getRouteHeaderService().saveRouteHeader(routeHeader);
91  	}
92  
93      private DocumentRouteHeaderValue finish(DocumentRouteHeaderValue routeHeader) {
94      	// reload the document from the database to get a "fresh and clean" copy if we aren't in the context of a
95      	// document being routed
96      	if (RouteContext.getCurrentRouteContext().getDocument() == null) {
97      		return KEWServiceLocator.getRouteHeaderService().getRouteHeader(routeHeader.getDocumentId(), true);
98      	} else {
99      		// we could enter this case if someone calls a method on WorkflowDocument (such as app specific route)
100     		// from their post processor, in that case, if we cleared the database case as above we would
101     		// end up getting an optimistic lock exception when the engine attempts to save the document after
102     		// the post processor call
103     		return routeHeader;
104     	}
105     }
106 
107 	public DocumentRouteHeaderValue acknowledgeDocument(String principalId, DocumentRouteHeaderValue routeHeader, String annotation) throws InvalidActionTakenException {
108 		Principal principal = loadPrincipal(principalId);
109 		AcknowledgeAction action = new AcknowledgeAction(routeHeader, principal, annotation);
110 		action.performAction();
111 		return finish(routeHeader);
112 	}
113 
114 	public DocumentRouteHeaderValue releaseGroupAuthority(String principalId, DocumentRouteHeaderValue routeHeader, String groupId, String annotation) throws InvalidActionTakenException {
115 		Principal principal = loadPrincipal(principalId);
116 		ReleaseWorkgroupAuthority action = new ReleaseWorkgroupAuthority(routeHeader, principal, annotation, groupId);
117 		action.performAction();
118 		return finish(routeHeader);
119 	}
120 
121 	public DocumentRouteHeaderValue takeGroupAuthority(String principalId, DocumentRouteHeaderValue routeHeader, String groupId, String annotation) throws InvalidActionTakenException {
122 		Principal principal = loadPrincipal(principalId);
123 		TakeWorkgroupAuthority action = new TakeWorkgroupAuthority(routeHeader, principal, annotation, groupId);
124 		action.performAction();
125 		return finish(routeHeader);
126 	}
127 
128 	public DocumentRouteHeaderValue approveDocument(String principalId, DocumentRouteHeaderValue routeHeader, String annotation) throws InvalidActionTakenException {
129 		Principal principal = loadPrincipal(principalId);
130 		ApproveAction action = new ApproveAction(routeHeader, principal, annotation);
131 		action.performAction();
132 		return finish(routeHeader);
133 	}
134 	
135 	public DocumentRouteHeaderValue placeInExceptionRouting(String principalId, DocumentRouteHeaderValue routeHeader, String annotation) throws InvalidActionTakenException {
136  	 	try {
137  	 		KEWServiceLocator.getExceptionRoutingService().placeInExceptionRouting(annotation, null, routeHeader.getDocumentId());
138  	 	} catch (Exception e) {
139  	 		throw new RiceRuntimeException("Failed to place the document into exception routing!", e);
140  	 	}
141  	 	return finish(routeHeader);
142  	 }
143 
144 	public DocumentRouteHeaderValue adHocRouteDocumentToPrincipal(String principalId, DocumentRouteHeaderValue document, String actionRequested, String nodeName, String annotation, String targetPrincipalId,
145 			String responsibilityDesc, Boolean forceAction, String requestLabel) throws WorkflowException {
146 		Principal principal = loadPrincipal(principalId);
147 		Recipient recipient = KEWServiceLocator.getIdentityHelperService().getPrincipalRecipient(targetPrincipalId);
148 		AdHocAction action = new AdHocAction(document, principal, annotation, actionRequested, nodeName, recipient, responsibilityDesc, forceAction, requestLabel);
149 		action.performAction();
150 		return finish(document);
151 	}
152 
153 	public DocumentRouteHeaderValue adHocRouteDocumentToGroup(String principalId, DocumentRouteHeaderValue document, String actionRequested, String nodeName, String annotation, String groupId,
154 			String responsibilityDesc, Boolean forceAction, String requestLabel) throws WorkflowException {
155 		Principal principal = loadPrincipal(principalId);
156 		final Recipient recipient = new KimGroupRecipient(KimApiServiceLocator.getGroupService().getGroup(groupId));
157 		AdHocAction action = new AdHocAction(document, principal, annotation, actionRequested, nodeName, recipient, responsibilityDesc, forceAction, requestLabel);
158 		action.performAction();
159 		return finish(document);
160 	}
161 
162 	public DocumentRouteHeaderValue blanketApproval(String principalId, DocumentRouteHeaderValue routeHeader, String annotation, Integer routeLevel) throws InvalidActionTakenException {
163 		RouteNode node = (routeLevel == null ? null : CompatUtils.getNodeForLevel(routeHeader.getDocumentType(), routeLevel));
164 		if (node == null && routeLevel != null) {
165 			throw new InvalidActionTakenException("Could not locate node for route level " + routeLevel);
166 		}
167 		Set<String> nodeNames = new HashSet<String>();
168 		if (node != null) {
169 			nodeNames = Collections.singleton(node.getRouteNodeName());
170 		}
171 		Principal principal = loadPrincipal(principalId);
172 		ActionTakenEvent action = new BlanketApproveAction(routeHeader, principal, annotation, nodeNames);
173 		action.performAction();
174 		return finish(routeHeader);
175 	}
176 
177 	public DocumentRouteHeaderValue blanketApproval(String principalId, DocumentRouteHeaderValue routeHeader, String annotation, Set nodeNames) throws InvalidActionTakenException {
178 		Principal principal = loadPrincipal(principalId);
179 		BlanketApproveAction action = new BlanketApproveAction(routeHeader, principal, annotation, nodeNames);
180 		action.recordAction();
181 
182 		return finish(routeHeader);
183 	}
184 
185 	public DocumentRouteHeaderValue cancelDocument(String principalId, DocumentRouteHeaderValue routeHeader, String annotation) throws InvalidActionTakenException {
186 		// init(routeHeader);
187 		Principal principal = loadPrincipal(principalId);
188 		CancelAction action = new CancelAction(routeHeader, principal, annotation);
189 		action.recordAction();
190 		indexForSearchAfterActionIfNecessary(routeHeader);
191 		return finish(routeHeader);
192 	}
193 	
194 	/**
195 	 * Does a search index after a non-post processing action completes
196 	 * @param routeHeader the route header of the document just acted upon
197 	 */
198 	protected void indexForSearchAfterActionIfNecessary(DocumentRouteHeaderValue routeHeader) {
199 		RouteContext routeContext = RouteContext.getCurrentRouteContext();
200 		if (routeHeader.getDocumentType().hasSearchableAttributes() && routeContext.isSearchIndexingRequestedForContext()) {
201 			SearchableAttributeProcessingService searchableAttService = (SearchableAttributeProcessingService) MessageServiceNames.getSearchableAttributeService(routeHeader);
202 			searchableAttService.indexDocument(routeHeader.getDocumentId()); 
203 		}
204 	}
205 
206 	public DocumentRouteHeaderValue clearFYIDocument(String principalId, DocumentRouteHeaderValue routeHeader, String annotation) throws InvalidActionTakenException {
207 		// init(routeHeader);
208 		Principal principal = loadPrincipal(principalId);
209 		ClearFYIAction action = new ClearFYIAction(routeHeader, principal, annotation);
210 		action.recordAction();
211 		return finish(routeHeader);
212 	}
213 
214 	public DocumentRouteHeaderValue completeDocument(String principalId, DocumentRouteHeaderValue routeHeader, String annotation) throws InvalidActionTakenException {
215 		Principal principal = loadPrincipal(principalId);
216 		CompleteAction action = new CompleteAction(routeHeader, principal, annotation);
217 		action.performAction();
218 		return finish(routeHeader);
219 	}
220 
221 	public DocumentRouteHeaderValue createDocument(String principalId, DocumentRouteHeaderValue routeHeader) throws WorkflowException {
222 
223 		if (routeHeader.getDocumentId() != null) { // this is a debateable
224 														// check - means the
225 														// client is off
226 			throw new InvalidActionTakenException("Document already has a Document id");
227 		}
228 		Principal principal = loadPrincipal(principalId);
229 		boolean canInitiate = KEWServiceLocator.getDocumentTypePermissionService().canInitiate(principalId, routeHeader.getDocumentType());
230 
231 		if (!canInitiate) {
232 			throw new InvalidActionTakenException("Principal with name '" + principal.getPrincipalName() + "' is not authorized to initiate documents of type '" + routeHeader.getDocumentType().getName());
233 		}
234 
235         if (!routeHeader.getDocumentType().isDocTypeActive()) {
236             // don't allow creation if document type is inactive
237             throw new IllegalDocumentTypeException("Document type '" + routeHeader.getDocumentType().getName() + "' is inactive");
238         }
239 
240 		routeHeader.setInitiatorWorkflowId(principalId);
241 		if (routeHeader.getDocRouteStatus() == null) {
242 			routeHeader.setDocRouteStatus(KEWConstants.ROUTE_HEADER_INITIATED_CD);
243 		}
244 		if (routeHeader.getDocRouteLevel() == null) {
245 			routeHeader.setDocRouteLevel(Integer.valueOf(KEWConstants.ADHOC_ROUTE_LEVEL));
246 		}
247 		if (routeHeader.getCreateDate() == null) {
248 			routeHeader.setCreateDate(new Timestamp(new Date().getTime()));
249 		}
250 		if (routeHeader.getDocVersion() == null) {
251 			routeHeader.setDocVersion(Integer.valueOf(KewApiConstants.DocumentContentVersions.CURRENT));
252 		}
253 		if (routeHeader.getDocContent() == null) {
254 			routeHeader.setDocContent(KEWConstants.DEFAULT_DOCUMENT_CONTENT);
255 		}
256 		routeHeader.setStatusModDate(new Timestamp(new Date().getTime()));
257 		KEWServiceLocator.getRouteHeaderService().saveRouteHeader(routeHeader);
258 		KEWServiceLocator.getWorkflowEngine().initializeDocument(routeHeader);
259 		KEWServiceLocator.getRouteHeaderService().saveRouteHeader(routeHeader);
260 		return routeHeader;
261 	}
262 
263 	public DocumentRouteHeaderValue disapproveDocument(String principalId, DocumentRouteHeaderValue routeHeader, String annotation) throws InvalidActionTakenException {
264 		Principal principal = loadPrincipal(principalId);
265 		DisapproveAction action = new DisapproveAction(routeHeader, principal, annotation);
266 		action.recordAction();
267 		indexForSearchAfterActionIfNecessary(routeHeader);
268 		return finish(routeHeader);
269 	}
270 
271 	public DocumentRouteHeaderValue returnDocumentToPreviousRouteLevel(String principalId, DocumentRouteHeaderValue routeHeader, Integer destRouteLevel, String annotation)
272 	        throws InvalidActionTakenException {
273 		DocumentRouteHeaderValue result = null;
274 		
275 		if (destRouteLevel != null) {
276 			RouteNode node = CompatUtils.getNodeForLevel(routeHeader.getDocumentType(), destRouteLevel);
277 			if (node == null) {
278 				throw new InvalidActionTakenException("Could not locate node for route level " + destRouteLevel);
279 			}
280 
281 			Principal principal = loadPrincipal(principalId);
282 			ReturnToPreviousNodeAction action = new ReturnToPreviousNodeAction(routeHeader, principal, annotation, node.getRouteNodeName(), true);
283 			action.performAction();
284 			result = finish(routeHeader);
285 		}
286 		return result;
287 	}
288 
289 	public DocumentRouteHeaderValue returnDocumentToPreviousNode(String principalId, DocumentRouteHeaderValue routeHeader, String destinationNodeName, String annotation)
290 			throws InvalidActionTakenException {
291 		Principal principal = loadPrincipal(principalId);
292 		ReturnToPreviousNodeAction action = new ReturnToPreviousNodeAction(routeHeader, principal, annotation, destinationNodeName, true);
293 		action.performAction();
294 		return finish(routeHeader);
295 	}
296 
297 	public DocumentRouteHeaderValue routeDocument(String principalId, DocumentRouteHeaderValue routeHeader, String annotation) throws WorkflowException,
298 			InvalidActionTakenException {
299 		Principal principal = loadPrincipal(principalId);
300 		RouteDocumentAction actionEvent = new RouteDocumentAction(routeHeader, principal, annotation);
301 		actionEvent.performAction();
302         LOG.info("routeDocument: " + routeHeader);
303 		return finish(routeHeader);
304 	}
305 
306 	public DocumentRouteHeaderValue saveRoutingData(String principalId, DocumentRouteHeaderValue routeHeader) {
307 		KEWServiceLocator.getRouteHeaderService().saveRouteHeader(routeHeader);
308 		
309 		// save routing data should invoke the post processor doActionTaken for SAVE
310  	 	ActionTakenValue val = new ActionTakenValue();
311  	 	val.setActionTaken(KEWConstants.ACTION_TAKEN_SAVED_CD);
312  	 	val.setDocumentId(routeHeader.getDocumentId());
313  	 	PostProcessor postProcessor = routeHeader.getDocumentType().getPostProcessor();
314  	 	try {
315  	 		postProcessor.doActionTaken(new org.kuali.rice.kew.postprocessor.ActionTakenEvent(routeHeader.getDocumentId(), routeHeader.getAppDocId(), val));
316  	 	} catch (Exception e) {
317  	 		if (e instanceof RuntimeException) {
318  	 			throw (RuntimeException)e;
319  	 		}
320  	 		throw new WorkflowRuntimeException(e);
321  	 	}
322 
323  	 	RouteContext routeContext = RouteContext.getCurrentRouteContext();
324  	 	if (routeHeader.getDocumentType().hasSearchableAttributes() && !routeContext.isSearchIndexingRequestedForContext()) {
325  	 		routeContext.requestSearchIndexingForContext();
326  	 		
327 			SearchableAttributeProcessingService searchableAttService = (SearchableAttributeProcessingService) MessageServiceNames.getSearchableAttributeService(routeHeader);
328 			searchableAttService.indexDocument(routeHeader.getDocumentId());
329 		}
330 		return finish(routeHeader);
331 	}
332 
333 	public DocumentRouteHeaderValue saveDocument(String principalId, DocumentRouteHeaderValue routeHeader, String annotation) throws InvalidActionTakenException {
334 		Principal principal = loadPrincipal(principalId);
335 		SaveActionEvent action = new SaveActionEvent(routeHeader, principal, annotation);
336 		action.performAction();
337 		return finish(routeHeader);
338 	}
339 
340 	public void deleteDocument(String principalId, DocumentRouteHeaderValue routeHeader) throws WorkflowException {
341 		if (routeHeader.getDocumentId() == null) {
342 			LOG.debug("Null Document id passed.");
343 			throw new WorkflowException("Document id must not be null.");
344 		}
345 		KEWServiceLocator.getRouteHeaderService().deleteRouteHeader(routeHeader);
346 	}
347 
348 	public void logDocumentAction(String principalId, DocumentRouteHeaderValue routeHeader, String annotation) throws InvalidActionTakenException {
349 		Principal principal = loadPrincipal(principalId);
350 		LogDocumentActionAction action = new LogDocumentActionAction(routeHeader, principal, annotation);
351 		action.recordAction();
352 	}
353 
354 	public DocumentRouteHeaderValue moveDocument(String principalId, DocumentRouteHeaderValue routeHeader, MovePoint movePoint, String annotation) throws InvalidActionTakenException {
355 		Principal principal = loadPrincipal(principalId);
356 		MoveDocumentAction action = new MoveDocumentAction(routeHeader, principal, annotation, movePoint);
357 		action.performAction();
358 		return finish(routeHeader);
359 	}
360 
361 	public DocumentRouteHeaderValue superUserActionRequestApproveAction(String principalId, DocumentRouteHeaderValue routeHeader, String actionRequestId, String annotation, boolean runPostProcessor)
362 			throws InvalidActionTakenException {
363 		init(routeHeader);
364 		Principal principal = loadPrincipal(principalId);
365 		SuperUserActionRequestApproveEvent suActionRequestApprove = new SuperUserActionRequestApproveEvent(routeHeader, principal, actionRequestId, annotation, runPostProcessor);
366 		suActionRequestApprove.recordAction();
367 		// suActionRequestApprove.queueDocument();
368 		RouteContext.getCurrentRouteContext().requestSearchIndexingForContext(); // make sure indexing is requested
369 		indexForSearchAfterActionIfNecessary(routeHeader);
370 		return finish(routeHeader);
371 	}
372 
373     /**
374      * TODO As with superUserReturnDocumentToPreviousNode, we allow for the passing in of a document ID here to allow for
375      * the document load inside the current running transaction.  Otherwise we get an optimistic lock exception
376      * when attempting to save the branch after the transition to the 'A' status.
377      */
378     public DocumentRouteHeaderValue superUserActionRequestApproveAction(String principalId, String documentId, String actionRequestId, String annotation, boolean runPostProcessor)
379         throws InvalidActionTakenException {
380         return superUserActionRequestApproveAction(principalId, KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId), actionRequestId, annotation, runPostProcessor);
381     }
382 
383 	public DocumentRouteHeaderValue superUserApprove(String principalId, DocumentRouteHeaderValue routeHeader, String annotation, boolean runPostProcessor) throws InvalidActionTakenException {
384 		init(routeHeader);
385 		Principal principal = loadPrincipal(principalId);
386 		new SuperUserApproveEvent(routeHeader, principal, annotation, runPostProcessor).recordAction();
387 		RouteContext.getCurrentRouteContext().requestSearchIndexingForContext(); // make sure indexing is requested
388 		indexForSearchAfterActionIfNecessary(routeHeader);
389 		return finish(routeHeader);
390 	}
391 
392 	public DocumentRouteHeaderValue superUserCancelAction(String principalId, DocumentRouteHeaderValue routeHeader, String annotation, boolean runPostProcessor) throws InvalidActionTakenException {
393 		init(routeHeader);
394 		Principal principal = loadPrincipal(principalId);
395 		new SuperUserCancelEvent(routeHeader, principal, annotation, runPostProcessor).recordAction();
396 		RouteContext.getCurrentRouteContext().requestSearchIndexingForContext(); // make sure indexing is requested
397 		indexForSearchAfterActionIfNecessary(routeHeader);
398 		return finish(routeHeader);
399 	}
400 
401 	public DocumentRouteHeaderValue superUserDisapproveAction(String principalId, DocumentRouteHeaderValue routeHeader, String annotation, boolean runPostProcessor) throws InvalidActionTakenException {
402 		init(routeHeader);
403 		Principal principal = loadPrincipal(principalId);
404 		new SuperUserDisapproveEvent(routeHeader, principal, annotation, runPostProcessor).recordAction();
405 		RouteContext.getCurrentRouteContext().requestSearchIndexingForContext(); // make sure indexing is requested
406 		indexForSearchAfterActionIfNecessary(routeHeader);
407 		return finish(routeHeader);
408 	}
409 
410 	public DocumentRouteHeaderValue superUserNodeApproveAction(String principalId, DocumentRouteHeaderValue routeHeader, String nodeName, String annotation, boolean runPostProcessor) throws InvalidActionTakenException {
411 		init(routeHeader);
412 		Principal principal = loadPrincipal(principalId);
413 		new SuperUserNodeApproveEvent(routeHeader, principal, annotation, runPostProcessor, nodeName).recordAction();
414 		indexForSearchAfterActionIfNecessary(routeHeader);
415 		return finish(routeHeader);
416 	}
417 
418 	/**
419 	 * TODO As with superUserReturnDocumentToPreviousNode, we allow for the passing in of a document ID here to allow for
420 	 * the document load inside the current running transaction.  Otherwise we get an optimistic lock exception
421 	 * when attempting to save the branch after the transition to the 'A' status.
422 	 */
423 	public DocumentRouteHeaderValue superUserNodeApproveAction(String principalId, String documentId, String nodeName, String annotation, boolean runPostProcessor) throws InvalidActionTakenException {
424 		return superUserNodeApproveAction(principalId, KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId), nodeName, annotation, runPostProcessor);
425 	}
426 
427 	/**
428 	 * TODO remove this implementation in favor of having the SuperUserAction call through the WorkflowDocument object.  This
429 	 * method is here to resolve KULWF-727 where we were getting an optimistic lock exception from the super user screen on
430 	 * return to previous node.  This allows us to load the DocumentRouteHeaderValue inside of the transaction interceptor
431 	 * so that we can stay within the same PersistenceBroker cache.
432 	 */
433 	public DocumentRouteHeaderValue superUserReturnDocumentToPreviousNode(String principalId, String documentId, String nodeName, String annotation, boolean runPostProcessor)
434 		throws InvalidActionTakenException {
435 		return superUserReturnDocumentToPreviousNode(principalId, KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId), nodeName, annotation, runPostProcessor);
436 	}
437 
438 	public DocumentRouteHeaderValue superUserReturnDocumentToPreviousNode(String principalId, DocumentRouteHeaderValue routeHeader, String nodeName, String annotation, boolean runPostProcessor)
439 			throws InvalidActionTakenException {
440 		init(routeHeader);
441 		Principal principal = loadPrincipal(principalId);
442 		SuperUserReturnToPreviousNodeAction action = new SuperUserReturnToPreviousNodeAction(routeHeader, principal, annotation, runPostProcessor, nodeName);
443 		action.recordAction();
444 		RouteContext.getCurrentRouteContext().requestSearchIndexingForContext(); // make sure indexing is requested
445 		indexForSearchAfterActionIfNecessary(routeHeader);
446 		return finish(routeHeader);
447 	}
448 
449 	public void takeMassActions(String principalId, List<ActionInvocation> actionInvocations) {
450 		Principal principal = loadPrincipal(principalId);
451 		for (ActionInvocation invocation : actionInvocations) {
452 			ActionItem actionItem = KEWServiceLocator.getActionListService().findByActionItemId(invocation.getActionItemId());
453 			if (actionItem == null) {
454 				LOG.warn("Could not locate action item for the given action item id [" + invocation.getActionItemId() + "], not taking mass action on it.");
455 				continue;
456 			}
457 			KEWServiceLocator.getActionListService().deleteActionItem(actionItem, true);
458 			ActionInvocationService actionInvocService = MessageServiceNames.getActionInvocationProcessorService(
459 					KEWServiceLocator.getRouteHeaderService().getRouteHeader(actionItem.getDocumentId()));
460 			actionInvocService.invokeAction(principalId, actionItem.getDocumentId(), invocation);
461 //			ActionInvocationProcessor.queueActionInvocation(user, actionItem.getDocumentId(), invocation);
462 		}
463 	}
464 
465 	public DocumentRouteHeaderValue revokeAdHocRequests(String principalId, DocumentRouteHeaderValue document, AdHocRevoke revoke, String annotation) throws InvalidActionTakenException {
466 		Principal principal = loadPrincipal(principalId);
467 		RevokeAdHocAction action = new RevokeAdHocAction(document, principal, revoke, annotation);
468 		action.performAction();
469 		return finish(document);
470 	}
471 	
472 	public DocumentRouteHeaderValue revokeAdHocRequests(String principalId, DocumentRouteHeaderValue document, String actionRequestId, String annotation) throws InvalidActionTakenException {
473 		Principal principal = loadPrincipal(principalId);
474 		RevokeAdHocAction action = new RevokeAdHocAction(document, principal, actionRequestId, annotation);
475 		action.performAction();
476 		return finish(document);
477 	}
478 
479 	protected Principal loadPrincipal(String principalId) {
480 		return KEWServiceLocator.getIdentityHelperService().getPrincipal(principalId);
481 	}
482 
483 }