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