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.data.impl;
017
018import org.apache.avalon.framework.configuration.Configuration;
019import org.apache.avalon.framework.configuration.ConfigurationException;
020import org.apache.commons.lang3.StringUtils;
021
022import org.ametys.core.migration.action.data.ActionData;
023import org.ametys.core.migration.version.Version;
024
025/**
026 * Representation of an upgrade line in the extension
027 */
028public abstract class AbstractActionData implements ActionData
029{
030    /**
031     * number of the version created by this migration
032     */
033    protected String _versionNumber;
034    
035    /**
036     * Type of upgrade
037     */
038    protected String _type;
039    
040    /**
041     * Comment about the action
042     */
043    protected String _comment;
044    
045    /**
046     * When an upgrade contains multiple upgrades, this represent the 1st upgrade impacted
047     */
048    protected String _from;
049    
050    /**
051     * Version used to determine the list of remaining upgrades
052     */
053    protected Version _version;
054    
055    /**
056     * Plugin containing the extension
057     */
058    protected String _pluginName;
059    
060    /**
061     * Create the Upgrade based on the upgrade xml line
062     * Must contains id and type
063     * May contain restartAfter, component and/or file
064     * @param versionNumber version number of the action
065     * @param version version concerned by this upgrade
066     * @param comment The comment about this action
067     * @param from if this actions is the equivalent of multiple actions, this is the version id just before the 1st action impacted by this action
068     * @param type type of action
069     * @param pluginName name of the plugin containing the extension
070     * @param configuration the extension upgrade line to add
071     * @throws ConfigurationException id or type missing
072     */
073    protected AbstractActionData(String versionNumber, Version version, String comment, String from, String type, String pluginName, Configuration configuration) throws ConfigurationException
074    {
075        _versionNumber = versionNumber;
076        _type = type;
077        _from = from;
078        _version = version;
079        _pluginName = pluginName;
080        _comment = comment;
081    }
082    
083    @Override
084    public String toString()
085    {
086        String log = "Upgrade '" + _versionNumber + "' of type '" + _type + "' for version: '" + _version.toString() + "'";
087        if (StringUtils.isNotBlank(_comment))
088        {
089            log += " (" + _comment + ")";
090        }
091        return log;
092    }
093
094    @Override
095    public String getVersionNumber()
096    {
097        return _versionNumber;
098    }
099
100    @Override
101    public String getType()
102    {
103        return _type;
104    }
105
106    @Override
107    public String getComment()
108    {
109        return _comment;
110    }
111
112    @Override
113    public String getFrom()
114    {
115        return _from;
116    }
117
118    @Override
119    public Version getVersion()
120    {
121        return _version;
122    }
123    
124    @Override
125    public String getPluginName()
126    {
127        return _pluginName;
128    }
129}