1
|
/**
|
2
|
* Copyright (C) 2015 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.api.service.dto;
|
10
|
|
11
|
import java.io.Serializable;
|
12
|
import java.util.AbstractMap;
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.Collection;
|
15
|
import java.util.Comparator;
|
16
|
import java.util.HashSet;
|
17
|
import java.util.List;
|
18
|
import java.util.Set;
|
19
|
import java.util.TreeSet;
|
20
|
|
21
|
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
|
22
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
23
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
24
|
import eu.etaxonomy.cdm.model.description.Feature;
|
25
|
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
|
26
|
import eu.etaxonomy.cdm.model.description.TextData;
|
27
|
import eu.etaxonomy.cdm.model.media.Media;
|
28
|
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
|
29
|
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
|
30
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
31
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
32
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
33
|
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
|
34
|
|
35
|
|
36
|
/**
|
37
|
* @author pplitzner
|
38
|
* @since Mar 27, 2015
|
39
|
*/
|
40
|
public abstract class SpecimenOrObservationBaseDTO extends UuidAndTitleCache<SpecimenOrObservationBase>{
|
41
|
|
42
|
private static final long serialVersionUID = -7597690654462090732L;
|
43
|
|
44
|
private TreeSet<AbstractMap.SimpleEntry<String, String>> characterData;
|
45
|
private DerivateDataDTO derivateDataDTO;
|
46
|
protected String taxonName;
|
47
|
protected String listLabel;
|
48
|
|
49
|
protected String citation;
|
50
|
protected boolean hasDetailImage;
|
51
|
private boolean hasCharacterData;
|
52
|
private boolean hasDna;
|
53
|
private boolean hasSpecimenScan;
|
54
|
|
55
|
private String recordBase;
|
56
|
private String kindOfUnit;
|
57
|
private CollectionDTO collection;
|
58
|
private String catalogNumber;
|
59
|
private String collectorsNumber;
|
60
|
private String barcode;
|
61
|
private String preservationMethod;
|
62
|
private Set<DerivedUnitDTO> derivates;
|
63
|
|
64
|
private Set<SpecimenTypeDesignationDTO> specimenTypeDesignations;
|
65
|
|
66
|
private DerivationEventDTO derivationEvent;
|
67
|
|
68
|
private Set<IdentifiableSource> sources;
|
69
|
private List<MediaDTO> listOfMedia = new ArrayList<>();
|
70
|
|
71
|
protected SpecimenOrObservationBaseDTO(SpecimenOrObservationBase specimenOrObservation) {
|
72
|
super(specimenOrObservation.getUuid(), specimenOrObservation.getId(), specimenOrObservation.getTitleCache());
|
73
|
addMedia(specimenOrObservation);
|
74
|
if (specimenOrObservation.getKindOfUnit() != null){
|
75
|
setKindOfUnit(specimenOrObservation.getKindOfUnit().getTitleCache());
|
76
|
}
|
77
|
if (specimenOrObservation instanceof DerivedUnit){
|
78
|
DerivedUnit derivedUnit = (DerivedUnit)specimenOrObservation;
|
79
|
if (derivedUnit.getSpecimenTypeDesignations() != null){
|
80
|
setSpecimenTypeDesignations(derivedUnit.getSpecimenTypeDesignations());
|
81
|
}
|
82
|
}
|
83
|
}
|
84
|
|
85
|
|
86
|
public String getListLabel() {
|
87
|
return listLabel;
|
88
|
}
|
89
|
|
90
|
public void setListLabel(String listLabel) {
|
91
|
this.listLabel = listLabel;
|
92
|
}
|
93
|
public void setCollection(CollectionDTO collection) {
|
94
|
this.collection = collection;
|
95
|
}
|
96
|
|
97
|
public String getCatalogNumber() {
|
98
|
return catalogNumber;
|
99
|
}
|
100
|
|
101
|
public void setCatalogNumber(String catalogNumber) {
|
102
|
this.catalogNumber = catalogNumber;
|
103
|
}
|
104
|
|
105
|
public String getCollectorsNumber() {
|
106
|
return collectorsNumber;
|
107
|
}
|
108
|
|
109
|
public void setCollectorsNumber(String collectorsNumber) {
|
110
|
this.collectorsNumber = collectorsNumber;
|
111
|
}
|
112
|
|
113
|
public String getBarcode() {
|
114
|
return barcode;
|
115
|
}
|
116
|
|
117
|
public void setBarcode(String barcode) {
|
118
|
this.barcode = barcode;
|
119
|
}
|
120
|
|
121
|
public String getPreservationMethod() {
|
122
|
return preservationMethod;
|
123
|
}
|
124
|
|
125
|
public void setPreservationMethod(String preservationMethod) {
|
126
|
this.preservationMethod = preservationMethod;
|
127
|
}
|
128
|
|
129
|
public Set<SpecimenTypeDesignationDTO> getSpecimenTypeDesignations() {
|
130
|
return specimenTypeDesignations;
|
131
|
}
|
132
|
|
133
|
public void setSpecimenTypeDesignations(Set<SpecimenTypeDesignation> specimenTypeDesignations) {
|
134
|
this.specimenTypeDesignations = new HashSet<>();
|
135
|
for (SpecimenTypeDesignation typeDes: specimenTypeDesignations){
|
136
|
if (typeDes != null){
|
137
|
this.specimenTypeDesignations.add(new SpecimenTypeDesignationDTO(typeDes));
|
138
|
}
|
139
|
}
|
140
|
|
141
|
}
|
142
|
|
143
|
|
144
|
public Set<IdentifiableSource> getSources() {
|
145
|
return sources;
|
146
|
}
|
147
|
|
148
|
public void setSources(Set<IdentifiableSource> sources) {
|
149
|
this.sources = sources;
|
150
|
}
|
151
|
|
152
|
|
153
|
/**
|
154
|
* @return the derivateDataDTO
|
155
|
*/
|
156
|
public DerivateDataDTO getDerivateDataDTO() {
|
157
|
return derivateDataDTO;
|
158
|
}
|
159
|
|
160
|
/**
|
161
|
* @param derivateDataDTO the derivateDataDTO to set
|
162
|
*/
|
163
|
public void setDerivateDataDTO(DerivateDataDTO derivateDataDTO) {
|
164
|
this.derivateDataDTO = derivateDataDTO;
|
165
|
if(derivateDataDTO != null) {
|
166
|
setHasSpecimenScan(isHasSpecimenScan() || !derivateDataDTO.getSpecimenScans().isEmpty());
|
167
|
setHasDetailImage(isHasDetailImage() || !derivateDataDTO.getDetailImages().isEmpty());
|
168
|
setHasDna(isHasDna() || !derivateDataDTO.getMolecularDataList().isEmpty());
|
169
|
}
|
170
|
}
|
171
|
|
172
|
/**
|
173
|
* @return the characterData
|
174
|
*/
|
175
|
public TreeSet<AbstractMap.SimpleEntry<String, String>> getCharacterData() {
|
176
|
return characterData;
|
177
|
}
|
178
|
|
179
|
public void addCharacterData(String character, String state){
|
180
|
if(characterData==null){
|
181
|
characterData = new TreeSet<AbstractMap.SimpleEntry<String,String>>(new PairComparator());
|
182
|
}
|
183
|
characterData.add(new AbstractMap.SimpleEntry<>(character, state));
|
184
|
}
|
185
|
|
186
|
private class PairComparator implements Comparator<AbstractMap.SimpleEntry<String,String>>, Serializable {
|
187
|
|
188
|
private static final long serialVersionUID = -8589392050761963540L;
|
189
|
|
190
|
@Override
|
191
|
public int compare(AbstractMap.SimpleEntry<String, String> o1, AbstractMap.SimpleEntry<String, String> o2) {
|
192
|
if(o1==null && o2!=null){
|
193
|
return -1;
|
194
|
}
|
195
|
if(o1!=null && o2==null){
|
196
|
return 1;
|
197
|
}
|
198
|
if(o1!=null && o2!=null){
|
199
|
return o1.getKey().compareTo(o2.getKey());
|
200
|
}
|
201
|
return 0;
|
202
|
}
|
203
|
}
|
204
|
|
205
|
/**
|
206
|
* @return the hasCharacterData
|
207
|
*/
|
208
|
public boolean isHasCharacterData() {
|
209
|
return hasCharacterData;
|
210
|
}
|
211
|
|
212
|
/**
|
213
|
* @param hasCharacterData the hasCharacterData to set
|
214
|
*/
|
215
|
public void setHasCharacterData(boolean hasCharacterData) {
|
216
|
this.hasCharacterData = hasCharacterData;
|
217
|
}
|
218
|
|
219
|
/**
|
220
|
* @return the hasDna
|
221
|
*/
|
222
|
public boolean isHasDna() {
|
223
|
return hasDna;
|
224
|
}
|
225
|
|
226
|
/**
|
227
|
* @param hasDna the hasDna to set
|
228
|
*/
|
229
|
public void setHasDna(boolean hasDna) {
|
230
|
this.hasDna = hasDna;
|
231
|
}
|
232
|
|
233
|
/**
|
234
|
* @return the hasDetailImage
|
235
|
*/
|
236
|
public boolean isHasDetailImage() {
|
237
|
return hasDetailImage;
|
238
|
}
|
239
|
|
240
|
/**
|
241
|
* @param hasDetailImage the hasDetailImage to set
|
242
|
*/
|
243
|
public void setHasDetailImage(boolean hasDetailImage) {
|
244
|
this.hasDetailImage = hasDetailImage;
|
245
|
}
|
246
|
|
247
|
/**
|
248
|
* @return the hasSpecimenScan
|
249
|
*/
|
250
|
public boolean isHasSpecimenScan() {
|
251
|
return hasSpecimenScan;
|
252
|
}
|
253
|
|
254
|
/**
|
255
|
* @param hasSpecimenScan the hasSpecimenScan to set
|
256
|
*/
|
257
|
public void setHasSpecimenScan(boolean hasSpecimenScan) {
|
258
|
this.hasSpecimenScan = hasSpecimenScan;
|
259
|
}
|
260
|
/**
|
261
|
* @return the citation
|
262
|
*/
|
263
|
public String getCitation() {
|
264
|
return citation;
|
265
|
}
|
266
|
/**
|
267
|
* @param citation the citation to set
|
268
|
*/
|
269
|
public void setCitation(String citation) {
|
270
|
this.citation = citation;
|
271
|
}
|
272
|
|
273
|
|
274
|
public String getRecordBase() {
|
275
|
return recordBase;
|
276
|
}
|
277
|
public void setRecordBase(String recordBase) {
|
278
|
this.recordBase = recordBase;
|
279
|
}
|
280
|
|
281
|
/**
|
282
|
* @return the collection
|
283
|
*
|
284
|
* @deprecated TODO remove as it only duplicates the information contained in the collectionDTO
|
285
|
*/
|
286
|
@Deprecated
|
287
|
public String getCollectionCode() {
|
288
|
if (collection != null){
|
289
|
return collection.getCode();
|
290
|
} else {
|
291
|
return null;
|
292
|
}
|
293
|
}
|
294
|
|
295
|
/**
|
296
|
* @return the collection
|
297
|
*/
|
298
|
public CollectionDTO getCollection() {
|
299
|
return collection;
|
300
|
}
|
301
|
/**
|
302
|
* @param collection the collection to set
|
303
|
*/
|
304
|
public void setCollectioDTo(CollectionDTO collection) {
|
305
|
this.collection = collection;
|
306
|
}
|
307
|
|
308
|
|
309
|
|
310
|
public Set<DerivedUnitDTO> getDerivates() {
|
311
|
if (this.derivates == null){
|
312
|
this.derivates = new HashSet<>();
|
313
|
}
|
314
|
return derivates;
|
315
|
}
|
316
|
|
317
|
public void setDerivates(Set<DerivedUnitDTO> derivates) {
|
318
|
this.derivates = derivates;
|
319
|
}
|
320
|
|
321
|
public void addDerivate(DerivedUnitDTO derivate){
|
322
|
if (this.derivates == null){
|
323
|
this.derivates = new HashSet<>();
|
324
|
}
|
325
|
this.derivates.add(derivate);
|
326
|
}
|
327
|
public void addAllDerivates(Set<DerivedUnitDTO> derivates){
|
328
|
if (this.derivates == null){
|
329
|
this.derivates = new HashSet<>();
|
330
|
}
|
331
|
this.derivates.addAll(derivates);
|
332
|
}
|
333
|
|
334
|
/**
|
335
|
* collects all derivatives from this an derivatives of this.
|
336
|
*/
|
337
|
public Collection<DerivedUnitDTO> collectDerivatives() {
|
338
|
return collectDerivatives(new HashSet<>());
|
339
|
}
|
340
|
|
341
|
/**
|
342
|
* private partner method to {@link #collectDerivatives()} for recursive calls.
|
343
|
*
|
344
|
* @param dtos
|
345
|
*/
|
346
|
private Collection<DerivedUnitDTO> collectDerivatives(Set<DerivedUnitDTO> dtos) {
|
347
|
dtos.addAll(getDerivates());
|
348
|
if(derivates != null) {
|
349
|
for(SpecimenOrObservationBaseDTO subDto : derivates) {
|
350
|
dtos.addAll(subDto.collectDerivatives(dtos));
|
351
|
}
|
352
|
}
|
353
|
return dtos;
|
354
|
}
|
355
|
|
356
|
public DerivationEventDTO getDerivationEvent() {
|
357
|
return derivationEvent;
|
358
|
}
|
359
|
|
360
|
public void setDerivationEvent(DerivationEventDTO derivationEvent) {
|
361
|
this.derivationEvent = derivationEvent;
|
362
|
}
|
363
|
|
364
|
|
365
|
/**
|
366
|
* @return the listOfMedia
|
367
|
*/
|
368
|
public List<MediaDTO> getListOfMedia() {
|
369
|
return listOfMedia;
|
370
|
}
|
371
|
|
372
|
/**
|
373
|
* @param listOfMedia the listOfMedia to set
|
374
|
*/
|
375
|
public void setListOfMedia(List<MediaDTO> listOfMedia) {
|
376
|
this.listOfMedia = listOfMedia;
|
377
|
}
|
378
|
|
379
|
public void addMedia(SpecimenOrObservationBase specimenOrObservation){
|
380
|
Set<DescriptionBase> descriptions = specimenOrObservation.getSpecimenDescriptionImageGallery();
|
381
|
for (DescriptionBase desc : descriptions){
|
382
|
if (desc instanceof SpecimenDescription){
|
383
|
SpecimenDescription specimenDesc = (SpecimenDescription)desc;
|
384
|
for (DescriptionElementBase element : specimenDesc.getElements()){
|
385
|
if (element.isInstanceOf(TextData.class)&& element.getFeature().equals(Feature.IMAGE())) {
|
386
|
for (Media media :element.getMedia()){
|
387
|
media.getAllTitles(); // initialize all titles!!!
|
388
|
for (MediaRepresentation rep :media.getRepresentations()){
|
389
|
for(MediaRepresentationPart p : rep.getParts()){
|
390
|
if(p.getUri() != null){
|
391
|
MediaDTO dto = new MediaDTO(media.getUuid());
|
392
|
dto.setUri(p.getUri().toString());
|
393
|
this.getListOfMedia().add(dto);
|
394
|
}
|
395
|
}
|
396
|
}
|
397
|
}
|
398
|
}
|
399
|
}
|
400
|
}
|
401
|
}
|
402
|
}
|
403
|
public String getKindOfUnit() {
|
404
|
return kindOfUnit;
|
405
|
}
|
406
|
public void setKindOfUnit(String kindOfUnit) {
|
407
|
this.kindOfUnit = kindOfUnit;
|
408
|
}
|
409
|
|
410
|
|
411
|
}
|