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 * Funsho David 018 * Kevin Leturc 019 */ 020package org.nuxeo.ecm.core.versioning; 021 022import java.util.ArrayList; 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 * @since 9.1 032 */ 033@XObject("policy") 034public class VersioningPolicyDescriptor implements Comparable<VersioningPolicyDescriptor> { 035 036 @XNode("@id") 037 protected String id; 038 039 @XNode("@order") 040 protected int order; 041 042 @XNode("@increment") 043 protected VersioningOption increment; 044 045 @XNode("@beforeUpdate") 046 protected boolean beforeUpdate; 047 048 @XNode("initialState") 049 protected InitialStateDescriptor initialState; 050 051 @XNodeList(value = "filter-id", componentType = String.class, type = ArrayList.class) 052 protected List<String> filterIds = new ArrayList<>(); 053 054 public String getId() { 055 return id; 056 } 057 058 public int getOrder() { 059 return order; 060 } 061 062 public VersioningOption getIncrement() { 063 return increment; 064 } 065 066 public boolean isBeforeUpdate() { 067 return beforeUpdate; 068 } 069 070 public InitialStateDescriptor getInitialState() { 071 return initialState; 072 } 073 074 public List<String> getFilterIds() { 075 return filterIds; 076 } 077 078 public void merge(VersioningPolicyDescriptor other) { 079 if (other.id != null) { 080 id = other.id; 081 } 082 order = other.order; 083 if (other.increment != null) { 084 increment = other.increment; 085 } 086 if (other.initialState != null) { 087 initialState = other.initialState; 088 } 089 filterIds.addAll(other.filterIds); 090 } 091 092 @Override 093 public int compareTo(VersioningPolicyDescriptor versioningPolicyDescriptor) { 094 return Integer.compare(order, versioningPolicyDescriptor.order); 095 } 096 097 @Override 098 public String toString() { 099 return getClass().getSimpleName() + '(' + id + ", increment=" + increment + ", beforeUpdate=" + beforeUpdate 100 + ')'; 101 } 102 103}