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.plugins.repository.migration.jcr.data;
017
018import org.ametys.core.migration.action.data.ActionData;
019import org.ametys.core.migration.handler.VersionHandler;
020import org.ametys.core.migration.version.AbstractVersion;
021import org.ametys.core.migration.version.Version;
022import org.ametys.plugins.repository.migration.jcr.data.repository.VersionAmetysObject;
023
024/**
025 * Implementation of {@link Version} for JCR data.
026 */
027public class JcrDataVersion extends AbstractVersion
028{
029    /** Version Ametys object */
030    protected VersionAmetysObject _versionAO;
031    
032    /**
033     * Constructor.
034     * @param versionHandlerId id of the {@link VersionHandler}
035     * @param componentId the component identifier
036     */
037    public JcrDataVersion(String versionHandlerId, String componentId)
038    {
039        super(versionHandlerId, componentId);
040        _versionAO = null;
041    }
042    
043    /**
044     * Constructor.
045     * The data are builded from the parameter versionAO.
046     * @param versionHandlerId id of the {@link VersionHandler}
047     * @param versionAO the version Ametys object
048     */
049    public JcrDataVersion(String versionHandlerId, VersionAmetysObject versionAO)
050    {
051        super(versionHandlerId, versionAO.getComponentId(), versionAO.getVersionNumber(), versionAO.getExecutionDate().toInstant(), versionAO.getComment());
052        _versionAO = versionAO;
053    }
054
055    /**
056     * Create a version from the data of an {@link ActionData} and its associated version.
057     * @param actionData The action data
058     */
059    protected JcrDataVersion(ActionData actionData)
060    {
061        super(actionData);
062        _versionAO = null;
063    }
064    
065    /**
066     * Get the version Ametys object
067     * @return the version Ametys object
068     */
069    public VersionAmetysObject getAmetysObject()
070    {
071        return _versionAO;
072    }
073    
074    /**
075     * Set the version Ametys object
076     * @param versionAO the version Ametys object
077     */
078    public void setAmetysObject(VersionAmetysObject versionAO)
079    {
080        setVersionNumber(versionAO.getVersionNumber());
081        setExecutionInstant(versionAO.getExecutionDate().toInstant());
082        setComment(versionAO.getComment());
083        _versionAO = versionAO;
084    }
085
086    @Override
087    public Version copyFromActionData(ActionData actionData)
088    {
089        return new JcrDataVersion(actionData);
090    }
091}