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 java.io.Serializable; 022import java.util.HashMap; 023import java.util.Map; 024 025import org.nuxeo.common.xmap.annotation.XNode; 026import org.nuxeo.common.xmap.annotation.XNodeMap; 027import org.nuxeo.common.xmap.annotation.XObject; 028 029/** 030 * Descriptor to contribute new versioning rules. 031 * 032 * @author Laurent Doguin 033 * @since 5.4.2 034 * @deprecated since 9.1 use 'policy', 'filter' and 'restriction' contributions instead 035 */ 036@Deprecated 037@XObject("versioningRule") 038public class VersioningRuleDescriptor implements Serializable { 039 040 private static final long serialVersionUID = 1L; 041 042 @XNode("@enabled") 043 protected Boolean enabled; 044 045 @XNodeMap(value = "options", key = "@lifeCycleState", type = HashMap.class, componentType = SaveOptionsDescriptor.class) 046 public Map<String, SaveOptionsDescriptor> options = new HashMap<>(); 047 048 @XNode("initialState") 049 public InitialStateDescriptor initialState; 050 051 @XNode("@typeName") 052 protected String typeName; 053 054 /** True if the boolean is null or TRUE, false otherwise. */ 055 private static boolean defaultTrue(Boolean bool) { 056 return !Boolean.FALSE.equals(bool); 057 } 058 059 public boolean isEnabled() { 060 return defaultTrue(enabled); 061 } 062 063 public String getTypeName() { 064 return typeName; 065 } 066 067 public Map<String, SaveOptionsDescriptor> getOptions() { 068 return options; 069 } 070 071 public InitialStateDescriptor getInitialState() { 072 return initialState; 073 } 074 075 /** Empty constructor. */ 076 public VersioningRuleDescriptor() { 077 } 078 079 /** Copy constructor. */ 080 public VersioningRuleDescriptor(VersioningRuleDescriptor other) { 081 this.enabled = other.enabled; 082 this.typeName = other.typeName; 083 this.options = other.options; 084 this.initialState = other.initialState; 085 } 086 087 public void merge(VersioningRuleDescriptor other) { 088 if (other.enabled != null) { 089 enabled = other.enabled; 090 } 091 if (other.typeName != null) { 092 typeName = other.typeName; 093 } 094 options.putAll(other.options); // always merge options TODO override flag 095 if (other.initialState != null) { 096 initialState = other.initialState; 097 } 098 } 099 100}