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