001/*
002 *  Copyright 2020 Anyware Services
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 */
016package org.ametys.core.migration;
017
018import org.ametys.core.migration.MigrationEngine.ActionData;
019
020/**
021 * Exception that occured during an automatic migration
022 */
023public class MigrationException extends Exception
024{
025    private String _causeMessage;
026    private ActionData _failedAction;
027    
028    /**
029     * Constructs a new exception with the specified detail message.
030     * @param message the detail message.
031     */
032    public MigrationException(String message)
033    {
034        super(message);
035        _causeMessage = message;
036    }
037    
038    /**
039     * Constructs a new exception with the specified detail message, associated with the initial failure cause.
040     * @param message the detail message.
041     * @param causeMessage the failure message.
042     */
043    public MigrationException(String message, String causeMessage)
044    {
045        super(message);
046        _causeMessage = causeMessage;
047    }
048
049    /**
050     * Constructs a new exception with the specified detail message and cause.
051     * @param message the detail message.
052     * @param cause the cause.
053     */
054    public MigrationException(String message, Throwable cause)
055    {
056        super(message, cause);
057        _causeMessage = cause.getMessage();
058    }
059
060    /**
061     * Constructs a new exception with the specified detail message and cause.
062     * @param message the detail message.
063     * @param causeMessage the failure message.
064     * @param cause the cause.
065     * @param action the failed action
066     */
067    public MigrationException(String message, String causeMessage, Throwable cause, ActionData action)
068    {
069        super(message, cause);
070        _causeMessage = causeMessage;
071        _failedAction = action;
072    }
073
074    /**
075     * Constructs a new exception with the specified cause.
076     * @param cause the specified cause.
077     */
078    public MigrationException(Throwable cause)
079    {
080        super(cause);
081        _causeMessage = cause.getMessage();
082    }
083    
084    /**
085     * Returns the failure message, if any.
086     * @return the failure message
087     */
088    public String getFailureMessage()
089    {
090        return _causeMessage;
091    }
092    
093    /**
094     * Returns the failed action, if any
095     * @return the failed action
096     */
097    public ActionData getFailedAction()
098    {
099        return _failedAction;
100    }
101}