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
|
|
37
|
public TermCollectionDto(UUID uuid, Set<Representation> representations, TermType termType, String titleCache, boolean isAllowDuplicate, boolean isOrderRelevant, boolean isFlat) {
|
38
|
super(uuid, representations, titleCache);
|
39
|
terms = new ArrayList<>();
|
40
|
setTermType(termType);
|
41
|
this.isAllowDuplicate = isAllowDuplicate;
|
42
|
this.isOrderRelevant = isOrderRelevant;
|
43
|
this.isFlat = isFlat;
|
44
|
}
|
45
|
|
46
|
public List<TermDto> getTerms() {
|
47
|
if (terms.isEmpty()){
|
48
|
|
49
|
}
|
50
|
return terms;
|
51
|
}
|
52
|
|
53
|
public void addTerm(TermDto term){
|
54
|
if (term == null){
|
55
|
return;
|
56
|
}
|
57
|
if (terms == null){
|
58
|
terms = new ArrayList<>();
|
59
|
}
|
60
|
if (terms.contains(term)){
|
61
|
containsDuplicates = true;
|
62
|
}
|
63
|
terms.add(term);
|
64
|
}
|
65
|
|
66
|
public void removeTerm(TermDto term){
|
67
|
terms.remove(term);
|
68
|
}
|
69
|
|
70
|
|
71
|
|
72
|
/**
|
73
|
* @return the isAllowDuplicate
|
74
|
*/
|
75
|
public boolean isAllowDuplicate() {
|
76
|
return isAllowDuplicate;
|
77
|
}
|
78
|
|
79
|
/**
|
80
|
* @param isAllowDuplicate the isAllowDuplicate to set
|
81
|
*/
|
82
|
public void setAllowDuplicate(boolean isAllowDuplicate) {
|
83
|
this.isAllowDuplicate = isAllowDuplicate;
|
84
|
}
|
85
|
|
86
|
public boolean isContainsDuplicates() {
|
87
|
Set<TermDto> dtoSet = new HashSet<>(terms);
|
88
|
if (dtoSet.size() == terms.size()){
|
89
|
containsDuplicates = false;
|
90
|
}
|
91
|
|
92
|
return containsDuplicates;
|
93
|
}
|
94
|
|
95
|
public void setContainsDuplicates(boolean containsDuplicates) {
|
96
|
this.containsDuplicates = containsDuplicates;
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* @return the isOrderRelevant
|
101
|
*/
|
102
|
public boolean isOrderRelevant() {
|
103
|
return isOrderRelevant;
|
104
|
}
|
105
|
|
106
|
/**
|
107
|
* @param isOrderRelevant the isOrderRelevant to set
|
108
|
*/
|
109
|
public void setOrderRelevant(boolean isOrderRelevant) {
|
110
|
this.isOrderRelevant = isOrderRelevant;
|
111
|
}
|
112
|
|
113
|
/**
|
114
|
* @return the isFlat
|
115
|
*/
|
116
|
public boolean isFlat() {
|
117
|
return isFlat;
|
118
|
}
|
119
|
|
120
|
/**
|
121
|
* @param isFlat the isFlat to set
|
122
|
*/
|
123
|
public void setFlat(boolean isFlat) {
|
124
|
this.isFlat = isFlat;
|
125
|
}
|
126
|
|
127
|
public static String getTermCollectionDtoSelect(){
|
128
|
return getTermCollectionDtoSelect("TermVocabulary");
|
129
|
}
|
130
|
|
131
|
public static String getTermCollectionDtoSelect(String fromTable){
|
132
|
return ""
|
133
|
+ "select a.uuid, "
|
134
|
+ "r, "
|
135
|
+ "a.termType,"
|
136
|
+ "a.titleCache,"
|
137
|
+ "a.allowDuplicates,"
|
138
|
+ "a.orderRelevant,"
|
139
|
+ "a.isFlat "
|
140
|
|
141
|
+ "FROM "+fromTable+" as a "
|
142
|
+ "LEFT JOIN a.representations AS r ";
|
143
|
}
|
144
|
|
145
|
|
146
|
|
147
|
|
148
|
}
|