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.Comparator;
|
15
|
import java.util.HashSet;
|
16
|
import java.util.List;
|
17
|
import java.util.Set;
|
18
|
import java.util.TreeSet;
|
19
|
|
20
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
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.molecular.DnaSample;
|
31
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
32
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
33
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
34
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
35
|
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
|
36
|
|
37
|
|
38
|
/**
|
39
|
* @author pplitzner
|
40
|
* @since Mar 27, 2015
|
41
|
*/
|
42
|
public abstract class DerivateDTO extends UuidAndTitleCache<SpecimenOrObservationBase>{
|
43
|
|
44
|
private static final long serialVersionUID = -7597690654462090732L;
|
45
|
|
46
|
private TreeSet<AbstractMap.SimpleEntry<String, String>> characterData;
|
47
|
private DerivateDataDTO derivateDataDTO;
|
48
|
protected String taxonName;
|
49
|
protected String listLabel;
|
50
|
|
51
|
protected String citation;
|
52
|
protected boolean hasDetailImage;
|
53
|
private boolean hasCharacterData;
|
54
|
private boolean hasDna;
|
55
|
private boolean hasSpecimenScan;
|
56
|
|
57
|
private String recordBase;
|
58
|
private String kindOfUnit;
|
59
|
private CollectionDTO collection;
|
60
|
private String catalogNumber;
|
61
|
private String collectorsNumber;
|
62
|
private String barcode;
|
63
|
private String preservationMethod;
|
64
|
private Set<DerivateDTO> derivates;
|
65
|
|
66
|
private Set<SpecimenTypeDesignationDTO> specimenTypeDesignations;
|
67
|
|
68
|
private DerivationEventDTO derivationEvent;
|
69
|
|
70
|
private Set<IdentifiableSource> sources;
|
71
|
private List<MediaDTO> listOfMedia = new ArrayList<>();
|
72
|
|
73
|
/**
|
74
|
* Factory method to create a new instance of the passed <code>SpecimenOrObservationBase</code> with the matching sub
|
75
|
* type of <code>DerivateDTO</code>
|
76
|
*
|
77
|
* @param sob
|
78
|
* @return
|
79
|
*/
|
80
|
public static DerivateDTO newInstance(SpecimenOrObservationBase sob){
|
81
|
if(sob == null) {
|
82
|
return null;
|
83
|
}
|
84
|
DerivateDTO derivateDto;
|
85
|
if (sob.isInstanceOf(FieldUnit.class)){
|
86
|
derivateDto = new FieldUnitDTO(HibernateProxyHelper.deproxy(sob, FieldUnit.class));
|
87
|
} else if (sob instanceof DnaSample){
|
88
|
derivateDto = new DNASampleDTO(HibernateProxyHelper.deproxy(sob, DnaSample.class));
|
89
|
} else {
|
90
|
derivateDto = new PreservedSpecimenDTO(HibernateProxyHelper.deproxy(sob, DerivedUnit.class));
|
91
|
}
|
92
|
return derivateDto;
|
93
|
}
|
94
|
|
95
|
public DerivateDTO(SpecimenOrObservationBase specimenOrObservation) {
|
96
|
super(specimenOrObservation.getUuid(), specimenOrObservation.getId(), specimenOrObservation.getTitleCache());
|
97
|
addMedia(specimenOrObservation);
|
98
|
if (specimenOrObservation.getKindOfUnit() != null){
|
99
|
setKindOfUnit(specimenOrObservation.getKindOfUnit().getTitleCache());
|
100
|
}
|
101
|
if (specimenOrObservation instanceof DerivedUnit){
|
102
|
DerivedUnit derivedUnit = (DerivedUnit)specimenOrObservation;
|
103
|
if (derivedUnit.getSpecimenTypeDesignations() != null){
|
104
|
setSpecimenTypeDesignations(derivedUnit.getSpecimenTypeDesignations());
|
105
|
}
|
106
|
}
|
107
|
|
108
|
|
109
|
}
|
110
|
// @Override
|
111
|
// public String getTitleCache() {
|
112
|
// return getLabel();
|
113
|
// }
|
114
|
|
115
|
|
116
|
public String getListLabel() {
|
117
|
return listLabel;
|
118
|
}
|
119
|
|
120
|
public void setListLabel(String listLabel) {
|
121
|
this.listLabel = listLabel;
|
122
|
}
|
123
|
public void setCollection(CollectionDTO collection) {
|
124
|
this.collection = collection;
|
125
|
}
|
126
|
|
127
|
public String getCatalogNumber() {
|
128
|
return catalogNumber;
|
129
|
}
|
130
|
|
131
|
public void setCatalogNumber(String catalogNumber) {
|
132
|
this.catalogNumber = catalogNumber;
|
133
|
}
|
134
|
|
135
|
public String getCollectorsNumber() {
|
136
|
return collectorsNumber;
|
137
|
}
|
138
|
|
139
|
public void setCollectorsNumber(String collectorsNumber) {
|
140
|
this.collectorsNumber = collectorsNumber;
|
141
|
}
|
142
|
|
143
|
public String getBarcode() {
|
144
|
return barcode;
|
145
|
}
|
146
|
|
147
|
public void setBarcode(String barcode) {
|
148
|
this.barcode = barcode;
|
149
|
}
|
150
|
|
151
|
public String getPreservationMethod() {
|
152
|
return preservationMethod;
|
153
|
}
|
154
|
|
155
|
public void setPreservationMethod(String preservationMethod) {
|
156
|
this.preservationMethod = preservationMethod;
|
157
|
}
|
158
|
|
159
|
public Set<SpecimenTypeDesignationDTO> getSpecimenTypeDesignations() {
|
160
|
return specimenTypeDesignations;
|
161
|
}
|
162
|
|
163
|
public void setSpecimenTypeDesignations(Set<SpecimenTypeDesignation> specimenTypeDesignations) {
|
164
|
this.specimenTypeDesignations = new HashSet<>();
|
165
|
for (SpecimenTypeDesignation typeDes: specimenTypeDesignations){
|
166
|
if (typeDes != null){
|
167
|
this.specimenTypeDesignations.add(new SpecimenTypeDesignationDTO(typeDes));
|
168
|
}
|
169
|
}
|
170
|
|
171
|
}
|
172
|
|
173
|
|
174
|
public Set<IdentifiableSource> getSources() {
|
175
|
return sources;
|
176
|
}
|
177
|
|
178
|
public void setSources(Set<IdentifiableSource> sources) {
|
179
|
this.sources = sources;
|
180
|
}
|
181
|
|
182
|
|
183
|
/**
|
184
|
* @return the derivateDataDTO
|
185
|
*/
|
186
|
public DerivateDataDTO getDerivateDataDTO() {
|
187
|
return derivateDataDTO;
|
188
|
}
|
189
|
|
190
|
/**
|
191
|
* @param derivateDataDTO the derivateDataDTO to set
|
192
|
*/
|
193
|
public void setDerivateDataDTO(DerivateDataDTO derivateDataDTO) {
|
194
|
this.derivateDataDTO = derivateDataDTO;
|
195
|
}
|
196
|
|
197
|
/**
|
198
|
* @return the characterData
|
199
|
*/
|
200
|
public TreeSet<AbstractMap.SimpleEntry<String, String>> getCharacterData() {
|
201
|
return characterData;
|
202
|
}
|
203
|
|
204
|
public void addCharacterData(String character, String state){
|
205
|
if(characterData==null){
|
206
|
characterData = new TreeSet<AbstractMap.SimpleEntry<String,String>>(new PairComparator());
|
207
|
}
|
208
|
characterData.add(new AbstractMap.SimpleEntry<>(character, state));
|
209
|
}
|
210
|
|
211
|
private class PairComparator implements Comparator<AbstractMap.SimpleEntry<String,String>>, Serializable {
|
212
|
|
213
|
private static final long serialVersionUID = -8589392050761963540L;
|
214
|
|
215
|
@Override
|
216
|
public int compare(AbstractMap.SimpleEntry<String, String> o1, AbstractMap.SimpleEntry<String, String> o2) {
|
217
|
if(o1==null && o2!=null){
|
218
|
return -1;
|
219
|
}
|
220
|
if(o1!=null && o2==null){
|
221
|
return 1;
|
222
|
}
|
223
|
if(o1!=null && o2!=null){
|
224
|
return o1.getKey().compareTo(o2.getKey());
|
225
|
}
|
226
|
return 0;
|
227
|
}
|
228
|
}
|
229
|
|
230
|
/**
|
231
|
* @return the hasCharacterData
|
232
|
*/
|
233
|
public boolean isHasCharacterData() {
|
234
|
return hasCharacterData;
|
235
|
}
|
236
|
|
237
|
/**
|
238
|
* @param hasCharacterData the hasCharacterData to set
|
239
|
*/
|
240
|
public void setHasCharacterData(boolean hasCharacterData) {
|
241
|
this.hasCharacterData = hasCharacterData;
|
242
|
}
|
243
|
|
244
|
/**
|
245
|
* @return the hasDna
|
246
|
*/
|
247
|
public boolean isHasDna() {
|
248
|
return hasDna;
|
249
|
}
|
250
|
|
251
|
/**
|
252
|
* @param hasDna the hasDna to set
|
253
|
*/
|
254
|
public void setHasDna(boolean hasDna) {
|
255
|
this.hasDna = hasDna;
|
256
|
}
|
257
|
|
258
|
/**
|
259
|
* @return the hasDetailImage
|
260
|
*/
|
261
|
public boolean isHasDetailImage() {
|
262
|
return hasDetailImage;
|
263
|
}
|
264
|
|
265
|
/**
|
266
|
* @param hasDetailImage the hasDetailImage to set
|
267
|
*/
|
268
|
public void setHasDetailImage(boolean hasDetailImage) {
|
269
|
this.hasDetailImage = hasDetailImage;
|
270
|
}
|
271
|
|
272
|
/**
|
273
|
* @return the hasSpecimenScan
|
274
|
*/
|
275
|
public boolean isHasSpecimenScan() {
|
276
|
return hasSpecimenScan;
|
277
|
}
|
278
|
|
279
|
/**
|
280
|
* @param hasSpecimenScan the hasSpecimenScan to set
|
281
|
*/
|
282
|
public void setHasSpecimenScan(boolean hasSpecimenScan) {
|
283
|
this.hasSpecimenScan = hasSpecimenScan;
|
284
|
}
|
285
|
/**
|
286
|
* @return the citation
|
287
|
*/
|
288
|
public String getCitation() {
|
289
|
return citation;
|
290
|
}
|
291
|
/**
|
292
|
* @param citation the citation to set
|
293
|
*/
|
294
|
public void setCitation(String citation) {
|
295
|
this.citation = citation;
|
296
|
}
|
297
|
|
298
|
|
299
|
public String getRecordBase() {
|
300
|
return recordBase;
|
301
|
}
|
302
|
public void setRecordBase(String recordBase) {
|
303
|
this.recordBase = recordBase;
|
304
|
}
|
305
|
|
306
|
/**
|
307
|
* @return the collection
|
308
|
*
|
309
|
* @deprecated TODO remove as it only duplicates the information contained in the collectionDTO
|
310
|
*/
|
311
|
@Deprecated
|
312
|
public String getCollectionCode() {
|
313
|
if (collection != null){
|
314
|
return collection.getCode();
|
315
|
} else {
|
316
|
return null;
|
317
|
}
|
318
|
}
|
319
|
|
320
|
/**
|
321
|
* @return the collection
|
322
|
*/
|
323
|
public CollectionDTO getCollection() {
|
324
|
return collection;
|
325
|
}
|
326
|
/**
|
327
|
* @param collection the collection to set
|
328
|
*/
|
329
|
public void setCollectioDTo(CollectionDTO collection) {
|
330
|
this.collection = collection;
|
331
|
}
|
332
|
|
333
|
|
334
|
|
335
|
public Set<DerivateDTO> getDerivates() {
|
336
|
return derivates;
|
337
|
}
|
338
|
|
339
|
public void setDerivates(Set<DerivateDTO> derivates) {
|
340
|
this.derivates = derivates;
|
341
|
}
|
342
|
|
343
|
public void addDerivate(DerivateDTO derivate){
|
344
|
if (this.derivates == null){
|
345
|
this.derivates = new HashSet<>();
|
346
|
}
|
347
|
this.derivates.add(derivate);
|
348
|
}
|
349
|
public void addAllDerivates(Set<DerivateDTO> derivates){
|
350
|
if (this.derivates == null){
|
351
|
this.derivates = new HashSet<>();
|
352
|
}
|
353
|
this.derivates.addAll(derivates);
|
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
|
}
|