001/* 002 * (C) Copyright 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 * Kevin Leturc 018 */ 019package org.nuxeo.ecm.core.versioning; 020 021import java.util.ArrayList; 022import java.util.LinkedList; 023import java.util.List; 024 025import org.nuxeo.common.xmap.annotation.XNode; 026import org.nuxeo.common.xmap.annotation.XNodeList; 027import org.nuxeo.common.xmap.annotation.XObject; 028import org.nuxeo.ecm.core.api.VersioningOption; 029 030/** 031 * Descriptor used to restrict versioning options for a given lifeCycleState 032 * 033 * @since 9.1 034 */ 035@XObject("options") 036public class VersioningRestrictionOptionsDescriptor { 037 038 @XNode("@lifeCycleState") 039 protected String lifeCycleState; 040 041 @XNodeList(value = "option", componentType = OptionDescriptor.class, type = ArrayList.class) 042 protected List<OptionDescriptor> optionDescriptors; 043 044 public String getLifeCycleState() { 045 return lifeCycleState; 046 } 047 048 public List<VersioningOption> getOptions() { 049 List<VersioningOption> options = new LinkedList<>(); 050 for (OptionDescriptor optionDescriptor : optionDescriptors) { 051 if (optionDescriptor.defaultOpt) { 052 options.add(0, optionDescriptor.option); 053 } else { 054 options.add(optionDescriptor.option); 055 } 056 } 057 return options; 058 } 059 060 @XObject("option") 061 protected static class OptionDescriptor { 062 063 @XNode("@default") 064 protected boolean defaultOpt; 065 066 @XNode 067 protected VersioningOption option; 068 069 } 070 071}