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