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