1
|
/**
|
2
|
* Copyright (C) 2021 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.math.BigDecimal;
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.HashSet;
|
14
|
import java.util.List;
|
15
|
import java.util.Set;
|
16
|
import java.util.UUID;
|
17
|
|
18
|
import eu.etaxonomy.cdm.model.description.QuantitativeData;
|
19
|
import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
|
20
|
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
|
21
|
import eu.etaxonomy.cdm.persistence.dto.FeatureDto;
|
22
|
import eu.etaxonomy.cdm.persistence.dto.TermDto;
|
23
|
|
24
|
/**
|
25
|
* @author k.luther
|
26
|
* @since Aug 18, 2021
|
27
|
*/
|
28
|
public class QuantitativeDataDto extends DescriptionElementDto {
|
29
|
|
30
|
|
31
|
|
32
|
private static final long serialVersionUID = 9043099217303520574L;
|
33
|
|
34
|
private TermDto measurementUnitDto;
|
35
|
// private String measurementIdInVocabulary;
|
36
|
|
37
|
private Set<StatisticalMeasurementValueDto> values = new HashSet<>();
|
38
|
|
39
|
public QuantitativeDataDto(UUID elementUuid, FeatureDto feature){
|
40
|
super(elementUuid, feature);
|
41
|
}
|
42
|
|
43
|
|
44
|
public static QuantitativeDataDto fromQuantitativeData (QuantitativeData data) {
|
45
|
QuantitativeDataDto dto = new QuantitativeDataDto(data.getUuid(), FeatureDto.fromFeature(data.getFeature()));
|
46
|
dto.measurementUnitDto = data.getUnit() != null? TermDto.fromTerm(data.getUnit()): null;
|
47
|
// dto.measurementIdInVocabulary = data.getUnit() != null? data.getUnit().getIdInVocabulary(): null;
|
48
|
for (StatisticalMeasurementValue value: data.getStatisticalValues()){
|
49
|
StatisticalMeasurementValueDto statDto = StatisticalMeasurementValueDto.fromStatisticalMeasurementValue(value);
|
50
|
dto.values.add(statDto);
|
51
|
}
|
52
|
return dto;
|
53
|
}
|
54
|
|
55
|
public QuantitativeDataDto(FeatureDto feature){
|
56
|
super(feature);
|
57
|
|
58
|
}
|
59
|
|
60
|
public TermDto getMeasurementUnit() {
|
61
|
return measurementUnitDto;
|
62
|
}
|
63
|
|
64
|
public void setMeasurementUnit(TermDto measurementUnit) {
|
65
|
this.measurementUnitDto = measurementUnit;
|
66
|
}
|
67
|
|
68
|
public Set<StatisticalMeasurementValueDto> getValues() {
|
69
|
return values;
|
70
|
}
|
71
|
|
72
|
public void setValues(Set<StatisticalMeasurementValueDto> values) {
|
73
|
this.values = values;
|
74
|
}
|
75
|
|
76
|
public void addValue(StatisticalMeasurementValueDto value) {
|
77
|
this.values.add(value);
|
78
|
}
|
79
|
|
80
|
public BigDecimal getSpecificStatisticalValue(UUID typeUUID){
|
81
|
BigDecimal result = null;
|
82
|
for (StatisticalMeasurementValueDto value : values){
|
83
|
if (typeUUID.equals(value.getType().getUuid())){
|
84
|
result = value.getValue();
|
85
|
break;
|
86
|
}
|
87
|
}
|
88
|
return result;
|
89
|
}
|
90
|
|
91
|
public String getMeasurementIdInVocabulary() {
|
92
|
return measurementUnitDto.getIdInVocabulary();
|
93
|
}
|
94
|
|
95
|
public static String getQuantitativeDataDtoSelect(){
|
96
|
String[] result = createSqlParts();
|
97
|
|
98
|
return result[0]+result[1]+result[2] + result[3];
|
99
|
}
|
100
|
|
101
|
private static String[] createSqlParts() {
|
102
|
//featureDto, uuid, states
|
103
|
|
104
|
String sqlSelectString = ""
|
105
|
+ "select a.uuid, "
|
106
|
+ "feature.uuid, "
|
107
|
+ "statVal.uuid, "
|
108
|
+ "statVal.value, "
|
109
|
+ "statVal.type, "
|
110
|
+ "unit";
|
111
|
|
112
|
String sqlFromString = " FROM QuantitativeData as a ";
|
113
|
|
114
|
String sqlJoinString = "LEFT JOIN a.statisticalValues as statVal "
|
115
|
+ "LEFT JOIN a.feature as feature "
|
116
|
+ "LEFT JOIN a.unit as unit ";
|
117
|
|
118
|
String sqlWhereString = "WHERE a.inDescription.uuid = :uuid";
|
119
|
|
120
|
String[] result = new String[4];
|
121
|
result[0] = sqlSelectString;
|
122
|
result[1] = sqlFromString;
|
123
|
result[2] = sqlJoinString;
|
124
|
result[3] = sqlWhereString;
|
125
|
return result;
|
126
|
}
|
127
|
|
128
|
/**
|
129
|
* @param result
|
130
|
* @return
|
131
|
*/
|
132
|
public static List<QuantitativeDataDto> quantitativeDataDtoListFrom(List<Object[]> result) {
|
133
|
List<QuantitativeDataDto> dtoResult = new ArrayList<>();
|
134
|
QuantitativeDataDto dto = null;
|
135
|
|
136
|
for (Object[] o: result){
|
137
|
UUID uuid = (UUID)o[0];
|
138
|
UUID featureUuid = (UUID)o[1];
|
139
|
if (dto == null || !dto.getElementUuid().equals(uuid)){
|
140
|
dto = new QuantitativeDataDto(uuid, new FeatureDto(featureUuid, null, null, null, null, null, null, true, false, true, null, true, false, null, null, null, null));
|
141
|
dtoResult.add(dto);
|
142
|
}
|
143
|
StatisticalMeasurementValueDto statVal = new StatisticalMeasurementValueDto(TermDto.fromTerm((DefinedTermBase)o[4]),(BigDecimal)o[3], (UUID)o[2]) ;
|
144
|
dto.addValue(statVal);
|
145
|
}
|
146
|
|
147
|
|
148
|
return dtoResult;
|
149
|
|
150
|
}
|
151
|
|
152
|
|
153
|
}
|