Project

General

Profile

Download (10.8 KB) Statistics
| Branch: | Tag: | Revision:
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.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 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

    
50

    
51

    
52
    protected String citation;
53
    protected boolean hasDetailImage;
54
    private boolean hasCharacterData;
55
    private boolean hasDna;
56
    private boolean hasSpecimenScan;
57

    
58
    private String recordBase;
59
    private String kindOfUnit;
60
    private CollectionDTO collection;
61
    private String catalogNumber;
62
    private String collectorsNumber;
63
    private String barcode;
64
    private String preservationMethod;
65
    private Set<DerivateDTO> derivates;
66

    
67
    private Set<SpecimenTypeDesignation> specimenTypeDesignations;
68

    
69
    private DerivationEventDTO derivationEvent;
70

    
71
    private Set<IdentifiableSource> sources;
72
    private List<MediaDTO> listOfMedia = new ArrayList<>();
73

    
74
    public DerivateDTO(SpecimenOrObservationBase specimenOrObservation) {
75
        super(specimenOrObservation.getClass(), specimenOrObservation.getUuid(), specimenOrObservation.getTitleCache());
76
        addMedia(specimenOrObservation);
77
        if (specimenOrObservation.getKindOfUnit() != null){
78
            setKindOfUnit(specimenOrObservation.getKindOfUnit().getTitleCache());
79
        }
80
        if (specimenOrObservation instanceof DerivedUnit){
81
            DerivedUnit derivedUnit = (DerivedUnit)specimenOrObservation;
82
            if (derivedUnit.getSpecimenTypeDesignations() != null){
83
                setSpecimenTypeDesignations(derivedUnit.getSpecimenTypeDesignations());
84
            }
85
        }
86

    
87

    
88
    }
89
    public String getTitleCache() {
90
        return getLabel();
91
    }
92

    
93

    
94
    public String getListLabel() {
95
        return listLabel;
96
    }
97

    
98
    public void setListLabel(String listLabel) {
99
        this.listLabel = listLabel;
100
    }
101
    public void setCollection(CollectionDTO collection) {
102
        this.collection = collection;
103
    }
104

    
105
    public String getCatalogNumber() {
106
        return catalogNumber;
107
    }
108

    
109
    public void setCatalogNumber(String catalogNumber) {
110
        this.catalogNumber = catalogNumber;
111
    }
112

    
113
    public String getCollectorsNumber() {
114
        return collectorsNumber;
115
    }
116

    
117
    public void setCollectorsNumber(String collectorsNumber) {
118
        this.collectorsNumber = collectorsNumber;
119
    }
120

    
121
    public String getBarcode() {
122
        return barcode;
123
    }
124

    
125
    public void setBarcode(String barcode) {
126
        this.barcode = barcode;
127
    }
128

    
129
    public String getPreservationMethod() {
130
        return preservationMethod;
131
    }
132

    
133
    public void setPreservationMethod(String preservationMethod) {
134
        this.preservationMethod = preservationMethod;
135
    }
136

    
137
    public Set<SpecimenTypeDesignation> getSpecimenTypeDesignations() {
138
        return specimenTypeDesignations;
139
    }
140

    
141
    public void setSpecimenTypeDesignations(Set<SpecimenTypeDesignation> specimenTypeDesignations) {
142
        this.specimenTypeDesignations = new HashSet<>();
143
        for (SpecimenTypeDesignation typeDes: specimenTypeDesignations){
144
            this.specimenTypeDesignations.add(typeDes);
145
        }
146

    
147
    }
148

    
149

    
150
    public Set<IdentifiableSource> getSources() {
151
        return sources;
152
    }
153

    
154
    public void setSources(Set<IdentifiableSource> sources) {
155
        this.sources = sources;
156
    }
157

    
158

    
159
    /**
160
     * @return the derivateDataDTO
161
     */
162
    public DerivateDataDTO getDerivateDataDTO() {
163
        return derivateDataDTO;
164
    }
165

    
166
    /**
167
     * @param derivateDataDTO the derivateDataDTO to set
168
     */
169
    public void setDerivateDataDTO(DerivateDataDTO derivateDataDTO) {
170
        this.derivateDataDTO = derivateDataDTO;
171
    }
172

    
173
    /**
174
     * @return the characterData
175
     */
176
    public TreeSet<AbstractMap.SimpleEntry<String, String>> getCharacterData() {
177
        return characterData;
178
    }
179

    
180
    public void addCharacterData(String character, String state){
181
      if(characterData==null){
182
          characterData = new TreeSet<AbstractMap.SimpleEntry<String,String>>(new PairComparator());
183
      }
184
      characterData.add(new AbstractMap.SimpleEntry<>(character, state));
185
    }
186

    
187
    private class PairComparator implements Comparator<AbstractMap.SimpleEntry<String,String>>, Serializable {
188

    
189
        private static final long serialVersionUID = -8589392050761963540L;
190

    
191
        @Override
192
        public int compare(AbstractMap.SimpleEntry<String, String> o1, AbstractMap.SimpleEntry<String, String> o2) {
193
            if(o1==null && o2!=null){
194
                return -1;
195
            }
196
            if(o1!=null && o2==null){
197
                return 1;
198
            }
199
            if(o1!=null && o2!=null){
200
                return o1.getKey().compareTo(o2.getKey());
201
            }
202
            return 0;
203
        }
204
    }
205

    
206
    /**
207
     * @return the hasCharacterData
208
     */
