001/*
002 * (C) Copyright 2006-2017 Nuxeo (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 *     Laurent Doguin
018 */
019package org.nuxeo.ecm.core.versioning;
020
021import static org.nuxeo.ecm.core.api.VersioningOption.MAJOR;
022import static org.nuxeo.ecm.core.api.VersioningOption.MINOR;
023import static org.nuxeo.ecm.core.api.VersioningOption.NONE;
024
025import java.io.Serializable;
026import java.util.ArrayList;
027import java.util.LinkedList;
028import java.util.List;
029
030import org.nuxeo.common.xmap.annotation.XNode;
031import org.nuxeo.common.xmap.annotation.XObject;
032import org.nuxeo.ecm.core.api.VersioningOption;
033
034/**
035 * Descriptor to contribute incrementation options.
036 *
037 * @author Laurent Doguin
038 * @since 5.4.2
039 * @deprecated since 9.1 use 'policy', 'filter' and 'restriction' contributions instead
040 */
041@Deprecated
042@XObject("options")
043public class SaveOptionsDescriptor implements Serializable {
044
045    private static final long serialVersionUID = 1L;
046
047    @XNode("@lifeCycleState")
048    private String lifeCycleState;
049
050    @XNode("none")
051    protected OptionDescriptor none;
052
053    @XNode("minor")
054    protected OptionDescriptor minor;
055
056    @XNode("major")
057    protected OptionDescriptor major;
058
059    public String getLifeCycleState() {
060        return lifeCycleState;
061    }
062
063    public List<VersioningOption> getVersioningOptionList() {
064        List<VersioningOption> opts = new LinkedList<>();
065        if (none != null) {
066            if (none.isDefault()) {
067                opts.add(0, NONE);
068            } else {
069                opts.add(NONE);
070            }
071        }
072        if (minor != null) {
073            if (minor.isDefault()) {
074                opts.add(0, MINOR);
075            } else {
076                opts.add(MINOR);
077            }
078        }
079        if (major != null) {
080            if (major.isDefault()) {
081                opts.add(0, MAJOR);
082            } else {
083                opts.add(MAJOR);
084            }
085        }
086        return opts;
087    }
088
089    /**
090     * @return the equivalent {@link VersioningRestrictionOptionsDescriptor}
091     * @since 9.1
092     */
093    public VersioningRestrictionOptionsDescriptor toRestrictionOptions() {
094        VersioningRestrictionOptionsDescriptor restrictionOption = new VersioningRestrictionOptionsDescriptor();
095        restrictionOption.lifeCycleState = lifeCycleState;
096        restrictionOption.optionDescriptors = new ArrayList<>();
097
098        VersioningRestrictionOptionsDescriptor.OptionDescriptor option;
099        if (none != null) {
100            option = new VersioningRestrictionOptionsDescriptor.OptionDescriptor();
101            option.defaultOpt = none.isDefault();
102            option.option = VersioningOption.NONE;
103            restrictionOption.optionDescriptors.add(option);
104        }
105        if (minor != null) {
106            option = new VersioningRestrictionOptionsDescriptor.OptionDescriptor();
107            option.defaultOpt = minor.isDefault();
108            option.option = VersioningOption.MINOR;
109            restrictionOption.optionDescriptors.add(option);
110        }
111        if (major != null) {
112            option = new VersioningRestrictionOptionsDescriptor.OptionDescriptor();
113            option.defaultOpt = major.isDefault();
114            option.option = VersioningOption.MAJOR;
115            restrictionOption.optionDescriptors.add(option);
116        }
117        return restrictionOption;
118    }
119
120}