1
|
/**
|
2
|
* Copyright (C) 2020 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.HashMap;
|
13
|
import java.util.HashSet;
|
14
|
import java.util.List;
|
15
|
import java.util.Map;
|
16
|
import java.util.Set;
|
17
|
import java.util.UUID;
|
18
|
|
19
|
import eu.etaxonomy.cdm.model.term.Representation;
|
20
|
import eu.etaxonomy.cdm.model.term.TermType;
|
21
|
import eu.etaxonomy.cdm.model.term.TermVocabulary;
|
22
|
|
23
|
/**
|
24
|
* @author k.luther
|
25
|
* @since 07.01.2020
|
26
|
*/
|
27
|
public class TermVocabularyDto extends TermCollectionDto {
|
28
|
|
29
|
private static final long serialVersionUID = 7667822208618658310L;
|
30
|
|
31
|
public TermVocabularyDto(UUID uuid, Set<Representation> representations, TermType termType, String titleCache, boolean isAllowDuplicate, boolean isOrderRelevant, boolean isFlat) {
|
32
|
super(uuid, representations, termType, titleCache, isAllowDuplicate, isOrderRelevant, isFlat);
|
33
|
}
|
34
|
|
35
|
public static TermVocabularyDto fromVocabulary(TermVocabulary<?> voc) {
|
36
|
TermVocabularyDto dto = new TermVocabularyDto(voc.getUuid(), voc.getRepresentations(), voc.getTermType(), voc.getTitleCache(), voc.isAllowDuplicates(), voc.isOrderRelevant(), voc.isFlat());
|
37
|
return dto;
|
38
|
}
|
39
|
|
40
|
public static List<TermVocabularyDto> termVocabularyDtoListFrom(List<Object[]> queryResult) {
|
41
|
List<TermVocabularyDto> dtos = new ArrayList<>(); // list to ensure order
|
42
|
// map to handle multiple representations because of LEFT JOIN
|
43
|
Map<UUID, TermCollectionDto> dtoMap = new HashMap<>(queryResult.size());
|
44
|
for (Object[] elements : queryResult) {
|
45
|
UUID uuid = (UUID)elements[0];
|
46
|
if(dtoMap.containsKey(uuid)){
|
47
|
// multiple results for one voc -> multiple (voc) representation
|
48
|
if(elements[1]!=null){
|
49
|
dtoMap.get(uuid).addRepresentation((Representation)elements[1]);
|
50
|
}
|
51
|
|
52
|
} else {
|
53
|
// voc representation
|
54
|
Set<Representation> representations = new HashSet<>();
|
55
|
if(elements[1] instanceof Representation) {
|
56
|
representations = new HashSet<>(1);
|
57
|
representations.add((Representation)elements[1]);
|
58
|
}
|
59
|
|
60
|
TermVocabularyDto termVocDto = new TermVocabularyDto(
|
61
|
uuid,
|
62
|
representations,
|
63
|
(TermType)elements[2],
|
64
|
(String)elements[3],
|
65
|
(boolean)elements[4],
|
66
|
(boolean)elements[5],
|
67
|
(boolean)elements[6]);
|
68
|
|
69
|
dtoMap.put(uuid, termVocDto);
|
70
|
dtos.add(termVocDto);
|
71
|
}
|
72
|
}
|
73
|
return dtos;
|
74
|
}
|
75
|
}
|