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.Collection;
|
13
|
import java.util.HashSet;
|
14
|
import java.util.LinkedHashMap;
|
15
|
import java.util.List;
|
16
|
import java.util.Optional;
|
17
|
import java.util.Set;
|
18
|
import java.util.UUID;
|
19
|
|
20
|
import org.apache.commons.lang3.StringUtils;
|
21
|
import org.apache.log4j.Logger;
|
22
|
import org.joda.time.DateTime;
|
23
|
|
24
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
25
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
26
|
import eu.etaxonomy.cdm.model.name.Registration;
|
27
|
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
|
28
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
29
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
30
|
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
|
31
|
import eu.etaxonomy.cdm.model.reference.IReference;
|
32
|
import eu.etaxonomy.cdm.vaadin.model.EntityReference;
|
33
|
import eu.etaxonomy.cdm.vaadin.model.TypedEntityReference;
|
34
|
import eu.etaxonomy.cdm.vaadin.model.registration.SpecimenTypeDesignationWorkingSetDTO;
|
35
|
import eu.etaxonomy.cdm.vaadin.util.converter.TypeDesignationSetManager;
|
36
|
import eu.etaxonomy.cdm.vaadin.util.converter.TypeDesignationSetManager.TypeDesignationWorkingSet;
|
37
|
|
38
|
public class RegistrationDTO{
|
39
|
|
40
|
private static final Logger logger = Logger.getLogger(RegistrationDTO.class);
|
41
|
|
42
|
private String summary = "";
|
43
|
|
44
|
private RegistrationType registrationType;
|
45
|
|
46
|
private IReference citation = null;
|
47
|
|
48
|
private String citationDetail = null;
|
49
|
|
50
|
private String submitterUserName = null;
|
51
|
|
52
|
private EntityReference name = null;
|
53
|
|
54
|
private TypeDesignationSetManager typeDesignationManager;
|
55
|
|
56
|
private Registration reg;
|
57
|
|
58
|
private List<String> messages = new ArrayList<>();
|
59
|
|
60
|
private Set<eu.etaxonomy.cdm.model.name.Registration> blockedBy = new HashSet<>();
|
61
|
|
62
|
|
63
|
/**
|
64
|
* @param reg
|
65
|
* @param typifiedName should be provided in for Registrations for TypeDesignations
|
66
|
* @throws RegistrationValidationException
|
67
|
*/
|
68
|
public RegistrationDTO(Registration reg) {
|
69
|
|
70
|
this.reg = reg;
|
71
|
|
72
|
registrationType = RegistrationType.from(reg);
|
73
|
|
74
|
if(reg.getSubmitter() != null ){
|
75
|
submitterUserName = reg.getSubmitter().getUsername();
|
76
|
}
|
77
|
|
78
|
if(hasName(reg)){
|
79
|
citation = reg.getName().getNomenclaturalReference();
|
80
|
citationDetail = reg.getName().getNomenclaturalMicroReference();
|
81
|
name = new EntityReference(reg.getName().getId(), reg.getName().getTitleCache());
|
82
|
}
|
83
|
if(hasTypifications(reg)){
|
84
|
if(!reg.getTypeDesignations().isEmpty()){
|
85
|
for(TypeDesignationBase td : reg.getTypeDesignations()){
|
86
|
if(citation == null) {
|
87
|
citation = td.getCitation();
|
88
|
citationDetail = td.getCitationMicroReference();
|
89
|
}
|
90
|
}
|
91
|
}
|
92
|
}
|
93
|
switch(registrationType) {
|
94
|
case EMPTY:
|
95
|
summary = "BLANK REGISTRATION";
|
96
|
break;
|
97
|
case NAME:
|
98
|
summary = reg.getName().getTitleCache();
|
99
|
break;
|
100
|
case NAME_AND_TYPIFICATION:
|
101
|
case TYPIFICATION:
|
102
|
default:
|
103
|
try {
|
104
|
typeDesignationManager = new TypeDesignationSetManager(reg, reg.getTypeDesignations());
|
105
|
summary = typeDesignationManager.buildString().print();
|
106
|
} catch (RegistrationValidationException e) {
|
107
|
messages.add("Validation errors: " + e.getMessage());
|
108
|
}
|
109
|
break;
|
110
|
}
|
111
|
|
112
|
// trigger initialization of the reference
|
113
|
getNomenclaturalCitationString();
|
114
|
|
115
|
}
|
116
|
|
117
|
/**
|
118
|
* @param reg
|
119
|
* @return
|
120
|
*/
|
121
|
private boolean hasTypifications(Registration reg) {
|
122
|
return reg.getTypeDesignations() != null && reg.getTypeDesignations().size() > 0;
|
123
|
}
|
124
|
|
125
|
/**
|
126
|
* @param reg
|
127
|
* @return
|
128
|
*/
|
129
|
private boolean hasName(Registration reg) {
|
130
|
return reg.getName() != null;
|
131
|
}
|
132
|
|
133
|
|
134
|
/**
|
135
|
* Provides access to the Registration entity this DTO has been build from.
|
136
|
* This method is purposely not a getter to hide the original Registration
|
137
|
* from generic processes which are exposing, binding bean properties.
|
138
|
*IReference
|
139
|
* @return
|
140
|
*/
|
141
|
public Registration registration() {
|
142
|
return reg;
|
143
|
}
|
144
|
|
145
|
|
146
|
/**
|
147
|
* @return the summary
|
148
|
*/
|
149
|
public String getSummary() {
|
150
|
return summary;
|
151
|
}
|
152
|
|
153
|
public String getSubmitterUserName(){
|
154
|
return submitterUserName;
|
155
|
}
|
156
|
|
157
|
/**
|
158
|
* @return the registrationType
|
159
|
*/
|
160
|
public RegistrationType getRegistrationType() {
|
161
|
return registrationType;
|
162
|
}
|
163
|
|
164
|
/**
|
165
|
* @return the status
|
166
|
*/
|
167
|
public RegistrationStatus getStatus() {
|
168
|
return reg.getStatus();
|
169
|
}
|
170
|
|
171
|
/**
|
172
|
* @return the identifier
|
173
|
*/
|
174
|
public String getIdentifier() {
|
175
|
return reg.getIdentifier();
|
176
|
}
|
177
|
|
178
|
|
179
|
/**
|
180
|
* The entity ID of the Registration Item
|
181
|
* @return
|
182
|
*/
|
183
|
public int getId() {
|
184
|
return reg.getId();
|
185
|
}
|
186
|
|
187
|
|
188
|
public UUID getUuid() {
|
189
|
return reg.getUuid();
|
190
|
}
|
191
|
|
192
|
/**
|
193
|
* @return the specificIdentifier
|
194
|
*/
|
195
|
public String getSpecificIdentifier() {
|
196
|
return reg.getSpecificIdentifier();
|
197
|
}
|
198
|
|
199
|
/**
|
200
|
* @return the registrationDate
|
201
|
*/
|
202
|
public DateTime getRegistrationDate() {
|
203
|
return reg.getRegistrationDate();
|
204
|
}
|
205
|
|
206
|
/**
|
207
|
* @return the registrationDate
|
208
|
*/
|
209
|
public TimePeriod getDatePublished() {
|
210
|
return citation == null ? null : citation.getDatePublished();
|
211
|
}
|
212
|
|
213
|
/**
|
214
|
* @return the created
|
215
|
*/
|
216
|
public DateTime getCreated() {
|
217
|
return reg.getCreated();
|
218
|
}
|
219
|
|
220
|
public IReference getCitation() {
|
221
|
return citation;
|
222
|
}
|
223
|
|
224
|
/**
|
225
|
* @return the citationID
|
226
|
*/
|
227
|
public Integer getCitationID() {
|
228
|
return citation == null ? null : citation.getId();
|
229
|
}
|
230
|
|
231
|
public EntityReference getTypifiedName() {
|
232
|
return typeDesignationManager != null ? typeDesignationManager.getTypifiedName() : null;
|
233
|
}
|
234
|
|
235
|
public EntityReference getName() {
|
236
|
return name;
|
237
|
}
|
238
|
|
239
|
public LinkedHashMap<TypedEntityReference, TypeDesignationWorkingSet> getOrderdTypeDesignationWorkingSets() {
|
240
|
return typeDesignationManager != null ? typeDesignationManager.getOrderdTypeDesignationWorkingSets() : null;
|
241
|
}
|
242
|
|
243
|
/**
|
244
|
* @param baseEntityReference
|
245
|
*/
|
246
|
public TypeDesignationWorkingSet getTypeDesignationWorkingSet(TypedEntityReference baseEntityReference) {
|
247
|
return typeDesignationManager != null ? typeDesignationManager.getOrderdTypeDesignationWorkingSets().get(baseEntityReference) : null;
|
248
|
|
249
|
}
|
250
|
|
251
|
/**
|
252
|
* @param baseEntityReference
|
253
|
*/
|
254
|
public Set<TypeDesignationBase> getTypeDesignationsInWorkingSet(TypedEntityReference baseEntityReference) {
|
255
|
Set<TypeDesignationBase> typeDesignations = new HashSet<>();
|
256
|
TypeDesignationWorkingSet workingSet = getTypeDesignationWorkingSet(baseEntityReference);
|
257
|
for(EntityReference ref : workingSet.getTypeDesignations()){
|
258
|
typeDesignations.add(findTypeDesignation(ref));
|
259
|
}
|
260
|
return typeDesignations;
|
261
|
}
|
262
|
|
263
|
public SpecimenTypeDesignationWorkingSetDTO getSpecimenTypeDesignationWorkingSetDTO(TypedEntityReference baseEntityReference) {
|
264
|
Set<TypeDesignationBase> typeDesignations = getTypeDesignationsInWorkingSet(baseEntityReference);
|
265
|
List<SpecimenTypeDesignation> specimenTypeDesignations = new ArrayList<>(typeDesignations.size());
|
266
|
typeDesignations.forEach(td -> specimenTypeDesignations.add((SpecimenTypeDesignation)td));
|
267
|
IdentifiableEntity<?> baseEntity = getTypeDesignationWorkingSet(baseEntityReference).getBaseEntity();
|
268
|
SpecimenTypeDesignationWorkingSetDTO dto = new SpecimenTypeDesignationWorkingSetDTO(reg, baseEntity, specimenTypeDesignations);
|
269
|
return dto;
|
270
|
}
|
271
|
|
272
|
/**
|
273
|
*
|
274
|
* @param workingSetId
|
275
|
* @return the TypeDesignationWorkingSet in this DTO with the matching workingSetId or NULL
|
276
|
*/
|
277
|
public TypeDesignationWorkingSet getTypeDesignationWorkingSet(int workingSetId) {
|
278
|
Optional<TypeDesignationWorkingSet> workingSetOptional = getOrderdTypeDesignationWorkingSets().values().stream().filter(workingSet -> workingSet.getWorkingSetId() == workingSetId).findFirst();
|
279
|
if(workingSetOptional.isPresent()){
|
280
|
return workingSetOptional.get();
|
281
|
}
|
282
|
return null;
|
283
|
|
284
|
}
|
285
|
|
286
|
/**
|
287
|
* @param ref
|
288
|
* @return
|
289
|
*/
|
290
|
private TypeDesignationBase findTypeDesignation(EntityReference ref) {
|
291
|
return typeDesignationManager != null ? typeDesignationManager.findTypeDesignation(ref) : null;
|
292
|
}
|
293
|
|
294
|
public Collection<TypeDesignationBase> getTypeDesignations() {
|
295
|
return typeDesignationManager != null ? typeDesignationManager.getTypeDesignations() : null;
|
296
|
}
|
297
|
|
298
|
/**
|
299
|
* @return the citationString
|
300
|
*/
|
301
|
public String getNomenclaturalCitationString() {
|
302
|
if(citation == null){
|
303
|
return null;
|
304
|
}
|
305
|
if(INomenclaturalReference.class.isAssignableFrom(citation.getClass())){
|
306
|
return ((INomenclaturalReference)citation).getNomenclaturalCitation(citationDetail);
|
307
|
} else {
|
308
|
logger.error("The citation is not a NomenclaturalReference");
|
309
|
return citation.generateTitle();
|
310
|
}
|
311
|
}
|
312
|
|
313
|
/**
|
314
|
* @return the citationString
|
315
|
*/
|
316
|
public String getBibliographicCitationString() {
|
317
|
if(citation == null){
|
318
|
return null;
|
319
|
} else {
|
320
|
if(StringUtils.isNotEmpty(citationDetail)){
|
321
|
// TODO see https://dev.e-taxonomy.eu/redmine/issues/6623
|
322
|
return citation.generateTitle().replaceAll("\\.$", "") + (StringUtils.isNotEmpty(citationDetail) ? ": " + citationDetail : "");
|
323
|
} else {
|
324
|
return citation.generateTitle();
|
325
|
|
326
|
}
|
327
|
|
328
|
}
|
329
|
}
|
330
|
|
331
|
/**
|
332
|
* @return the blockedBy
|
333
|
*/
|
334
|
public Set<Registration> getBlockedBy() {
|
335
|
return blockedBy;
|
336
|
}
|
337
|
|
338
|
/**
|
339
|
* @return
|
340
|
*/
|
341
|
public List<String> getMessages() {
|
342
|
return messages;
|
343
|
}
|
344
|
|
345
|
}
|