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