001/**
002 * Copyright 2005-2018 The Kuali Foundation
003 *
004 * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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 */
016package org.kuali.rice.kew.api.doctype;
017
018import org.apache.commons.lang.StringUtils;
019import org.kuali.rice.core.api.CoreConstants;
020import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
021import org.kuali.rice.core.api.mo.ModelBuilder;
022import org.kuali.rice.core.api.util.collect.CollectionUtils;
023import org.w3c.dom.Element;
024
025import javax.xml.bind.annotation.XmlAccessType;
026import javax.xml.bind.annotation.XmlAccessorType;
027import javax.xml.bind.annotation.XmlAnyElement;
028import javax.xml.bind.annotation.XmlElement;
029import javax.xml.bind.annotation.XmlElementWrapper;
030import javax.xml.bind.annotation.XmlRootElement;
031import javax.xml.bind.annotation.XmlType;
032import java.io.Serializable;
033import java.util.ArrayList;
034import java.util.Collection;
035import java.util.List;
036
037@XmlRootElement(name = RouteNode.Constants.ROOT_ELEMENT_NAME)
038@XmlAccessorType(XmlAccessType.NONE)
039@XmlType(name = RouteNode.Constants.TYPE_NAME, propOrder = {
040        RouteNode.Elements.ID,
041        RouteNode.Elements.DOCUMENT_TYPE_ID,
042        RouteNode.Elements.NAME,
043        RouteNode.Elements.ROUTE_METHOD_NAME,
044        RouteNode.Elements.ROUTE_METHOD_CODE,
045        RouteNode.Elements.FINAL_APPROVAL,
046        RouteNode.Elements.MANDATORY,
047        RouteNode.Elements.ACTIVATION_TYPE,
048        RouteNode.Elements.EXCEPTION_GROUP_ID,
049        RouteNode.Elements.TYPE,
050        RouteNode.Elements.BRANCH_NAME,
051        RouteNode.Elements.NEXT_DOCUMENT_STATUS,
052        RouteNode.Elements.CONFIGURATION_PARAMETERS,
053        RouteNode.Elements.PREVIOUS_NODE_IDS,
054        RouteNode.Elements.NEXT_NODE_IDS,
055        CoreConstants.CommonElements.VERSION_NUMBER,
056        CoreConstants.CommonElements.FUTURE_ELEMENTS
057})
058public final class RouteNode extends AbstractDataTransferObject implements RouteNodeContract {
059
060    private static final long serialVersionUID = -1756380702013287285L;
061
062    @XmlElement(name = Elements.ID, required = false)
063    private final String id;
064
065    @XmlElement(name = Elements.DOCUMENT_TYPE_ID, required = false)
066    private final String documentTypeId;
067
068    @XmlElement(name = Elements.NAME, required = true)
069    private final String name;
070
071    @XmlElement(name = Elements.ROUTE_METHOD_NAME, required = false)
072    private final String routeMethodName;
073
074    @XmlElement(name = Elements.ROUTE_METHOD_CODE, required = false)
075    private final String routeMethodCode;
076
077    @XmlElement(name = Elements.FINAL_APPROVAL, required = false)
078    private final boolean finalApproval;
079
080    @XmlElement(name = Elements.MANDATORY, required = false)
081    private final boolean mandatory;
082
083    @XmlElement(name = Elements.ACTIVATION_TYPE, required = false)
084    private final String activationType;
085
086    @XmlElement(name = Elements.EXCEPTION_GROUP_ID, required = false)
087    private final String exceptionGroupId;
088
089    @XmlElement(name = Elements.TYPE, required = true)
090    private final String type;
091
092    @XmlElement(name = Elements.BRANCH_NAME, required = false)
093    private final String branchName;
094    
095    @XmlElement(name = Elements.NEXT_DOCUMENT_STATUS, required = false)
096    private final String nextDocumentStatus;
097    
098    @XmlElementWrapper(name = Elements.CONFIGURATION_PARAMETERS, required = false)
099    @XmlElement(name = Elements.CONFIGURATION_PARAMETER, required = false)
100    private final List<RouteNodeConfigurationParameter> configurationParameters;
101
102    @XmlElementWrapper(name = Elements.PREVIOUS_NODE_IDS, required = false)
103    @XmlElement(name = Elements.PREVIOUS_NODE_ID, required = false)
104    private final List<String> previousNodeIds;
105
106    @XmlElementWrapper(name = Elements.NEXT_NODE_IDS, required = false)
107    @XmlElement(name = Elements.NEXT_NODE_ID, required = false)
108    private final List<String> nextNodeIds;
109    
110    @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
111    private final Long versionNumber;
112
113    @SuppressWarnings("unused")
114    @XmlAnyElement
115    private final Collection<Element> _futureElements = null;
116
117    /**
118     * Private constructor used only by JAXB.
119     */
120    private RouteNode() {
121        this.id = null;
122        this.documentTypeId = null;
123        this.name = null;
124        this.routeMethodName = null;
125        this.routeMethodCode = null;
126        this.finalApproval = false;
127        this.mandatory = false;
128        this.activationType = null;
129        this.exceptionGroupId = null;
130        this.type = null;
131        this.branchName = null;
132        this.nextDocumentStatus = null;
133        this.configurationParameters = null;
134        this.previousNodeIds = null;
135        this.nextNodeIds = null;
136        this.versionNumber = null;
137    }
138
139    private RouteNode(Builder builder) {
140        this.id = builder.getId();
141        this.documentTypeId = builder.getDocumentTypeId();
142        this.name = builder.getName();
143        this.routeMethodName = builder.getRouteMethodName();
144        this.routeMethodCode = builder.getRouteMethodCode();
145        this.finalApproval = builder.isFinalApproval();
146        this.mandatory = builder.isMandatory();
147        this.activationType = builder.getActivationType();
148        this.exceptionGroupId = builder.getExceptionGroupId();
149        this.type = builder.getType();
150        this.branchName = builder.getBranchName();
151        this.nextDocumentStatus = builder.getNextDocumentStatus();
152        this.configurationParameters = new ArrayList<RouteNodeConfigurationParameter>();
153        if (builder.getConfigurationParameters() != null) {
154            for (RouteNodeConfigurationParameter.Builder configurationParameter : builder.getConfigurationParameters()) {
155                this.configurationParameters.add(configurationParameter.build());
156            }
157        }
158        this.previousNodeIds = new ArrayList<String>(builder.getPreviousNodeIds());
159        this.nextNodeIds = new ArrayList<String>(builder.getNextNodeIds());
160        this.versionNumber = builder.getVersionNumber();
161    }
162
163    @Override
164    public String getId() {
165        return this.id;
166    }
167
168    @Override
169    public String getName() {
170        return this.name;
171    }
172
173    @Override
174    public String getDocumentTypeId() {
175        return this.documentTypeId;
176    }
177
178    @Override
179    public String getRouteMethodName() {
180        return this.routeMethodName;
181    }
182
183    @Override
184    public String getRouteMethodCode() {
185        return this.routeMethodCode;
186    }
187
188    @Override
189    public boolean isFinalApproval() {
190        return this.finalApproval;
191    }
192
193    @Override
194    public boolean isMandatory() {
195        return this.mandatory;
196    }
197
198    @Override
199    public String getActivationType() {
200        return this.activationType;
201    }
202
203    @Override
204    public String getExceptionGroupId() {
205        return this.exceptionGroupId;
206    }
207
208    @Override
209    public String getType() {
210        return this.type;
211    }
212
213    @Override
214    public String getBranchName() {
215        return this.branchName;
216    }
217
218    @Override
219    public String getNextDocumentStatus() {
220        return this.nextDocumentStatus;
221    }
222
223    @Override
224    public List<RouteNodeConfigurationParameter> getConfigurationParameters() {
225        return CollectionUtils.unmodifiableListNullSafe(this.configurationParameters);
226    }
227
228    @Override
229    public List<String> getPreviousNodeIds() {
230        return CollectionUtils.unmodifiableListNullSafe(this.previousNodeIds);
231    }
232
233    @Override
234    public List<String> getNextNodeIds() {
235        return CollectionUtils.unmodifiableListNullSafe(this.nextNodeIds);
236    }
237
238    @Override
239    public Long getVersionNumber() {
240        return this.versionNumber;
241    }
242
243    /**
244     * A builder which can be used to construct {@link RouteNode} instances. Enforces the
245     * constraints of the {@link RouteNodeContract}.
246     */
247    public final static class Builder implements Serializable, ModelBuilder, RouteNodeContract {
248
249        private static final long serialVersionUID = 7076065049417371344L;
250        private String id;
251        private String documentTypeId;
252        private String name;
253        private String routeMethodName;
254        private String routeMethodCode;
255        private boolean finalApproval;
256        private boolean mandatory;
257        private String activationType;
258        private String exceptionGroupId;
259        private String type;
260        private String branchName;
261        private String nextDocumentStatus;
262        private List<RouteNodeConfigurationParameter.Builder> configurationParameters;
263        private List<String> previousNodeIds;
264        private List<String> nextNodeIds;
265        private Long versionNumber;
266
267        private Builder(String name, String type) {
268            setName(name);
269            setType(type);
270            setConfigurationParameters(new ArrayList<RouteNodeConfigurationParameter.Builder>());
271            setPreviousNodeIds(new ArrayList<String>());
272            setNextNodeIds(new ArrayList<String>());
273        }
274
275        public static Builder create(String name, String type) {
276            return new Builder(name, type);
277        }
278
279        public static Builder create(RouteNodeContract contract) {
280            if (contract == null) {
281                throw new IllegalArgumentException("contract was null");
282            }
283            Builder builder = create(contract.getName(), contract.getType());
284            builder.setId(contract.getId());
285            builder.setDocumentTypeId(contract.getDocumentTypeId());
286            builder.setName(contract.getName());
287            builder.setRouteMethodName(contract.getRouteMethodName());
288            builder.setRouteMethodCode(contract.getRouteMethodCode());
289            builder.setFinalApproval(contract.isFinalApproval());
290            builder.setMandatory(contract.isMandatory());
291            builder.setActivationType(contract.getActivationType());
292            builder.setExceptionGroupId(contract.getExceptionGroupId());
293            builder.setType(contract.getType());
294            builder.setBranchName(contract.getBranchName());
295            builder.setNextDocumentStatus(contract.getNextDocumentStatus());
296            List<RouteNodeConfigurationParameter.Builder> parameterBuilders = new ArrayList<RouteNodeConfigurationParameter.Builder>();
297            for (RouteNodeConfigurationParameterContract configurationParameter : contract.getConfigurationParameters()) {
298                parameterBuilders.add(RouteNodeConfigurationParameter.Builder.create(configurationParameter));
299            }
300            builder.setConfigurationParameters(parameterBuilders);
301            builder.setPreviousNodeIds(contract.getPreviousNodeIds());
302            builder.setNextNodeIds(contract.getNextNodeIds());
303            builder.setVersionNumber(contract.getVersionNumber());
304            
305            return builder;
306        }
307
308        public RouteNode build() {
309            return new RouteNode(this);
310        }
311        
312        @Override
313        public String getId() {
314            return this.id;
315        }
316
317        @Override
318        public String getDocumentTypeId() {
319            return this.documentTypeId;
320        }
321
322        @Override
323        public String getName() {
324            return this.name;
325        }
326
327        @Override
328        public String getRouteMethodName() {
329            return this.routeMethodName;
330        }
331
332        @Override
333        public String getRouteMethodCode() {
334            return this.routeMethodCode;
335        }
336
337        @Override
338        public boolean isFinalApproval() {
339            return this.finalApproval;
340        }
341
342        @Override
343        public boolean isMandatory() {
344            return this.mandatory;
345        }
346
347        @Override
348        public String getActivationType() {
349            return this.activationType;
350        }
351
352        @Override
353        public String getExceptionGroupId() {
354            return this.exceptionGroupId;
355        }
356
357        @Override
358        public String getType() {
359            return this.type;
360        }
361
362        @Override
363        public String getBranchName() {
364            return this.branchName;
365        }
366
367        @Override
368        public String getNextDocumentStatus() {
369            return this.nextDocumentStatus;
370        }
371
372        @Override
373        public List<RouteNodeConfigurationParameter.Builder> getConfigurationParameters() {
374            return this.configurationParameters;
375        }
376
377        @Override
378        public List<String> getPreviousNodeIds() {
379            return this.previousNodeIds;
380        }
381
382        @Override
383        public List<String> getNextNodeIds() {
384            return this.nextNodeIds;
385        }
386        
387        @Override
388        public Long getVersionNumber() {
389            return this.versionNumber;
390        }
391        
392        public void setId(String id) {
393            this.id = id;
394        }
395
396        public void setDocumentTypeId(String documentTypeId) {
397            this.documentTypeId = documentTypeId;
398        }
399        
400        public void setName(String name) {
401            if (StringUtils.isBlank(name)) {
402                throw new IllegalArgumentException("name was null or blank");
403            }
404            this.name = name;
405        }
406
407        public void setRouteMethodName(String routeMethodName) {
408            this.routeMethodName = routeMethodName;
409        }
410
411        public void setRouteMethodCode(String routeMethodCode) {
412            this.routeMethodCode = routeMethodCode;
413        }
414
415        public void setFinalApproval(boolean finalApproval) {
416            this.finalApproval = finalApproval;
417        }
418
419        public void setMandatory(boolean mandatory) {
420            this.mandatory = mandatory;
421        }
422
423        public void setActivationType(String activationType) {
424            this.activationType = activationType;
425        }
426
427        public void setExceptionGroupId(String exceptionGroupId) {
428            this.exceptionGroupId = exceptionGroupId;
429        }
430        
431        public void setType(String type) {
432            if (StringUtils.isBlank(type)) {
433                throw new IllegalArgumentException("type was null or blank");
434            }
435            this.type = type;
436        }
437
438        public void setBranchName(String branchName) {
439            this.branchName = branchName;
440        }
441        
442        public void setNextDocumentStatus(String nextDocumentStatus) {
443            this.nextDocumentStatus = nextDocumentStatus;
444        }
445        
446        public void setConfigurationParameters(List<RouteNodeConfigurationParameter.Builder> configurationParameters) {
447            if (configurationParameters == null) {
448                throw new IllegalArgumentException("configurationParameters was null");
449            }
450            this.configurationParameters = configurationParameters;
451        }
452
453        public void setPreviousNodeIds(List<String> previousNodeIds) {
454            if (previousNodeIds == null) {
455                throw new IllegalArgumentException("previousNodeIds was null");
456            }
457            this.previousNodeIds = previousNodeIds;
458        }
459
460        public void setNextNodeIds(List<String> nextNodeIds) {
461            if (nextNodeIds == null) {
462                throw new IllegalArgumentException("nextNodeIds was null");
463            }
464            this.nextNodeIds = nextNodeIds;
465        }
466        
467        public void setVersionNumber(Long versionNumber) {
468            this.versionNumber = versionNumber;
469        }
470
471    }
472
473    /**
474     * Defines some internal constants used on this class.
475     */
476    static class Constants {
477        final static String ROOT_ELEMENT_NAME = "routeNode";
478        final static String TYPE_NAME = "RouteNodeType";
479    }
480
481    /**
482     * A private class which exposes constants which define the XML element names to use when this
483     * object is marshalled to XML.
484     */
485    static class Elements {
486        final static String ID = "id";
487        final static String DOCUMENT_TYPE_ID = "documentTypeId";
488        final static String NAME = "name";
489        final static String ROUTE_METHOD_NAME = "routeMethodName";
490        final static String ROUTE_METHOD_CODE = "routeMethodCode";
491        final static String FINAL_APPROVAL = "finalApproval";
492        final static String MANDATORY = "mandatory";
493        final static String ACTIVATION_TYPE = "activationType";
494        final static String EXCEPTION_GROUP_ID = "exceptionGroupId";
495        final static String TYPE = "type";
496        final static String BRANCH_NAME = "branchName";
497        final static String NEXT_DOCUMENT_STATUS = "nextDocumentStatus";
498        final static String CONFIGURATION_PARAMETERS = "configurationParameters";
499        final static String CONFIGURATION_PARAMETER = "configurationParameter";
500        final static String PREVIOUS_NODE_IDS = "previousNodeIds";
501        final static String PREVIOUS_NODE_ID = "previousNodeId";
502        final static String NEXT_NODE_IDS = "nextNodeIds";
503        final static String NEXT_NODE_ID = "nextNodeId";
504    }
505
506}