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.util.converter;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Collection;
|
13
|
import java.util.Collections;
|
14
|
import java.util.Comparator;
|
15
|
import java.util.HashMap;
|
16
|
import java.util.LinkedHashMap;
|
17
|
import java.util.LinkedList;
|
18
|
import java.util.List;
|
19
|
import java.util.Map;
|
20
|
import java.util.Optional;
|
21
|
import java.util.Set;
|
22
|
|
23
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeCacheStrategy;
|
24
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
25
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
26
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
27
|
import eu.etaxonomy.cdm.model.common.VersionableEntity;
|
28
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
|
29
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
30
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
31
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
32
|
import eu.etaxonomy.cdm.model.name.TypeDesignationStatusBase;
|
33
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
34
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
35
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
36
|
import eu.etaxonomy.cdm.vaadin.model.EntityReference;
|
37
|
import eu.etaxonomy.cdm.vaadin.model.TypedEntityReference;
|
38
|
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationValidationException;
|
39
|
|
40
|
/**
|
41
|
* Converts a collection of TypeDesignations, which should belong to the
|
42
|
* same name of course, into a string representation.
|
43
|
*
|
44
|
* Order of TypeDesignations in the resulting string:
|
45
|
* Type, Holotype, Lectotype, Epitypes
|
46
|
* @author a.kohlbecker
|
47
|
* @since Mar 10, 2017
|
48
|
*
|
49
|
*/
|
50
|
public class TypeDesignationConverter {
|
51
|
|
52
|
|
53
|
private static final String TYPE_STATUS_SEPARATOR = "; ";
|
54
|
|
55
|
private static final String TYPE_SEPARATOR = "; ";
|
56
|
|
57
|
private static final String TYPE_DESIGNATION_SEPARATOR = ", ";
|
58
|
|
59
|
private Collection<TypeDesignationBase> typeDesignations;
|
60
|
|
61
|
private int workingSetIdAutoIncrement = 0;
|
62
|
|
63
|
/**
|
64
|
* Groups the EntityReferences for each of the TypeDesignations by the according TypeDesignationStatus.
|
65
|
* The TypeDesignationStatusBase keys are already ordered by the term order defined in the vocabulary.
|
66
|
*/
|
67
|
private LinkedHashMap<TypedEntityReference, TypeDesignationWorkingSet> orderedByTypesByBaseEntity;
|
68
|
|
69
|
private EntityReference typifiedName;
|
70
|
|
71
|
private String finalString = null;
|
72
|
|
73
|
final NullTypeDesignationStatus NULL_STATUS = new NullTypeDesignationStatus();
|
74
|
|
75
|
private List<String> probelms = new ArrayList<>();
|
76
|
|
77
|
/**
|
78
|
* @param taxonName
|
79
|
* @throws RegistrationValidationException
|
80
|
*
|
81
|
*/
|
82
|
public TypeDesignationConverter(CdmBase containgEntity, Collection<TypeDesignationBase> typeDesignations) throws RegistrationValidationException {
|
83
|
this.typeDesignations = typeDesignations;
|
84
|
Map<TypedEntityReference, TypeDesignationWorkingSet> byBaseEntityByTypeStatus = new HashMap<>();
|
85
|
typeDesignations.forEach(td -> mapTypeDesignation(containgEntity, byBaseEntityByTypeStatus, td));
|
86
|
orderedByTypesByBaseEntity = orderByTypeByBaseEntity(byBaseEntityByTypeStatus);
|
87
|
this.typifiedName = findTypifiedName();
|
88
|
}
|
89
|
|
90
|
|
91
|
private void mapTypeDesignation(CdmBase containgEntity, Map<TypedEntityReference, TypeDesignationWorkingSet> byBaseEntityByTypeStatus,
|
92
|
TypeDesignationBase<?> td){
|
93
|
|
94
|
TypeDesignationStatusBase<?> status = td.getTypeStatus();
|
95
|
|
96
|
try {
|
97
|
final IdentifiableEntity<?> baseEntity = baseEntity(td);
|
98
|
final TypedEntityReference<IdentifiableEntity<?>> baseEntityReference = makeEntityReference(baseEntity);
|
99
|
|
100
|
EntityReference typeDesignationEntityReference = new EntityReference(td.getId(), stringify(td));
|
101
|
|
102
|
TypeDesignationWorkingSet typedesignationWorkingSet;
|
103
|
if(!byBaseEntityByTypeStatus.containsKey(baseEntityReference)){
|
104
|
TypedEntityReference containigEntityReference = new TypedEntityReference(containgEntity.getClass(), containgEntity.getId(), containgEntity.toString());
|
105
|
byBaseEntityByTypeStatus.put(baseEntityReference, new TypeDesignationWorkingSet(containigEntityReference, baseEntity, baseEntityReference));
|
106
|
}
|
107
|
|
108
|
typedesignationWorkingSet = byBaseEntityByTypeStatus.get(baseEntityReference);
|
109
|
typedesignationWorkingSet.insert(status, typeDesignationEntityReference);
|
110
|
} catch (DataIntegrityException e){
|
111
|
probelms.add(e.getMessage());
|
112
|
}
|
113
|
}
|
114
|
|
115
|
/**
|
116
|
* @param td
|
117
|
* @return
|
118
|
* @throws DataIntegrityException
|
119
|
*/
|
120
|
protected IdentifiableEntity<?> baseEntity(TypeDesignationBase<?> td) throws DataIntegrityException {
|
121
|
|
122
|
IdentifiableEntity<?> baseEntity = null;
|
123
|
if(td instanceof SpecimenTypeDesignation){
|
124
|
SpecimenTypeDesignation std = (SpecimenTypeDesignation) td;
|
125
|
FieldUnit fu = findFieldUnit(std);
|
126
|
if(fu != null){
|
127
|
baseEntity = fu;
|
128
|
} else if(((SpecimenTypeDesignation) td).getTypeSpecimen() != null){
|
129
|
baseEntity = ((SpecimenTypeDesignation) td).getTypeSpecimen();
|
130
|
}
|
131
|
} else if(td instanceof NameTypeDesignation){
|
132
|
baseEntity = ((NameTypeDesignation)td).getTypeName();
|
133
|
}
|
134
|
if(baseEntity == null) {
|
135
|
throw new DataIntegrityException("Incomplete TypeDesignation, no type missin in " + td.toString());
|
136
|
}
|
137
|
return baseEntity;
|
138
|
}
|
139
|
|
140
|
/**
|
141
|
* @param td
|
142
|
* @return
|
143
|
*/
|
144
|
protected TypedEntityReference<IdentifiableEntity<?>> makeEntityReference(IdentifiableEntity<?> baseEntity) {
|
145
|
;
|
146
|
String label = "";
|
147
|
if(baseEntity instanceof FieldUnit){
|
148
|
label = ((FieldUnit)baseEntity).getTitleCache();
|
149
|
}
|
150
|
|
151
|
TypedEntityReference<IdentifiableEntity<?>> baseEntityReference = new TypedEntityReference(baseEntity.getClass(), baseEntity.getId(), label);
|
152
|
|
153
|
return baseEntityReference;
|
154
|
}
|
155
|
|
156
|
|
157
|
private LinkedHashMap<TypedEntityReference, TypeDesignationWorkingSet> orderByTypeByBaseEntity(
|
158
|
Map<TypedEntityReference, TypeDesignationWorkingSet> stringsByTypeByBaseEntity){
|
159
|
|
160
|
// order the FieldUnit TypeName keys
|
161
|
List<TypedEntityReference> baseEntityKeyList = new LinkedList<>(stringsByTypeByBaseEntity.keySet());
|
162
|
Collections.sort(baseEntityKeyList, new Comparator<TypedEntityReference>(){
|
163
|
/**
|
164
|
* Sorts the base entities (TypedEntityReference) in the following order:
|
165
|
*
|
166
|
* 1. FieldUnits
|
167
|
* 2. DerivedUnit (in case of missing FieldUnit we expect the base type to be DerivedUnit)
|
168
|
* 3. NameType
|
169
|
*
|
170
|
* {@inheritDoc}
|
171
|
*/
|
172
|
@Override
|
173
|
public int compare(TypedEntityReference o1, TypedEntityReference o2) {
|
174
|
|
175
|
Class type1 = o1.getType();
|
176
|
Class type2 = o2.getType();
|
177
|
|
178
|
if(!type1.equals(type2)) {
|
179
|
if(type1.equals(FieldUnit.class) || type2.equals(FieldUnit.class)){
|
180
|
// FieldUnits first
|
181
|
return type1.equals(FieldUnit.class) ? -1 : 1;
|
182
|
} else {
|
183
|
// name types last (in case of missing FieldUnit we expect the base type to be DerivedUnit which comes into the middle)
|
184
|
return type2.equals(TaxonName.class) ? -1 : 1;
|
185
|
}
|
186
|
} else {
|
187
|
return o1.getLabel().compareTo(o2.getLabel());
|
188
|
}
|
189
|
}});
|
190
|
|
191
|
// new LinkedHashMap for the ordered FieldUnitOrTypeName keys
|
192
|
LinkedHashMap<TypedEntityReference, TypeDesignationWorkingSet> stringsOrderedbyBaseEntityOrderdByType = new LinkedHashMap<>(stringsByTypeByBaseEntity.size());
|
193
|
|
194
|
for(TypedEntityReference baseEntityRef : baseEntityKeyList){
|
195
|
|
196
|
TypeDesignationWorkingSet typeDesignationWorkingSet = stringsByTypeByBaseEntity.get(baseEntityRef);
|
197
|
// order the TypeDesignationStatusBase keys
|
198
|
List<TypeDesignationStatusBase<?>> keyList = new LinkedList<>(typeDesignationWorkingSet.keySet());
|
199
|
Collections.sort(keyList, new Comparator<TypeDesignationStatusBase>() {
|
200
|
@SuppressWarnings("unchecked")
|
201
|
@Override
|
202
|
public int compare(TypeDesignationStatusBase o1, TypeDesignationStatusBase o2) {
|
203
|
// fix inverted order of cdm terms by -1*
|
204
|
return -1 * o1.compareTo(o2);
|
205
|
}
|
206
|
});
|
207
|
// new LinkedHashMap for the ordered TypeDesignationStatusBase keys
|
208
|
TypeDesignationWorkingSet orderedStringsByOrderedTypes = new TypeDesignationWorkingSet(typeDesignationWorkingSet.getContainigEntityReference(),
|
209
|
typeDesignationWorkingSet.getBaseEntity(),
|
210
|
baseEntityRef);
|
211
|
orderedStringsByOrderedTypes.setWorkingSetId(typeDesignationWorkingSet.workingSetId); // preserve original workingSetId
|
212
|
keyList.forEach(key -> orderedStringsByOrderedTypes.put(key, typeDesignationWorkingSet.get(key)));
|
213
|
stringsOrderedbyBaseEntityOrderdByType.put(baseEntityRef, orderedStringsByOrderedTypes);
|
214
|
}
|
215
|
|
216
|
return stringsOrderedbyBaseEntityOrderdByType;
|
217
|
}
|
218
|
|
219
|
/*
|
220
|
private LinkedHashMap<TypedEntityReference, LinkedHashMap<String, Collection<EntityReference>>> buildOrderedRepresentations(){
|
221
|
|
222
|
orderedStringsByOrderedTypes.keySet().forEach(
|
223
|
key -> orderedRepresentations.put(
|
224
|
getTypeDesignationStytusLabel(key),
|
225
|
orderedStringsByOrderedTypes.get(key))
|
226
|
);
|
227
|
return orderedRepresentations;
|
228
|
}
|
229
|
*/
|
230
|
|
231
|
public TypeDesignationConverter buildString(){
|
232
|
|
233
|
if(finalString == null){
|
234
|
|
235
|
finalString = "";
|
236
|
if(getTypifiedNameCache() != null){
|
237
|
finalString += getTypifiedNameCache() + " ";
|
238
|
}
|
239
|
|
240
|
int typeCount = 0;
|
241
|
for(TypedEntityReference baseEntityRef : orderedByTypesByBaseEntity.keySet()) {
|
242
|
StringBuilder sb = new StringBuilder();
|
243
|
if(typeCount++ > 0){
|
244
|
sb.append(TYPE_SEPARATOR);
|
245
|
}
|
246
|
boolean isNameTypeDesignation = false;
|
247
|
if(SpecimenOrObservationBase.class.isAssignableFrom(baseEntityRef.getType())){
|
248
|
sb.append("Type: ");
|
249
|
} else {
|
250
|
sb.append("NameType: ");
|
251
|
isNameTypeDesignation = true;
|
252
|
}
|
253
|
if(!baseEntityRef.getLabel().isEmpty()){
|
254
|
sb.append(baseEntityRef.getLabel()).append(" ");
|
255
|
}
|
256
|
TypeDesignationWorkingSet typeDesignationWorkingSet = orderedByTypesByBaseEntity.get(baseEntityRef);
|
257
|
if(!isNameTypeDesignation ){
|
258
|
sb.append("(");
|
259
|
}
|
260
|
int typeStatusCount = 0;
|
261
|
for(TypeDesignationStatusBase<?> typeStatus : typeDesignationWorkingSet.keySet()) {
|
262
|
if(typeStatusCount++ > 0){
|
263
|
sb.append(TYPE_STATUS_SEPARATOR);
|
264
|
}
|
265
|
boolean isPlural = typeDesignationWorkingSet.get(typeStatus).size() > 1;
|
266
|
if(!typeStatus.equals(NULL_STATUS)) {
|
267
|
sb.append(typeStatus.getLabel());
|
268
|
if(isPlural){
|
269
|
sb.append("s: ");
|
270
|
} else {
|
271
|
sb.append(", ");
|
272
|
}
|
273
|
}
|
274
|
int typeDesignationCount = 0;
|
275
|
for(EntityReference typeDesignationEntityReference : typeDesignationWorkingSet.get(typeStatus)) {
|
276
|
if(typeDesignationCount++ > 0){
|
277
|
sb.append(TYPE_DESIGNATION_SEPARATOR);
|
278
|
}
|
279
|
sb.append(typeDesignationEntityReference.getLabel());
|
280
|
}
|
281
|
}
|
282
|
if(!isNameTypeDesignation ){
|
283
|
sb.append(")");
|
284
|
}
|
285
|
typeDesignationWorkingSet.setRepresentation(sb.toString());
|
286
|
finalString += typeDesignationWorkingSet.getRepresentation();
|
287
|
}
|
288
|
|
289
|
}
|
290
|
return this;
|
291
|
}
|
292
|
|
293
|
/**
|
294
|
* FIXME use the validation framework validators and to store the validation problems!!!
|
295
|
*
|
296
|
* @return
|
297
|
* @throws RegistrationValidationException
|
298
|
*/
|
299
|
private EntityReference findTypifiedName() throws RegistrationValidationException {
|
300
|
|
301
|
List<String> problems = new ArrayList<>();
|
302
|
|
303
|
TaxonName typifiedName = null;
|
304
|
|
305
|
for(TypeDesignationBase<?> typeDesignation : typeDesignations){
|
306
|
typeDesignation.getTypifiedNames();
|
307
|
if(typeDesignation.getTypifiedNames().isEmpty()){
|
308
|
|
309
|
//TODO instead throw RegistrationValidationException()
|
310
|
problems.add("Missing typifiedName in " + typeDesignation.toString());
|
311
|
continue;
|
312
|
}
|
313
|
if(typeDesignation.getTypifiedNames().size() > 1){
|
314
|
//TODO instead throw RegistrationValidationException()
|
315
|
problems.add("Multiple typifiedName in " + typeDesignation.toString());
|
316
|
continue;
|
317
|
}
|
318
|
if(typifiedName == null){
|
319
|
// remember
|
320
|
typifiedName = typeDesignation.getTypifiedNames().iterator().next();
|
321
|
} else {
|
322
|
// compare
|
323
|
TaxonName otherTypifiedName = typeDesignation.getTypifiedNames().iterator().next();
|
324
|
if(typifiedName.getId() != otherTypifiedName.getId()){
|
325
|
//TODO instead throw RegistrationValidationException()
|
326
|
problems.add("Multiple typifiedName in " + typeDesignation.toString());
|
327
|
}
|
328
|
}
|
329
|
|
330
|
}
|
331
|
if(!problems.isEmpty()){
|
332
|
// FIXME use the validation framework
|
333
|
throw new RegistrationValidationException("Inconsistent type designations", problems);
|
334
|
}
|
335
|
|
336
|
if(typifiedName != null){
|
337
|
return new EntityReference(typifiedName.getId(), typifiedName.getTitleCache());
|
338
|
}
|
339
|
return null;
|
340
|
}
|
341
|
|
342
|
|
343
|
/**
|
344
|
* @return the title cache of the typifying name or <code>null</code>
|
345
|
*/
|
346
|
public String getTypifiedNameCache() {
|
347
|
if(typifiedName != null){
|
348
|
return typifiedName.getLabel();
|
349
|
}
|
350
|
return null;
|
351
|
}
|
352
|
|
353
|
/**
|
354
|
* @return the title cache of the typifying name or <code>null</code>
|
355
|
*/
|
356
|
public EntityReference getTypifiedName() {
|
357
|
|
358
|
return typifiedName;
|
359
|
}
|
360
|
|
361
|
/**
|
362
|
* @return
|
363
|
*/
|
364
|
public Collection<TypeDesignationBase> getTypeDesignations() {
|
365
|
return typeDesignations;
|
366
|
}
|
367
|
|
368
|
/**
|
369
|
* @param ref
|
370
|
* @return
|
371
|
*/
|
372
|
public TypeDesignationBase findTypeDesignation(EntityReference typeDesignationRef) {
|
373
|
for(TypeDesignationBase td : typeDesignations){
|
374
|
if(td.getId() == typeDesignationRef.getId()){
|
375
|
return td;
|
376
|
}
|
377
|
}
|
378
|
// TODO Auto-generated method stub
|
379
|
return null;
|
380
|
}
|
381
|
|
382
|
|
383
|
public LinkedHashMap<TypedEntityReference, TypeDesignationWorkingSet> getOrderdTypeDesignationWorkingSets() {
|
384
|
return orderedByTypesByBaseEntity;
|
385
|
}
|
386
|
|
387
|
/**
|
388
|
* @param td
|
389
|
* @return
|
390
|
*/
|
391
|
private String stringify(TypeDesignationBase td) {
|
392
|
|
393
|
if(td instanceof NameTypeDesignation){
|
394
|
return stringify((NameTypeDesignation)td);
|
395
|
} else {
|
396
|
return stringify((SpecimenTypeDesignation)td, false);
|
397
|
}
|
398
|
}
|
399
|
|
400
|
|
401
|
/**
|
402
|
* @param td
|
403
|
* @return
|
404
|
*/
|
405
|
protected String stringify(NameTypeDesignation td) {
|
406
|
|
407
|
StringBuffer sb = new StringBuffer();
|
408
|
|
409
|
if(td.getTypeName() != null){
|
410
|
sb.append(td.getTypeName().getTitleCache());
|
411
|
}
|
412
|
if(td.getCitation() != null){
|
413
|
sb.append(" ").append(td.getCitation().getTitleCache());
|
414
|
if(td.getCitationMicroReference() != null){
|
415
|
sb.append(":").append(td.getCitationMicroReference());
|
416
|
}
|
417
|
}
|
418
|
if(td.isNotDesignated()){
|
419
|
sb.append(" not designated");
|
420
|
}
|
421
|
if(td.isRejectedType()){
|
422
|
sb.append(" rejected");
|
423
|
}
|
424
|
if(td.isConservedType()){
|
425
|
sb.append(" conserved");
|
426
|
}
|
427
|
return sb.toString();
|
428
|
}
|
429
|
|
430
|
/**
|
431
|
* @param td
|
432
|
* @return
|
433
|
*/
|
434
|
private String stringify(SpecimenTypeDesignation td, boolean useFullTitleCache) {
|
435
|
String result = "";
|
436
|
|
437
|
if(useFullTitleCache){
|
438
|
if(td.getTypeSpecimen() != null){
|
439
|
String nameTitleCache = td.getTypeSpecimen().getTitleCache();
|
440
|
if(getTypifiedNameCache() != null){
|
441
|
nameTitleCache = nameTitleCache.replace(getTypifiedNameCache(), "");
|
442
|
}
|
443
|
result += nameTitleCache;
|
444
|
}
|
445
|
} else {
|
446
|
if(td.getTypeSpecimen() != null){
|
447
|
DerivedUnit du = td.getTypeSpecimen();
|
448
|
if(du.isProtectedTitleCache()){
|
449
|
result += du.getTitleCache();
|
450
|
} else {
|
451
|
DerivedUnitFacadeCacheStrategy cacheStrategy = new DerivedUnitFacadeCacheStrategy();
|
452
|
result += cacheStrategy.getTitleCache(du, true);
|
453
|
}
|
454
|
}
|
455
|
}
|
456
|
|
457
|
if(td.getCitation() != null){
|
458
|
result += " " + td.getCitation().getTitleCache();
|
459
|
if(td.getCitationMicroReference() != null){
|
460
|
result += " :" + td.getCitationMicroReference();
|
461
|
}
|
462
|
}
|
463
|
if(td.isNotDesignated()){
|
464
|
result += " not designated";
|
465
|
}
|
466
|
|
467
|
return result;
|
468
|
}
|
469
|
|
470
|
/**
|
471
|
* @param td
|
472
|
* @return
|
473
|
* @deprecated
|
474
|
*/
|
475
|
@Deprecated
|
476
|
private FieldUnit findFieldUnit(SpecimenTypeDesignation td) {
|
477
|
|
478
|
DerivedUnit du = td.getTypeSpecimen();
|
479
|
return findFieldUnit(du);
|
480
|
}
|
481
|
|
482
|
private FieldUnit findFieldUnit(DerivedUnit du) {
|
483
|
|
484
|
if(du == null || du.getOriginals() == null){
|
485
|
return null;
|
486
|
}
|
487
|
@SuppressWarnings("rawtypes")
|
488
|
Set<SpecimenOrObservationBase> originals = du.getDerivedFrom().getOriginals();
|
489
|
@SuppressWarnings("rawtypes")
|
490
|
Optional<SpecimenOrObservationBase> fieldUnit = originals.stream()
|
491
|
.filter(original -> original instanceof FieldUnit).findFirst();
|
492
|
if (fieldUnit.isPresent()) {
|
493
|
return (FieldUnit) fieldUnit.get();
|
494
|
} else {
|
495
|
for (@SuppressWarnings("rawtypes")
|
496
|
SpecimenOrObservationBase sob : originals) {
|
497
|
if (sob instanceof DerivedUnit) {
|
498
|
FieldUnit fu = findFieldUnit((DerivedUnit) sob);
|
499
|
if (fu != null) {
|
500
|
return fu;
|
501
|
}
|
502
|
}
|
503
|
}
|
504
|
}
|
505
|
|
506
|
return null;
|
507
|
}
|
508
|
|
509
|
public String print() {
|
510
|
return finalString;
|
511
|
}
|
512
|
|
513
|
/**
|
514
|
* Groups the EntityReferences for TypeDesignations by the according TypeDesignationStatus.
|
515
|
* The TypeDesignationStatusBase keys can be ordered by the term order defined in the vocabulary.
|
516
|
*/
|
517
|
public class TypeDesignationWorkingSet extends LinkedHashMap<TypeDesignationStatusBase<?>, Collection<EntityReference>> {
|
518
|
|
519
|
private static final long serialVersionUID = -1329007606500890729L;
|
520
|
|
521
|
String workingSetRepresentation = null;
|
522
|
|
523
|
TypedEntityReference<?> containigEntityReference;
|
524
|
|
525
|
TypedEntityReference<IdentifiableEntity<?>> baseEntityReference;
|
526
|
|
527
|
IdentifiableEntity<?> baseEntity;
|
528
|
|
529
|
List<DerivedUnit> derivedUnits = null;
|
530
|
|
531
|
int workingSetId = workingSetIdAutoIncrement++;
|
532
|
|
533
|
/**
|
534
|
* @param baseEntityReference
|
535
|
*/
|
536
|
public TypeDesignationWorkingSet(TypedEntityReference<? extends VersionableEntity> containigEntityReference, IdentifiableEntity<?> baseEntity, TypedEntityReference<IdentifiableEntity<?>> baseEntityReference) {
|
537
|
this.containigEntityReference = containigEntityReference;
|
538
|
this.baseEntity = baseEntity;
|
539
|
this.baseEntityReference = baseEntityReference;
|
540
|
}
|
541
|
|
542
|
/**
|
543
|
* @return
|
544
|
*/
|
545
|
public IdentifiableEntity<?> getBaseEntity() {
|
546
|
return baseEntity;
|
547
|
}
|
548
|
|
549
|
public List<EntityReference> getTypeDesignations() {
|
550
|
List<EntityReference> typeDesignations = new ArrayList<>();
|
551
|
this.values().forEach(typeDesignationReferences -> typeDesignationReferences.forEach(td -> typeDesignations.add(td)));
|
552
|
return typeDesignations;
|
553
|
}
|
554
|
|
555
|
/**
|
556
|
* @param status
|
557
|
* @param typeDesignationEntityReference
|
558
|
*/
|
559
|
public void insert(TypeDesignationStatusBase<?> status, EntityReference typeDesignationEntityReference) {
|
560
|
|
561
|
if(status == null){
|
562
|
status = NULL_STATUS;
|
563
|
}
|
564
|
if(!containsKey(status)){
|
565
|
put(status, new ArrayList<EntityReference>());
|
566
|
}
|
567
|
get(status).add(typeDesignationEntityReference);
|
568
|
}
|
569
|
|
570
|
/**
|
571
|
* @return the workingSetId
|
572
|
*/
|
573
|
public int getWorkingSetId() {
|
574
|
return workingSetId;
|
575
|
}
|
576
|
|
577
|
/**
|
578
|
* @param workingSetId the workingSetId to set
|
579
|
*/
|
580
|
public void setWorkingSetId(int workingSetId) {
|
581
|
this.workingSetId = workingSetId;
|
582
|
}
|
583
|
|
584
|
public String getRepresentation() {
|
585
|
return workingSetRepresentation;
|
586
|
}
|
587
|
|
588
|
public void setRepresentation(String representation){
|
589
|
this.workingSetRepresentation = representation;
|
590
|
}
|
591
|
|
592
|
/**
|
593
|
* A reference to the entity which is the common base entity for all TypeDesignations in this workingset.
|
594
|
* For a {@link SpecimenTypeDesignation} this is usually the {@link FieldUnit} if it is present. Otherwise it can also be
|
595
|
* a {@link DerivedUnit} or something else depending on the specific use case.
|
596
|
*
|
597
|
* @return the baseEntityReference
|
598
|
*/
|
599
|
public TypedEntityReference getBaseEntityReference() {
|
600
|
return baseEntityReference;
|
601
|
}
|
602
|
|
603
|
/**
|
604
|
* A reference to the entity which contains the TypeDesignations bundled in this working set.
|
605
|
* This can be for example a {@link TaxonName} or a {@link Registration} entity.
|
606
|
*
|
607
|
* @return the baseEntityReference
|
608
|
*/
|
609
|
public TypedEntityReference getContainigEntityReference() {
|
610
|
return containigEntityReference;
|
611
|
}
|
612
|
|
613
|
@Override
|
614
|
public String toString(){
|
615
|
if(workingSetRepresentation != null){
|
616
|
return workingSetRepresentation;
|
617
|
} else {
|
618
|
return super.toString();
|
619
|
}
|
620
|
}
|
621
|
|
622
|
/**
|
623
|
* @return
|
624
|
*/
|
625
|
public boolean isSpecimenTypeDesigationWorkingSet() {
|
626
|
return SpecimenOrObservationBase.class.isAssignableFrom(baseEntityReference.getType());
|
627
|
}
|
628
|
|
629
|
}
|
630
|
|
631
|
@SuppressWarnings({ "deprecation", "serial" })
|
632
|
class NullTypeDesignationStatus extends TypeDesignationStatusBase<NullTypeDesignationStatus>{
|
633
|
|
634
|
/**
|
635
|
* {@inheritDoc}
|
636
|
*/
|
637
|
@Override
|
638
|
public void resetTerms() {
|
639
|
// empty
|
640
|
|
641
|
}
|
642
|
|
643
|
/**
|
644
|
* {@inheritDoc}
|
645
|
*/
|
646
|
@Override
|
647
|
protected void setDefaultTerms(TermVocabulary<NullTypeDesignationStatus> termVocabulary) {
|
648
|
// empty
|
649
|
}
|
650
|
|
651
|
|
652
|
|
653
|
}
|
654
|
|
655
|
}
|