1
|
/**
|
2
|
* Copyright (C) 2017 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.view.registration;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.HashSet;
|
13
|
import java.util.List;
|
14
|
import java.util.Set;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import org.joda.time.DateTime;
|
18
|
|
19
|
import eu.etaxonomy.cdm.mock.Registration;
|
20
|
import eu.etaxonomy.cdm.mock.RegistrationStatus;
|
21
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
22
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
23
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
24
|
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
|
25
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
26
|
import eu.etaxonomy.cdm.vaadin.util.converter.TypeDesignationConverter;
|
27
|
|
28
|
public class RegistrationDTO{
|
29
|
|
30
|
private String summary = "";
|
31
|
|
32
|
private String citationString = "";
|
33
|
|
34
|
private int citationID;
|
35
|
|
36
|
private RegistrationType registrationType;
|
37
|
|
38
|
private Registration reg;
|
39
|
|
40
|
private List<String> messages = new ArrayList<>();
|
41
|
|
42
|
private Set<Registration> blockedBy = new HashSet<>();
|
43
|
|
44
|
private TaxonNameBase<?, ?> typifiedName;
|
45
|
|
46
|
private TimePeriod datePublished;
|
47
|
|
48
|
/**
|
49
|
* @param reg
|
50
|
* @param typifiedName should be provided in for Registrations for TypeDesignations
|
51
|
*/
|
52
|
public RegistrationDTO(Registration reg) {
|
53
|
|
54
|
this.reg = reg;
|
55
|
|
56
|
registrationType = RegistrationType.from(reg);
|
57
|
if(registrationType.isName()){
|
58
|
summary = reg.getName().getTitleCache();
|
59
|
INomenclaturalReference citation = reg.getName().getNomenclaturalReference();
|
60
|
if(citation != null){
|
61
|
citationString = citation.generateTitle();
|
62
|
citationID = citation.getId();
|
63
|
datePublished = citation.getDatePublished();
|
64
|
}
|
65
|
} else if(registrationType.isTypification()){
|
66
|
try {
|
67
|
typifiedName = findTypifiedName();
|
68
|
} catch (RegistrationValidationException e) {
|
69
|
messages.add("Validation errors: " + e.getMessage());
|
70
|
}
|
71
|
summary = new TypeDesignationConverter(reg.getTypeDesignations(), typifiedName)
|
72
|
.buildString().print();
|
73
|
if(!reg.getTypeDesignations().isEmpty()){
|
74
|
Reference citation = reg.getTypeDesignations().iterator().next().getCitation();
|
75
|
if(citation != null) {
|
76
|
citationString = citation.generateTitle();
|
77
|
citationID = citation.getId();
|
78
|
}
|
79
|
}
|
80
|
} else {
|
81
|
summary = "- INVALID REGISTRATION -";
|
82
|
}
|
83
|
|
84
|
messages.add("dummy");
|
85
|
}
|
86
|
|
87
|
|
88
|
|
89
|
/**
|
90
|
* FIXME use the validation framework validators and to store the validation problems!!!
|
91
|
*
|
92
|
* @return
|
93
|
* @throws RegistrationValidationException
|
94
|
*/
|
95
|
private TaxonNameBase<?,?> findTypifiedName() throws RegistrationValidationException {
|
96
|
|
97
|
List<String> problems = new ArrayList<>();
|
98
|
|
99
|
TaxonNameBase<?,?> typifiedName = null;
|
100
|
|
101
|
for(TypeDesignationBase<?> typeDesignation : reg.getTypeDesignations()){
|
102
|
typeDesignation.getTypifiedNames();
|
103
|
if(typeDesignation.getTypifiedNames().isEmpty()){
|
104
|
|
105
|
//TODO instead throw RegistrationValidationException()
|
106
|
problems.add("Missing typifiedName in " + typeDesignation.toString());
|
107
|
continue;
|
108
|
}
|
109
|
if(typeDesignation.getTypifiedNames().size() > 1){
|
110
|
//TODO instead throw RegistrationValidationException()
|
111
|
problems.add("Multiple typifiedName in " + typeDesignation.toString());
|
112
|
continue;
|
113
|
}
|
114
|
if(typifiedName == null){
|
115
|
// remember
|
116
|
typifiedName = typeDesignation.getTypifiedNames().iterator().next();
|
117
|
} else {
|
118
|
// compare
|
119
|
TaxonNameBase<?,?> otherTypifiedName = typeDesignation.getTypifiedNames().iterator().next();
|
120
|
if(typifiedName.getId() != otherTypifiedName.getId()){
|
121
|
//TODO instead throw RegistrationValidationException()
|
122
|
problems.add("Multiple typifiedName in " + typeDesignation.toString());
|
123
|
}
|
124
|
}
|
125
|
|
126
|
}
|
127
|
if(!problems.isEmpty()){
|
128
|
// FIXME use the validation framework
|
129
|
throw new RegistrationValidationException("Inconsistent Registration entity. " + reg.toString(), problems);
|
130
|
}
|
131
|
|
132
|
return typifiedName;
|
133
|
}
|
134
|
|
135
|
/**
|
136
|
* Provides access to the Registration entity this DTO has been build from.
|
137
|
* This method is purposely not a getter to hide the original Registration
|
138
|
* from generic processes which are exposing, binding bean properties.
|
139
|
*
|
140
|
* @return
|
141
|
*/
|
142
|
public Registration registration() {
|
143
|
return reg;
|
144
|
}
|
145
|
|
146
|
|
147
|
/**
|
148
|
* @return the summary
|
149
|
*/
|
150
|
public String getSummary() {
|
151
|
return summary;
|
152
|
}
|
153
|
|
154
|
|
155
|
/**
|
156
|
* @return the registrationType
|
157
|
*/
|
158
|
public RegistrationType getRegistrationType() {
|
159
|
return registrationType;
|
160
|
}
|
161
|
|
162
|
|
163
|
/**
|
164
|
* @return the status
|
165
|
*/
|
166
|
public RegistrationStatus getStatus() {
|
167
|
return reg.getStatus();
|
168
|
}
|
169
|
|
170
|
|
171
|
/**
|
172
|
* @return the identifier
|
173
|
*/
|
174
|
public String getIdentifier() {
|
175
|
return reg.getIdentifier();
|
176
|
}
|
177
|
|
178
|
|
179
|
public int getId() {
|
180
|
return reg.getId();
|
181
|
}
|
182
|
|
183
|
|
184
|
public UUID getUuid() {
|
185
|
return reg.getUuid();
|
186
|
}
|
187
|
|
188
|
/**
|
189
|
* @return the specificIdentifier
|
190
|
*/
|
191
|
public String getSpecificIdentifier() {
|
192
|
return reg.getSpecificIdentifier();
|
193
|
}
|
194
|
|
195
|
/**
|
196
|
* @return the registrationDate
|
197
|
*/
|
198
|
public DateTime getRegistrationDate() {
|
199
|
return reg.getRegistrationDate();
|
200
|
}
|
201
|
|
202
|
/**
|
203
|
* @return the registrationDate
|
204
|
*/
|
205
|
public TimePeriod getDatePublished() {
|
206
|
return datePublished;
|
207
|
}
|
208
|
|
209
|
/**
|
210
|
* @return the created
|
211
|
*/
|
212
|
public DateTime getCreated() {
|
213
|
return reg.getCreated();
|
214
|
}
|
215
|
|
216
|
public String getCitation() {
|
217
|
return citationString;
|
218
|
}
|
219
|
|
220
|
/**
|
221
|
* @return the blockedBy
|
222
|
*/
|
223
|
public Set<Registration> getBlockedBy() {
|
224
|
return blockedBy;
|
225
|
}
|
226
|
|
227
|
/**
|
228
|
* @return the citationString
|
229
|
*/
|
230
|
public String getCitationString() {
|
231
|
return citationString;
|
232
|
}
|
233
|
|
234
|
/**
|
235
|
* @return the citationID
|
236
|
*/
|
237
|
public int getCitationID() {
|
238
|
return citationID;
|
239
|
}
|
240
|
|
241
|
|
242
|
|
243
|
/**
|
244
|
* @return
|
245
|
*/
|
246
|
public List<String> getMessages() {
|
247
|
return messages;
|
248
|
}
|
249
|
|
250
|
}
|