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