001/* 002 * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Mariana Cedica 018 */ 019package org.nuxeo.ecm.platform.routing.core.api.operation; 020 021import org.nuxeo.ecm.automation.OperationContext; 022import org.nuxeo.ecm.automation.core.Constants; 023import org.nuxeo.ecm.automation.core.annotations.Context; 024import org.nuxeo.ecm.automation.core.annotations.Operation; 025import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 026import org.nuxeo.ecm.automation.core.annotations.Param; 027import org.nuxeo.ecm.core.api.CoreSession; 028import org.nuxeo.ecm.core.api.NuxeoException; 029import org.nuxeo.ecm.platform.routing.api.DocumentRoutingService; 030 031/** 032 * Resumes a workflow on a give node. If nodeId is null, is applies to the current node of the given workflow resumed. 033 * 034 * @since 5.7.2 035 */ 036@Operation(id = ResumeNodeOperation.ID, category = Constants.CAT_WORKFLOW, label = "Resume workflow", requires = Constants.WORKFLOW_CONTEXT, description = "Resumes a route instance on a given node. " 037 + "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" }) 038public class ResumeNodeOperation { 039 public static final String ID = "Workflow.ResumeNode"; 040 041 @Context 042 protected CoreSession session; 043 044 @Context 045 protected OperationContext ctx; 046 047 @Param(name = "workflowInstanceId", required = false) 048 protected String workflowInstanceId; 049 050 @Param(name = "nodeId", required = false) 051 protected String nodeId; 052 053 @Context 054 protected DocumentRoutingService documentRoutingService; 055 056 @OperationMethod 057 public void resumeWorkflow() { 058 if (workflowInstanceId == null) { 059 workflowInstanceId = (String) ctx.get("workflowInstanceId"); 060 } 061 if (nodeId == null) { 062 nodeId = (String) ctx.get("nodeId"); 063 } 064 if (workflowInstanceId == null) { 065 throw new NuxeoException("Can not resume workflow instance with id " + workflowInstanceId 066 + ". No current instance in the context"); 067 } 068 documentRoutingService.resumeInstance(workflowInstanceId, nodeId, null, null, session); 069 } 070}