Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2005-2013 The Kuali Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.opensource.org/licenses/ecl2.php Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.kuali.rice.kew.routeheader.service.impl;
 
 
 import java.util.Date;
 import java.util.List;
 import java.util.Set;

Author(s):
Kuali Rice Team (rice.collab@kuali.org) this class mainly interacts with ActionEvent 'action' classes and non-vo objects.
 
 
 
 	private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(WorkflowDocumentServiceImpl.class);
 
 	private void init(DocumentRouteHeaderValue routeHeader) {
 		KEWServiceLocator.getRouteHeaderService().lockRouteHeader(routeHeader.getDocumentId(), true);
 		KEWServiceLocator.getRouteHeaderService().saveRouteHeader(routeHeader);
 	}
 
     private DocumentRouteHeaderValue finish(DocumentRouteHeaderValue routeHeader) {
     	// reload the document from the database to get a "fresh and clean" copy if we aren't in the context of a
     	// document being routed
     	if (RouteContext.getCurrentRouteContext().getDocument() == null) {
     		return KEWServiceLocator.getRouteHeaderService().getRouteHeader(routeHeader.getDocumentId(), true);
     	} else {
     		// we could enter this case if someone calls a method on WorkflowDocument (such as app specific route)
    		// from their post processor, in that case, if we cleared the database case as above we would
    		// end up getting an optimistic lock exception when the engine attempts to save the document after
    		// the post processor call
    		return routeHeader;
    	}
    }
		Principal principal = loadPrincipal(principalId);
		AcknowledgeAction action = new AcknowledgeAction(routeHeaderprincipalannotation);
		action.performAction();
		return finish(routeHeader);
	}
	public DocumentRouteHeaderValue releaseGroupAuthority(String principalIdDocumentRouteHeaderValue routeHeaderString groupIdString annotationthrows InvalidActionTakenException {
		Principal principal = loadPrincipal(principalId);
		ReleaseWorkgroupAuthority action = new ReleaseWorkgroupAuthority(routeHeaderprincipalannotationgroupId);
		action.performAction();
		return finish(routeHeader);
	}
	public DocumentRouteHeaderValue takeGroupAuthority(String principalIdDocumentRouteHeaderValue routeHeaderString groupIdString annotationthrows InvalidActionTakenException {
		Principal principal = loadPrincipal(principalId);
		TakeWorkgroupAuthority action = new TakeWorkgroupAuthority(routeHeaderprincipalannotationgroupId);
		action.performAction();
		return finish(routeHeader);
	}
	public DocumentRouteHeaderValue approveDocument(String principalIdDocumentRouteHeaderValue routeHeaderString annotationthrows InvalidActionTakenException {
		Principal principal = loadPrincipal(principalId);
		ApproveAction action = new ApproveAction(routeHeaderprincipalannotation);
		action.performAction();
		return finish(routeHeader);
	}
 	 	try {
            // sends null as the PersistedMessage since this is an explicit external call.
 	 		KEWServiceLocator.getExceptionRoutingService().placeInExceptionRouting(annotationnullrouteHeader.getDocumentId());
 	 	} catch (Exception e) {
 	 		throw new RiceRuntimeException("Failed to place the document into exception routing!"e);
 	 	}
 	 	return finish(routeHeader);
 	 }
	public DocumentRouteHeaderValue adHocRouteDocumentToPrincipal(String principalIdDocumentRouteHeaderValue documentString actionRequestedString nodeNameInteger priorityString annotationString targetPrincipalId,
			String responsibilityDescBoolean forceActionString requestLabelthrows WorkflowException {
		Principal principal = loadPrincipal(principalId);
		Recipient recipient = KEWServiceLocator.getIdentityHelperService().getPrincipalRecipient(targetPrincipalId);
		AdHocAction action = new AdHocAction(documentprincipalannotationactionRequestednodeNamepriorityrecipientresponsibilityDescforceActionrequestLabel);
		action.performAction();
		return finish(document);
	}
	public DocumentRouteHeaderValue adHocRouteDocumentToGroup(String principalIdDocumentRouteHeaderValue documentString actionRequestedString nodeNameInteger priorityString annotationString groupId,
			String responsibilityDescBoolean forceActionString requestLabelthrows WorkflowException {
		Principal principal = loadPrincipal(principalId);
		final Recipient recipient = new KimGroupRecipient(KimApiServiceLocator.getGroupService().getGroup(groupId));
		AdHocAction action = new AdHocAction(documentprincipalannotationactionRequestednodeNamepriorityrecipientresponsibilityDescforceActionrequestLabel);
		action.performAction();
		return finish(document);
	}
	public DocumentRouteHeaderValue blanketApproval(String principalIdDocumentRouteHeaderValue routeHeaderString annotationInteger routeLevelthrows InvalidActionTakenException {
		RouteNode node = (routeLevel == null ? null : CompatUtils.getNodeForLevel(routeHeader.getDocumentType(), routeLevel));
		if (node == null && routeLevel != null) {
			throw new InvalidActionTakenException("Could not locate node for route level " + routeLevel);
		}
		Set<StringnodeNames = new HashSet<String>();
		if (node != null) {
			nodeNames = Collections.singleton(node.getRouteNodeName());
		}
		Principal principal = loadPrincipal(principalId);
		ActionTakenEvent action = new BlanketApproveAction(routeHeaderprincipalannotationnodeNames);
		action.performAction();
		return finish(routeHeader);
	}
	public DocumentRouteHeaderValue blanketApproval(String principalIdDocumentRouteHeaderValue routeHeaderString annotationSet nodeNamesthrows InvalidActionTakenException {
		Principal principal = loadPrincipal(principalId);
		BlanketApproveAction action = new BlanketApproveAction(routeHeaderprincipalannotationnodeNames);
		action.recordAction();
		return finish(routeHeader);
	}
	public DocumentRouteHeaderValue cancelDocument(String principalIdDocumentRouteHeaderValue routeHeaderString annotationthrows InvalidActionTakenException {
		// init(routeHeader);
		Principal principal = loadPrincipal(principalId);
		CancelAction action = new CancelAction(routeHeaderprincipalannotation);
		action.recordAction();
		return finish(routeHeader);
	}
    public DocumentRouteHeaderValue recallDocument(String principalIdDocumentRouteHeaderValue routeHeaderString annotationboolean cancelthrows InvalidActionTakenException {
        // init(routeHeader);
        Principal principal = loadPrincipal(principalId);
        RecallAction action = new RecallAction(routeHeaderprincipalannotationcancel);
        action.performAction();
        indexForSearchAfterActionIfNecessary(routeHeader);
        return finish(routeHeader);
    }

Does a search index after a non-post processing action completes

Parameters:
routeHeader the route header of the document just acted upon
		RouteContext routeContext = RouteContext.getCurrentRouteContext();
            DocumentAttributeIndexingQueue queue = KewApiServiceLocator.getDocumentAttributeIndexingQueue(routeHeader.getDocumentType().getApplicationId());
            queue.indexDocument(routeHeader.getDocumentId());
		}
	}
		// init(routeHeader);
		Principal principal = loadPrincipal(principalId);
		ClearFYIAction action = new ClearFYIAction(routeHeaderprincipalannotation);
		action.recordAction();
		return finish(routeHeader);
	}
		Principal principal = loadPrincipal(principalId);
		CompleteAction action = new CompleteAction(routeHeaderprincipalannotation);
		action.performAction();
		return finish(routeHeader);
	}
		if (routeHeader.getDocumentId() != null) { // this is a debateable
														// check - means the
														// client is off
			throw new InvalidActionTakenException("Document already has a Document id");
		}
		Principal principal = loadPrincipal(principalId);
		boolean canInitiate = KEWServiceLocator.getDocumentTypePermissionService().canInitiate(principalIdrouteHeader.getDocumentType());
		if (!canInitiate) {
			throw new InvalidActionTakenException("Principal with name '" + principal.getPrincipalName() + "' is not authorized to initiate documents of type '" + routeHeader.getDocumentType().getName());
		}
        if (!routeHeader.getDocumentType().isDocTypeActive()) {
            // don't allow creation if document type is inactive
            throw new IllegalDocumentTypeException("Document type '" + routeHeader.getDocumentType().getName() + "' is inactive");
        }
		routeHeader.setInitiatorWorkflowId(principalId);
		if (routeHeader.getDocRouteStatus() == null) {
		}
		if (routeHeader.getDocRouteLevel() == null) {
		}
		if (routeHeader.getCreateDate() == null) {
			routeHeader.setCreateDate(new Timestamp(new Date().getTime()));
		}
		if (routeHeader.getDocVersion() == null) {
		}
		if (routeHeader.getDocContent() == null) {
		}
		routeHeader.setDateModified(new Timestamp(new Date().getTime()));
		KEWServiceLocator.getRouteHeaderService().saveRouteHeader(routeHeader);
		KEWServiceLocator.getWorkflowEngineFactory().newEngine(config).initializeDocument(routeHeader);
		KEWServiceLocator.getRouteHeaderService().saveRouteHeader(routeHeader);
		return routeHeader;
	}
		Principal principal = loadPrincipal(principalId);
		DisapproveAction action = new DisapproveAction(routeHeaderprincipalannotation);
		action.recordAction();
		return finish(routeHeader);
	}
	public DocumentRouteHeaderValue returnDocumentToPreviousRouteLevel(String principalIdDocumentRouteHeaderValue routeHeaderInteger destRouteLevelString annotation)
	        throws InvalidActionTakenException {
		DocumentRouteHeaderValue result = null;
		if (destRouteLevel != null) {
			RouteNode node = CompatUtils.getNodeForLevel(routeHeader.getDocumentType(), destRouteLevel);
			if (node == null) {
				throw new InvalidActionTakenException("Could not locate node for route level " + destRouteLevel);
			}
			Principal principal = loadPrincipal(principalId);
			ReturnToPreviousNodeAction action = new ReturnToPreviousNodeAction(routeHeaderprincipalannotationnode.getRouteNodeName(), true);
			action.performAction();
			result = finish(routeHeader);
		}
		return result;
	}
	public DocumentRouteHeaderValue returnDocumentToPreviousNode(String principalIdDocumentRouteHeaderValue routeHeaderString destinationNodeNameString annotation)
		Principal principal = loadPrincipal(principalId);
		ReturnToPreviousNodeAction action = new ReturnToPreviousNodeAction(routeHeaderprincipalannotationdestinationNodeNametrue);
		action.performAction();
		return finish(routeHeader);
	}
	public DocumentRouteHeaderValue routeDocument(String principalIdDocumentRouteHeaderValue routeHeaderString annotationthrows WorkflowException,
		Principal principal = loadPrincipal(principalId);
		RouteDocumentAction actionEvent = new RouteDocumentAction(routeHeaderprincipalannotation);
		actionEvent.performAction();
        .info("routeDocument: " + routeHeader);
		return finish(routeHeader);
	}
		KEWServiceLocator.getRouteHeaderService().saveRouteHeader(routeHeader);
		// save routing data should invoke the post processor doActionTaken for SAVE
 	 	ActionTakenValue val = new ActionTakenValue();
 	 	val.setDocumentId(routeHeader.getDocumentId());
        val.setPrincipalId(principalId);
 	 	PostProcessor postProcessor = routeHeader.getDocumentType().getPostProcessor();
 	 	try {
 	 		postProcessor.doActionTaken(new org.kuali.rice.kew.framework.postprocessor.ActionTakenEvent(routeHeader.getDocumentId(), routeHeader.getAppDocId(), ActionTakenValue.to(val)));
 	 	} catch (Exception e) {
 	 		if (e instanceof RuntimeException) {
 	 			throw (RuntimeException)e;
 	 		}
 	 		throw new WorkflowRuntimeException(e);
 	 	}
 	 	RouteContext routeContext = RouteContext.getCurrentRouteContext();
 	 	if (routeHeader.getDocumentType().hasSearchableAttributes() && !routeContext.isSearchIndexingRequestedForContext()) {
            DocumentAttributeIndexingQueue queue = KewApiServiceLocator.getDocumentAttributeIndexingQueue(routeHeader.getDocumentType().getApplicationId());
            queue.indexDocument(routeHeader.getDocumentId());
		}
		return finish(routeHeader);
	}
	public DocumentRouteHeaderValue saveDocument(String principalIdDocumentRouteHeaderValue routeHeaderString annotationthrows InvalidActionTakenException {
		Principal principal = loadPrincipal(principalId);
		SaveActionEvent action = new SaveActionEvent(routeHeaderprincipalannotation);
		action.performAction();
		return finish(routeHeader);
	}
	public void deleteDocument(String principalIdDocumentRouteHeaderValue routeHeaderthrows WorkflowException {
		if (routeHeader.getDocumentId() == null) {
			.debug("Null Document id passed.");
			throw new WorkflowException("Document id must not be null.");
		}
		KEWServiceLocator.getRouteHeaderService().deleteRouteHeader(routeHeader);
	}
	public void logDocumentAction(String principalIdDocumentRouteHeaderValue routeHeaderString annotationthrows InvalidActionTakenException {
		Principal principal = loadPrincipal(principalId);
		LogDocumentActionAction action = new LogDocumentActionAction(routeHeaderprincipalannotation);
		action.recordAction();
	}
	public DocumentRouteHeaderValue moveDocument(String principalIdDocumentRouteHeaderValue routeHeaderMovePoint movePointString annotationthrows InvalidActionTakenException {
		Principal principal = loadPrincipal(principalId);
		MoveDocumentAction action = new MoveDocumentAction(routeHeaderprincipalannotationmovePoint);
		action.performAction();
		return finish(routeHeader);
	}
	public DocumentRouteHeaderValue superUserActionRequestApproveAction(String principalIdDocumentRouteHeaderValue routeHeaderString actionRequestIdString annotationboolean runPostProcessor)
		init(routeHeader);
		Principal principal = loadPrincipal(principalId);
		SuperUserActionRequestApproveEvent suActionRequestApprove = new SuperUserActionRequestApproveEvent(routeHeaderprincipalactionRequestIdannotationrunPostProcessor);
		suActionRequestApprove.recordAction();
		// suActionRequestApprove.queueDocument();
		RouteContext.getCurrentRouteContext().requestSearchIndexingForContext(); // make sure indexing is requested
		return finish(routeHeader);
	}

    
TODO As with superUserReturnDocumentToPreviousNode, we allow for the passing in of a document ID here to allow for the document load inside the current running transaction. Otherwise we get an optimistic lock exception when attempting to save the branch after the transition to the 'A' status.
    public DocumentRouteHeaderValue superUserActionRequestApproveAction(String principalIdString documentIdString actionRequestIdString annotationboolean runPostProcessor)
        throws InvalidActionTakenException {
        return superUserActionRequestApproveAction(principalId, KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId), actionRequestIdannotationrunPostProcessor);
    }
	public DocumentRouteHeaderValue superUserApprove(String principalIdDocumentRouteHeaderValue routeHeaderString annotationboolean runPostProcessorthrows InvalidActionTakenException {
		init(routeHeader);
		Principal principal = loadPrincipal(principalId);
		new SuperUserApproveEvent(routeHeaderprincipalannotationrunPostProcessor).recordAction();
		RouteContext.getCurrentRouteContext().requestSearchIndexingForContext(); // make sure indexing is requested
		return finish(routeHeader);
	}
	public DocumentRouteHeaderValue superUserCancelAction(String principalIdDocumentRouteHeaderValue routeHeaderString annotationboolean runPostProcessorthrows InvalidActionTakenException {
		init(routeHeader);
		Principal principal = loadPrincipal(principalId);
		new SuperUserCancelEvent(routeHeaderprincipalannotationrunPostProcessor).recordAction();
		RouteContext.getCurrentRouteContext().requestSearchIndexingForContext(); // make sure indexing is requested
		return finish(routeHeader);
	}
	public DocumentRouteHeaderValue superUserDisapproveAction(String principalIdDocumentRouteHeaderValue routeHeaderString annotationboolean runPostProcessorthrows InvalidActionTakenException {
		init(routeHeader);
		Principal principal = loadPrincipal(principalId);
		new SuperUserDisapproveEvent(routeHeaderprincipalannotationrunPostProcessor).recordAction();
		RouteContext.getCurrentRouteContext().requestSearchIndexingForContext(); // make sure indexing is requested
		return finish(routeHeader);
	}
	public DocumentRouteHeaderValue superUserNodeApproveAction(String principalIdDocumentRouteHeaderValue routeHeaderString nodeNameString annotationboolean runPostProcessorthrows InvalidActionTakenException {
		init(routeHeader);
		Principal principal = loadPrincipal(principalId);
		new SuperUserNodeApproveEvent(routeHeaderprincipalannotationrunPostProcessornodeName).recordAction();
		return finish(routeHeader);
	}

TODO As with superUserReturnDocumentToPreviousNode, we allow for the passing in of a document ID here to allow for the document load inside the current running transaction. Otherwise we get an optimistic lock exception when attempting to save the branch after the transition to the 'A' status.
	public DocumentRouteHeaderValue superUserNodeApproveAction(String principalIdString documentIdString nodeNameString annotationboolean runPostProcessorthrows InvalidActionTakenException {
		return superUserNodeApproveAction(principalId, KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId), nodeNameannotationrunPostProcessor);
	}

TODO remove this implementation in favor of having the SuperUserAction call through the WorkflowDocument object. This method is here to resolve KULWF-727 where we were getting an optimistic lock exception from the super user screen on return to previous node. This allows us to load the DocumentRouteHeaderValue inside of the transaction interceptor so that we can stay within the same PersistenceBroker cache.
	public DocumentRouteHeaderValue superUserReturnDocumentToPreviousNode(String principalIdString documentIdString nodeNameString annotationboolean runPostProcessor)
		return superUserReturnDocumentToPreviousNode(principalId, KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId), nodeNameannotationrunPostProcessor);
	}
	public DocumentRouteHeaderValue superUserReturnDocumentToPreviousNode(String principalIdDocumentRouteHeaderValue routeHeaderString nodeNameString annotationboolean runPostProcessor)
		init(routeHeader);
		Principal principal = loadPrincipal(principalId);
		SuperUserReturnToPreviousNodeAction action = new SuperUserReturnToPreviousNodeAction(routeHeaderprincipalannotationrunPostProcessornodeName);
		action.recordAction();
		RouteContext.getCurrentRouteContext().requestSearchIndexingForContext(); // make sure indexing is requested
		return finish(routeHeader);
	}
	public void takeMassActions(String principalIdList<ActionInvocationactionInvocations) {
		Principal principal = loadPrincipal(principalId);
		for (ActionInvocation invocation : actionInvocations) {
			ActionItem actionItem = KEWServiceLocator.getActionListService().findByActionItemId(invocation.getActionItemId());
			if (actionItem == null) {
				.warn("Could not locate action item for the given action item id [" + invocation.getActionItemId() + "], not taking mass action on it.");
				continue;
			}
			KEWServiceLocator.getActionListService().deleteActionItem(actionItemtrue);
            DocumentRouteHeaderValue document = KEWServiceLocator.getRouteHeaderService().getRouteHeader(actionItem.getDocumentId());
            String applicationId = document.getDocumentType().getApplicationId();
			ActionInvocationQueue actionInvocQueue = KewApiServiceLocator.getActionInvocationProcessorService(
                    document.getDocumentId(), applicationId);
			actionInvocQueue.invokeAction(principalIdactionItem.getDocumentId(), invocation);
//			ActionInvocationQueueImpl.queueActionInvocation(user, actionItem.getDocumentId(), invocation);
		}
	}
		Principal principal = loadPrincipal(principalId);
		RevokeAdHocAction action = new RevokeAdHocAction(documentprincipalrevokeannotation);
		action.performAction();
		return finish(document);
	}
	public DocumentRouteHeaderValue revokeAdHocRequests(String principalIdDocumentRouteHeaderValue documentString actionRequestIdString annotationthrows InvalidActionTakenException {
		Principal principal = loadPrincipal(principalId);
		RevokeAdHocAction action = new RevokeAdHocAction(documentprincipalactionRequestIdannotation);
		action.performAction();
		return finish(document);
	}
	protected Principal loadPrincipal(String principalId) {
		return KEWServiceLocator.getIdentityHelperService().getPrincipal(principalId);
	}
New to GrepCode? Check out our FAQ X