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.version.Version;
023
024/**
025 * Data for a java upgrade
026 */
027public class JavaActionData extends AbstractActionData
028{
029    
030    private String _role;
031    
032    /**
033     * Create the Upgrade based on the upgrade xml line
034     * Must contains id and type, plus a script or the file where to get the script
035     * May contain restartAfter, component and/or file
036     * @param id id of the action
037     * @param version version concerned by this upgrade
038     * @param comment The comment about this action
039     * @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
040     * @param type type of action
041     * @param pluginName name of the plugin
042     * @param configuration the extension upgrade line to add
043     * @param restartRequired true if a restart is required after the action
044     * @throws ConfigurationException something is missing
045     */
046    public JavaActionData(String id, Version version, String comment, String from, String type, String pluginName, Configuration configuration, boolean restartRequired) throws ConfigurationException
047    {
048        super(id, version, comment, from, type, pluginName, configuration, restartRequired);
049        _role = configuration.getAttribute("role", null);
050        if (StringUtils.isBlank(_role))
051        {
052            throw new ConfigurationException("The attribute 'role' is missing to declare the component to use for this migration", configuration);
053        }
054    }
055
056    /**
057     * Get the role of the component to call
058     * @return The role of the component to call
059     */
060    public String getRole()
061    {
062        return _role;
063    }
064    
065    @Override
066    public String toString()
067    {
068        String result = super.toString();
069
070        result += " role : '" + _role + "'";
071        
072        return result;
073    }
074}