001/* 002 * Copyright (c) 2012 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 * mcedica 011 */ 012package org.nuxeo.ecm.platform.routing.api.operation; 013 014import java.io.Serializable; 015import java.util.Map; 016 017import org.nuxeo.ecm.automation.OperationContext; 018import org.nuxeo.ecm.automation.core.Constants; 019import org.nuxeo.ecm.automation.core.annotations.Context; 020import org.nuxeo.ecm.automation.core.annotations.Operation; 021import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 022import org.nuxeo.ecm.automation.core.annotations.Param; 023 024/** 025 * Generic fetch document operation that can be used on any context that has a document as the input. This operation 026 * takes the context input and it returns it as a document. If the input is not a document, an exception is thrown. 027 */ 028@Operation(id = SetWorkflowNodeVar.ID, category = Constants.CAT_WORKFLOW, requires = Constants.WORKFLOW_CONTEXT, label = "Set Node Variable", description = "Set a workflow node variable given a name and the value in the context of a running workflow. To compute the value at runtime from the current context you should use an EL expression as the value. This operation works on any input type and return back the input as the output.", aliases = { "Context.SetWorkflowNodeVar" }) 029public class SetWorkflowNodeVar { 030 031 public static final String ID = "Workflow.SetNodeVariable"; 032 033 @Context 034 protected OperationContext ctx; 035 036 @Param(name = "name") 037 protected String name; 038 039 @Param(name = "value", required = false) 040 protected Object value; 041 042 @SuppressWarnings("unchecked") 043 @OperationMethod 044 public void run() { 045 if (ctx.get(Constants.VAR_WORKFLOW_NODE) != null) { 046 ((Map<String, Serializable>) ctx.get(Constants.VAR_WORKFLOW_NODE)).put(name, (Serializable) value); 047 } 048 } 049}