3 * Copyright (C) 2018 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.api
.service
.dto
;
12 import java
.io
.Serializable
;
13 import java
.util
.ArrayList
;
14 import java
.util
.Collection
;
15 import java
.util
.HashMap
;
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
;
36 public class RowWrapperDTO
implements Serializable
{
38 private static final long serialVersionUID
= -7817164423660563673L;
40 private DescriptionBase description
;
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
;
49 public RowWrapperDTO(DescriptionBase description
, SpecimenOrObservationBase specimen
, TaxonNode taxonNode
, FieldUnit fieldUnit
, String identifier
,
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
);
59 else if(specimen
!=null){
60 this.specimen
= specimen
;
64 public QuantitativeData
addQuantitativeData(Feature feature
){
65 QuantitativeData data
= QuantitativeData
.NewInstance(feature
);
66 description
.addElement(data
);
67 featureToElementMap
.put(feature
, data
);
71 public CategoricalData
addCategoricalData(Feature feature
){
72 CategoricalData data
= CategoricalData
.NewInstance(feature
);
73 description
.addElement(data
);
74 featureToElementMap
.put(feature
, data
);
78 public DescriptionBase
getSpecimenDescription() {
82 public SpecimenOrObservationBase
getSpecimen() {
86 public TaxonNode
getTaxonNode() {
90 public FieldUnit
getFieldUnit() {
94 public String
getIdentifier() {
98 public NamedArea
getCountry() {
102 public void setDescription(DescriptionBase description
) {
103 this.description
= description
;
104 this.specimen
= description
.getDescribedSpecimenOrObservation();
105 Set
<DescriptionElementBase
> elements
= description
.getElements();
106 for (DescriptionElementBase descriptionElementBase
: elements
) {
107 Feature feature
= descriptionElementBase
.getFeature();
108 featureToElementMap
.put(feature
, descriptionElementBase
);
112 public DescriptionElementBase
getDataValueForFeature(Feature feature
){
113 DescriptionElementBase descriptionElementBase
= featureToElementMap
.get(feature
);
114 return descriptionElementBase
;
117 public void setDataValueForFeature(Feature feature
, Object newValue
){
118 /* Only CategoricalData is handled here because for QuantitativeData the value
119 * is set in the ModifyListener of the swt.Text in the CellEditor
120 * for each StatisticalMeasure. So no need to set it again here.
122 DescriptionElementBase descriptionElementBase
= featureToElementMap
.get(feature
);
123 if(descriptionElementBase
!=null && descriptionElementBase
.isInstanceOf(CategoricalData
.class) && newValue
instanceof Collection
){
124 CategoricalData categoricalData
= HibernateProxyHelper
.deproxy(descriptionElementBase
, CategoricalData
.class);
125 categoricalData
.setStateDataOnly(new ArrayList
<>((Collection
<State
>) newValue
));