001/*
002 * (C) Copyright 2006-2010 Nuxeo SA (http://nuxeo.com/) and others.
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 *
016 * Contributors:
017 *     Dragos Mihalache
018 *     Florent Guillaume
019 */
020
021package org.nuxeo.ecm.platform.versioning.api;
022
023import java.io.Serializable;
024
025import org.nuxeo.ecm.core.api.VersioningOption;
026import org.nuxeo.ecm.core.api.facet.VersioningDocument;
027
028/**
029 * Defines actions to be taken in a document versioning increment process.
030 * <p>
031 * Used by UI.
032 */
033public enum VersioningActions implements Serializable {
034
035    ACTION_NO_INCREMENT("no_inc", VersioningOption.NONE), //
036    ACTION_INCREMENT_MINOR("inc_minor", VersioningOption.MINOR), //
037    ACTION_INCREMENT_MAJOR("inc_major", VersioningOption.MAJOR);
038
039    public static final String KEY_FOR_INC_OPTION = VersioningDocument.KEY_FOR_INC_OPTION;
040
041    /**
042     * @deprecated use {@link org.nuxeo.ecm.core.versioning.VersioningService#SKIP_VERSIONING} instead
043     */
044    @Deprecated
045    public static final String SKIP_VERSIONING = "SKIP_VERSIONING";
046
047    private final String name;
048
049    /**
050     * Equivalent core increment option.
051     *
052     * @since 5.7.3
053     */
054    private final VersioningOption vo;
055
056    VersioningActions(String name, VersioningOption vo) {
057        this.name = name;
058        this.vo = vo;
059    }
060
061    @Override
062    public String toString() {
063        return name;
064    }
065
066    public VersioningOption getVersioningOption() {
067        return vo;
068    }
069
070    public static VersioningActions getByActionName(String actionName) {
071        for (VersioningActions va : VersioningActions.values()) {
072            if (va.toString().equals(actionName)) {
073                return va;
074            }
075        }
076        return null;
077    }
078
079    /**
080     * Returns the corresponding core versioning option for this UI versioning action.
081     *
082     * @since 5.7.3
083     */
084    public static VersioningActions getByVersioningOption(VersioningOption vo) {
085        for (VersioningActions va : VersioningActions.values()) {
086            if (va.getVersioningOption().equals(vo)) {
087                return va;
088            }
089        }
090        return null;
091    }
092
093}