1
|
/**
|
2
|
* Copyright (C) 2015 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.util.ArrayList;
|
12
|
import java.util.Collection;
|
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.common.DefinedTermBase;
|
21
|
import eu.etaxonomy.cdm.model.common.OrderedTermBase;
|
22
|
import eu.etaxonomy.cdm.model.common.Representation;
|
23
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
24
|
|
25
|
/**
|
26
|
* @author andreas
|
27
|
* @since Mar 25, 2015
|
28
|
*
|
29
|
*/
|
30
|
public class TermDto extends AbstractTermDto{
|
31
|
|
32
|
private static final long serialVersionUID = 5627308906985438034L;
|
33
|
|
34
|
private UUID kindOfUuid = null;
|
35
|
private UUID partOfUuid = null;
|
36
|
private UUID vocabularyUuid = null;
|
37
|
private TermDto kindOfDto = null;
|
38
|
private TermDto partOfDto = null;
|
39
|
private TermVocabularyDto vocabularyDto = null;
|
40
|
private Integer orderIndex = null;
|
41
|
private String idInVocabulary = null;
|
42
|
private Collection<TermDto> includes;
|
43
|
private Collection<TermDto> generalizationOf;
|
44
|
private Set<Representation> vocRepresentations = null;
|
45
|
private String vocRepresentation_L10n = null;
|
46
|
private String vocRepresentation_L10n_abbreviatedLabel = null;
|
47
|
|
48
|
private TermDto(UUID uuid, Set<Representation> representations, UUID partOfUuid, UUID kindOfUuid,
|
49
|
UUID vocabularyUuid, Integer orderIndex, String idInVocabulary) {
|
50
|
this(uuid, representations, partOfUuid, kindOfUuid, vocabularyUuid, orderIndex, idInVocabulary, null);
|
51
|
}
|
52
|
|
53
|
private TermDto(UUID uuid, Set<Representation> representations, UUID partOfUuid, UUID kindOfUuid,
|
54
|
UUID vocabularyUuid, Integer orderIndex, String idInVocabulary, Set<Representation> vocRepresentations) {
|
55
|
super(uuid, representations);
|
56
|
this.partOfUuid = partOfUuid;
|
57
|
this.kindOfUuid = kindOfUuid;
|
58
|
this.vocabularyUuid = vocabularyUuid;
|
59
|
this.orderIndex = orderIndex;
|
60
|
this.idInVocabulary = idInVocabulary;
|
61
|
this.vocRepresentations = vocRepresentations;
|
62
|
}
|
63
|
|
64
|
static public TermDto fromTerm(DefinedTermBase term) {
|
65
|
return fromTerm(term, null, false);
|
66
|
}
|
67
|
|
68
|
static public TermDto fromTerm(DefinedTermBase term, boolean initializeToTop) {
|
69
|
return fromTerm(term, null, initializeToTop);
|
70
|
}
|
71
|
|
72
|
static public TermDto fromTerm(DefinedTermBase term, Set<Representation> representations) {
|
73
|
return fromTerm(term, representations, false);
|
74
|
}
|
75
|
|
76
|
static public TermDto fromTerm(DefinedTermBase term, Set<Representation> representations, boolean initializeToTop) {
|
77
|
DefinedTermBase partOf = term.getPartOf();
|
78
|
DefinedTermBase kindOf = term.getKindOf();
|
79
|
TermVocabulary vocabulary = term.getVocabulary();
|
80
|
TermDto dto = new TermDto(
|
81
|
term.getUuid(),
|
82
|
representations!=null?representations:term.getRepresentations(),
|
83
|
(partOf!=null?partOf.getUuid():null),
|
84
|
(kindOf!=null?kindOf.getUuid():null),
|
85
|
vocabulary.getUuid(),
|
86
|
(term instanceof OrderedTermBase)?((OrderedTermBase) term).getOrderIndex():null,
|
87
|
term.getIdInVocabulary());
|
88
|
if(initializeToTop){
|
89
|
if(partOf!=null){
|
90
|
dto.setPartOfDto(fromTerm(partOf, initializeToTop));
|
91
|
}
|
92
|
if(kindOf!=null){
|
93
|
dto.setKindOfDto(fromTerm(kindOf, initializeToTop));
|
94
|
}
|
95
|
dto.setVocabularyDto(new TermVocabularyDto(vocabulary.getUuid(), vocabulary.getRepresentations()));
|
96
|
}
|
97
|
return dto;
|
98
|
}
|
99
|
|
100
|
@Override
|
101
|
public void localize(ITermRepresentation_L10n representation_L10n) {
|
102
|
if(vocRepresentations!=null){
|
103
|
representation_L10n.localize(vocRepresentations);
|
104
|
if (representation_L10n.getLabel() != null) {
|
105
|
setVocRepresentation_L10n(representation_L10n.getLabel());
|
106
|
}
|
107
|
if (representation_L10n.getAbbreviatedLabel() != null) {
|
108
|
setVocRepresentation_L10n_abbreviatedLabel(representation_L10n.getAbbreviatedLabel());
|
109
|
}
|
110
|
}
|
111
|
super.localize(representation_L10n);
|
112
|
}
|
113
|
|
114
|
public void setVocRepresentation_L10n(String vocRepresentation_L10n) {
|
115
|
this.vocRepresentation_L10n = vocRepresentation_L10n;
|
116
|
}
|
117
|
|
118
|
public String getVocRepresentation_L10n() {
|
119
|
return vocRepresentation_L10n;
|
120
|
}
|
121
|
|
122
|
public void setVocRepresentation_L10n_abbreviatedLabel(String vocRepresentation_L10n_abbreviatedLabel) {
|
123
|
this.vocRepresentation_L10n_abbreviatedLabel = vocRepresentation_L10n_abbreviatedLabel;
|
124
|
}
|
125
|
|
126
|
public String getVocRepresentation_L10n_abbreviatedLabel() {
|
127
|
return vocRepresentation_L10n_abbreviatedLabel;
|
128
|
}
|
129
|
|
130
|
public void setPartOfDto(TermDto partOfDto) {
|
131
|
this.partOfDto = partOfDto;
|
132
|
}
|
133
|
|
134
|
public TermDto getPartOfDto() {
|
135
|
return partOfDto;
|
136
|
}
|
137
|
|
138
|
public void setKindOfDto(TermDto kindOfDto) {
|
139
|
this.kindOfDto = kindOfDto;
|
140
|
}
|
141
|
|
142
|
public TermDto getKindOfDto() {
|
143
|
return kindOfDto;
|
144
|
}
|
145
|
|
146
|
public void setVocabularyDto(TermVocabularyDto vocabularyDto) {
|
147
|
this.vocabularyDto = vocabularyDto;
|
148
|
}
|
149
|
|
150
|
public TermVocabularyDto getVocabularyDto() {
|
151
|
return vocabularyDto;
|
152
|
}
|
153
|
|
154
|
public UUID getVocabularyUuid() {
|
155
|
return vocabularyUuid;
|
156
|
}
|
157
|
|
158
|
public void setVocabularyUuid(UUID vocabularyUuid) {
|
159
|
this.vocabularyUuid = vocabularyUuid;
|
160
|
}
|
161
|
|
162
|
public UUID getPartOfUuid() {
|
163
|
return partOfUuid;
|
164
|
}
|
165
|
|
166
|
public UUID getKindOfUuid() {
|
167
|
return kindOfUuid;
|
168
|
}
|
169
|
|
170
|
public Integer getOrderIndex() {
|
171
|
return orderIndex;
|
172
|
}
|
173
|
|
174
|
public void setOrderIndex(Integer orderIndex) {
|
175
|
this.orderIndex = orderIndex;
|
176
|
}
|
177
|
|
178
|
public String getIdInVocabulary() {
|
179
|
return idInVocabulary;
|
180
|
}
|
181
|
|
182
|
public void setIdInVocabulary(String idInVocabulary) {
|
183
|
this.idInVocabulary = idInVocabulary;
|
184
|
}
|
185
|
|
186
|
public Collection<TermDto> getIncludes() {
|
187
|
return includes;
|
188
|
}
|
189
|
|
190
|
public void setIncludes(Collection<TermDto> includes) {
|
191
|
this.includes = includes;
|
192
|
}
|
193
|
|
194
|
public Collection<TermDto> getGeneralizationOf() {
|
195
|
return generalizationOf;
|
196
|
}
|
197
|
|
198
|
public void setGeneralizationOf(Collection<TermDto> generalizationOf) {
|
199
|
this.generalizationOf = generalizationOf;
|
200
|
}
|
201
|
|
202
|
public static String getTermDtoSelect(){
|
203
|
return getTermDtoSelect("DefinedTermBase");
|
204
|
}
|
205
|
|
206
|
public static String getTermDtoSelect(String fromTable){
|
207
|
return ""
|
208
|
+ "select a.uuid, r, p.uuid, k.uuid, v.uuid, a.orderIndex, a.idInVocabulary, voc_rep "
|
209
|
+ "from "+fromTable+" as a "
|
210
|
+ "LEFT JOIN a.partOf as p "
|
211
|
+ "LEFT JOIN a.kindOf as k "
|
212
|
+ "LEFT JOIN a.representations AS r "
|
213
|
+ "LEFT JOIN a.vocabulary as v "
|
214
|
+ "LEFT JOIN v.representations as voc_rep ";
|
215
|
}
|
216
|
|
217
|
public static List<TermDto> termDtoListFrom(List<Object[]> results) {
|
218
|
Map<UUID, TermDto> dtoMap = new HashMap<>(results.size());
|
219
|
for (Object[] elements : results) {
|
220
|
UUID uuid = (UUID)elements[0];
|
221
|
if(dtoMap.containsKey(uuid)){
|
222
|
dtoMap.get(uuid).addRepresentation((Representation)elements[1]);
|
223
|
} else {
|
224
|
Set<Representation> representations = new HashSet<>();
|
225
|
if(elements[1] instanceof Representation) {
|
226
|
representations = new HashSet<Representation>(1);
|
227
|
representations.add((Representation)elements[1]);
|
228
|
} else {
|
229
|
representations = (Set<Representation>)elements[1];
|
230
|
}
|
231
|
Set<Representation> vocRepresentations = new HashSet<>();
|
232
|
if(elements[7] instanceof Representation) {
|
233
|
vocRepresentations = new HashSet<Representation>(7);
|
234
|
vocRepresentations.add((Representation)elements[7]);
|
235
|
} else {
|
236
|
vocRepresentations = (Set<Representation>)elements[7];
|
237
|
}
|
238
|
dtoMap.put(uuid, new TermDto(uuid, representations, (UUID)elements[2], (UUID)elements[3], (UUID)elements[4], (Integer)elements[5], (String)elements[6], vocRepresentations));
|
239
|
}
|
240
|
}
|
241
|
return new ArrayList<>(dtoMap.values());
|
242
|
}
|
243
|
|
244
|
}
|