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