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     * Is restart required after action
062     */
063    protected boolean _restartRequired;
064    
065    /**
066     * Create the Upgrade based on the upgrade xml line
067     * Must contains id and type
068     * May contain restartAfter, component and/or file
069     * @param versionNumber version number of the action
070     * @param version version concerned by this upgrade
071     * @param comment The comment about this action
072     * @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
073     * @param type type of action
074     * @param pluginName name of the plugin containing the extension
075     * @param configuration the extension upgrade line to add
076     * @param restartRequired true if a restart is required after the action
077     * @throws ConfigurationException id or type missing
078     */
079    protected AbstractActionData(String versionNumber, Version version, String comment, String from, String type, String pluginName, Configuration configuration, boolean restartRequired) throws ConfigurationException
080    {
081        _versionNumber = versionNumber;
082        _type = type;
083        _from = from;
084        _version = version;
085        _pluginName = pluginName;
086        _comment = comment;
087        _restartRequired = restartRequired;
088    }
089    
090    @Override
091    public String toString()
092    {
093        String log = "Upgrade '" + _versionNumber + "' of type '" + _type + "' for version: '" + _version.toString() + "'";
094        if (StringUtils.isNotBlank(_comment))
095        {
096            log += " (" + _comment + ")";
097        }
098        return log;
099    }
100
101    @Override
102    public String getVersionNumber()
103    {
104        return _versionNumber;
105    }
106
107    @Override
108    public String getType()
109    {
110        return _type;
111    }
112
113    @Override
114    public String getComment()
115    {
116        return _comment;
117    }
118
119    @Override
120    public String getFrom()
121    {
122        return _from;
123    }
124
125    @Override
126    public Version getVersion()
127    {
128        return _version;
129    }
130    
131    @Override
132    public String getPluginName()
133    {
134        return _pluginName;
135    }
136    
137    @Override
138    public boolean requiresRestart()
139    {
140        return _restartRequired;
141    }
142    
143    @Override
144    public void setRequiresRestart(boolean requiresRestart)
145    {
146        _restartRequired = requiresRestart;
147    }
148}