209
    public boolean isHasCharacterData() {
210
        return hasCharacterData;
211
    }
212

    
213
    /**
214
     * @param hasCharacterData the hasCharacterData to set
215
     */
216
    public void setHasCharacterData(boolean hasCharacterData) {
217
        this.hasCharacterData = hasCharacterData;
218
    }
219

    
220
    /**
221
     * @return the hasDna
222
     */
223
    public boolean isHasDna() {
224
        return hasDna;
225
    }
226

    
227
    /**
228
     * @param hasDna the hasDna to set
229
     */
230
    public void setHasDna(boolean hasDna) {
231
        this.hasDna = hasDna;
232
    }
233

    
234
    /**
235
     * @return the hasDetailImage
236
     */
237
    public boolean isHasDetailImage() {
238
        return hasDetailImage;
239
    }
240

    
241
    /**
242
     * @param hasDetailImage the hasDetailImage to set
243
     */
244
    public void setHasDetailImage(boolean hasDetailImage) {
245
        this.hasDetailImage = hasDetailImage;
246
    }
247

    
248
    /**
249
     * @return the hasSpecimenScan
250
     */
251
    public boolean isHasSpecimenScan() {
252
        return hasSpecimenScan;
253
    }
254

    
255
    /**
256
     * @param hasSpecimenScan the hasSpecimenScan to set
257
     */
258
    public void setHasSpecimenScan(boolean hasSpecimenScan) {
259
        this.hasSpecimenScan = hasSpecimenScan;
260
    }
261
    /**
262
     * @return the citation
263
     */
264
    public String getCitation() {
265
        return citation;
266
    }
267
    /**
268
     * @param citation the citation to set
269
     */
270
    public void setCitation(String citation) {
271
        this.citation = citation;
272
    }
273

    
274

    
275
    public String getRecordBase() {
276
        return recordBase;
277
    }
278
    public void setRecordBase(String recordBase) {
279
        this.recordBase = recordBase;
280
    }
281

    
282
    /**
283
     * @return the collection
284
     */
285
    public String getCollection() {
286
        if (collection != null){
287
            return collection.getCode();
288
        } else {
289
            return null;
290
        }
291
    }
292
    /**
293
     * @param collection the collection to set
294
     */
295
    public void setCollection(String herbarium) {
296
        if (collection == null){
297
            collection = new CollectionDTO(herbarium, null, null, null);
298
        }else{
299
            this.collection.setCode(herbarium);
300
        }
301
    }
302
    /**
303
     * @return the collection
304
     */
305
    public CollectionDTO getCollectionDTO() {
306
        return collection;
307
    }
308
    /**
309
     * @param collection the collection to set
310
     */
311
    public void setCollectioDTo(CollectionDTO collection) {
312
        this.collection = collection;
313
    }
314

    
315

    
316

    
317
    public Set<DerivateDTO> getDerivates() {
318
        return derivates;
319
    }
320

    
321
    public void setDerivates(Set<DerivateDTO> derivates) {
322
        this.derivates = derivates;
323
    }
324

    
325
    public void addDerivate(DerivateDTO derivate){
326
        if (this.derivates == null){
327
            this.derivates = new HashSet<>();
328
        }
329
        this.derivates.add(derivate);
330
    }
331
    public void addAllDerivates(Set<DerivateDTO> derivates){
332
        if (this.derivates == null){
333
            this.derivates = new HashSet<>();
334
        }
335
        this.derivates.addAll(derivates);
336
    }
337

    
338
    public DerivationEventDTO getDerivationEvent() {
339
        return derivationEvent;
340
    }
341

    
342
    public void setDerivationEvent(DerivationEventDTO derivationEvent) {
343
        this.derivationEvent = derivationEvent;
344
    }
345

    
346

    
347
    /**
348
     * @return the listOfMedia
349
     */
350
    public List<MediaDTO> getListOfMedia() {
351
        return listOfMedia;
352
    }
353

    
354
    /**
355
     * @param listOfMedia the listOfMedia to set
356
     */
357
    public void setListOfMedia(List<MediaDTO> listOfMedia) {
358
        this.listOfMedia = listOfMedia;
359
    }
360

    
361
    public void addMedia(SpecimenOrObservationBase specimenOrObservation){
362
        Set<DescriptionBase> descriptions = specimenOrObservation.getSpecimenDescriptionImageGallery();
363
        for (DescriptionBase desc : descriptions){
364
            if (desc instanceof SpecimenDescription){
365
                SpecimenDescription specimenDesc = (SpecimenDescription)desc;
366
                for (DescriptionElementBase element : specimenDesc.getElements()){
367
                    if (element.isInstanceOf(TextData.class)&& element.getFeature().equals(Feature.IMAGE())) {
368
                        for (Media media :element.getMedia()){
369
                            for (MediaRepresentation rep :media.getRepresentations()){
370
                                for(MediaRepresentationPart p : rep.getParts()){
371
                                    if(p.getUri() != null){
372
                                        MediaDTO dto = new MediaDTO(media.getUuid());
373
                                        dto.setUri(p.getUri().toString());
374
                                        this.getListOfMedia().add(dto);
375
                                    }
376
                                }
377
                            }
378
                        }
379
                    }
380
                }
381
            }
382
        }
383
    }
384
    public String getKindOfUnit() {
385
        return kindOfUnit;
386
    }
387
    public void setKindOfUnit(String kindOfUnit) {
388
        this.kindOfUnit = kindOfUnit;
389
    }
390

    
391

    
392
}
(5-5/30)