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.ArrayList;
019import java.util.Collections;
020import java.util.List;
021
022import org.apache.avalon.framework.configuration.Configuration;
023import org.apache.avalon.framework.configuration.ConfigurationException;
024
025import org.ametys.core.migration.MigrationException;
026import org.ametys.core.migration.NotMigrableInSafeModeException;
027import org.ametys.core.migration.configuration.VersionConfiguration;
028import org.ametys.core.migration.version.Version;
029
030/**
031 * Class for {@link VersionHandler} returning only one version.
032 */
033public class SingleVersionHandler extends AbstractVersionHandler
034{
035    @Override
036    public List<Version> getCurrentVersions(String componentId, VersionConfiguration configuration) throws MigrationException, NotMigrableInSafeModeException
037    {
038        getLogger().debug("Get versions for component id: " + componentId);
039        Version currentVersion = getVersionStorage().getCurrentVersion(componentId, configuration, _id);
040        if (currentVersion != null)
041        {
042            return Collections.singletonList(currentVersion);
043        }
044
045        return new ArrayList<>();
046    }
047
048    @Override
049    public VersionConfiguration getConfiguration(String componentId, Configuration versionConfiguration) throws ConfigurationException, NotMigrableInSafeModeException
050    {
051        getLogger().debug("Get configuration for component id: " + componentId);
052        return getVersionStorage().getConfiguration(componentId, versionConfiguration);
053    }
054}