Project

General

Profile

Download (3.17 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 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.HashSet;
13
import java.util.List;
14
import java.util.Set;
15
import java.util.UUID;
16

    
17
import eu.etaxonomy.cdm.model.term.Representation;
18
import eu.etaxonomy.cdm.model.term.TermType;
19

    
20
/**
21
 * @author pplitzner
22
 * @date 05.11.2018
23
 */
24
public class TermCollectionDto extends AbstractTermDto {
25

    
26
    private static final long serialVersionUID = 6053392236860675874L;
27

    
28
    private List<TermDto> terms;
29

    
30
    private boolean isAllowDuplicate;
31
    private boolean containsDuplicates = false;
32
    private boolean isOrderRelevant;
33
    private boolean isFlat;
34

    
35
    public TermCollectionDto(UUID uuid, Set<Representation> representations, TermType termType, String titleCache, boolean isAllowDuplicate, boolean isOrderRelevant, boolean isFlat) {
36
        super(uuid, representations, titleCache);
37
        terms = new ArrayList<>();
38
        setTermType(termType);
39
        this.isAllowDuplicate = isAllowDuplicate;
40
        this.isOrderRelevant = isOrderRelevant;
41
        this.isFlat = isFlat;
42
    }
43

    
44
    public List<TermDto> getTerms() {
45
        if (terms.isEmpty()){
46

    
47
        }
48
        return terms;
49
    }
50

    
51
    public void addTerm(TermDto term){
52
        if (term == null){
53
            return;
54
        }
55
        if (terms == null){
56
            terms = new ArrayList<>();
57
        }
58
        if (terms.contains(term)){
59
            containsDuplicates = true;
60
        }
61
        terms.add(term);
62
    }
63

    
64
    public void removeTerm(TermDto term){
65
        terms.remove(term);
66
    }
67

    
68
    public boolean isAllowDuplicate() {
69
        return isAllowDuplicate;
70
    }
71
    public void setAllowDuplicate(boolean isAllowDuplicate) {
72
        this.isAllowDuplicate = isAllowDuplicate;
73
    }
74

    
75
    public boolean isContainsDuplicates() {
76
        Set<TermDto> dtoSet = new HashSet<>(terms);
77
        if (dtoSet.size() == terms.size()){
78
            containsDuplicates = false;
79
        }
80

    
81
        return containsDuplicates;
82
    }
83

    
84
    public void setContainsDuplicates(boolean containsDuplicates) {
85
        this.containsDuplicates = containsDuplicates;
86
    }
87

    
88
    public boolean isOrderRelevant() {
89
        return isOrderRelevant;
90
    }
91
    public void setOrderRelevant(boolean isOrderRelevant) {
92
        this.isOrderRelevant = isOrderRelevant;
93
    }
94

    
95
    public boolean isFlat() {
96
        return isFlat;
97
    }
98
    public void setFlat(boolean isFlat) {
99
        this.isFlat = isFlat;
100
    }
101

    
102
    public static String getTermCollectionDtoSelect(){
103
        return getTermCollectionDtoSelect("TermVocabulary");
104
    }
105

    
106
    public static String getTermCollectionDtoSelect(String fromTable){
107
        return ""
108
                + "select a.uuid, "
109
                + "r, "
110
                + "a.termType,"
111
                + "a.titleCache,"
112
                + "a.allowDuplicates,"
113
                + "a.orderRelevant,"
114
                + "a.isFlat "
115

    
116
                + "FROM "+fromTable+" as a "
117
                + "LEFT JOIN a.representations AS r ";
118
    }
119
}
(26-26/30)