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.handler;
017
018import java.util.List;
019
020import org.apache.avalon.framework.configuration.Configuration;
021import org.apache.avalon.framework.configuration.ConfigurationException;
022
023import org.ametys.core.migration.MigrationException;
024import org.ametys.core.migration.NotMigrableInSafeModeException;
025import org.ametys.core.migration.configuration.VersionConfiguration;
026import org.ametys.core.migration.version.Version;
027
028/**
029 * Handler to get or set version
030 */
031public interface VersionHandler
032{
033    /**
034     * Create a specific object containing usefull data for the handler/storage
035     * @param componentId id of the component
036     * @param versionConfiguration configuration from the plugin.xml
037     * @return the confuguration object
038     * @throws ConfigurationException something wrong in the configuration
039     * @throws NotMigrableInSafeModeException Impossible to determine the version (e.g. Safe Mode without access to the conf)
040     */
041    VersionConfiguration getConfiguration(String componentId, Configuration versionConfiguration) throws ConfigurationException, NotMigrableInSafeModeException;
042    
043    /**
044     * Get the list of all curent versions for this component id based on the configuration
045     * 
046     * @param componentId id to check
047     * @param configuration configuration of this version
048     * @return a non-null list of {@link Version}. Can be an empty list if no version can be computed (e.g. configuration not filled). Beware, returning an empty list will not initialize the component ; to initialize a component, you need to return a list with a Version with null id.
049     * @throws MigrationException Something went wrong
050     * @throws NotMigrableInSafeModeException Impossible to determine the version (e.g. Safe Mode without access to the conf)
051     */
052    List<Version> getCurrentVersions(String componentId, VersionConfiguration configuration) throws MigrationException, NotMigrableInSafeModeException;
053
054    /**
055     * Adds a new version for a component
056     * @param newVersion Version to set
057     * @throws MigrationException Something went wrong
058     */
059    void addVersion(Version newVersion) throws MigrationException;
060}