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.taxon;
|
11
|
|
12
|
import java.lang.reflect.Method;
|
13
|
|
14
|
import javax.persistence.Entity;
|
15
|
import javax.persistence.FetchType;
|
16
|
import javax.persistence.ManyToOne;
|
17
|
import javax.persistence.Transient;
|
18
|
import javax.validation.constraints.NotNull;
|
19
|
import javax.xml.bind.annotation.XmlAccessType;
|
20
|
import javax.xml.bind.annotation.XmlAccessorType;
|
21
|
import javax.xml.bind.annotation.XmlAttribute;
|
22
|
import javax.xml.bind.annotation.XmlElement;
|
23
|
import javax.xml.bind.annotation.XmlIDREF;
|
24
|
import javax.xml.bind.annotation.XmlSchemaType;
|
25
|
import javax.xml.bind.annotation.XmlType;
|
26
|
|
27
|
import org.apache.log4j.Logger;
|
28
|
import org.hibernate.annotations.Cascade;
|
29
|
import org.hibernate.annotations.CascadeType;
|
30
|
import org.hibernate.annotations.Index;
|
31
|
import org.hibernate.annotations.Table;
|
32
|
import org.hibernate.envers.Audited;
|
33
|
import org.hibernate.search.annotations.IndexedEmbedded;
|
34
|
|
35
|
import org.springframework.security.access.prepost.PreFilter;
|
36
|
|
37
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
38
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
39
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
40
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
41
|
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
|
42
|
import eu.etaxonomy.cdm.validation.Level2;
|
43
|
import eu.etaxonomy.cdm.validation.Level3;
|
44
|
import eu.etaxonomy.cdm.validation.annotation.TaxonNameCannotBeAcceptedAndSynonym;
|
45
|
|
46
|
/**
|
47
|
* The upmost (abstract) class for the use of a {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name} in a {@link eu.etaxonomy.cdm.model.reference.Reference reference}
|
48
|
* or within a taxonomic view/treatment either as a {@link Taxon taxon}
|
49
|
* ("accepted" respectively "correct" name) or as a (junior) {@link Synonym synonym}.
|
50
|
* Within a taxonomic view/treatment or a reference a taxon name can be used
|
51
|
* only in one of both described meanings. The reference using the taxon name
|
52
|
* is generally cited with "sec." (secundum, sensu). For instance:
|
53
|
* "<i>Juncus longirostris</i> Kuvaev sec. Kirschner, J. et al. 2002".
|
54
|
* <P>
|
55
|
* This class corresponds to: <ul>
|
56
|
* <li> TaxonConcept according to the TDWG ontology
|
57
|
* <li> TaxonConcept according to the TCS
|
58
|
* </ul>
|
59
|
*
|
60
|
* @author m.doering
|
61
|
* @version 1.0
|
62
|
* @created 08-Nov-2007 13:06:56
|
63
|
*/
|
64
|
@XmlAccessorType(XmlAccessType.FIELD)
|
65
|
@XmlType(name = "TaxonBase", propOrder = {
|
66
|
"name",
|
67
|
"sec",
|
68
|
"doubtful",
|
69
|
"appendedPhrase",
|
70
|
"useNameCache"
|
71
|
})
|
72
|
@Entity
|
73
|
@Audited
|
74
|
//@PreFilter("hasPermission(filterObject, 'edit')")
|
75
|
@Table(appliesTo="TaxonBase", indexes = { @Index(name = "taxonBaseTitleCacheIndex", columnNames = { "titleCache" }) })
|
76
|
@TaxonNameCannotBeAcceptedAndSynonym(groups = Level3.class)
|
77
|
public abstract class TaxonBase<S extends IIdentifiableEntityCacheStrategy> extends IdentifiableEntity<S> implements Cloneable {
|
78
|
private static final long serialVersionUID = -3589185949928938529L;
|
79
|
private static final Logger logger = Logger.getLogger(TaxonBase.class);
|
80
|
|
81
|
private static Method methodTaxonNameAddTaxonBase;
|
82
|
|
83
|
static {
|
84
|
try {
|
85
|
methodTaxonNameAddTaxonBase = TaxonNameBase.class.getDeclaredMethod("addTaxonBase", TaxonBase.class);
|
86
|
methodTaxonNameAddTaxonBase.setAccessible(true);
|
87
|
} catch (Exception e) {
|
88
|
logger.error(e);
|
89
|
for(StackTraceElement ste : e.getStackTrace()) {
|
90
|
logger.error(ste);
|
91
|
}
|
92
|
}
|
93
|
}
|
94
|
|
95
|
//The assignment to the Taxon or to the Synonym class is not definitive
|
96
|
@XmlAttribute(name = "isDoubtful")
|
97
|
private boolean doubtful;
|
98
|
|
99
|
@XmlElement(name = "Name", required = true)
|
100
|
@XmlIDREF
|
101
|
@XmlSchemaType(name = "IDREF")
|
102
|
@ManyToOne(fetch = FetchType.LAZY)
|
103
|
// @JoinColumn(name="name_id")
|
104
|
@IndexedEmbedded
|
105
|
@Cascade(CascadeType.SAVE_UPDATE)
|
106
|
@NotNull(groups = Level2.class)
|
107
|
private TaxonNameBase name;
|
108
|
|
109
|
// The concept reference
|
110
|
@XmlElement(name = "Sec")
|
111
|
@XmlIDREF
|
112
|
@XmlSchemaType(name = "IDREF")
|
113
|
@ManyToOne(fetch = FetchType.LAZY)
|
114
|
@IndexedEmbedded
|
115
|
@Cascade(CascadeType.SAVE_UPDATE)
|
116
|
@NotNull(groups = Level2.class)
|
117
|
private Reference sec;
|
118
|
|
119
|
|
120
|
@XmlElement(name = "AppendedPhrase")
|
121
|
private String appendedPhrase;
|
122
|
|
123
|
@XmlAttribute(name= "UseNameCache")
|
124
|
private boolean useNameCache = false;
|
125
|
|
126
|
|
127
|
// ************* CONSTRUCTORS *************/
|
128
|
/**
|
129
|
* Class constructor: creates a new empty (abstract) taxon.
|
130
|
*
|
131
|
* @see #TaxonBase(TaxonNameBase, Reference)
|
132
|
*/
|
133
|
protected TaxonBase(){
|
134
|
super();
|
135
|
}
|
136
|
|
137
|
/**
|
138
|
* Class constructor: creates a new (abstract) taxon with the
|
139
|
* {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name} used and the {@link eu.etaxonomy.cdm.model.reference.Reference reference}
|
140
|
* using it.
|
141
|
*
|
142
|
* @param taxonNameBase the taxon name used
|
143
|
* @param sec the reference using the taxon name
|
144
|
* @see #TaxonBase()
|
145
|
*/
|
146
|
protected TaxonBase(TaxonNameBase taxonNameBase, Reference sec){
|
147
|
super();
|
148
|
if (taxonNameBase != null){
|
149
|
this.invokeSetMethod(methodTaxonNameAddTaxonBase, taxonNameBase);
|
150
|
}
|
151
|
this.setSec(sec);
|
152
|
}
|
153
|
|
154
|
//********* METHODS **************************************/
|
155
|
|
156
|
/**
|
157
|
* Generates and returns the string with the full scientific name (including
|
158
|
* authorship) of the {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name} used in <i>this</i>
|
159
|
* (abstract) taxon as well as the title of the {@link eu.etaxonomy.cdm.model.reference.Reference reference} using
|
160
|
* this taxon name. This string may be stored in the inherited
|
161
|
* {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache() titleCache} attribute.
|
162
|
* This method overrides the generic and inherited generateTitle() method
|
163
|
* from {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity IdentifiableEntity}.
|
164
|
*
|
165
|
* @return the string with the full scientific name of the taxon name
|
166
|
* and with the title of the reference involved in <i>this</i> (abstract) taxon
|
167
|
* @see eu.etaxonomy.cdm.model.common.IdentifiableEntity#generateTitle()
|
168
|
* @see eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache()
|
169
|
*/
|
170
|
// @Override
|
171
|
// public String generateTitle() {
|
172
|
// String title;
|
173
|
// if (name != null && name.getTitleCache() != null){
|
174
|
// title = name.getTitleCache() + " sec. ";
|
175
|
// if (sec != null){
|
176
|
// title += sec.getTitleCache();
|
177
|
// }else{
|
178
|
// title += "???";
|
179
|
// }
|
180
|
// }else{
|
181
|
// title = this.toString();
|
182
|
// }
|
183
|
// return title;
|
184
|
// }
|
185
|
|
186
|
/**
|
187
|
* Returns the {@link TaxonNameBase taxon name} used in <i>this</i> (abstract) taxon.
|
188
|
*/
|
189
|
public TaxonNameBase getName(){
|
190
|
return this.name;
|
191
|
}
|
192
|
|
193
|
/*
|
194
|
* @see #getName
|
195
|
*/
|
196
|
public void setName(TaxonNameBase name) {
|
197
|
if(name != null) {
|
198
|
name.getTaxonBases().add(this);
|
199
|
}
|
200
|
this.name = name;
|
201
|
}
|
202
|
|
203
|
/**
|
204
|
* Returns the {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup homotypical group} of the
|
205
|
* {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name} used in <i>this</i> (abstract) taxon.
|
206
|
*/
|
207
|
@Transient
|
208
|
public HomotypicalGroup getHomotypicGroup(){
|
209
|
if (this.getName() == null){
|
210
|
return null;
|
211
|
}else{
|
212
|
return this.getName().getHomotypicalGroup();
|
213
|
}
|
214
|
}
|
215
|
|
216
|
/**
|
217
|
* Returns the boolean value indicating whether the assignment of <i>this</i>
|
218
|
* (abstract) taxon to the {@link Taxon Taxon} or to the {@link Synonym Synonym} class is definitive
|
219
|
* (false) or not (true). If this flag is set the use of <i>this</i> (abstract)
|
220
|
* taxon as an "accepted/correct" name or as a (junior) "synonym" might
|
221
|
* still change in the course of taxonomical working process.
|
222
|
*/
|
223
|
public boolean isDoubtful(){
|
224
|
return this.doubtful;
|
225
|
}
|
226
|
/**
|
227
|
* @see #isDoubtful()
|
228
|
*/
|
229
|
public void setDoubtful(boolean doubtful){
|
230
|
this.doubtful = doubtful;
|
231
|
}
|
232
|
|
233
|
/**
|
234
|
* Returns the {@link eu.etaxonomy.cdm.model.reference.Reference reference} of <i>this</i> (abstract) taxon.
|
235
|
* This is the reference or the treatment using the {@link TaxonNameBase taxon name}
|
236
|
* in <i>this</i> (abstract) taxon.
|
237
|
*/
|
238
|
public Reference getSec() {
|
239
|
return sec;
|
240
|
}
|
241
|
|
242
|
/**
|
243
|
* @see #getSec()
|
244
|
*/
|
245
|
public void setSec(Reference sec) {
|
246
|
this.sec = sec;
|
247
|
}
|
248
|
|
249
|
|
250
|
|
251
|
/**
|
252
|
* An appended phrase is a phrase that is added to the {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name}
|
253
|
* 's title cache to be used just in this taxon. E.g. the phrase "sensu latu" may be added
|
254
|
* to the name to describe this taxon more precisely.
|
255
|
* If {@link #isUseNameCache()}
|
256
|
* @return the appendedPhrase
|
257
|
*/
|
258
|
public String getAppendedPhrase() {
|
259
|
return appendedPhrase;
|
260
|
}
|
261
|
|
262
|
/**
|
263
|
* @param appendedPhrase the appendedPhrase to set
|
264
|
*/
|
265
|
public void setAppendedPhrase(String appendedPhrase) {
|
266
|
this.appendedPhrase = appendedPhrase;
|
267
|
}
|
268
|
|
269
|
/**
|
270
|
* @return the useNameCache
|
271
|
*/
|
272
|
public boolean isUseNameCache() {
|
273
|
return useNameCache;
|
274
|
}
|
275
|
|
276
|
/**
|
277
|
* @param useNameCache the useNameCache to set
|
278
|
*/
|
279
|
public void setUseNameCache(boolean useNameCache) {
|
280
|
this.useNameCache = useNameCache;
|
281
|
}
|
282
|
//*********************** CLONE ********************************************************/
|
283
|
|
284
|
/**
|
285
|
* Clones <i>this</i> taxon. This is a shortcut that enables to create
|
286
|
* a new instance with empty taxon name and sec reference.
|
287
|
*
|
288
|
* @see eu.etaxonomy.cdm.model.media.IdentifiableEntity#clone()
|
289
|
* @see java.lang.Object#clone()
|
290
|
*/
|
291
|
@Override
|
292
|
public Object clone() {
|
293
|
TaxonBase result;
|
294
|
try {
|
295
|
result = (TaxonBase)super.clone();
|
296
|
result.setSec(null);
|
297
|
|
298
|
return result;
|
299
|
} catch (CloneNotSupportedException e) {
|
300
|
logger.warn("Object does not implement cloneable");
|
301
|
e.printStackTrace();
|
302
|
return null;
|
303
|
}
|
304
|
|
305
|
|
306
|
}
|
307
|
|
308
|
}
|