Project

General

Profile

Download (3 KB) Statistics
| Branch: | Tag: | Revision:
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
     * @param uuid
32
     * @param representations
33
     * @param termType
34
     */
35
    public TermVocabularyDto(UUID uuid, Set<Representation> representations, TermType termType, String titleCache, boolean isAllowDuplicate, boolean isOrderRelevant, boolean isFlat) {
36
        super(uuid, representations, termType, titleCache, isAllowDuplicate, isOrderRelevant, isFlat);
37
        // TODO Auto-generated constructor stub
38
    }
39

    
40
    public static TermVocabularyDto fromVocabulary(TermVocabulary voc) {
41
        TermVocabularyDto dto = new TermVocabularyDto(voc.getUuid(), voc.getRepresentations(), voc.getTermType(), voc.getTitleCache(), voc.isAllowDuplicates(), voc.isOrderRelevant(), voc.isFlat());
42
        return dto;
43
    }
44

    
45
    public static List<TermVocabularyDto> termVocabularyDtoListFrom(List<Object[]> results) {
46
        List<TermVocabularyDto> dtos = new ArrayList<>(); // list to ensure order
47
        // map to handle multiple representations because of LEFT JOIN
48
        Map<UUID, TermCollectionDto> dtoMap = new HashMap<>(results.size());
49
        for (Object[] elements : results) {
50
            UUID uuid = (UUID)elements[0];
51
            if(dtoMap.containsKey(uuid)){
52
                // multiple results for one voc -> multiple (voc) representation
53
                if(elements[1]!=null){
54
                    dtoMap.get(uuid).addRepresentation((Representation)elements[1]);
55
                }
56

    
57
            } else {
58
                // voc representation
59
                Set<Representation> representations = new HashSet<>();
60
                if(elements[1] instanceof Representation) {
61
                    representations = new HashSet<Representation>(1);
62
                    representations.add((Representation)elements[1]);
63
                }
64

    
65

    
66
                TermVocabularyDto termVocDto = new TermVocabularyDto(
67
                        uuid,
68
                        representations,
69
                        (TermType)elements[2],
70
                        (String)elements[3],
71
                        (boolean)elements[4],
72
                        (boolean)elements[5],
73
                        (boolean)elements[6]);
74

    
75

    
76
                dtoMap.put(uuid, termVocDto);
77
                dtos.add(termVocDto);
78
            }
79
        }
80
        return dtos;
81
    }
82

    
83
}
(23-23/24)