1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.model.common;
|
11
|
|
12
|
import java.net.URI;
|
13
|
import java.net.URISyntaxException;
|
14
|
import java.util.HashSet;
|
15
|
import java.util.Set;
|
16
|
|
17
|
import javax.persistence.Entity;
|
18
|
import javax.persistence.FetchType;
|
19
|
import javax.persistence.ManyToOne;
|
20
|
import javax.persistence.OneToMany;
|
21
|
import javax.xml.bind.annotation.XmlAccessType;
|
22
|
import javax.xml.bind.annotation.XmlAccessorType;
|
23
|
import javax.xml.bind.annotation.XmlElement;
|
24
|
import javax.xml.bind.annotation.XmlElementWrapper;
|
25
|
import javax.xml.bind.annotation.XmlIDREF;
|
26
|
import javax.xml.bind.annotation.XmlSchemaType;
|
27
|
import javax.xml.bind.annotation.XmlType;
|
28
|
|
29
|
import org.apache.commons.lang.StringUtils;
|
30
|
import org.apache.log4j.Logger;
|
31
|
import org.hibernate.annotations.Cascade;
|
32
|
import org.hibernate.annotations.CascadeType;
|
33
|
import org.hibernate.annotations.Type;
|
34
|
import org.hibernate.envers.Audited;
|
35
|
|
36
|
import eu.etaxonomy.cdm.model.agent.Person;
|
37
|
|
38
|
/**
|
39
|
* @author m.doering
|
40
|
* @since 08-Nov-2007 13:06:10
|
41
|
*/
|
42
|
@XmlAccessorType(XmlAccessType.FIELD)
|
43
|
@XmlType(name = "Annotation", propOrder = {
|
44
|
"commentator",
|
45
|
"annotationType",
|
46
|
"linkbackUri",
|
47
|
"intextReferences"
|
48
|
})
|
49
|
@Entity
|
50
|
@Audited
|
51
|
public class Annotation extends LanguageStringBase implements Cloneable, IIntextReferencable {
|
52
|
private static final long serialVersionUID = -4484677078599520233L;
|
53
|
@SuppressWarnings("unused")
|
54
|
private static final Logger logger = Logger.getLogger(Annotation.class);
|
55
|
|
56
|
/**
|
57
|
* Factory method.
|
58
|
* @param text
|
59
|
* @param lang
|
60
|
* @return
|
61
|
*/
|
62
|
public static Annotation NewInstance(String text, Language lang){
|
63
|
return new Annotation(text, lang);
|
64
|
}
|
65
|
|
66
|
public static Annotation NewInstance(String text, AnnotationType annotationType, Language lang){
|
67
|
Annotation annotation = new Annotation(text, lang);
|
68
|
annotation.setAnnotationType(annotationType);
|
69
|
return annotation;
|
70
|
}
|
71
|
|
72
|
/**
|
73
|
* Factory method. Using default language.
|
74
|
* @param text
|
75
|
* @return
|
76
|
*/
|
77
|
public static Annotation NewDefaultLanguageInstance(String text){
|
78
|
return new Annotation(text, Language.DEFAULT());
|
79
|
}
|
80
|
|
81
|
|
82
|
//TODO do we need to add it to JAXB? #4706
|
83
|
@XmlElementWrapper(name = "IntextReferences", nillable = true)
|
84
|
@XmlElement(name = "IntextReference")
|
85
|
@OneToMany(mappedBy="languageString", fetch=FetchType.LAZY, orphanRemoval=true)
|
86
|
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE})
|
87
|
// @Merge(MergeMode.ADD_CLONE)
|
88
|
private Set<IntextReference> intextReferences = new HashSet<>();
|
89
|
|
90
|
//Human annotation
|
91
|
@XmlElement(name = "Commentator")
|
92
|
@XmlIDREF
|
93
|
@XmlSchemaType(name = "IDREF")
|
94
|
@ManyToOne(fetch = FetchType.LAZY)
|
95
|
@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
|
96
|
private Person commentator;
|
97
|
|
98
|
@XmlElement(name = "AnnotationType")
|
99
|
@XmlIDREF
|
100
|
@XmlSchemaType(name = "IDREF")
|
101
|
@ManyToOne(fetch = FetchType.LAZY)
|
102
|
private AnnotationType annotationType;
|
103
|
|
104
|
// for external annotations/comments the URI of these can be set.
|
105
|
// should be useful to implement trackback, pingback or linkback:
|
106
|
// http://en.wikipedia.org/wiki/Linkback
|
107
|
@XmlElement(name = "LinkbackUri")
|
108
|
@Type(type="uriUserType")
|
109
|
private URI linkbackUri;
|
110
|
|
111
|
|
112
|
// *********** CONSTRUCTOR **************************************/
|
113
|
|
114
|
protected Annotation(){
|
115
|
super();
|
116
|
}
|
117
|
|
118
|
/**
|
119
|
* Constructor
|
120
|
* @param text
|
121
|
* @param lang
|
122
|
*/
|
123
|
protected Annotation(String text, Language language) {
|
124
|
super(text, language);
|
125
|
}
|
126
|
|
127
|
//******************** GETTER /SETTER *************************/
|
128
|
|
129
|
|
130
|
public AnnotationType getAnnotationType() {
|
131
|
return annotationType;
|
132
|
}
|
133
|
|
134
|
public void setAnnotationType(AnnotationType annotationType) {
|
135
|
this.annotationType = annotationType;
|
136
|
}
|
137
|
|
138
|
public Person getCommentator(){
|
139
|
return this.commentator;
|
140
|
}
|
141
|
public void setCommentator(Person commentator){
|
142
|
this.commentator = commentator;
|
143
|
}
|
144
|
|
145
|
|
146
|
public URI getLinkbackUri() {
|
147
|
return linkbackUri;
|
148
|
}
|
149
|
public void setLinkbackUri(URI linkbackUri) {
|
150
|
this.linkbackUri = linkbackUri;
|
151
|
}
|
152
|
|
153
|
|
154
|
//*************** INTEXT REFERENCE **********************************************
|
155
|
|
156
|
@Override
|
157
|
public Set<IntextReference> getIntextReferences(){
|
158
|
return this.intextReferences;
|
159
|
}
|
160
|
|
161
|
@Override
|
162
|
public IntextReference addIntextReference(IIntextReferenceTarget target, String start, String inner, String end){
|
163
|
return IntextReferenceHelper.addIntextReference(target, this, start, inner, end);
|
164
|
}
|
165
|
@Override
|
166
|
public IntextReference addIntextReference(IIntextReferenceTarget target, int start, int end){
|
167
|
return IntextReferenceHelper.addIntextReference(target, this, start, end);
|
168
|
}
|
169
|
|
170
|
@Override
|
171
|
public void addIntextReference(IntextReference intextReference){
|
172
|
if (intextReference != null){
|
173
|
intextReference.setReferencedEntity(this);
|
174
|
getIntextReferences().add(intextReference);
|
175
|
}
|
176
|
}
|
177
|
|
178
|
@Override
|
179
|
public void removeIntextReference(IntextReference intextReference){
|
180
|
if(getIntextReferences().contains(intextReference)) {
|
181
|
getIntextReferences().remove(intextReference);
|
182
|
intextReference.setReferencedEntity((Annotation)null);
|
183
|
}
|
184
|
}
|
185
|
|
186
|
|
187
|
// ***************************** TO STRING ***********************************
|
188
|
|
189
|
|
190
|
/* (non-Javadoc)
|
191
|
* @see eu.etaxonomy.cdm.model.common.CdmBase#toString()
|
192
|
*/
|
193
|
@Override
|
194
|
public String toString() {
|
195
|
if (StringUtils.isNotBlank(this.text)){
|
196
|
return "Ann.: " + this.text;
|
197
|
}else{
|
198
|
return super.toString();
|
199
|
}
|
200
|
}
|
201
|
|
202
|
|
203
|
|
204
|
//****************** CLONE ************************************************/
|
205
|
|
206
|
@Override
|
207
|
public Object clone() throws CloneNotSupportedException{
|
208
|
Annotation result = (Annotation)super.clone();
|
209
|
//TODO do we really need this, it should not change anything
|
210
|
result.setCommentator(this.getCommentator());
|
211
|
//TODO do we really need this, it should not change anything
|
212
|
result.setAnnotationType(this.getAnnotationType());
|
213
|
|
214
|
try {
|
215
|
result.setLinkbackUri(this.linkbackUri == null ? null : new URI(this.linkbackUri.toString()));
|
216
|
} catch (URISyntaxException e) {
|
217
|
//do nothing
|
218
|
}
|
219
|
//IntextReferences
|
220
|
result.intextReferences = new HashSet<IntextReference>();
|
221
|
for (IntextReference intextReference : getIntextReferences()){
|
222
|
IntextReference newIntextReference = (IntextReference)intextReference.clone();
|
223
|
result.addIntextReference(newIntextReference);
|
224
|
}
|
225
|
|
226
|
return result;
|
227
|
}
|
228
|
|
229
|
}
|