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.storage;
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.handler.VersionHandler;
027import org.ametys.core.migration.version.Version;
028
029/**
030 * Store the versions of a migrable component
031 */
032public interface VersionStorage
033{
034    /**
035     * Create a specific object containing usefull data for the handler/storage
036     * @param componentId id of the component
037     * @param versionConfiguration configuration from the plugin.xml
038     * @return the confuguration object
039     * @throws ConfigurationException something wrong in the configuration
040     * @throws NotMigrableInSafeModeException Impossible to determine the version
041     */
042    VersionConfiguration getConfiguration(String componentId, Configuration versionConfiguration) throws ConfigurationException, NotMigrableInSafeModeException;
043    
044    /**
045     * Find the current version for a component identifier
046     * @param componentIdentifier component to look for
047     * @param configuration configuration to use
048     * @param versionHandlerId id of the {@link VersionHandler}
049     * @return the current version for this component (can have a versionId null if no version is found), or null if it is impossible to determine the version (e.g. safe mode).
050     * @throws MigrationException Something went wrong
051     * @throws NotMigrableInSafeModeException Impossible to determine the version
052     */
053    Version getCurrentVersion(String componentIdentifier, VersionConfiguration configuration, String versionHandlerId) throws MigrationException, NotMigrableInSafeModeException;   
054    
055    /**
056     * Get the history of all versions for a component identifier
057     * @param componentIdentifier component to look for
058     * @param configuration configuration to use
059     * @param versionHandlerId id of the {@link VersionHandler}
060     * @return list of all versions for this component
061     * @throws MigrationException Something went wrong
062     * @throws NotMigrableInSafeModeException Impossible to determine the version
063     */
064    List<Version> getAllVersions(String componentIdentifier, VersionConfiguration configuration, String versionHandlerId) throws MigrationException, NotMigrableInSafeModeException;   
065    
066    /**
067     * Add a version
068     * @param version Version to store (contains the component identifier)
069     * @throws MigrationException Something went wrong
070     */
071    void addVersion(Version version) throws MigrationException;
072    
073    /**
074     * Remove all versions for a component identifier
075     * @param componentIdentifier component to clear
076     * @param configuration configuration to use
077     * @throws MigrationException Something went wrong
078     */
079    void removeAllVersions(String componentIdentifier, VersionConfiguration configuration) throws MigrationException;  
080}