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 *     Florent Guillaume
018 */
019package org.nuxeo.runtime.migration;
020
021import java.util.LinkedHashMap;
022import java.util.Map;
023
024import org.nuxeo.common.xmap.annotation.XNode;
025import org.nuxeo.common.xmap.annotation.XNodeMap;
026import org.nuxeo.common.xmap.annotation.XObject;
027
028/**
029 * Descriptor of a Migration, consisting of States and Steps.
030 *
031 * @since 9.3
032 */
033@XObject("migration")
034public class MigrationDescriptor {
035
036    @XObject("state")
037    public static class MigrationStateDescriptor {
038
039        @XNode("@id")
040        public String id;
041
042        @XNode("description@label")
043        public String descriptionLabel;
044
045        @XNode("description")
046        public String description;
047
048        public String getId() {
049            return id;
050        }
051
052        public String getDescriptionLabel() {
053            return descriptionLabel;
054        }
055
056        public String getDescription() {
057            return description;
058        }
059    }
060
061    @XObject("step")
062    public static class MigrationStepDescriptor {
063
064        @XNode("@id")
065        public String id;
066
067        @XNode("@fromState")
068        public String fromState;
069
070        @XNode("@toState")
071        public String toState;
072
073        @XNode("description@label")
074        public String descriptionLabel;
075
076        @XNode("description")
077        public String description;
078
079        @XNode("class")
080        public Class<?> klass;
081
082        public String getId() {
083            return id;
084        }
085
086        public String getFromState() {
087            return fromState;
088        }
089
090        public String getToState() {
091            return toState;
092        }
093
094        public String getDescriptionLabel() {
095            return descriptionLabel;
096        }
097
098        public String getDescription() {
099            return description;
100        }
101
102        public Class<?> getKlass() {
103            return klass;
104        }
105    }
106
107    @XNode("@id")
108    public String id;
109
110    @XNode("description@label")
111    public String descriptionLabel;
112
113    @XNode("description")
114    public String description;
115
116    @XNode("statusChangeNotifier")
117    public Class<?> statusChangeNotifierClass;
118
119    @XNode("defaultState")
120    public String defaultState;
121
122    @XNodeMap(value = "state", key = "@id", type = LinkedHashMap.class, componentType = MigrationStateDescriptor.class)
123    public Map<String, MigrationStateDescriptor> states = new LinkedHashMap<>();
124
125    @XNodeMap(value = "step", key = "@id", type = LinkedHashMap.class, componentType = MigrationStepDescriptor.class)
126    public Map<String, MigrationStepDescriptor> steps = new LinkedHashMap<>();
127
128    public String getId() {
129        return id;
130    }
131
132    public String getDescriptionLabel() {
133        return descriptionLabel;
134    }
135
136    public String getDescription() {
137        return description;
138    }
139
140    public Class<?> getStatusChangeNotifierClass() {
141        return statusChangeNotifierClass;
142    }
143
144    public String getDefaultState() {
145        return defaultState;
146    }
147
148    public Map<String, MigrationStateDescriptor> getStates() {
149        return states;
150    }
151
152    public Map<String, MigrationStepDescriptor> getSteps() {
153        return steps;
154    }
155
156    /** Default constructor. */
157    public MigrationDescriptor() {
158    }
159
160    /** Copy constructor. */
161    public MigrationDescriptor(MigrationDescriptor other) {
162        id = other.id;
163        descriptionLabel = other.descriptionLabel;
164        statusChangeNotifierClass = other.statusChangeNotifierClass;
165        description = other.description;
166        defaultState = other.defaultState;
167        states = new LinkedHashMap<>(other.states);
168        steps = new LinkedHashMap<>(other.steps);
169    }
170
171    /** Merge. */
172    public void merge(MigrationDescriptor other) {
173        if (other.descriptionLabel != null) {
174            descriptionLabel = other.descriptionLabel;
175        }
176        if (other.description != null) {
177            description = other.description;
178        }
179        if (other.statusChangeNotifierClass != null) {
180            statusChangeNotifierClass = other.statusChangeNotifierClass;
181        }
182        if (other.defaultState != null) {
183            defaultState = other.defaultState;
184        }
185        states.putAll(other.states);
186        steps.putAll(other.steps);
187    }
188
189}