001/* 002 * Copyright (c) 2013 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Mariana Cedica 011 */ 012package org.nuxeo.ecm.platform.routing.core.api.operation; 013 014import org.nuxeo.ecm.automation.OperationContext; 015import org.nuxeo.ecm.automation.core.Constants; 016import org.nuxeo.ecm.automation.core.annotations.Context; 017import org.nuxeo.ecm.automation.core.annotations.Operation; 018import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 019import org.nuxeo.ecm.automation.core.annotations.Param; 020import org.nuxeo.ecm.core.api.CoreSession; 021import org.nuxeo.ecm.core.api.NuxeoException; 022import org.nuxeo.ecm.platform.routing.api.DocumentRoutingService; 023 024/** 025 * Resumes a workflow on a give node. If nodeId is null, is applies to the current node of the given workflow resumed. 026 * 027 * @since 5.7.2 028 */ 029@Operation(id = ResumeNodeOperation.ID, category = Constants.CAT_WORKFLOW, label = "Resume workflow", requires = Constants.WORKFLOW_CONTEXT, description = "Resumes a route instance on a given node. " 030 + "When a parameter is not specified, it will be fetched from the current context if the operation is executed in the context of a running workflow (it applies to the current workflow and to the current node).", aliases = { "Workflow.ResumeNodeOperation" }) 031public class ResumeNodeOperation { 032 public static final String ID = "Workflow.ResumeNode"; 033 034 @Context 035 protected CoreSession session; 036 037 @Context 038 protected OperationContext ctx; 039 040 @Param(name = "workflowInstanceId", required = false) 041 protected String workflowInstanceId; 042 043 @Param(name = "nodeId", required = false) 044 protected String nodeId; 045 046 @Context 047 protected DocumentRoutingService documentRoutingService; 048 049 @OperationMethod 050 public void resumeWorkflow() { 051 if (workflowInstanceId == null) { 052 workflowInstanceId = (String) ctx.get("workflowInstanceId"); 053 } 054 if (nodeId == null) { 055 nodeId = (String) ctx.get("nodeId"); 056 } 057 if (workflowInstanceId == null) { 058 throw new NuxeoException("Can not resume workflow instance with id " + workflowInstanceId 059 + ". No current instance in the context"); 060 } 061 documentRoutingService.resumeInstance(workflowInstanceId, nodeId, null, null, session); 062 } 063}