1
|
/**
|
2
|
* Copyright (C) 2017 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.taxeditor.editor.workingSet.matrix;
|
10
|
|
11
|
import java.util.Collection;
|
12
|
import java.util.HashMap;
|
13
|
import java.util.Map;
|
14
|
import java.util.Set;
|
15
|
|
16
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
17
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
18
|
import eu.etaxonomy.cdm.model.description.CategoricalData;
|
19
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
20
|
import eu.etaxonomy.cdm.model.description.Feature;
|
21
|
import eu.etaxonomy.cdm.model.description.QuantitativeData;
|
22
|
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
|
23
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
24
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
25
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
26
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
27
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
28
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
29
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
30
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
31
|
|
32
|
/**
|
33
|
* @author pplitzner
|
34
|
* @since Dec 14, 2017
|
35
|
*
|
36
|
*/
|
37
|
public class RowWrapper {
|
38
|
|
39
|
private SpecimenDescription description;
|
40
|
|
41
|
private Taxon associatedTaxon;
|
42
|
private FieldUnit fieldUnit;
|
43
|
private String identifier;
|
44
|
private NamedArea country;
|
45
|
private Map<Feature, DescriptionElementBase> featureToElementMap = new HashMap<>();
|
46
|
|
47
|
public RowWrapper(SpecimenDescription description) {
|
48
|
this.description = description;
|
49
|
|
50
|
IOccurrenceService occurrenceService = CdmStore.getService(IOccurrenceService.class);
|
51
|
SpecimenOrObservationBase<?> specimen = HibernateProxyHelper.deproxy(description.getDescribedSpecimenOrObservation(), SpecimenOrObservationBase.class);
|
52
|
//supplemental information
|
53
|
if(specimen!=null){
|
54
|
Collection<TaxonBase<?>> associatedTaxa = occurrenceService.listAssociatedTaxa(specimen, null, null, null, null);
|
55
|
if(associatedTaxa!=null){
|
56
|
associatedTaxon = (Taxon) associatedTaxa.iterator().next();
|
57
|
}
|
58
|
Collection<FieldUnit> fieldUnits = occurrenceService.getFieldUnits(specimen.getUuid());
|
59
|
if(fieldUnits.size()!=1){
|
60
|
MessagingUtils.error(RowWrapper.class, "More than one or no field unit found for specimen", null);
|
61
|
}
|
62
|
else{
|
63
|
fieldUnit = fieldUnits.iterator().next();
|
64
|
}
|
65
|
if(specimen instanceof DerivedUnit){
|
66
|
identifier = occurrenceService.getMostSignificantIdentifier(HibernateProxyHelper.deproxy(specimen, DerivedUnit.class));
|
67
|
}
|
68
|
if(fieldUnit!=null && fieldUnit.getGatheringEvent()!=null){
|
69
|
country = fieldUnit.getGatheringEvent().getCountry();
|
70
|
}
|
71
|
}
|
72
|
//description elements
|
73
|
Set<DescriptionElementBase> elements = description.getElements();
|
74
|
for (DescriptionElementBase descriptionElementBase : elements) {
|
75
|
Feature feature = descriptionElementBase.getFeature();
|
76
|
featureToElementMap.put(feature, descriptionElementBase);
|
77
|
}
|
78
|
}
|
79
|
|
80
|
public QuantitativeData addQuantitativeData(Feature feature){
|
81
|
QuantitativeData data = QuantitativeData.NewInstance(feature);
|
82
|
description.addElement(data);
|
83
|
featureToElementMap.put(feature, data);
|
84
|
return data;
|
85
|
}
|
86
|
|
87
|
public CategoricalData addCategoricalData(Feature feature){
|
88
|
CategoricalData data = CategoricalData.NewInstance(feature);
|
89
|
description.addElement(data);
|
90
|
featureToElementMap.put(feature, data);
|
91
|
return data;
|
92
|
}
|
93
|
|
94
|
public SpecimenDescription getSpecimenDescription() {
|
95
|
return description;
|
96
|
}
|
97
|
|
98
|
public Taxon getAssociatedTaxon() {
|
99
|
return associatedTaxon;
|
100
|
}
|
101
|
|
102
|
public FieldUnit getFieldUnit() {
|
103
|
return fieldUnit;
|
104
|
}
|
105
|
|
106
|
public String getIdentifier() {
|
107
|
return identifier;
|
108
|
}
|
109
|
|
110
|
public NamedArea getCountry() {
|
111
|
return country;
|
112
|
}
|
113
|
|
114
|
public DescriptionElementBase getDescriptionElementForFeature(Feature feature){
|
115
|
return featureToElementMap.get(feature);
|
116
|
}
|
117
|
|
118
|
}
|