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 *     vpasquier <vpasquier@nuxeo.com>
016 */
017package org.nuxeo.ecm.automation.core.exception;
018
019import java.util.ArrayList;
020
021import org.nuxeo.ecm.automation.ChainException;
022import org.nuxeo.ecm.automation.core.ChainExceptionDescriptor;
023
024/**
025 * @since 5.7.3
026 */
027public class ChainExceptionImpl implements ChainException {
028
029    protected final String id;
030
031    protected final String onChainId;
032
033    protected final ArrayList<CatchChainException> catchChainExceptions = new ArrayList<>();
034
035    @Override
036    public String getId() {
037        return id;
038    }
039
040    @Override
041    public String getOnChainId() {
042        return onChainId;
043    }
044
045    @Override
046    public ArrayList<CatchChainException> getCatchChainExceptions() {
047        return catchChainExceptions;
048    }
049
050    public ChainExceptionImpl(String id, String onChainId, ArrayList<CatchChainException> chainExceptionRuns) {
051        this.id = id;
052        this.onChainId = onChainId;
053        catchChainExceptions.addAll(chainExceptionRuns);
054    }
055
056    public ChainExceptionImpl(ChainExceptionDescriptor chainExceptionDescriptor) {
057        id = chainExceptionDescriptor.getId();
058        onChainId = chainExceptionDescriptor.getOnChainId();
059        for (ChainExceptionDescriptor.ChainExceptionRun chainExceptionRunDesc : chainExceptionDescriptor.getChainExceptionsRun()) {
060            CatchChainException chainExceptionRun = new CatchChainException(chainExceptionRunDesc.getChainId(),
061                    chainExceptionRunDesc.getPriority(), chainExceptionRunDesc.getRollBack(),
062                    chainExceptionRunDesc.getFilterId());
063            catchChainExceptions.add(chainExceptionRun);
064        }
065    }
066}