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 javax.persistence.Entity;
|
13
|
import javax.persistence.FetchType;
|
14
|
import javax.persistence.ManyToOne;
|
15
|
import javax.persistence.Transient;
|
16
|
import javax.xml.bind.annotation.XmlAccessType;
|
17
|
import javax.xml.bind.annotation.XmlAccessorType;
|
18
|
import javax.xml.bind.annotation.XmlElement;
|
19
|
import javax.xml.bind.annotation.XmlIDREF;
|
20
|
import javax.xml.bind.annotation.XmlRootElement;
|
21
|
import javax.xml.bind.annotation.XmlSchemaType;
|
22
|
import javax.xml.bind.annotation.XmlType;
|
23
|
|
24
|
import org.apache.log4j.Logger;
|
25
|
import org.hibernate.annotations.Cascade;
|
26
|
import org.hibernate.annotations.CascadeType;
|
27
|
import org.hibernate.envers.Audited;
|
28
|
import org.hibernate.search.annotations.Indexed;
|
29
|
import org.hibernate.search.annotations.IndexedEmbedded;
|
30
|
|
31
|
import eu.etaxonomy.cdm.model.common.RelationshipBase;
|
32
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
33
|
|
34
|
/**
|
35
|
* The class representing a relationship between two {@link Taxon ("accepted/correct") taxa}.
|
36
|
* This includes a {@link TaxonRelationshipType taxon relationship type} (for instance "congruent to" or
|
37
|
* "misapplied name for").
|
38
|
* <P>
|
39
|
* This class corresponds in part to: <ul>
|
40
|
* <li> Relationship according to the TDWG ontology
|
41
|
* <li> TaxonRelationship according to the TCS
|
42
|
* </ul>
|
43
|
*
|
44
|
* @author m.doering
|
45
|
* @version 1.0
|
46
|
* @created 08-Nov-2007 13:06:58
|
47
|
*/
|
48
|
@XmlAccessorType(XmlAccessType.FIELD)
|
49
|
@XmlType(name = "TaxonRelationship", propOrder = {
|
50
|
"relatedFrom",
|
51
|
"relatedTo",
|
52
|
"type"
|
53
|
})
|
54
|
@XmlRootElement(name = "TaxonRelationship")
|
55
|
@Entity
|
56
|
@Audited
|
57
|
@Indexed(index = "eu.etaxonomy.cdm.model.taxon.TaxonRelationship")
|
58
|
public class TaxonRelationship extends RelationshipBase<Taxon, Taxon, TaxonRelationshipType> {
|
59
|
private static final long serialVersionUID = 1378437971941534653L;
|
60
|
static private final Logger logger = Logger.getLogger(TaxonRelationship.class);
|
61
|
|
62
|
@XmlElement(name = "RelatedFrom")
|
63
|
@XmlIDREF
|
64
|
@XmlSchemaType(name = "IDREF")
|
65
|
@ManyToOne(fetch=FetchType.EAGER)
|
66
|
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
|
67
|
@IndexedEmbedded(includeEmbeddedObjectId=true, depth=1)
|
68
|
private Taxon relatedFrom;
|
69
|
|
70
|
@XmlElement(name = "RelatedTo")
|
71
|
@XmlIDREF
|
72
|
@XmlSchemaType(name = "IDREF")
|
73
|
@ManyToOne(fetch=FetchType.EAGER)
|
74
|
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
|
75
|
@IndexedEmbedded(includeEmbeddedObjectId=true, depth=1)
|
76
|
private Taxon relatedTo;
|
77
|
|
78
|
@XmlElement(name = "Type")
|
79
|
@XmlIDREF
|
80
|
@XmlSchemaType(name = "IDREF")
|
81
|
@ManyToOne(fetch=FetchType.EAGER)
|
82
|
@IndexedEmbedded(depth=1)
|
83
|
private TaxonRelationshipType type;
|
84
|
|
85
|
/**
|
86
|
* @deprecated for hibernate only, don't use
|
87
|
*/
|
88
|
@Deprecated
|
89
|
private TaxonRelationship(){}
|
90
|
|
91
|
/**
|
92
|
* Class constructor: creates a new taxon relationship instance (with the
|
93
|
* given "accepted/correct" {@link Taxon taxa}, the given {@link SynonymRelationshipType synonym relationship type}
|
94
|
* and with the {@link eu.etaxonomy.cdm.model.reference.Reference reference source} on which the relationship
|
95
|
* assertion is based). Moreover the new taxon relationship will be added to
|
96
|
* the respective sets of taxon relationships assigned to both taxa.
|
97
|
*
|
98
|
* @param from the taxon instance to be involved as a source in the new taxon relationship
|
99
|
* @param to the taxon instance to be involved as a target in the new taxon relationship
|
100
|
* @param type the taxon relationship type of the new taxon relationship
|
101
|
* @param citation the reference source for the new taxon relationship
|
102
|
* @param citationMicroReference the string with the details describing the exact localisation within the reference
|
103
|
* @see eu.etaxonomy.cdm.model.common.RelationshipBase
|
104
|
*/
|
105
|
protected TaxonRelationship(Taxon from, Taxon to, TaxonRelationshipType type, Reference citation, String citationMicroReference) {
|
106
|
super(from, to, type, citation, citationMicroReference);
|
107
|
}
|
108
|
|
109
|
/**
|
110
|
* Returns the {@link Taxon taxon} involved as a source in <i>this</i>
|
111
|
* taxon relationship.
|
112
|
*
|
113
|
* @see #getToTaxon()
|
114
|
* @see Taxon#getRelationsFromThisTaxon()
|
115
|
* @see eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedFrom()
|
116
|
* @see eu.etaxonomy.cdm.model.common.RelationshipBase#getType()
|
117
|
*/
|
118
|
@Transient
|
119
|
public Taxon getFromTaxon(){
|
120
|
return getRelatedFrom();
|
121
|
}
|
122
|
/**
|
123
|
* Sets the given {@link Taxon taxon} as a source in <i>this</i> taxon relationship.
|
124
|
* Therefore <i>this</i> taxon relationship will be added to the corresponding
|
125
|
* set of taxon relationships assigned to the given taxon. Furthermore if
|
126
|
* the given taxon replaces an "old" one <i>this</i> taxon relationship will
|
127
|
* be removed from the set of taxon relationships assigned to the "old"
|
128
|
* source taxon.
|
129
|
*
|
130
|
* @param fromTaxon the taxon instance to be set as a source in <i>this</i> synonym relationship
|
131
|
* @see #getFromTaxon()
|
132
|
*/
|
133
|
public void setFromTaxon(Taxon fromTaxon){
|
134
|
setRelatedFrom(fromTaxon);
|
135
|
}
|
136
|
|
137
|
/**
|
138
|
* Returns the {@link Taxon taxon} involved as a target in <i>this</i>
|
139
|
* taxon relationship.
|
140
|
*
|
141
|
* @see #getFromTaxon()
|
142
|
* @see Taxon#getRelationsToThisTaxon()
|
143
|
* @see eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedTo()
|
144
|
* @see eu.etaxonomy.cdm.model.common.RelationshipBase#getType()
|
145
|
*/
|
146
|
@Transient
|
147
|
public Taxon getToTaxon(){
|
148
|
return getRelatedTo();
|
149
|
}
|
150
|
|
151
|
/**
|
152
|
* Sets the given {@link Taxon taxon} as a target in <i>this</i> taxon relationship.
|
153
|
* Therefore <i>this</i> taxon relationship will be added to the corresponding
|
154
|
* set of taxon relationships assigned to the given taxon. Furthermore if
|
155
|
* the given taxon replaces an "old" one <i>this</i> taxon relationship will
|
156
|
* be removed from the set of taxon relationships assigned to the "old"
|
157
|
* target taxon.
|
158
|
*
|
159
|
* @param toTaxon the taxon instance to be set as a target in <i>this</i> synonym relationship
|
160
|
* @see #getToTaxon()
|
161
|
*/
|
162
|
public void setToTaxon(Taxon toTaxon){
|
163
|
setRelatedTo(toTaxon);
|
164
|
}
|
165
|
|
166
|
// for extra-package access to relatedFrom use getFromTaxon instead
|
167
|
@Override
|
168
|
protected Taxon getRelatedFrom() {
|
169
|
return relatedFrom;
|
170
|
}
|
171
|
|
172
|
// for extra-package access to relatedFrom use getToTaxon instead
|
173
|
@Override
|
174
|
protected Taxon getRelatedTo() {
|
175
|
return relatedTo;
|
176
|
}
|
177
|
|
178
|
@Override
|
179
|
public TaxonRelationshipType getType() {
|
180
|
return type;
|
181
|
}
|
182
|
|
183
|
@Override
|
184
|
protected void setRelatedFrom(Taxon relatedFrom) {
|
185
|
if (relatedFrom == null){
|
186
|
// this.deletedObjects.add(this.relatedFrom);
|
187
|
}
|
188
|
this.relatedFrom = relatedFrom;
|
189
|
}
|
190
|
|
191
|
@Override
|
192
|
protected void setRelatedTo(Taxon relatedTo) {
|
193
|
if (relatedTo == null){
|
194
|
// this.deletedObjects.add(this.relatedTo);
|
195
|
}
|
196
|
this.relatedTo = relatedTo;
|
197
|
}
|
198
|
|
199
|
@Override
|
200
|
public void setType(TaxonRelationshipType type) {
|
201
|
this.type = type;
|
202
|
}
|
203
|
|
204
|
//*********************************** CLONE *****************************************/
|
205
|
|
206
|
/**
|
207
|
* Clones <i>this</i> TaxonRelationship. This is a shortcut that enables to create
|
208
|
* a new instance that differs only slightly from <i>this</i> TaxonRelationship by
|
209
|
* modifying only some of the attributes.
|
210
|
*
|
211
|
* @see eu.etaxonomy.cdm.model.common.RelationshipBase#clone()
|
212
|
* @see java.lang.Object#clone()
|
213
|
*/
|
214
|
@Override
|
215
|
public Object clone() {
|
216
|
TaxonRelationship result;
|
217
|
|
218
|
try{
|
219
|
result = (TaxonRelationship) super.clone();
|
220
|
//no changes to relatedFrom, relatedTo, type
|
221
|
|
222
|
return result;
|
223
|
} catch (CloneNotSupportedException e) {
|
224
|
logger.warn("Object does not implement cloneable");
|
225
|
e.printStackTrace();
|
226
|
return null;
|
227
|
}
|
228
|
}
|
229
|
}
|