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.persistence.dto;
|
10
|
|
11
|
import java.io.Serializable;
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.HashMap;
|
14
|
import java.util.HashSet;
|
15
|
import java.util.List;
|
16
|
import java.util.Map;
|
17
|
import java.util.Set;
|
18
|
import java.util.UUID;
|
19
|
|
20
|
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
|
21
|
import eu.etaxonomy.cdm.model.term.Representation;
|
22
|
|
23
|
/**
|
24
|
* @author k.luther
|
25
|
* @since Aug 31, 2021
|
26
|
*/
|
27
|
public class DescriptiveDataSetBaseDto implements Serializable{
|
28
|
|
29
|
private static final long serialVersionUID = 7310069387512600745L;
|
30
|
|
31
|
private UUID uuid;
|
32
|
private Integer id;
|
33
|
private String titleCache;
|
34
|
private TermTreeDto descriptiveSystem;
|
35
|
private Set<TaxonNodeDto> subTreeFilter;
|
36
|
private Set<TermDto> geoFilter;
|
37
|
private Set<UUID> descriptionUuids;
|
38
|
|
39
|
private Set<Representation> representations = new HashSet<>();
|
40
|
private String representation_L10n = null;
|
41
|
private String representation_L10n_abbreviatedLabel = null;
|
42
|
private String representation_L10n_text = null;
|
43
|
|
44
|
private TermDto maxRank;
|
45
|
private TermDto minRank;
|
46
|
|
47
|
|
48
|
|
49
|
public DescriptiveDataSetBaseDto(UUID uuid, Integer id, String titleCache){
|
50
|
this.uuid = uuid;
|
51
|
this.id = id;
|
52
|
this.titleCache = titleCache;
|
53
|
}
|
54
|
|
55
|
public UUID getUuid() {
|
56
|
return uuid;
|
57
|
}
|
58
|
|
59
|
|
60
|
public void setUuid(UUID uuid) {
|
61
|
this.uuid = uuid;
|
62
|
}
|
63
|
|
64
|
public Integer getId() {
|
65
|
return id;
|
66
|
}
|
67
|
|
68
|
public void setId(Integer id) {
|
69
|
this.id = id;
|
70
|
}
|
71
|
|
72
|
public String getTitleCache() {
|
73
|
return titleCache;
|
74
|
}
|
75
|
|
76
|
public void setTitleCache(String titleCache) {
|
77
|
this.titleCache = titleCache;
|
78
|
}
|
79
|
|
80
|
public TermTreeDto getDescriptiveSystem() {
|
81
|
return descriptiveSystem;
|
82
|
}
|
83
|
|
84
|
public void setDescriptiveSystem(TermTreeDto descriptiveSystem) {
|
85
|
this.descriptiveSystem = descriptiveSystem;
|
86
|
}
|
87
|
|
88
|
|
89
|
private void addRepresentation(Representation representation) {
|
90
|
if (this.representations == null){
|
91
|
this.representations = new HashSet<>();
|
92
|
}
|
93
|
this.representations.add(representation);
|
94
|
|
95
|
}
|
96
|
public TermDto getMaxRank() {
|
97
|
return maxRank;
|
98
|
}
|
99
|
|
100
|
public void setMaxRank(TermDto minRank) {
|
101
|
this.maxRank = minRank;
|
102
|
}
|
103
|
|
104
|
public TermDto getMinRank() {
|
105
|
return minRank;
|
106
|
}
|
107
|
|
108
|
public void setMinRank(TermDto minRank) {
|
109
|
this.minRank = minRank;
|
110
|
}
|
111
|
|
112
|
|
113
|
/** sql queries to get descriptive data set dto*/
|
114
|
|
115
|
public static String getDescriptiveDataSetDtoSelect(){
|
116
|
String[] result = createSqlParts();
|
117
|
|
118
|
return result[0]+result[1]+result[2];
|
119
|
}
|
120
|
|
121
|
private static String[] createSqlParts() {
|
122
|
String sqlSelectString = ""
|
123
|
+ "select a.uuid, "
|
124
|
+ "a.id, "
|
125
|
+ "a.titleCache, "
|
126
|
+ "r, "
|
127
|
+ "d.uuid, "
|
128
|
+ "minRank.uuid, "
|
129
|
// + "minRank.representations, "
|
130
|
// + "minRank.termType, "
|
131
|
// + "minRank.orderIndex, "
|
132
|
// + "minRank.idInVocabulary, "
|
133
|
// + "minRank.titleCache, "
|
134
|
+ "maxRank.uuid ";
|
135
|
// + "maxRank.representations, "
|
136
|
// + "maxRank.termType, "
|
137
|
// + "maxRank.orderIndex, "
|
138
|
// + "maxRank.idInVocabulary, "
|
139
|
// + "maxRank.titleCache ";
|
140
|
//UUID uuid, Set<Representation> representations, TermType termType, UUID partOfUuid, UUID kindOfUuid,
|
141
|
// UUID vocabularyUuid, Integer orderIndex, String idInVocabulary, String titleCache
|
142
|
String sqlFromString = " FROM DescriptiveDataSet as a ";
|
143
|
|
144
|
String sqlJoinString = " LEFT JOIN a.descriptiveSystem as d "
|
145
|
+ " LEFT JOIN a.representations AS r "
|
146
|
+ " LEFT JOIN a.minRank as minRank "
|
147
|
+ " LEFT JOIN a.maxRank as maxRank ";
|
148
|
|
149
|
String[] result = new String[3];
|
150
|
result[0] = sqlSelectString;
|
151
|
result[1] = sqlFromString;
|
152
|
result[2] = sqlJoinString;
|
153
|
return result;
|
154
|
}
|
155
|
|
156
|
/**
|
157
|
* @param result
|
158
|
* @return
|
159
|
*/
|
160
|
public static List<DescriptiveDataSetBaseDto> descriptiveDataSetBaseDtoListFrom(List<Object[]> results) {
|
161
|
|
162
|
List<DescriptiveDataSetBaseDto> dtos = new ArrayList<>(); // list to ensure order
|
163
|
// map to handle multiple representations/media/vocRepresentation because of LEFT JOIN
|
164
|
Map<UUID, DescriptiveDataSetBaseDto> dtoMap = new HashMap<>(results.size());
|
165
|
for (Object[] elements : results) {
|
166
|
UUID uuid = (UUID)elements[0];
|
167
|
Integer id = (Integer)elements[1];
|
168
|
|
169
|
if(dtoMap.containsKey(uuid)){
|
170
|
// multiple results for one dataset -> multiple (voc) representation/media
|
171
|
if(elements[1]!=null){
|
172
|
dtoMap.get(uuid).addRepresentation((Representation)elements[1]);
|
173
|
}
|
174
|
} else {
|
175
|
// dataset representation
|
176
|
Set<Representation> representations = new HashSet<>();
|
177
|
if(elements[1] instanceof Representation) {
|
178
|
representations = new HashSet<>(1);
|
179
|
representations.add((Representation)elements[1]);
|
180
|
}
|
181
|
|
182
|
DescriptiveDataSetBaseDto datasetDto = new DescriptiveDataSetBaseDto(
|
183
|
uuid,
|
184
|
id,
|
185
|
(String)elements[2]);
|
186
|
|
187
|
// TermDto minRank = new TermDto((UUID)elements[5], (Set<Representation>)elements[6], (TermType)elements[7], null, null, null, (Integer)elements[8], (String)elements[9], (String)elements[10]);
|
188
|
// TermDto maxRank = new TermDto((UUID)elements[11], (Set<Representation>)elements[12], (TermType)elements[13], null, null, null, (Integer)elements[14], (String)elements[15], (String)elements[16]);
|
189
|
// datasetDto.setMinRank(minRank);
|
190
|
// datasetDto.setMaxRank(maxRank);
|
191
|
|
192
|
dtoMap.put(uuid, datasetDto);
|
193
|
dtos.add(datasetDto);
|
194
|
}
|
195
|
}
|
196
|
return dtos;
|
197
|
}
|
198
|
|
199
|
public static DescriptiveDataSetBaseDto fromDescriptiveDataSet(DescriptiveDataSet dataSet){
|
200
|
DescriptiveDataSetBaseDto dto = new DescriptiveDataSetBaseDto(dataSet.getUuid(), dataSet.getId(), dataSet.getTitleCache());
|
201
|
if (dataSet.getDescriptiveSystem() != null){
|
202
|
dto.setDescriptiveSystem(TermTreeDto.fromTree(dataSet.getDescriptiveSystem()));
|
203
|
}
|
204
|
return dto;
|
205
|
}
|
206
|
|
207
|
public Set<TaxonNodeDto> getSubTreeFilter() {
|
208
|
return subTreeFilter;
|
209
|
}
|
210
|
|
211
|
public void setSubTreeFilter(Set<TaxonNodeDto> subTreeFilter) {
|
212
|
this.subTreeFilter = subTreeFilter;
|
213
|
}
|
214
|
|
215
|
public Set<TermDto> getGeoFilter() {
|
216
|
return geoFilter;
|
217
|
}
|
218
|
|
219
|
public void setGeoFilter(Set<TermDto> geoFilter) {
|
220
|
this.geoFilter = geoFilter;
|
221
|
}
|
222
|
|
223
|
public Set<UUID> getDescriptionUuids() {
|
224
|
return descriptionUuids;
|
225
|
}
|
226
|
|
227
|
public void setDescriptionUuids(Set<UUID> descriptionUuids) {
|
228
|
this.descriptionUuids = descriptionUuids;
|
229
|
}
|
230
|
|
231
|
|
232
|
}
|