1
|
/**
|
2
|
* Copyright (C) 2018 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.util.ArrayList;
|
12
|
import java.util.HashSet;
|
13
|
import java.util.List;
|
14
|
import java.util.Set;
|
15
|
import java.util.stream.Collectors;
|
16
|
|
17
|
import org.joda.time.DateTime;
|
18
|
|
19
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
20
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
21
|
import eu.etaxonomy.cdm.model.common.Credit;
|
22
|
import eu.etaxonomy.cdm.model.common.Extension;
|
23
|
import eu.etaxonomy.cdm.model.common.Identifier;
|
24
|
import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction;
|
25
|
import eu.etaxonomy.cdm.model.common.User;
|
26
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
27
|
import eu.etaxonomy.cdm.model.name.NameRelationship;
|
28
|
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
|
29
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
30
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
|
31
|
import eu.etaxonomy.cdm.model.name.Rank;
|
32
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
33
|
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
|
34
|
import eu.etaxonomy.cdm.vaadin.model.CdmEntityAdapterDTO;
|
35
|
|
36
|
/**
|
37
|
* @author a.kohlbecker
|
38
|
* @since Apr 23, 2018
|
39
|
*
|
40
|
*/
|
41
|
public class TaxonNameDTO extends CdmEntityAdapterDTO<TaxonName> {
|
42
|
|
43
|
private static final long serialVersionUID = -8018109905949198530L;
|
44
|
|
45
|
private TaxonName name;
|
46
|
|
47
|
private Set<TaxonName> persistedBasionyms;
|
48
|
|
49
|
private Set<TaxonName> persistedReplacedSynonyms;
|
50
|
|
51
|
private TaxonName persistedValidatedName;
|
52
|
|
53
|
/**
|
54
|
* @param entity
|
55
|
*/
|
56
|
public TaxonNameDTO(TaxonName entity) {
|
57
|
super(entity);
|
58
|
name = entity;
|
59
|
}
|
60
|
|
61
|
public String getAcronym() {
|
62
|
return name.getAcronym();
|
63
|
}
|
64
|
|
65
|
public Set<Annotation> getAnnotations() {
|
66
|
return name.getAnnotations();
|
67
|
}
|
68
|
|
69
|
public void setAnnotations(Set<Annotation> annotations) {
|
70
|
List<Annotation> currentAnnotations = new ArrayList<>(name.getAnnotations());
|
71
|
List<Annotation> annotationsSeen = new ArrayList<>();
|
72
|
for(Annotation a : annotations){
|
73
|
if(a == null){
|
74
|
continue;
|
75
|
}
|
76
|
if(!currentAnnotations.contains(a)){
|
77
|
name.addAnnotation(a);
|
78
|
}
|
79
|
annotationsSeen.add(a);
|
80
|
}
|
81
|
for(Annotation a : currentAnnotations){
|
82
|
if(!annotationsSeen.contains(a)){
|
83
|
name.removeAnnotation(a);
|
84
|
}
|
85
|
}
|
86
|
}
|
87
|
|
88
|
public String getAppendedPhrase() {
|
89
|
return name.getAppendedPhrase();
|
90
|
}
|
91
|
|
92
|
public String getAuthorshipCache() {
|
93
|
|
94
|
return name.getAuthorshipCache();
|
95
|
}
|
96
|
|
97
|
public TeamOrPersonBase<?> getBasionymAuthorship() {
|
98
|
return name.getBasionymAuthorship();
|
99
|
}
|
100
|
|
101
|
public Set<TaxonName> getBasionyms() {
|
102
|
Set<TaxonName> basionyms = name.getRelatedNames(Direction.relatedTo, NameRelationshipType.BASIONYM());
|
103
|
if(persistedBasionyms == null){
|
104
|
// remember the persisted state before starting to operate on the DTO
|
105
|
persistedBasionyms = basionyms;
|
106
|
}
|
107
|
return basionyms;
|
108
|
}
|
109
|
|
110
|
public Set<TaxonName> getReplacedSynonyms() {
|
111
|
Set<TaxonName> replacedSynonyms = name.getRelatedNames(Direction.relatedTo, NameRelationshipType.REPLACED_SYNONYM());
|
112
|
if(persistedReplacedSynonyms == null){
|
113
|
// remember the persisted state before starting to operate on the DTO
|
114
|
persistedReplacedSynonyms = replacedSynonyms;
|
115
|
}
|
116
|
return replacedSynonyms;
|
117
|
}
|
118
|
|
119
|
public NameRelationshipDTO getValidationFor() {
|
120
|
NameRelationshipDTO nameRelDto = null;
|
121
|
NameRelationship validatingRelationship = validatingRelationship();
|
122
|
if(validatingRelationship != null){
|
123
|
nameRelDto = new NameRelationshipDTO(Direction.relatedTo, validatingRelationship);
|
124
|
if(persistedValidatedName == null){
|
125
|
persistedValidatedName = nameRelDto.getOtherName();
|
126
|
}
|
127
|
}
|
128
|
return nameRelDto;
|
129
|
}
|
130
|
|
131
|
/**
|
132
|
* @return
|
133
|
*/
|
134
|
protected NameRelationship validatingRelationship() {
|
135
|
Set<NameRelationship> toRelations = name.getRelationsToThisName();
|
136
|
Set<NameRelationship> validatedNameRelations = toRelations.stream().filter(
|
137
|
nr -> nr.getType().equals(NameRelationshipType.VALIDATED_BY_NAME())
|
138
|
).collect(Collectors.toSet());
|
139
|
if(validatedNameRelations.size() > 1){
|
140
|
// TODO use non RuntimeException
|
141
|
throw new RuntimeException("More than one validated name found.");
|
142
|
} else if(validatedNameRelations.size() == 0) {
|
143
|
return null;
|
144
|
}
|
145
|
return validatedNameRelations.iterator().next();
|
146
|
}
|
147
|
|
148
|
public void setValidationFor(NameRelationshipDTO nameRelDto) {
|
149
|
|
150
|
if(nameRelDto != null && nameRelDto.getOtherName() == null){
|
151
|
// treat as if there is no validation
|
152
|
nameRelDto = null;
|
153
|
}
|
154
|
|
155
|
NameRelationship validatingRelationship = validatingRelationship();
|
156
|
|
157
|
if(nameRelDto != null){
|
158
|
// add or update ...
|
159
|
if(validatingRelationship != null && persistedValidatedName != null && validatingRelationship.getFromName().equals(persistedValidatedName)){
|
160
|
// validated name has not changed, so we can update the relation
|
161
|
validatingRelationship.setCitation(nameRelDto.getCitation());
|
162
|
validatingRelationship.setCitationMicroReference(nameRelDto.getCitationMicroReference());
|
163
|
validatingRelationship.setRuleConsidered(nameRelDto.getRuleConsidered());
|
164
|
} else {
|
165
|
// need to remove the old relationship and to create a new one.
|
166
|
// the actual removal will take place ....
|
167
|
name.addRelationshipFromName(nameRelDto.getOtherName(), NameRelationshipType.VALIDATED_BY_NAME(),
|
168
|
nameRelDto.getCitation(), nameRelDto.getCitationMicroReference(), nameRelDto.getRuleConsidered());
|
169
|
if(persistedValidatedName != null){
|
170
|
name.removeRelationWithTaxonName(persistedValidatedName, Direction.relatedTo, NameRelationshipType.VALIDATED_BY_NAME());
|
171
|
}
|
172
|
}
|
173
|
} else {
|
174
|
// remove ...
|
175
|
if(persistedValidatedName != null && validatingRelationship != null){
|
176
|
name.removeRelationWithTaxonName(persistedValidatedName, Direction.relatedTo, NameRelationshipType.VALIDATED_BY_NAME());
|
177
|
}
|
178
|
}
|
179
|
}
|
180
|
|
181
|
public void setBasionyms(Set<TaxonName> basionyms) {
|
182
|
setRelatedNames(Direction.relatedTo, NameRelationshipType.BASIONYM(), basionyms);
|
183
|
}
|
184
|
|
185
|
public void setReplacedSynonyms(Set<TaxonName> replacedSynonyms) {
|
186
|
setRelatedNames(Direction.relatedTo, NameRelationshipType.REPLACED_SYNONYM(), replacedSynonyms);
|
187
|
}
|
188
|
|
189
|
/**
|
190
|
* @param basionyms
|
191
|
* @param relType
|
192
|
* @param direction
|
193
|
*/
|
194
|
protected void setRelatedNames(Direction direction, NameRelationshipType relType, Set<TaxonName> relatedNames) {
|
195
|
Set<TaxonName> currentRelatedNames = new HashSet<>();
|
196
|
Set<TaxonName> namesSeen = new HashSet<>();
|
197
|
|
198
|
for(TaxonName tn : name.getRelatedNames(direction, relType)){
|
199
|
currentRelatedNames.add(tn);
|
200
|
}
|
201
|
for(TaxonName tn : relatedNames){
|
202
|
if(tn == null){
|
203
|
continue;
|
204
|
}
|
205
|
if(!currentRelatedNames.contains(tn)){
|
206
|
if(direction.equals(Direction.relatedTo)){
|
207
|
tn.addRelationshipToName(name, relType, null);
|
208
|
} else {
|
209
|
tn.addRelationshipFromName(name, relType, null);
|
210
|
}
|
211
|
}
|
212
|
namesSeen.add(tn);
|
213
|
}
|
214
|
for(TaxonName tn : currentRelatedNames){
|
215
|
if(!namesSeen.contains(tn)){
|
216
|
name.removeRelationWithTaxonName(tn, direction, relType);
|
217
|
}
|
218
|
}
|
219
|
}
|
220
|
|
221
|
public Set<TaxonName> persistedBasionyms(){
|
222
|
return persistedBasionyms;
|
223
|
}
|
224
|
|
225
|
public TeamOrPersonBase<?> getCombinationAuthorship() {
|
226
|
return name.getCombinationAuthorship();
|
227
|
}
|
228
|
|
229
|
public List<Credit> getCredits() {
|
230
|
return name.getCredits();
|
231
|
}
|
232
|
|
233
|
public String getCultivarName() {
|
234
|
return name.getCultivarName();
|
235
|
}
|
236
|
|
237
|
public TeamOrPersonBase<?> getExBasionymAuthorship() {
|
238
|
return name.getExBasionymAuthorship();
|
239
|
}
|
240
|
|
241
|
public TeamOrPersonBase<?> getExCombinationAuthorship() {
|
242
|
return name.getExCombinationAuthorship();
|
243
|
}
|
244
|
|
245
|
public Set<Extension> getExtensions() {
|
246
|
return name.getExtensions();
|
247
|
}
|
248
|
|
249
|
public String getFullTitleCache() {
|
250
|
return name.getFullTitleCache();
|
251
|
}
|
252
|
|
253
|
public String getGenusOrUninomial() {
|
254
|
return name.getGenusOrUninomial();
|
255
|
}
|
256
|
|
257
|
public HomotypicalGroup getHomotypicalGroup() {
|
258
|
return name.getHomotypicalGroup();
|
259
|
}
|
260
|
|
261
|
public List<Identifier> getIdentifiers() {
|
262
|
return name.getIdentifiers();
|
263
|
}
|
264
|
|
265
|
public String getInfraGenericEpithet() {
|
266
|
return name.getInfraGenericEpithet();
|
267
|
}
|
268
|
|
269
|
public String getInfraSpecificEpithet() {
|
270
|
return name.getInfraSpecificEpithet();
|
271
|
}
|
272
|
|
273
|
public String getSpecificEpithet() {
|
274
|
return name.getSpecificEpithet();
|
275
|
}
|
276
|
|
277
|
public String getNameCache() {
|
278
|
return name.getNameCache();
|
279
|
}
|
280
|
|
281
|
public String getNomenclaturalMicroReference() {
|
282
|
return name.getNomenclaturalMicroReference();
|
283
|
}
|
284
|
|
285
|
public INomenclaturalReference getNomenclaturalReference() {
|
286
|
return name.getNomenclaturalReference();
|
287
|
}
|
288
|
|
289
|
public Rank getRank() {
|
290
|
return name.getRank();
|
291
|
}
|
292
|
|
293
|
public Set<NomenclaturalStatus> getStatus() {
|
294
|
return name.getStatus();
|
295
|
}
|
296
|
|
297
|
public boolean isProtectedAuthorshipCache() {
|
298
|
return name.isProtectedAuthorshipCache();
|
299
|
}
|
300
|
|
301
|
public boolean isProtectedFullTitleCache() {
|
302
|
return name.isProtectedFullTitleCache();
|
303
|
}
|
304
|
|
305
|
public boolean isProtectedNameCache() {
|
306
|
return name.isProtectedNameCache();
|
307
|
}
|
308
|
|
309
|
public boolean isProtectedTitleCache() {
|
310
|
return name.isProtectedTitleCache();
|
311
|
}
|
312
|
|
313
|
public void setAcronym(String acronym) {
|
314
|
name.setAcronym(acronym);
|
315
|
}
|
316
|
|
317
|
public void setAppendedPhrase(String appendedPhrase) {
|
318
|
name.setAppendedPhrase(appendedPhrase);
|
319
|
}
|
320
|
|
321
|
public void setBasionymAuthorship(TeamOrPersonBase<?> basionymAuthorship) {
|
322
|
name.setBasionymAuthorship(basionymAuthorship);
|
323
|
}
|
324
|
|
325
|
public void setBinomHybrid(boolean binomHybrid) {
|
326
|
name.setBinomHybrid(binomHybrid);
|
327
|
}
|
328
|
|
329
|
public void setBreed(String breed) {
|
330
|
name.setBreed(breed);
|
331
|
}
|
332
|
|
333
|
public void setCombinationAuthorship(TeamOrPersonBase<?> combinationAuthorship) {
|
334
|
name.setCombinationAuthorship(combinationAuthorship);
|
335
|
}
|
336
|
|
337
|
public void setCultivarName(String cultivarName) {
|
338
|
name.setCultivarName(cultivarName);
|
339
|
}
|
340
|
|
341
|
public void setExBasionymAuthorship(TeamOrPersonBase<?> exBasionymAuthorship) {
|
342
|
name.setExBasionymAuthorship(exBasionymAuthorship);
|
343
|
}
|
344
|
|
345
|
public void setExCombinationAuthorship(TeamOrPersonBase<?> exCombinationAuthorship) {
|
346
|
name.setExCombinationAuthorship(exCombinationAuthorship);
|
347
|
}
|
348
|
|
349
|
public void setFullTitleCache(String fullTitleCache) {
|
350
|
name.setFullTitleCache(fullTitleCache);
|
351
|
}
|
352
|
|
353
|
public void setGenusOrUninomial(String genusOrUninomial) {
|
354
|
name.setGenusOrUninomial(genusOrUninomial);
|
355
|
}
|
356
|
|
357
|
public void setHybridFormula(boolean hybridFormula) {
|
358
|
name.setHybridFormula(hybridFormula);
|
359
|
}
|
360
|
|
361
|
public void setInfraGenericEpithet(String infraGenericEpithet) {
|
362
|
name.setInfraGenericEpithet(infraGenericEpithet);
|
363
|
}
|
364
|
|
365
|
public void setInfraSpecificEpithet(String infraSpecificEpithet) {
|
366
|
name.setInfraSpecificEpithet(infraSpecificEpithet);
|
367
|
}
|
368
|
|
369
|
public void setMonomHybrid(boolean monomHybrid) {
|
370
|
name.setMonomHybrid(monomHybrid);
|
371
|
}
|
372
|
|
373
|
public void setNameApprobation(String nameApprobation) {
|
374
|
name.setNameApprobation(nameApprobation);
|
375
|
}
|
376
|
|
377
|
public void setNameCache(String nameCache) {
|
378
|
name.setNameCache(nameCache);
|
379
|
}
|
380
|
|
381
|
public void setNameType(NomenclaturalCode nameType) {
|
382
|
name.setNameType(nameType);
|
383
|
}
|
384
|
|
385
|
public void setNomenclaturalMicroReference(String nomenclaturalMicroReference) {
|
386
|
name.setNomenclaturalMicroReference(nomenclaturalMicroReference);
|
387
|
}
|
388
|
|
389
|
public void setNomenclaturalReference(INomenclaturalReference nomenclaturalReference) {
|
390
|
name.setNomenclaturalReference(nomenclaturalReference);
|
391
|
}
|
392
|
|
393
|
public void setProtectedAuthorshipCache(boolean protectedAuthorshipCache) {
|
394
|
name.setProtectedAuthorshipCache(protectedAuthorshipCache);
|
395
|
}
|
396
|
|
397
|
public void setProtectedFullTitleCache(boolean protectedFullTitleCache) {
|
398
|
name.setProtectedFullTitleCache(protectedFullTitleCache);
|
399
|
}
|
400
|
|
401
|
public void setProtectedNameCache(boolean protectedNameCache) {
|
402
|
name.setProtectedNameCache(protectedNameCache);
|
403
|
}
|
404
|
|
405
|
public void setProtectedTitleCache(boolean protectedTitleCache) {
|
406
|
name.setProtectedTitleCache(protectedTitleCache);
|
407
|
}
|
408
|
|
409
|
public void setRank(Rank rank) {
|
410
|
name.setRank(rank);
|
411
|
}
|
412
|
|
413
|
public void setSpecificEpithet(String specificEpithet) {
|
414
|
name.setSpecificEpithet(specificEpithet);
|
415
|
}
|
416
|
|
417
|
public void setTitleCache(String titleCache) {
|
418
|
name.setTitleCache(titleCache);
|
419
|
}
|
420
|
|
421
|
public void setTrinomHybrid(boolean trinomHybrid) {
|
422
|
name.setTrinomHybrid(trinomHybrid);
|
423
|
}
|
424
|
|
425
|
public void setUpdated(DateTime updated) {
|
426
|
name.setUpdated(updated);
|
427
|
}
|
428
|
|
429
|
public void setUpdatedBy(User updatedBy) {
|
430
|
name.setUpdatedBy(updatedBy);
|
431
|
}
|
432
|
|
433
|
}
|