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.io.Serializable;
|
13
|
import java.net.URI;
|
14
|
import java.util.HashSet;
|
15
|
import java.util.Iterator;
|
16
|
import java.util.Set;
|
17
|
import java.util.UUID;
|
18
|
|
19
|
import eu.etaxonomy.cdm.model.common.Language;
|
20
|
import eu.etaxonomy.cdm.model.term.Representation;
|
21
|
import eu.etaxonomy.cdm.model.term.TermType;
|
22
|
|
23
|
/**
|
24
|
* @author pplitzner
|
25
|
* @date 05.11.2018
|
26
|
*
|
27
|
*/
|
28
|
public class AbstractTermDto implements Serializable, Comparable<AbstractTermDto> {
|
29
|
|
30
|
private static final long serialVersionUID = -7160319884811828125L;
|
31
|
|
32
|
private UUID uuid;
|
33
|
private URI uri;
|
34
|
private TermType termType;
|
35
|
private Set<Representation> representations = new HashSet<>();
|
36
|
private String representation_L10n = null;
|
37
|
private String representation_L10n_abbreviatedLabel = null;
|
38
|
private String representation_L10n_text = null;
|
39
|
private String titleCache;
|
40
|
|
41
|
protected AbstractTermDto(){
|
42
|
|
43
|
}
|
44
|
|
45
|
public AbstractTermDto(UUID uuid, Set<Representation> representations, String titleCache) {
|
46
|
this.uuid = uuid;
|
47
|
this.titleCache = titleCache;
|
48
|
|
49
|
for(Representation rep: representations){
|
50
|
this.representations.add(rep.clone());
|
51
|
}
|
52
|
|
53
|
|
54
|
}
|
55
|
|
56
|
/**
|
57
|
*
|
58
|
* @param representation_L10n a blank instance of ITermRepresentation_L10n
|
59
|
* created by the default constructor
|
60
|
*/
|
61
|
public void localize(ITermRepresentation_L10n representation_L10n) {
|
62
|
|
63
|
representation_L10n.localize(representations);
|
64
|
if (representation_L10n.getLabel() != null) {
|
65
|
setRepresentation_L10n(representation_L10n.getLabel());
|
66
|
}
|
67
|
if (representation_L10n.getAbbreviatedLabel() != null) {
|
68
|
setRepresentation_L10n_abbreviatedLabel(representation_L10n.getAbbreviatedLabel());
|
69
|
}
|
70
|
if (representation_L10n.getText() != null) {
|
71
|
setRepresentation_L10n_text(representation_L10n.getText());
|
72
|
}
|
73
|
}
|
74
|
|
75
|
public URI getUri() {
|
76
|
return uri;
|
77
|
}
|
78
|
|
79
|
public void setUri(URI uri) {
|
80
|
this.uri = uri;
|
81
|
}
|
82
|
|
83
|
public TermType getTermType() {
|
84
|
return termType;
|
85
|
}
|
86
|
|
87
|
public void setTermType(TermType termType) {
|
88
|
this.termType = termType;
|
89
|
}
|
90
|
|
91
|
public String getRepresentation_L10n() {
|
92
|
return representation_L10n;
|
93
|
}
|
94
|
|
95
|
public void setRepresentation_L10n(String representation_L10n) {
|
96
|
this.representation_L10n = representation_L10n;
|
97
|
}
|
98
|
|
99
|
public void addRepresentation(Representation representation) {
|
100
|
representations.add(representation);
|
101
|
|
102
|
}
|
103
|
|
104
|
public String getRepresentation_L10n_abbreviatedLabel() {
|
105
|
return representation_L10n_abbreviatedLabel;
|
106
|
}
|
107
|
|
108
|
public void setRepresentation_L10n_abbreviatedLabel(String representation_L10n_abbreviatedLabel) {
|
109
|
this.representation_L10n_abbreviatedLabel = representation_L10n_abbreviatedLabel;
|
110
|
}
|
111
|
|
112
|
public String getRepresentation_L10n_text() {
|
113
|
return representation_L10n_text;
|
114
|
}
|
115
|
|
116
|
public void setRepresentation_L10n_text(String representation_L10n_text) {
|
117
|
this.representation_L10n_text = representation_L10n_text;
|
118
|
}
|
119
|
|
120
|
|
121
|
|
122
|
public UUID getUuid() {
|
123
|
return uuid;
|
124
|
}
|
125
|
|
126
|
public Set<Representation> getRepresentations() {
|
127
|
return representations;
|
128
|
}
|
129
|
public Representation getPreferredRepresentation(Language lang){
|
130
|
|
131
|
Language language = lang;
|
132
|
if(lang != null){
|
133
|
language = Language.DEFAULT();
|
134
|
}
|
135
|
for (Representation rep: representations){
|
136
|
if(rep != null && rep.getLanguage().equals(language)){
|
137
|
return rep;
|
138
|
}
|
139
|
}
|
140
|
language = Language.DEFAULT();
|
141
|
for (Representation rep: representations){
|
142
|
if(rep != null && rep.getLanguage().equals(language)){
|
143
|
return rep;
|
144
|
}
|
145
|
}
|
146
|
|
147
|
Iterator<Representation> it = getRepresentations().iterator();
|
148
|
if(it.hasNext()){
|
149
|
return getRepresentations().iterator().next();
|
150
|
}
|
151
|
|
152
|
return null;
|
153
|
}
|
154
|
|
155
|
public Representation getRepresentation(Language lang) {
|
156
|
for (Representation repr : representations){
|
157
|
Language reprLanguage = repr.getLanguage();
|
158
|
if (reprLanguage != null && reprLanguage.equals(lang)){
|
159
|
return repr;
|
160
|
}
|
161
|
}
|
162
|
return null;
|
163
|
}
|
164
|
|
165
|
|
166
|
public String getTitleCache() {
|
167
|
return titleCache;
|
168
|
}
|
169
|
|
170
|
|
171
|
public void setTitleCache(String titleCache) {
|
172
|
this.titleCache = titleCache;
|
173
|
}
|
174
|
|
175
|
@Override
|
176
|
public int hashCode() {
|
177
|
final int prime = 31;
|
178
|
int result = 1;
|
179
|
result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
|
180
|
return result;
|
181
|
}
|
182
|
|
183
|
@Override
|
184
|
public boolean equals(Object obj) {
|
185
|
if (this == obj) {
|
186
|
return true;
|
187
|
}
|
188
|
if (obj == null) {
|
189
|
return false;
|
190
|
}
|
191
|
if (getClass() != obj.getClass()) {
|
192
|
return false;
|
193
|
}
|
194
|
AbstractTermDto other = (AbstractTermDto) obj;
|
195
|
if (uuid == null) {
|
196
|
if (other.uuid != null) {
|
197
|
return false;
|
198
|
}
|
199
|
} else if (!uuid.equals(other.uuid)) {
|
200
|
return false;
|
201
|
}
|
202
|
return true;
|
203
|
}
|
204
|
|
205
|
@Override
|
206
|
public int compareTo(AbstractTermDto o) {
|
207
|
if(o == null){
|
208
|
return 1;
|
209
|
}
|
210
|
if(o.getRepresentation_L10n()!=null){
|
211
|
if(representation_L10n==null){
|
212
|
return -1;
|
213
|
}
|
214
|
else{
|
215
|
return representation_L10n.toLowerCase().compareTo(o.getRepresentation_L10n().toLowerCase());
|
216
|
}
|
217
|
}
|
218
|
else if(representation_L10n!=null){
|
219
|
return 1;
|
220
|
}
|
221
|
return uuid.compareTo(o.getUuid());
|
222
|
}
|
223
|
|
224
|
}
|