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.action.impl;
017
018import org.apache.avalon.framework.configuration.Configuration;
019import org.apache.avalon.framework.configuration.ConfigurationException;
020
021import org.ametys.core.migration.MigrationException;
022import org.ametys.core.migration.action.Action;
023import org.ametys.core.migration.action.data.ActionData;
024import org.ametys.core.migration.action.data.impl.ManualActionData;
025import org.ametys.core.migration.version.Version;
026import org.ametys.runtime.plugin.component.AbstractLogEnabled;
027
028/**
029 * Manual action: no code will be executed, and an exception will be thrown to stop the migration
030 */
031public class ManualAction extends AbstractLogEnabled implements Action
032{
033    @Override
034    public void doAction(ActionData actionData) throws MigrationException
035    {
036        StringBuilder message = new StringBuilder();
037        message.append("ACTION: '");
038        message.append(actionData.getVersionNumber());
039        message.append("'/'");
040        message.append(actionData.getVersion().getComponentId());
041        message.append("' for version '");
042        message.append(actionData.getVersion().getVersionNumber());
043        message.append("' was not done automatically. [");
044        message.append(((ManualActionData) actionData).getComment());
045        message.append("]");
046        throw new MigrationException(message.toString());
047    }
048
049    @Override
050    public ActionData generateActionData(String versionNumber, Version version, String comment, String from, String type, String pluginName, Configuration configuration) throws MigrationException, ConfigurationException
051    {
052        return new ManualActionData(versionNumber, version, comment, from, type, pluginName, configuration);
053    }
054}