Project

General

Profile

Download (3.58 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2018 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.persistence.dto;
11

    
12
import java.util.ArrayList;
13
import java.util.HashSet;
14
import java.util.List;
15
import java.util.Set;
16
import java.util.UUID;
17

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

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

    
28
    private static final long serialVersionUID = 6053392236860675874L;
29

    
30
    private List<TermDto> terms;
31

    
32
    private boolean isAllowDuplicate;
33
    private boolean containsDuplicates = false;
34
    private boolean isOrderRelevant;
35
    private boolean isFlat;
36
    private boolean isAllowModifications = true;
37

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

    
47
    public List<TermDto> getTerms() {
48
        if (terms.isEmpty()){
49

    
50
        }
51
        return terms;
52
    }
53

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

    
67
    public void removeTerm(TermDto term){
68
        terms.remove(term);
69
    }
70

    
71

    
72

    
73
    /**
74
     * @return the isAllowDuplicate
75
     */
76
    public boolean isAllowDuplicate() {
77
        return isAllowDuplicate;
78
    }
79

    
80
    /**
81
     * @param isAllowDuplicate the isAllowDuplicate to set
82
     */
83
    public void setAllowDuplicate(boolean isAllowDuplicate) {
84
        this.isAllowDuplicate = isAllowDuplicate;
85
    }
86

    
87
    public boolean isContainsDuplicates() {
88
        Set<TermDto> dtoSet = new HashSet<>(terms);
89
        if (dtoSet.size() == terms.size()){
90
            containsDuplicates = false;
91
        }
92

    
93
        return containsDuplicates;
94
    }
95

    
96
    public void setContainsDuplicates(boolean containsDuplicates) {
97
        this.containsDuplicates = containsDuplicates;
98
    }
99

    
100
    /**
101
     * @return the isOrderRelevant
102
     */
103
    public boolean isOrderRelevant() {
104
        return isOrderRelevant;
105
    }
106

    
107
    /**
108
     * @param isOrderRelevant the isOrderRelevant to set
109
     */
110
    public void setOrderRelevant(boolean isOrderRelevant) {
111
        this.isOrderRelevant = isOrderRelevant;
112
    }
113

    
114
    /**
115
     * @return the isFlat
116
     */
117
    public boolean isFlat() {
118
        return isFlat;
119
    }
120

    
121
    /**
122
     * @param isFlat the isFlat to set
123
     */
124
    public void setFlat(boolean isFlat) {
125
        this.isFlat = isFlat;
126
    }
127

    
128
    public static String getTermCollectionDtoSelect(){
129
        return getTermCollectionDtoSelect("TermVocabulary");
130
    }
131

    
132
    public static String getTermCollectionDtoSelect(String fromTable){
133
        return ""
134
                + "select a.uuid, "
135
                + "r, "
136
                + "a.termType,"
137
                + "a.titleCache,"
138
                + "a.allowDuplicates,"
139
                + "a.orderRelevant,"
140
                + "a.isFlat "
141

    
142

    
143
                + "FROM "+fromTable+" as a "
144
                + "LEFT JOIN a.representations AS r ";
145

    
146
    }
147

    
148

    
149

    
150

    
151
}
(24-24/29)