001/*
002 * Copyright (c) 2006-2011 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 *     bstefanescu
011 */
012package org.nuxeo.ecm.automation.core.operations.execution;
013
014import java.util.Map;
015
016import org.nuxeo.ecm.automation.AutomationService;
017import org.nuxeo.ecm.automation.OperationContext;
018import org.nuxeo.ecm.automation.OperationException;
019import org.nuxeo.ecm.automation.core.Constants;
020import org.nuxeo.ecm.automation.core.annotations.Context;
021import org.nuxeo.ecm.automation.core.annotations.Operation;
022import org.nuxeo.ecm.automation.core.annotations.OperationMethod;
023import org.nuxeo.ecm.automation.core.annotations.Param;
024import org.nuxeo.ecm.automation.core.util.Properties;
025
026/**
027 * Run an embedded operation chain using the current input. The output is undefined (Void)
028 *
029 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
030 */
031@Operation(id = RunOperation.ID, category = Constants.CAT_SUBCHAIN_EXECUTION, label = "Run Chain", description = "Run an operation chain in the current context. The 'parameters' injected are accessible in the subcontext ChainParameters. For instance, @{ChainParameters['parameterKey']}.", aliases = { "Context.RunOperation" })
032public class RunOperation {
033
034    public static final String ID = "RunOperation";
035
036    @Context
037    protected OperationContext ctx;
038
039    @Context
040    protected AutomationService service;
041
042    @Param(name = "id")
043    protected String chainId;
044
045    @Param(name = "isolate", required = false, values = "false")
046    protected boolean isolate = false;
047
048    @Param(name = "parameters", description = "Accessible in the subcontext ChainParameters. For instance, @{ChainParameters['parameterKey']}.", required = false)
049    protected Properties chainParameters;
050
051    @OperationMethod
052    public void run() throws OperationException {
053        OperationContext subctx = ctx.getSubContext(isolate, ctx.getInput());
054        service.run(subctx, chainId, (Map) chainParameters);
055    }
056
057}