Project

General

Profile

Download (11 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.persistence.dto.UuidAndTitleCache;
33

    
34

    
35
/**
36
 * @author pplitzner
37
 * @since Mar 27, 2015
38
 */
39
public abstract class SpecimenOrObservationBaseDTO extends UuidAndTitleCache<SpecimenOrObservationBase>{
40

    
41
    private static final long serialVersionUID = -7597690654462090732L;
42

    
43
    private TreeSet<AbstractMap.SimpleEntry<String, String>> characterData;
44
    private DerivateDataDTO derivateDataDTO;
45
    protected String taxonName;
46
    protected String listLabel;
47

    
48
    protected String citation;
49
    protected boolean hasDetailImage;
50
    private boolean hasCharacterData;
51
    private boolean hasDna;
52
    private boolean hasSpecimenScan;
53

    
54
    private String recordBase;
55
    private String kindOfUnit;
56
    private CollectionDTO collection;
57
    private String catalogNumber;
58
    private String collectorsNumber;
59
    private String barcode;
60
    private String preservationMethod;
61
    private Set<SpecimenOrObservationBaseDTO> derivates;
62

    
63
    private Set<SpecimenTypeDesignationDTO> specimenTypeDesignations;
64

    
65
    private DerivationEventDTO derivationEvent;
66

    
67
    private Set<IdentifiableSource> sources;
68
    private List<MediaDTO> listOfMedia = new ArrayList<>();
69

    
70
    protected SpecimenOrObservationBaseDTO(SpecimenOrObservationBase specimenOrObservation) {
71
        super(specimenOrObservation.getUuid(), specimenOrObservation.getId(), specimenOrObservation.getTitleCache());
72
        addMedia(specimenOrObservation);
73
        if (specimenOrObservation.getKindOfUnit() != null){
74
            setKindOfUnit(specimenOrObservation.getKindOfUnit().getTitleCache());
75
        }
76
        if (specimenOrObservation instanceof DerivedUnit){
77
            DerivedUnit derivedUnit = (DerivedUnit)specimenOrObservation;
78
            if (derivedUnit.getSpecimenTypeDesignations() != null){
79
                setSpecimenTypeDesignations(derivedUnit.getSpecimenTypeDesignations());
80
            }
81
        }
82

    
83

    
84
    }
85
//    @Override
86
//    public String getTitleCache() {
87
//        return getLabel();
88
//    }
89

    
90

    
91
    public String getListLabel() {
92
        return listLabel;
93
    }
94

    
95
    public void setListLabel(String listLabel) {
96
        this.listLabel = listLabel;
97
    }
98
    public void setCollection(CollectionDTO collection) {
99
        this.collection = collection;
100
    }
101

    
102
    public String getCatalogNumber() {
103
        return catalogNumber;
104
    }
105

    
106
    public void setCatalogNumber(String catalogNumber) {
107
        this.catalogNumber = catalogNumber;
108
    }
109

    
110
    public String getCollectorsNumber() {
111
        return collectorsNumber;
112
    }
113

    
114
    public void setCollectorsNumber(String collectorsNumber) {
115
        this.collectorsNumber = collectorsNumber;
116
    }
117

    
118
    public String getBarcode() {
119
        return barcode;
120
    }
121

    
122
    public void setBarcode(String barcode) {
123
        this.barcode = barcode;
124
    }
125

    
126
    public String getPreservationMethod() {
127
        return preservationMethod;
128
    }
129

    
130
    public void setPreservationMethod(String preservationMethod) {
131
        this.preservationMethod = preservationMethod;
132
    }
133

    
134
    public Set<SpecimenTypeDesignationDTO> getSpecimenTypeDesignations() {
135
        return specimenTypeDesignations;
136
    }
137

    
138
    public void setSpecimenTypeDesignations(Set<SpecimenTypeDesignation> specimenTypeDesignations) {
139
        this.specimenTypeDesignations = new HashSet<>();
140
        for (SpecimenTypeDesignation typeDes: specimenTypeDesignations){
141
            if (typeDes != null){
142
                this.specimenTypeDesignations.add(new SpecimenTypeDesignationDTO(typeDes));
143
            }
144
        }
145

    
146
    }
147

    
148

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

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

    
157

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

    
165
    /**
166
     * @param derivateDataDTO the derivateDataDTO to set
167
     */
168
    public void setDerivateDataDTO(DerivateDataDTO derivateDataDTO) {
169
        this.derivateDataDTO = derivateDataDTO;
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<SpecimenOrObservationBaseDTO> getDerivates() {
311
        return derivates;
312
    }
313

    
314
    public void setDerivates(Set<SpecimenOrObservationBaseDTO> derivates) {
315
        this.derivates = derivates;
316
    }
317

    
318
    public void addDerivate(SpecimenOrObservationBaseDTO derivate){
319
        if (this.derivates == null){
320
            this.derivates = new HashSet<>();
321
        }
322
        this.derivates.add(derivate);
323
    }
324
    public void addAllDerivates(Set<SpecimenOrObservationBaseDTO> derivates){
325
        if (this.derivates == null){
326
            this.derivates = new HashSet<>();
327
        }
328
        this.derivates.addAll(derivates);
329
    }
330

    
331
    public DerivationEventDTO getDerivationEvent() {
332
        return derivationEvent;
333
    }
334

    
335
    public void setDerivationEvent(DerivationEventDTO derivationEvent) {
336
        this.derivationEvent = derivationEvent;
337
    }
338

    
339

    
340
    /**
341
     * @return the listOfMedia
342
     */
343
    public List<MediaDTO> getListOfMedia() {
344
        return listOfMedia;
345
    }
346

    
347
    /**
348
     * @param listOfMedia the listOfMedia to set
349
     */
350
    public void setListOfMedia(List<MediaDTO> listOfMedia) {
351
        this.listOfMedia = listOfMedia;
352
    }
353

    
354
    public void addMedia(SpecimenOrObservationBase specimenOrObservation){
355
        Set<DescriptionBase> descriptions = specimenOrObservation.getSpecimenDescriptionImageGallery();
356
        for (DescriptionBase desc : descriptions){
357
            if (desc instanceof SpecimenDescription){
358
                SpecimenDescription specimenDesc = (SpecimenDescription)desc;
359
                for (DescriptionElementBase element : specimenDesc.getElements()){
360
                    if (element.isInstanceOf(TextData.class)&& element.getFeature().equals(Feature.IMAGE())) {
361
                        for (Media media :element.getMedia()){
362
                            media.getAllTitles(); // initialize all titles!!!
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
}
(27-27/36)