removing unused duplicate property PreservedSpecimenDTOs
[cdmlib.git] / cdmlib-services / src / main / java / eu / etaxonomy / cdm / api / service / dto / RowWrapperDTO.java
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 * @since 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, SpecimenOrObservationBase specimen, 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 else if(specimen!=null){
60 this.specimen = specimen;
61 }
62 }
63
64 public QuantitativeData addQuantitativeData(Feature feature){
65 QuantitativeData data = QuantitativeData.NewInstance(feature);
66 description.addElement(data);
67 featureToElementMap.put(feature, data);
68 return data;
69 }
70
71 public CategoricalData addCategoricalData(Feature feature){
72 CategoricalData data = CategoricalData.NewInstance(feature);
73 description.addElement(data);
74 featureToElementMap.put(feature, data);
75 return data;
76 }
77
78 public DescriptionBase getSpecimenDescription() {
79 return description;
80 }
81
82 public SpecimenOrObservationBase getSpecimen() {
83 return specimen;
84 }
85
86 public TaxonNode getTaxonNode() {
87 return taxonNode;
88 }
89
90 public FieldUnit getFieldUnit() {
91 return fieldUnit;
92 }
93
94 public String getIdentifier() {
95 return identifier;
96 }
97
98 public NamedArea getCountry() {
99 return country;
100 }
101
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);
109 }
110 }
111
112 public DescriptionElementBase getDataValueForFeature(Feature feature){
113 DescriptionElementBase descriptionElementBase = featureToElementMap.get(feature);
114 return descriptionElementBase;
115 }
116
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.
121 */
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));
126 }
127 }
128 }