1 |
a2a6c354
|
m.doering
|
package eu.etaxonomy.cdm.model.common;
|
2 |
|
|
|
3 |
|
|
import java.util.HashSet;
|
4 |
|
|
import java.util.Set;
|
5 |
|
|
|
6 |
18e081ac
|
m.doering
|
import javax.persistence.FetchType;
|
7 |
45f2c148
|
m.doering
|
import javax.persistence.JoinTable;
|
8 |
a2a6c354
|
m.doering
|
import javax.persistence.MappedSuperclass;
|
9 |
|
|
import javax.persistence.OneToMany;
|
10 |
|
|
import javax.persistence.Transient;
|
11 |
|
|
|
12 |
|
|
import org.apache.log4j.Logger;
|
13 |
|
|
import org.hibernate.annotations.Cascade;
|
14 |
|
|
import org.hibernate.annotations.CascadeType;
|
15 |
|
|
|
16 |
|
|
@MappedSuperclass
|
17 |
|
|
public abstract class TermBase extends VersionableEntity {
|
18 |
|
|
static Logger logger = Logger.getLogger(TermBase.class);
|
19 |
407dc559
|
Andreas Müller
|
|
20 |
a2a6c354
|
m.doering
|
private String uri;
|
21 |
407dc559
|
Andreas Müller
|
private Set<Representation> representations = new HashSet<Representation>();
|
22 |
|
|
|
23 |
a2a6c354
|
m.doering
|
public TermBase() {
|
24 |
|
|
super();
|
25 |
|
|
}
|
26 |
|
|
public TermBase(String term, String label) {
|
27 |
|
|
super();
|
28 |
|
|
this.addRepresentation(new Representation(term, label, Language.DEFAULT()) );
|
29 |
|
|
}
|
30 |
|
|
|
31 |
407dc559
|
Andreas Müller
|
@OneToMany//(fetch=FetchType.EAGER)
|
32 |
a2a6c354
|
m.doering
|
@Cascade( { CascadeType.SAVE_UPDATE, CascadeType.DELETE })
|
33 |
|
|
public Set<Representation> getRepresentations() {
|
34 |
|
|
return this.representations;
|
35 |
|
|
}
|
36 |
|
|
|
37 |
|
|
public void setRepresentations(Set<Representation> representations) {
|
38 |
|
|
this.representations = representations;
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
public void addRepresentation(Representation representation) {
|
42 |
|
|
this.representations.add(representation);
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
public void removeRepresentation(Representation representation) {
|
46 |
|
|
this.representations.remove(representation);
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
@Transient
|
50 |
|
|
public Representation getRepresentation(Language lang) {
|
51 |
|
|
for (Representation repr : representations){
|
52 |
407dc559
|
Andreas Müller
|
Language reprLanguage = repr.getLanguage();
|
53 |
|
|
if (reprLanguage != null && reprLanguage.equals(lang)){
|
54 |
a2a6c354
|
m.doering
|
return repr;
|
55 |
|
|
}
|
56 |
|
|
}
|
57 |
|
|
return null;
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
public String getUri() {
|
61 |
|
|
return this.uri;
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
public void setUri(String uri) {
|
65 |
|
|
this.uri = uri;
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
@Transient
|
69 |
d723f0d5
|
m.doering
|
public String getLabel() {
|
70 |
|
|
if(getLabel(Language.DEFAULT())!=null){
|
71 |
407dc559
|
Andreas Müller
|
Representation repr = getRepresentation(Language.DEFAULT());
|
72 |
|
|
return (repr == null)? null :repr.getLabel();
|
73 |
d723f0d5
|
m.doering
|
}else{
|
74 |
|
|
for (Representation r : representations){
|
75 |
|
|
return r.getLabel();
|
76 |
|
|
}
|
77 |
|
|
}
|
78 |
|
|
return super.getUuid();
|
79 |
a2a6c354
|
m.doering
|
}
|
80 |
|
|
|
81 |
|
|
@Transient
|
82 |
d723f0d5
|
m.doering
|
public String getLabel(Language lang) {
|
83 |
407dc559
|
Andreas Müller
|
Representation repr = this.getRepresentation(lang);
|
84 |
|
|
return (repr == null) ? null : repr.getLabel();
|
85 |
a2a6c354
|
m.doering
|
}
|
86 |
|
|
|
87 |
|
|
@Transient
|
88 |
d723f0d5
|
m.doering
|
public String getDescription() {
|
89 |
407dc559
|
Andreas Müller
|
return this.getDescription(Language.DEFAULT());
|
90 |
a2a6c354
|
m.doering
|
}
|
91 |
|
|
|
92 |
|
|
@Transient
|
93 |
d723f0d5
|
m.doering
|
public String getDescription(Language lang) {
|
94 |
407dc559
|
Andreas Müller
|
Representation repr = this.getRepresentation(lang);
|
95 |
|
|
return (repr == null) ? null :repr.getDescription();
|
96 |
a2a6c354
|
m.doering
|
}
|
97 |
|
|
|
98 |
|
|
@Override
|
99 |
|
|
public boolean equals(Object obj) {
|
100 |
|
|
if (DefinedTermBase.class.isAssignableFrom(obj.getClass())){
|
101 |
|
|
DefinedTermBase dtb = (DefinedTermBase)obj;
|
102 |
|
|
if (dtb.getUuid().equals(this.getUuid())){
|
103 |
|
|
return true;
|
104 |
|
|
}
|
105 |
|
|
}
|
106 |
|
|
return false;
|
107 |
|
|
}
|
108 |
|
|
|
109 |
d723f0d5
|
m.doering
|
@Override
|
110 |
|
|
public String toString() {
|
111 |
af6f16cf
|
m.doering
|
return super.toString()+" "+this.getLabel();
|
112 |
d723f0d5
|
m.doering
|
}
|
113 |
|
|
|
114 |
a2a6c354
|
m.doering
|
}
|