update testH2 in vaadin
[cdm-vaadin.git] / src / main / java / eu / etaxonomy / cdm / vaadin / model / name / NomenclaturalStatusDTO.java
1 /**
2 * Copyright (C) 2020 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.cdm.vaadin.model.name;
10
11 import java.io.Serializable;
12
13 import eu.etaxonomy.cdm.model.name.NomenclaturalCodeEdition;
14 import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
15 import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
16 import eu.etaxonomy.cdm.model.reference.NamedSource;
17 import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
18 import eu.etaxonomy.cdm.model.reference.Reference;
19
20 /**
21 * @author a.kohlbecker
22 * @since Sep 17, 2020
23 */
24 public class NomenclaturalStatusDTO implements Serializable {
25
26 private static final long serialVersionUID = -7019899466081978199L;
27
28 private Integer id = 0;
29
30 NomenclaturalStatusType type;
31
32 Reference citation;
33
34 NomenclaturalCodeEdition codeEdition;
35
36 String citationMicroReference;
37
38 String ruleConsidered;
39
40 public static NomenclaturalStatusDTO from(NomenclaturalStatus nomStatus) {
41 return new NomenclaturalStatusDTO(nomStatus.getId(), nomStatus.getType(), nomStatus.getCitation(),
42 nomStatus.getCitationMicroReference(), nomStatus.getRuleConsidered(), nomStatus.getCodeEdition());
43
44 }
45
46 public static NomenclaturalStatusDTO newInstance() {
47 return new NomenclaturalStatusDTO();
48 }
49
50
51 /**
52 * Update an existing or create a new {@link NomenclaturalStatus} for this
53 * DTO.
54 *
55 * @param nomStatus
56 * the {@link NomenclaturalStatus} to update or <code>null</code>
57 * in which case a new entity instance will be created.
58 * @return the new or updated entity
59 */
60 public NomenclaturalStatus update(NomenclaturalStatus nomStatus) {
61 if (nomStatus == null) {
62 nomStatus = NomenclaturalStatus.NewInstance(type);
63 } else {
64 nomStatus.setType(type);
65 }
66 nomStatus.setRuleConsidered(ruleConsidered);
67 if (citation != null || citationMicroReference != null) {
68 if (nomStatus.getSource() == null) {
69 // below line as in
70 // DescriptionElementSource.NewInstance(OriginalSourceType.PrimaryTaxonomicSource)
71 nomStatus.setSource(NamedSource.NewInstance(OriginalSourceType.PrimaryTaxonomicSource));
72 }
73 nomStatus.getSource().setCitation(citation);
74 nomStatus.getSource().setCitationMicroReference(citationMicroReference);
75 }
76 nomStatus.setCodeEdition(codeEdition);
77 return nomStatus;
78
79 }
80
81 public NomenclaturalStatusDTO(Integer id, NomenclaturalStatusType type, Reference citation,
82 String citationMicroReference, String ruleConsidered, NomenclaturalCodeEdition codeEdition) {
83 this.id = id;
84 this.type = type;
85 this.citation = citation;
86 this.citationMicroReference = citationMicroReference;
87 this.ruleConsidered = ruleConsidered;
88 this.codeEdition = codeEdition;
89 }
90
91 /**
92 *
93 */
94 public NomenclaturalStatusDTO() {
95 // TODO Auto-generated constructor stub
96 }
97
98 public NomenclaturalStatusType getType() {
99 return type;
100 }
101
102 public void setType(NomenclaturalStatusType type) {
103 this.type = type;
104 }
105
106 public Reference getCitation() {
107 return citation;
108 }
109
110 public void setCitation(Reference citation) {
111 this.citation = citation;
112 }
113
114 public String getCitationMicroReference() {
115 return citationMicroReference;
116 }
117
118 public NomenclaturalCodeEdition getCodeEdition() {
119 return codeEdition;
120 }
121
122 public void setCodeEdition(NomenclaturalCodeEdition codeEdition) {
123 this.codeEdition = codeEdition;
124 }
125
126 public void setCitationMicroReference(String citationMicroReference) {
127 this.citationMicroReference = citationMicroReference;
128 }
129
130 public String getRuleConsidered() {
131 return ruleConsidered;
132 }
133
134 public void setRuleConsidered(String ruleConsidered) {
135 this.ruleConsidered = ruleConsidered;
136 }
137
138 /**
139 * The {@link NomenclaturalStatus#getId()} of the original status entity for
140 * which this DTO has been created.
141 * <p>
142 * When the DTO has no corresponding entity in the db the id has the value
143 * of <code>0</code>
144 */
145 public Integer getId() {
146 return id;
147 }
148 }