Project

General

Profile

Download (4.29 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2018 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.api.service.dto;
11

    
12
import java.io.Serializable;
13
import java.util.ArrayList;
14
import java.util.Collection;
15
import java.util.HashMap;
16
import java.util.Map;
17
import java.util.Set;
18

    
19
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
20
import eu.etaxonomy.cdm.model.description.CategoricalData;
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.QuantitativeData;
25
import eu.etaxonomy.cdm.model.description.State;
26
import eu.etaxonomy.cdm.model.location.NamedArea;
27
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
28
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
29
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
30

    
31
/**
32
 * @author pplitzner
33
 * @date 16.04.2018
34
 *
35
 */
36
public class RowWrapperDTO implements Serializable {
37

    
38
    private static final long serialVersionUID = -7817164423660563673L;
39

    
40
    private DescriptionBase description;
41

    
42
    private SpecimenOrObservationBase specimen;
43
    private TaxonNode taxonNode;
44
    private FieldUnit fieldUnit;
45
    private String identifier;
46
    private NamedArea country;
47
    private Map<Feature, DescriptionElementBase> featureToElementMap;
48

    
49
    public RowWrapperDTO(DescriptionBase description, TaxonNode taxonNode, FieldUnit fieldUnit, String identifier,
50
            NamedArea country) {
51
        this.taxonNode = taxonNode;
52
        this.fieldUnit = fieldUnit;
53
        this.identifier = identifier;
54
        this.country = country;
55
        this.featureToElementMap = new HashMap<>();
56
        if(description!=null){
57
            setDescription(description);
58
        }
59
    }
60

    
61
    public QuantitativeData addQuantitativeData(Feature feature){
62
        QuantitativeData data = QuantitativeData.NewInstance(feature);
63
        description.addElement(data);
64
        featureToElementMap.put(feature, data);
65
        return data;
66
    }
67

    
68
    public CategoricalData addCategoricalData(Feature feature){
69
        CategoricalData data = CategoricalData.NewInstance(feature);
70
        description.addElement(data);
71
        featureToElementMap.put(feature, data);
72
        return data;
73
    }
74

    
75
    public DescriptionBase getSpecimenDescription() {
76
        return description;
77
    }
78

    
79
    public SpecimenOrObservationBase getSpecimen() {
80
        return specimen;
81
    }
82

    
83
    public TaxonNode getTaxonNode() {
84
        return taxonNode;
85
    }
86

    
87
    public FieldUnit getFieldUnit() {
88
        return fieldUnit;
89
    }
90

    
91
    public String getIdentifier() {
92
        return identifier;
93
    }
94

    
95
    public NamedArea getCountry() {
96
        return country;
97
    }
98

    
99
    public void setDescription(DescriptionBase description) {
100
        this.description = description;
101
        this.specimen = description.getDescribedSpecimenOrObservation();
102
        Set<DescriptionElementBase> elements = description.getElements();
103
        for (DescriptionElementBase descriptionElementBase : elements) {
104
            Feature feature = descriptionElementBase.getFeature();
105
            featureToElementMap.put(feature, descriptionElementBase);
106
        }
107
    }
108

    
109
    public Object getDataValueForFeature(Feature feature){
110
        DescriptionElementBase descriptionElementBase = featureToElementMap.get(feature);
111
        return descriptionElementBase;
112
    }
113

    
114
    public void setDataValueForFeature(Feature feature, Object newValue){
115
        /* Only CategoricalData is handled here because for QuantitativeData the value
116
         * is set in the ModifyListener of the swt.Text in the CellEditor
117
         * for each StatisticalMeasure. So no need to set it again here.
118
         */
119
        DescriptionElementBase descriptionElementBase = featureToElementMap.get(feature);
120
        if(descriptionElementBase!=null && descriptionElementBase.isInstanceOf(CategoricalData.class) && newValue instanceof Collection){
121
            CategoricalData categoricalData = HibernateProxyHelper.deproxy(descriptionElementBase, CategoricalData.class);
122
            categoricalData.setStateDataOnly(new ArrayList<>((Collection<State>) newValue));
123
        }
124
    }
125
}
(17-17/19)