001/*
002 * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     bstefanescu
016 *     vpasquier
017 */
018package org.nuxeo.ecm.automation;
019
020import java.io.Serializable;
021import java.util.ArrayList;
022import java.util.HashMap;
023import java.util.List;
024import java.util.Map;
025
026/**
027 * Describes an operation chain execution.
028 *
029 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
030 */
031public class OperationChain implements Serializable {
032
033    private static final long serialVersionUID = 1L;
034
035    protected final String id;
036
037    // (via REST for example)
038    protected final List<OperationParameters> operations;
039
040    protected final Map<String, Object> chainParameters;
041
042    protected String description;
043
044    /**
045     * @since 7.1
046     */
047    protected String[] aliases;
048
049    protected boolean isPublic; // whether this chain is visible to clients
050
051    public OperationChain(String id) {
052        this.id = id;
053        operations = new ArrayList<OperationParameters>();
054        chainParameters = new HashMap<String, Object>();
055    }
056
057    public OperationChain(String id, List<OperationParameters> operations) {
058        this.id = id;
059        this.operations = operations;
060        chainParameters = new HashMap<String, Object>();
061    }
062
063    public OperationChain(String id, List<OperationParameters> operations, Map<String, Object> chainParameters) {
064        this.id = id;
065        this.operations = operations;
066        this.chainParameters = chainParameters;
067    }
068
069    public String getId() {
070        return id;
071    }
072
073    /**
074     * @since 7.1
075     */
076    public String[] getAliases() {
077        return aliases;
078    }
079
080    public String getDescription() {
081        return description;
082    }
083
084    public void setDescription(String description) {
085        this.description = description;
086    }
087
088    /**
089     * @since 7.1
090     */
091    public void setAliases(String[] aliases) {
092        this.aliases = aliases;
093    }
094
095    public boolean isPublic() {
096        return isPublic;
097    }
098
099    public void setPublic(boolean isPublic) {
100        this.isPublic = isPublic;
101    }
102
103    public List<OperationParameters> getOperations() {
104        return operations;
105    }
106
107    public void add(OperationParameters op) {
108        operations.add(op);
109    }
110
111    public OperationParameters add(String operationId) {
112        OperationParameters op = new OperationParameters(operationId);
113        operations.add(op);
114        return op;
115    }
116
117    /**
118     * @since 5.7.2 Adding chain parameters
119     */
120    public void addChainParameters(Map<String, Object> chainParameter) {
121        chainParameters.putAll(chainParameter);
122    }
123
124    /**
125     * @since 5.7.2 Getting chain parameters
126     */
127    public Map<String, Object> getChainParameters() {
128        return chainParameters;
129    }
130
131}