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
|
|
13
|
import java.lang.reflect.Field;
|
14
|
import java.util.ArrayList;
|
15
|
import java.util.Collections;
|
16
|
import java.util.HashMap;
|
17
|
import java.util.HashSet;
|
18
|
import java.util.Iterator;
|
19
|
import java.util.List;
|
20
|
import java.util.Map;
|
21
|
import java.util.Set;
|
22
|
|
23
|
import javax.persistence.Entity;
|
24
|
import javax.persistence.FetchType;
|
25
|
import javax.persistence.ManyToOne;
|
26
|
import javax.persistence.OneToMany;
|
27
|
import javax.persistence.Transient;
|
28
|
import javax.validation.Valid;
|
29
|
import javax.validation.constraints.NotNull;
|
30
|
import javax.xml.bind.annotation.XmlAccessType;
|
31
|
import javax.xml.bind.annotation.XmlAccessorType;
|
32
|
import javax.xml.bind.annotation.XmlAttribute;
|
33
|
import javax.xml.bind.annotation.XmlElement;
|
34
|
import javax.xml.bind.annotation.XmlElementWrapper;
|
35
|
import javax.xml.bind.annotation.XmlIDREF;
|
36
|
import javax.xml.bind.annotation.XmlRootElement;
|
37
|
import javax.xml.bind.annotation.XmlSchemaType;
|
38
|
import javax.xml.bind.annotation.XmlType;
|
39
|
|
40
|
import org.apache.log4j.Logger;
|
41
|
import org.hibernate.annotations.Cascade;
|
42
|
import org.hibernate.annotations.CascadeType;
|
43
|
import org.hibernate.envers.Audited;
|
44
|
import org.hibernate.search.annotations.ClassBridge;
|
45
|
import org.hibernate.search.annotations.ClassBridges;
|
46
|
import org.hibernate.search.annotations.ContainedIn;
|
47
|
import org.hibernate.search.annotations.Indexed;
|
48
|
import org.hibernate.search.annotations.IndexedEmbedded;
|
49
|
import org.springframework.beans.factory.annotation.Configurable;
|
50
|
import org.springframework.util.ReflectionUtils;
|
51
|
|
52
|
import eu.etaxonomy.cdm.hibernate.search.GroupByTaxonClassBridge;
|
53
|
import eu.etaxonomy.cdm.hibernate.search.TaxonRelationshipClassBridge;
|
54
|
import eu.etaxonomy.cdm.model.common.IRelated;
|
55
|
import eu.etaxonomy.cdm.model.common.RelationshipBase;
|
56
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
57
|
import eu.etaxonomy.cdm.model.description.IDescribable;
|
58
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
59
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
60
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
61
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
62
|
import eu.etaxonomy.cdm.strategy.cache.taxon.ITaxonCacheStrategy;
|
63
|
import eu.etaxonomy.cdm.strategy.cache.taxon.TaxonBaseDefaultCacheStrategy;
|
64
|
|
65
|
/**
|
66
|
* The class for "accepted/correct" {@link TaxonBase taxa} (only these taxa according to
|
67
|
* the opinion of the {@link eu.etaxonomy.cdm.model.reference.Reference reference} can build a classification).
|
68
|
* An {@link java.lang.Iterable interface} is supported to iterate through taxonomic children.<BR>
|
69
|
* Splitting taxa in "accepted/correct" and {@link Synonym "synonyms"} makes it easier to handle
|
70
|
* particular relationships between ("accepted/correct") taxa on the one hand
|
71
|
* and between ("synonym") taxa and ("accepted/correct") taxa on the other.
|
72
|
*
|
73
|
* @author m.doering
|
74
|
* @version 1.0
|
75
|
* @created 08-Nov-2007 13:06:56
|
76
|
*/
|
77
|
@XmlAccessorType(XmlAccessType.FIELD)
|
78
|
@XmlType(name = "Taxon", propOrder = {
|
79
|
"taxonomicParentCache",
|
80
|
"taxonNodes",
|
81
|
"taxonomicChildrenCount",
|
82
|
"synonymRelations",
|
83
|
"relationsFromThisTaxon",
|
84
|
"relationsToThisTaxon",
|
85
|
"descriptions"
|
86
|
})
|
87
|
@XmlRootElement(name = "Taxon")
|
88
|
@Entity
|
89
|
@Indexed(index = "eu.etaxonomy.cdm.model.taxon.TaxonBase")
|
90
|
@Audited
|
91
|
@Configurable
|
92
|
@ClassBridges({
|
93
|
@ClassBridge(impl = GroupByTaxonClassBridge.class),
|
94
|
@ClassBridge(impl = TaxonRelationshipClassBridge.class)
|
95
|
})
|
96
|
public class Taxon
|
97
|
extends TaxonBase<ITaxonCacheStrategy<Taxon>>
|
98
|
implements IRelated<RelationshipBase>, IDescribable<TaxonDescription>, Cloneable{
|
99
|
|
100
|
private static final long serialVersionUID = -584946869762749006L;
|
101
|
private static final Logger logger = Logger.getLogger(Taxon.class);
|
102
|
|
103
|
@XmlElementWrapper(name = "Descriptions")
|
104
|
@XmlElement(name = "Description")
|
105
|
@OneToMany(mappedBy="taxon", fetch= FetchType.LAZY)
|
106
|
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE})
|
107
|
@NotNull
|
108
|
@ContainedIn
|
109
|
private Set<TaxonDescription> descriptions = new HashSet<TaxonDescription>();
|
110
|
|
111
|
// all related synonyms
|
112
|
@XmlElementWrapper(name = "SynonymRelations")
|
113
|
@XmlElement(name = "SynonymRelationship")
|
114
|
@OneToMany(mappedBy="relatedTo", fetch=FetchType.LAZY, orphanRemoval=true)
|
115
|
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE})
|
116
|
@NotNull
|
117
|
@Valid
|
118
|
private Set<SynonymRelationship> synonymRelations = new HashSet<SynonymRelationship>();
|
119
|
|
120
|
// all taxa relations with rel.fromTaxon==this
|
121
|
@XmlElementWrapper(name = "RelationsFromThisTaxon")
|
122
|
@XmlElement(name = "FromThisTaxonRelationship")
|
123
|
@OneToMany(mappedBy="relatedFrom", fetch=FetchType.LAZY, orphanRemoval=true)
|
124
|
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE})
|
125
|
@NotNull
|
126
|
// @Valid
|
127
|
private Set<TaxonRelationship> relationsFromThisTaxon = new HashSet<TaxonRelationship>();
|
128
|
|
129
|
// all taxa relations with rel.toTaxon==this
|
130
|
@XmlElementWrapper(name = "RelationsToThisTaxon")
|
131
|
@XmlElement(name = "ToThisTaxonRelationship")
|
132
|
@XmlIDREF
|
133
|
@XmlSchemaType(name = "IDREF")
|
134
|
@OneToMany(mappedBy="relatedTo", fetch=FetchType.LAZY, orphanRemoval=true)
|
135
|
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
|
136
|
@NotNull
|
137
|
// @Valid
|
138
|
private Set<TaxonRelationship> relationsToThisTaxon = new HashSet<TaxonRelationship>();
|
139
|
|
140
|
@XmlAttribute(name= "taxonStatusUnknown")
|
141
|
private boolean taxonStatusUnknown = false;
|
142
|
/**
|
143
|
* The status of this taxon is unknown it could also be some kind of synonym.
|
144
|
* @return the taxonStatusUnknown
|
145
|
*/
|
146
|
public boolean isTaxonStatusUnknown() {return taxonStatusUnknown;}
|
147
|
/** @see #isTaxonStatusUnknown()*/
|
148
|
public void setTaxonStatusUnknown(boolean taxonStatusUnknown) {this.taxonStatusUnknown = taxonStatusUnknown;}
|
149
|
|
150
|
|
151
|
@XmlAttribute(name= "unplaced")
|
152
|
private boolean unplaced = false;
|
153
|
public boolean isUnplaced() {return unplaced;}
|
154
|
public void setUnplaced(boolean unplaced) {this.unplaced = unplaced;}
|
155
|
|
156
|
|
157
|
@XmlAttribute(name= "excluded")
|
158
|
private boolean excluded = false;
|
159
|
public boolean isExcluded() {return excluded;}
|
160
|
public void setExcluded(boolean excluded) {this.excluded = excluded;}
|
161
|
|
162
|
|
163
|
// shortcut to the taxonomicIncluded (parent) taxon. Managed by the taxonRelations setter
|
164
|
@XmlElement(name = "TaxonomicParentCache")
|
165
|
@XmlIDREF
|
166
|
@XmlSchemaType(name = "IDREF")
|
167
|
@ManyToOne(fetch = FetchType.LAZY)
|
168
|
@Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
|
169
|
private Taxon taxonomicParentCache;
|
170
|
|
171
|
|
172
|
@XmlElementWrapper(name = "taxonNodes")
|
173
|
@XmlElement(name = "taxonNode")
|
174
|
@XmlIDREF
|
175
|
@XmlSchemaType(name = "IDREF")
|
176
|
@OneToMany(mappedBy="taxon", fetch=FetchType.LAZY)
|
177
|
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
|
178
|
@IndexedEmbedded
|
179
|
private Set<TaxonNode> taxonNodes = new HashSet<TaxonNode>();
|
180
|
|
181
|
//cached number of taxonomic children
|
182
|
@XmlElement(name = "TaxonomicChildrenCount")
|
183
|
@Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
|
184
|
private int taxonomicChildrenCount;
|
185
|
|
186
|
// ************************* FACTORY METHODS ********************************/
|
187
|
|
188
|
/**
|
189
|
* Creates a new (accepted/correct) taxon instance with
|
190
|
* the {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name} used and the {@link eu.etaxonomy.cdm.model.reference.Reference reference}
|
191
|
* using it.
|
192
|
*
|
193
|
* @param taxonNameBase the taxon name used
|
194
|
* @param sec the reference using the taxon name
|
195
|
* @see #Taxon(TaxonNameBase, Reference)
|
196
|
*/
|
197
|
public static Taxon NewInstance(TaxonNameBase taxonNameBase, Reference sec){
|
198
|
Taxon result = new Taxon(taxonNameBase, sec);
|
199
|
return result;
|
200
|
}
|
201
|
|
202
|
/**
|
203
|
* Creates a new taxon instance with an unknown status (accepted/synonym) and with
|
204
|
* the {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name} used and the {@link eu.etaxonomy.cdm.model.reference.Reference reference}
|
205
|
* using it.
|
206
|
*
|
207
|
* @param taxonNameBase the taxon name used
|
208
|
* @param sec the reference using the taxon name
|
209
|
* @see #Taxon(TaxonNameBase, Reference)
|
210
|
*/
|
211
|
public static Taxon NewUnknownStatusInstance(TaxonNameBase taxonNameBase, Reference sec){
|
212
|
Taxon result = new Taxon(taxonNameBase, sec);
|
213
|
result.setTaxonStatusUnknown(true);
|
214
|
return result;
|
215
|
}
|
216
|
// ************* CONSTRUCTORS *************/
|
217
|
|
218
|
//TODO should be private, but still produces Spring init errors
|
219
|
@Deprecated
|
220
|
public Taxon(){
|
221
|
this.cacheStrategy = new TaxonBaseDefaultCacheStrategy<Taxon>();
|
222
|
}
|
223
|
|
224
|
/**
|
225
|
* Class constructor: creates a new (accepted/correct) taxon instance with
|
226
|
* the {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name} used and the {@link eu.etaxonomy.cdm.model.reference.Reference reference}
|
227
|
* using it.
|
228
|
*
|
229
|
* @param taxonNameBase the taxon name used
|
230
|
* @param sec the reference using the taxon name
|
231
|
* @see TaxonBase#TaxonBase(TaxonNameBase, Reference)
|
232
|
*/
|
233
|
public Taxon(TaxonNameBase taxonNameBase, Reference sec){
|
234
|
super(taxonNameBase, sec);
|
235
|
this.cacheStrategy = new TaxonBaseDefaultCacheStrategy<Taxon>();
|
236
|
}
|
237
|
|
238
|
//********* METHODS **************************************/
|
239
|
|
240
|
|
241
|
|
242
|
/**
|
243
|
* Returns the set of {@link eu.etaxonomy.cdm.model.description.TaxonDescription taxon descriptions}
|
244
|
* concerning <i>this</i> taxon.
|
245
|
*
|
246
|
* @see #removeDescription(TaxonDescription)
|
247
|
* @see #addDescription(TaxonDescription)
|
248
|
* @see eu.etaxonomy.cdm.model.description.TaxonDescription#getTaxon()
|
249
|
*/
|
250
|
@Override
|
251
|
public Set<TaxonDescription> getDescriptions() {
|
252
|
if(descriptions == null) {
|
253
|
descriptions = new HashSet<TaxonDescription>();
|
254
|
}
|
255
|
return descriptions;
|
256
|
}
|
257
|
|
258
|
/**
|
259
|
* Adds a new {@link eu.etaxonomy.cdm.model.description.TaxonDescription taxon description} to the set
|
260
|
* of taxon descriptions assigned to <i>this</i> (accepted/correct) taxon.
|
261
|
* Due to bidirectionality the content of the {@link eu.etaxonomy.cdm.model.description.TaxonDescription#getTaxon() taxon attribute} of the
|
262
|
* taxon description itself will be replaced with <i>this</i> taxon. The taxon
|
263
|
* description will also be removed from the set of taxon descriptions
|
264
|
* assigned to its previous taxon.
|
265
|
*
|
266
|
* @param description the taxon description to be added for <i>this</i> taxon
|
267
|
* @see #getDescriptions()
|
268
|
* @see #removeDescription(TaxonDescription)
|
269
|
* @see eu.etaxonomy.cdm.model.description.TaxonDescription#getTaxon()
|
270
|
*/
|
271
|
@Override
|
272
|
public void addDescription(TaxonDescription description) {
|
273
|
if (description.getTaxon() != null){
|
274
|
description.getTaxon().removeDescription(description);
|
275
|
}
|
276
|
Field field = ReflectionUtils.findField(TaxonDescription.class, "taxon", Taxon.class);
|
277
|
ReflectionUtils.makeAccessible(field);
|
278
|
ReflectionUtils.setField(field, description, this);
|
279
|
descriptions.add(description);
|
280
|
|
281
|
}
|
282
|
/**
|
283
|
* Removes one element from the set of {@link eu.etaxonomy.cdm.model.description.TaxonDescription taxon descriptions} assigned
|
284
|
* to <i>this</i> (accepted/correct) taxon. Due to bidirectionality the content of
|
285
|
* the {@link eu.etaxonomy.cdm.model.description.TaxonDescription#getTaxon() taxon attribute} of the taxon description
|
286
|
* itself will be set to "null".
|
287
|
*
|
288
|
* @param description the taxon description which should be removed
|
289
|
* @see #getDescriptions()
|
290
|
* @see #addDescription(TaxonDescription)
|
291
|
* @see eu.etaxonomy.cdm.model.description.TaxonDescription#getTaxon()
|
292
|
*/
|
293
|
@Override
|
294
|
public void removeDescription(TaxonDescription description) {
|
295
|
//description.setTaxon(null) for not visible method
|
296
|
Field field = ReflectionUtils.findField(TaxonDescription.class, "taxon", Taxon.class);
|
297
|
ReflectionUtils.makeAccessible(field);
|
298
|
ReflectionUtils.setField(field, description, null);
|
299
|
descriptions.remove(description);
|
300
|
}
|
301
|
|
302
|
|
303
|
public void removeDescription(TaxonDescription description, boolean removeElements){
|
304
|
if (removeElements){
|
305
|
Set<DescriptionElementBase> elements = new HashSet<DescriptionElementBase>(description.getElements());
|
306
|
for (DescriptionElementBase el:elements){
|
307
|
description.getElements().remove(el);
|
308
|
}
|
309
|
removeDescription(description);
|
310
|
} else{
|
311
|
removeDescription(description);
|
312
|
}
|
313
|
}
|
314
|
|
315
|
/**
|
316
|
* Returns the image gallery for a taxon. If there are multiple taxon descriptions
|
317
|
* marked as image galleries an arbitrary one is chosen.
|
318
|
* If no image gallery exists, a new one is created if <code>createNewIfNotExists</code>
|
319
|
* is <code>true</code>.
|
320
|
* @param createNewIfNotExists
|
321
|
* @return
|
322
|
*/
|
323
|
public TaxonDescription getImageGallery(boolean createNewIfNotExists) {
|
324
|
TaxonDescription result = null;
|
325
|
Set<TaxonDescription> descriptions= getDescriptions();
|
326
|
for (TaxonDescription description : descriptions){
|
327
|
if (description.isImageGallery()){
|
328
|
result = description;
|
329
|
break;
|
330
|
}
|
331
|
}
|
332
|
if (result == null && createNewIfNotExists){
|
333
|
result = TaxonDescription.NewInstance(this);
|
334
|
result.setImageGallery(true);
|
335
|
}
|
336
|
return result;
|
337
|
}
|
338
|
|
339
|
|
340
|
|
341
|
public Set<TaxonNode> getTaxonNodes() {
|
342
|
return taxonNodes;
|
343
|
}
|
344
|
// protected void setTaxonNodes(Set<TaxonNode> taxonNodes) {
|
345
|
// this.taxonNodes = taxonNodes;
|
346
|
// }
|
347
|
protected void addTaxonNode(TaxonNode taxonNode){
|
348
|
taxonNodes.add(taxonNode);
|
349
|
}
|
350
|
|
351
|
public boolean removeTaxonNode(TaxonNode taxonNode){
|
352
|
if (!taxonNodes.contains(taxonNode)){
|
353
|
return false;
|
354
|
}
|
355
|
TaxonNode parent = taxonNode.getParent();
|
356
|
if (parent != null){
|
357
|
parent.removeChildNode(taxonNode);
|
358
|
}
|
359
|
taxonNode.setTaxon(null);
|
360
|
return taxonNodes.remove(taxonNode);
|
361
|
|
362
|
}
|
363
|
|
364
|
public boolean removeTaxonNode(TaxonNode taxonNode, boolean deleteChildren){
|
365
|
TaxonNode parent = taxonNode.getParent();
|
366
|
boolean success = true;
|
367
|
|
368
|
if ((!taxonNode.getChildNodes().isEmpty() && deleteChildren) || (taxonNode.getChildNodes().isEmpty()) ){
|
369
|
|
370
|
taxonNode.delete();
|
371
|
|
372
|
} else if (!taxonNode.isTopmostNode()){
|
373
|
|
374
|
List<TaxonNode> nodes = new ArrayList<TaxonNode> (taxonNode.getChildNodes());
|
375
|
for (TaxonNode childNode: nodes){
|
376
|
taxonNode.getChildNodes().remove(childNode);
|
377
|
parent.addChildNode(childNode, null, null);
|
378
|
}
|
379
|
|
380
|
taxonNode.delete();
|
381
|
|
382
|
} else if (taxonNode.isTopmostNode()){
|
383
|
success = false;
|
384
|
}
|
385
|
return success;
|
386
|
}
|
387
|
|
388
|
public boolean removeTaxonNodes(boolean deleteChildren){
|
389
|
Iterator<TaxonNode> nodesIterator = taxonNodes.iterator();
|
390
|
TaxonNode node;
|
391
|
TaxonNode parent;
|
392
|
boolean success = false;
|
393
|
List<TaxonNode> removeNodes = new ArrayList<TaxonNode>();
|
394
|
while (nodesIterator.hasNext()){
|
395
|
node = nodesIterator.next();
|
396
|
if (!deleteChildren){
|
397
|
List<TaxonNode> children = node.getChildNodes();
|
398
|
Iterator<TaxonNode> childrenIterator = children.iterator();
|
399
|
parent = node.getParent();
|
400
|
while (childrenIterator.hasNext()){
|
401
|
TaxonNode childNode = childrenIterator.next();
|
402
|
if (parent != null){
|
403
|
parent.addChildNode(childNode, null, null);
|
404
|
}else{
|
405
|
childNode.setParent(null);
|
406
|
}
|
407
|
}
|
408
|
|
409
|
for (int i = 0; i<node.getChildNodes().size(); i++){
|
410
|
node.removeChild(i);
|
411
|
}
|
412
|
|
413
|
|
414
|
}
|
415
|
|
416
|
removeNodes.add(node);
|
417
|
}
|
418
|
for (int i = 0; i<removeNodes.size(); i++){
|
419
|
TaxonNode removeNode = removeNodes.get(i);
|
420
|
success = removeNode.delete(deleteChildren);
|
421
|
removeNode.setTaxon(null);
|
422
|
removeTaxonNode(removeNode);
|
423
|
}
|
424
|
return success;
|
425
|
|
426
|
}
|
427
|
|
428
|
|
429
|
|
430
|
|
431
|
/**
|
432
|
* Returns the set of all {@link SynonymRelationship synonym relationships}
|
433
|
* in which <i>this</i> ("accepted/correct") taxon is involved. <i>This</i> taxon can only
|
434
|
* be the target of these synonym relationships.
|
435
|
*
|
436
|
* @see #addSynonymRelation(SynonymRelationship)
|
437
|
* @see #removeSynonymRelation(SynonymRelationship)
|
438
|
* @see #getSynonyms()
|
439
|
*/
|
440
|
public Set<SynonymRelationship> getSynonymRelations() {
|
441
|
if(synonymRelations == null) {
|
442
|
this.synonymRelations = new HashSet<SynonymRelationship>();
|
443
|
}
|
444
|
return synonymRelations;
|
445
|
}
|
446
|
|
447
|
/**
|
448
|
* Adds an existing {@link SynonymRelationship synonym relationship} to the set of
|
449
|
* {@link #getSynonymRelations() synonym relationships} assigned to <i>this</i> taxon. If
|
450
|
* the target of the synonym relationship does not match with <i>this</i> taxon
|
451
|
* no addition will be carried out.
|
452
|
*
|
453
|
* @param synonymRelation the synonym relationship to be added to <i>this</i> taxon's
|
454
|
* synonym relationships set
|
455
|
* @see #getSynonymRelations()
|
456
|
* @see #addSynonym(Synonym, SynonymRelationshipType)
|
457
|
* @see #addSynonym(Synonym, SynonymRelationshipType, Reference, String)
|
458
|
* @see #addSynonymName(TaxonNameBase, SynonymRelationshipType)
|
459
|
* @see #addSynonymName(TaxonNameBase, SynonymRelationshipType, Reference, String)
|
460
|
*/
|
461
|
protected void addSynonymRelation(SynonymRelationship synonymRelation) {
|
462
|
this.synonymRelations.add(synonymRelation);
|
463
|
}
|
464
|
/**
|
465
|
* Removes one element from the set of {@link SynonymRelationship synonym relationships} assigned
|
466
|
* to <i>this</i> (accepted/correct) taxon. Due to bidirectionality the given
|
467
|
* synonym relationship will also be removed from the set of synonym
|
468
|
* relationships assigned to the {@link Synonym#getSynonymRelations() synonym} involved in the
|
469
|
* relationship. Furthermore the content of
|
470
|
* the {@link SynonymRelationship#getAcceptedTaxon() accepted taxon} attribute and of the
|
471
|
* {@link SynonymRelationship#getSynonym() synonym} attribute within the synonym relationship
|
472
|
* itself will be set to "null".
|
473
|
*
|
474
|
* @param synonymRelation the synonym relationship which should be deleted
|
475
|
* @param removeSynonymNameFromHomotypicalGroup
|
476
|
* if <code>true</code> the synonym name will also be deleted from its homotypical group if the
|
477
|
* group contains other names
|
478
|
* @see #getSynonymRelations()
|
479
|
* @see #addSynonymRelation(SynonymRelationship)
|
480
|
* @see #removeSynonym(Synonym)
|
481
|
*/
|
482
|
public void removeSynonymRelation(SynonymRelationship synonymRelation, boolean removeSynonymNameFromHomotypicalGroup) {
|
483
|
synonymRelation.setAcceptedTaxon(null);
|
484
|
Synonym synonym = synonymRelation.getSynonym();
|
485
|
if (synonym != null){
|
486
|
synonymRelation.setSynonym(null);
|
487
|
synonym.removeSynonymRelation(synonymRelation);
|
488
|
if(removeSynonymNameFromHomotypicalGroup){
|
489
|
HomotypicalGroup synHG = synonym.getName().getHomotypicalGroup();
|
490
|
if (synHG.getTypifiedNames().size() > 1){
|
491
|
synHG.removeTypifiedName(synonym.getName(), false);
|
492
|
}
|
493
|
}
|
494
|
}
|
495
|
this.synonymRelations.remove(synonymRelation);
|
496
|
}
|
497
|
|
498
|
/**
|
499
|
* Like {@link Taxon#removeSynonymRelation(SynonymRelationship, boolean)} but synonym name
|
500
|
* will be deleted from homotypical group by default
|
501
|
*
|
502
|
* @param synonymRelation the synonym relationship which should be deleted
|
503
|
*
|
504
|
* @see #removeSynonymRelation(SynonymRelationship, boolean)
|
505
|
*/
|
506
|
public void removeSynonymRelation(SynonymRelationship synonymRelation){
|
507
|
removeSynonymRelation(synonymRelation, true);
|
508
|
}
|
509
|
|
510
|
|
511
|
/**
|
512
|
* Returns the set of all {@link TaxonRelationship taxon relationships}
|
513
|
* between two taxa in which <i>this</i> taxon is involved as a source.
|
514
|
*
|
515
|
* @see #getRelationsToThisTaxon()
|
516
|
* @see #getTaxonRelations()
|
517
|
*/
|
518
|
public Set<TaxonRelationship> getRelationsFromThisTaxon() {
|
519
|
if(relationsFromThisTaxon == null) {
|
520
|
this.relationsFromThisTaxon = new HashSet<TaxonRelationship>();
|
521
|
}
|
522
|
return relationsFromThisTaxon;
|
523
|
}
|
524
|
|
525
|
|
526
|
/**
|
527
|
* Returns the set of all {@link TaxonRelationship taxon relationships}
|
528
|
* between two taxa in which <i>this</i> taxon is involved as a target.
|
529
|
*
|
530
|
* @see #getRelationsFromThisTaxon()
|
531
|
* @see #getTaxonRelations()
|
532
|
*/
|
533
|
public Set<TaxonRelationship> getRelationsToThisTaxon() {
|
534
|
if(relationsToThisTaxon == null) {
|
535
|
this.relationsToThisTaxon = new HashSet<TaxonRelationship>();
|
536
|
}
|
537
|
return relationsToThisTaxon;
|
538
|
}
|
539
|
/**
|
540
|
* Returns the set of all {@link TaxonRelationship taxon relationships}
|
541
|
* between two taxa in which <i>this</i> taxon is involved either as a source or
|
542
|
* as a target.
|
543
|
*
|
544
|
* @see #getRelationsFromThisTaxon()
|
545
|
* @see #getRelationsToThisTaxon()
|
546
|
*/
|
547
|
@Transient
|
548
|
public Set<TaxonRelationship> getTaxonRelations() {
|
549
|
Set<TaxonRelationship> rels = new HashSet<TaxonRelationship>();
|
550
|
rels.addAll(getRelationsToThisTaxon());
|
551
|
rels.addAll(getRelationsFromThisTaxon());
|
552
|
return rels;
|
553
|
}
|
554
|
|
555
|
/**
|
556
|
* @see #getRelationsToThisTaxon()
|
557
|
*/
|
558
|
protected void setRelationsToThisTaxon(Set<TaxonRelationship> relationsToThisTaxon) {
|
559
|
this.relationsToThisTaxon = relationsToThisTaxon;
|
560
|
}
|
561
|
|
562
|
/**
|
563
|
* @see #getRelationsFromThisTaxon()
|
564
|
*/
|
565
|
protected void setRelationsFromThisTaxon(Set<TaxonRelationship> relationsFromThisTaxon) {
|
566
|
this.relationsFromThisTaxon = relationsFromThisTaxon;
|
567
|
}
|
568
|
|
569
|
/**
|
570
|
* If a relationships between <i>this</i> and the given taxon exists they will be returned.
|
571
|
* <i>This</i> taxon is involved either as a source or as a target in the relationships.
|
572
|
* The method will return <code>null</code> if no relations exist between the two taxa.
|
573
|
*
|
574
|
* @param possiblyRelatedTaxon
|
575
|
* a taxon to check for a relationship
|
576
|
* @return
|
577
|
* a set of <code>TaxonRelationship</code>s or <code>null</null> if none exists.
|
578
|
*/
|
579
|
public Set<TaxonRelationship> getTaxonRelations(Taxon possiblyRelatedTaxon){
|
580
|
Set<TaxonRelationship> relations = new HashSet<TaxonRelationship>();
|
581
|
|
582
|
for(TaxonRelationship relationship : getTaxonRelations()){
|
583
|
if(relationship.getFromTaxon().equals(possiblyRelatedTaxon)) {
|
584
|
relations.add(relationship);
|
585
|
}
|
586
|
if(relationship.getToTaxon().equals(possiblyRelatedTaxon)) {
|
587
|
relations.add(relationship);
|
588
|
}
|
589
|
}
|
590
|
|
591
|
return relations.size() > 0 ? relations : null;
|
592
|
}
|
593
|
|
594
|
/**
|
595
|
* Removes one {@link TaxonRelationship taxon relationship} from one of both sets of
|
596
|
* {@link #getTaxonRelations() taxon relationships} in which <i>this</i> taxon is involved
|
597
|
* either as a {@link #getRelationsFromThisTaxon() source} or as a {@link #getRelationsToThisTaxon() target}.
|
598
|
* The taxon relationship will also be removed from one of both sets
|
599
|
* belonging to the second taxon involved. Furthermore the inherited RelatedFrom and
|
600
|
* RelatedTo attributes of the given taxon relationship will be nullified.<P>
|
601
|
* If the taxon relationship concerns the classification possible
|
602
|
* modifications of the {@link #getTaxonomicParent() parent taxon} or of the number of
|
603
|
* {@link #getTaxonomicChildrenCount() childrens} will be stored.
|
604
|
*
|
605
|
* @param rel the taxon relationship which should be removed from one
|
606
|
* of both sets
|
607
|
* @see #getTaxonRelations()
|
608
|
* @see #getTaxonomicParent()
|
609
|
* @see #getTaxonomicChildrenCount()
|
610
|
* @see eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedFrom()
|
611
|
* @see eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedTo()
|
612
|
*
|
613
|
*/
|
614
|
public void removeTaxonRelation(TaxonRelationship rel) {
|
615
|
this.relationsToThisTaxon.remove(rel);
|
616
|
this.relationsFromThisTaxon.remove(rel);
|
617
|
Taxon fromTaxon = rel.getFromTaxon();
|
618
|
Taxon toTaxon = rel.getToTaxon();
|
619
|
// check if this removes the taxonomical parent. If so, also remove shortcut to the higher taxon
|
620
|
if (rel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN()) ){
|
621
|
if (fromTaxon != null && fromTaxon.equals(this)){
|
622
|
this.taxonomicParentCache = null;
|
623
|
}else if (toTaxon != null && toTaxon.equals(this)){
|
624
|
this.setTaxonomicChildrenCount(computeTaxonomicChildrenCount());
|
625
|
}
|
626
|
}
|
627
|
//delete Relationship from other related Taxon
|
628
|
if (fromTaxon != this){
|
629
|
rel.setToTaxon(null); //remove this Taxon from relationship
|
630
|
if (fromTaxon != null){
|
631
|
if (fromTaxon.getTaxonRelations().contains(rel)){
|
632
|
fromTaxon.removeTaxonRelation(rel);
|
633
|
}
|
634
|
}
|
635
|
}
|
636
|
if (toTaxon != this ){
|
637
|
rel.setFromTaxon(null); //remove this Taxon from relationship
|
638
|
if (toTaxon != null){
|
639
|
if (toTaxon.getTaxonRelations().contains(rel)) {
|
640
|
toTaxon.removeTaxonRelation(rel);
|
641
|
}
|
642
|
}
|
643
|
}
|
644
|
}
|
645
|
|
646
|
/**
|
647
|
* Adds an existing {@link TaxonRelationship taxon relationship} either to the set of
|
648
|
* {@link #getRelationsToThisTaxon() taxon relationships to <i>this</i> taxon} or to the set of
|
649
|
* {@link #getRelationsFromThisTaxon() taxon relationships from <i>this</i> taxon}. If neither the
|
650
|
* source nor the target of the taxon relationship match with <i>this</i> taxon
|
651
|
* no addition will be carried out. The taxon relationship will also be
|
652
|
* added to the second taxon involved in the given relationship.<P>
|
653
|
* If the taxon relationship concerns the classification possible
|
654
|
* modifications of the {@link #getTaxonomicParent() parent taxon} or of the number of
|
655
|
* {@link #getTaxonomicChildrenCount() childrens} will be stored.
|
656
|
*
|
657
|
* @param rel the taxon relationship to be added to one of <i>this</i> taxon's taxon relationships sets
|
658
|
* @see #addTaxonRelation(Taxon, TaxonRelationshipType, Reference, String)
|
659
|
* @see #getTaxonRelations()
|
660
|
* @see #getRelationsFromThisTaxon()
|
661
|
* @see #getRelationsToThisTaxon()
|
662
|
* @see #getTaxonomicParent()
|
663
|
* @see #getTaxonomicChildrenCount()
|
664
|
*/
|
665
|
public void addTaxonRelation(TaxonRelationship rel) {
|
666
|
if (rel!=null && rel.getType()!=null && !getTaxonRelations().contains(rel) ){
|
667
|
Taxon toTaxon=rel.getToTaxon();
|
668
|
Taxon fromTaxon=rel.getFromTaxon();
|
669
|
if ( this.equals(toTaxon) || this.equals(fromTaxon) ){
|
670
|
if (this.equals(fromTaxon)){
|
671
|
relationsFromThisTaxon.add(rel);
|
672
|
// also add relation to other taxon object
|
673
|
if (toTaxon!=null){
|
674
|
toTaxon.addTaxonRelation(rel);
|
675
|
}
|
676
|
// check if this sets the taxonomical parent. If so, remember a shortcut to this taxon
|
677
|
if (rel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN()) && toTaxon!=null ){
|
678
|
this.taxonomicParentCache = toTaxon;
|
679
|
}
|
680
|
}else if (this.equals(toTaxon)){
|
681
|
relationsToThisTaxon.add(rel);
|
682
|
// also add relation to other taxon object
|
683
|
if (fromTaxon!=null){
|
684
|
fromTaxon.addTaxonRelation(rel);
|
685
|
}
|
686
|
if (rel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN()) && fromTaxon!=null ){
|
687
|
this.taxonomicChildrenCount++;
|
688
|
}
|
689
|
|
690
|
}
|
691
|
}else if (toTaxon == null || fromTaxon == null){
|
692
|
if (toTaxon == null){
|
693
|
toTaxon = this;
|
694
|
relationsToThisTaxon.add(rel);
|
695
|
if (fromTaxon!= null){
|
696
|
fromTaxon.addTaxonRelation(rel);
|
697
|
}
|
698
|
if (rel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN()) && fromTaxon!=null ){
|
699
|
this.taxonomicChildrenCount++;
|
700
|
}
|
701
|
}else if (fromTaxon == null && toTaxon != null){
|
702
|
fromTaxon = this;
|
703
|
relationsFromThisTaxon.add(rel);
|
704
|
if (toTaxon!=null){
|
705
|
toTaxon.addTaxonRelation(rel);
|
706
|
}
|
707
|
if (rel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN()) && toTaxon!=null ){
|
708
|
this.taxonomicParentCache = toTaxon;
|
709
|
}
|
710
|
}
|
711
|
}
|
712
|
}
|
713
|
}
|
714
|
|
715
|
/* (non-Javadoc)
|
716
|
* @see eu.etaxonomy.cdm.model.common.IRelated#addRelationship(eu.etaxonomy.cdm.model.common.RelationshipBase)
|
717
|
*/
|
718
|
@Override
|
719
|
@Deprecated //for inner use by RelationshipBase only
|
720
|
public void addRelationship(RelationshipBase rel){
|
721
|
if (rel instanceof TaxonRelationship){
|
722
|
addTaxonRelation((TaxonRelationship)rel);
|
723
|
}else if (rel instanceof SynonymRelationship){
|
724
|
addSynonymRelation((SynonymRelationship)rel);
|
725
|
}else{
|
726
|
throw new ClassCastException("Wrong Relationsship type for Taxon.addRelationship");
|
727
|
}
|
728
|
}
|
729
|
|
730
|
/**
|
731
|
* Creates a new {@link TaxonRelationship taxon relationship} instance where <i>this</i> taxon
|
732
|
* plays the source role and adds it to the set of
|
733
|
* {@link #getRelationsFromThisTaxon() "taxon relationships from"} belonging to <i>this</i> taxon.
|
734
|
* The taxon relationship will also be added to the set of taxon
|
735
|
* relationships to the second taxon involved in the created relationship.<P>
|
736
|
* If the taxon relationship concerns the classification possible
|
737
|
* modifications of the {@link #getTaxonomicParent() parent taxon} or of the number of
|
738
|
* {@link #getTaxonomicChildrenCount() childrens} will be stored.
|
739
|
*
|
740
|
* @param toTaxon the taxon which plays the target role in the new taxon relationship
|
741
|
* @param type the taxon relationship type for the new taxon relationship
|
742
|
* @param citation the reference source for the new taxon relationship
|
743
|
* @param microcitation the string with the details describing the exact localisation within the reference
|
744
|
* @return
|
745
|
* @see #addTaxonRelation(TaxonRelationship)
|
746
|
* @see #getTaxonRelations()
|
747
|
* @see #getRelationsFromThisTaxon()
|
748
|
* @see #getRelationsToThisTaxon()
|
749
|
* @see #getTaxonomicParent()
|
750
|
* @see #getTaxonomicChildrenCount()
|
751
|
*/
|
752
|
public TaxonRelationship addTaxonRelation(Taxon toTaxon, TaxonRelationshipType type, Reference citation, String microcitation) {
|
753
|
return new TaxonRelationship(this, toTaxon, type, citation, microcitation);
|
754
|
}
|
755
|
/**
|
756
|
* Creates a new {@link TaxonRelationship taxon relationship} (with {@link TaxonRelationshipType taxon relationship type}
|
757
|
* "misapplied name for") instance where <i>this</i> taxon plays the target role
|
758
|
* and adds it to the set of {@link #getRelationsToThisTaxon() taxon relationships to <i>this</i> taxon}.
|
759
|
* The taxon relationship will also be added to the set of taxon
|
760
|
* relationships to the other (misapplied name) taxon involved in the created relationship.
|
761
|
*
|
762
|
* @param misappliedNameTaxon the taxon which plays the target role in the new taxon relationship
|
763
|
* @param citation the reference source for the new taxon relationship
|
764
|
* @param microcitation the string with the details describing the exact localisation within the reference
|
765
|
* @return
|
766
|
* @see #getMisappliedNames()
|
767
|
* @see #addTaxonRelation(Taxon, TaxonRelationshipType, Reference, String)
|
768
|
* @see #addTaxonRelation(TaxonRelationship)
|
769
|
* @see #getTaxonRelations()
|
770
|
* @see #getRelationsFromThisTaxon()
|
771
|
* @see #getRelationsToThisTaxon()
|
772
|
*/
|
773
|
public TaxonRelationship addMisappliedName(Taxon misappliedNameTaxon, Reference citation, String microcitation) {
|
774
|
return misappliedNameTaxon.addTaxonRelation(this, TaxonRelationshipType.MISAPPLIED_NAME_FOR(), citation, microcitation);
|
775
|
}
|
776
|
|
777
|
// public void removeMisappliedName(Taxon misappliedNameTaxon){
|
778
|
// Set<TaxonRelationship> taxRels = this.getTaxonRelations();
|
779
|
// for (TaxonRelationship taxRel : taxRels ){
|
780
|
// if (taxRel.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())
|
781
|
// && taxRel.getFromTaxon().equals(misappliedNameTaxon)){
|
782
|
// this.removeTaxonRelation(taxRel);
|
783
|
// }
|
784
|
// }
|
785
|
// }
|
786
|
|
787
|
/**
|
788
|
* TODO update documentation
|
789
|
* Removes one {@link TaxonRelationship taxon relationship} with {@link TaxonRelationshipType taxon relationship type}
|
790
|
* taxonRelType and with the given child taxon playing the
|
791
|
* source role from the set of {@link #getRelationsToThisTaxon() "taxon relationships to"} belonging
|
792
|
* to <i>this</i> taxon. The taxon relationship will also be removed from the set
|
793
|
* of {@link #getRelationsFromThisTaxon() "taxon relationships from"} belonging to the other side taxon.
|
794
|
* Furthermore, the inherited RelatedFrom and RelatedTo attributes of the
|
795
|
* taxon relationship will be nullified.<P>
|
796
|
*
|
797
|
* @param taxon the taxon which plays the source role in the taxon relationship
|
798
|
* @param taxonRelType the taxon relationship type
|
799
|
*/
|
800
|
public void removeTaxon(Taxon taxon, TaxonRelationshipType taxonRelType){
|
801
|
Set<TaxonRelationship> taxRels = this.getTaxonRelations();
|
802
|
for (TaxonRelationship taxRel : taxRels ){
|
803
|
if (taxRel.getType().equals(taxonRelType)
|
804
|
&& taxRel.getFromTaxon().equals(taxon)){
|
805
|
this.removeTaxonRelation(taxRel);
|
806
|
}
|
807
|
}
|
808
|
}
|
809
|
|
810
|
/**
|
811
|
* Creates a new {@link TaxonRelationship taxon relationship} (with {@link TaxonRelationshipType taxon relationship type}
|
812
|
* "taxonomically included in") instance where <i>this</i> taxon plays the target
|
813
|
* role (parent) and adds it to the set of
|
814
|
* {@link #getRelationsToThisTaxon() "taxon relationships to"} belonging to <i>this</i> taxon.
|
815
|
* The taxon relationship will also be added to the set of
|
816
|
* {@link #getRelationsFromThisTaxon() "taxon relationships from"} belonging to the second taxon
|
817
|
* (child) involved in the created relationship.<P>
|
818
|
* Since the taxon relationship concerns the modifications
|
819
|
* of the number of {@link #getTaxonomicChildrenCount() childrens} for <i>this</i> taxon and
|
820
|
* of the {@link #getTaxonomicParent() parent taxon} for the child taxon will be stored.
|
821
|
* The {@link name.Rank rank} of the taxon name used as a parent taxon must be higher
|
822
|
* than the rank of the taxon name used as a child taxon.
|
823
|
*
|
824
|
* @param child the taxon which plays the source role (child) in the new taxon relationship
|
825
|
* @param citation the reference source for the new taxon relationship
|
826
|
* @param microcitation the string with the details describing the exact localisation within the reference
|
827
|
* @see #setTaxonomicParent(Taxon, Reference, String)
|
828
|
* @see #addTaxonRelation(Taxon, TaxonRelationshipType, Reference, String)
|
829
|
* @see #addTaxonRelation(TaxonRelationship)
|
830
|
* @see #getTaxonRelations()
|
831
|
* @see #getRelationsFromThisTaxon()
|
832
|
* @see #getRelationsToThisTaxon()
|
833
|
* @see #getTaxonomicParent()
|
834
|
* @see #getTaxonomicChildrenCount()
|
835
|
*/
|
836
|
@Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
|
837
|
public void addTaxonomicChild(Taxon child, Reference citation, String microcitation){
|
838
|
if (child == null){
|
839
|
throw new NullPointerException("Child Taxon is 'null'");
|
840
|
}else{
|
841
|
child.setTaxonomicParent(this, citation, microcitation);
|
842
|
}
|
843
|
}
|
844
|
|
845
|
/**
|
846
|
* Removes one {@link TaxonRelationship taxon relationship} with {@link TaxonRelationshipType taxon relationship type}
|
847
|
* "taxonomically included in" and with the given child taxon playing the
|
848
|
* source role from the set of {@link #getRelationsToThisTaxon() "taxon relationships to"} belonging
|
849
|
* to <i>this</i> taxon. The taxon relationship will also be removed from the set
|
850
|
* of {@link #getRelationsFromThisTaxon() "taxon relationships from"} belonging to the child taxon.
|
851
|
* Furthermore the inherited RelatedFrom and RelatedTo attributes of the
|
852
|
* taxon relationship will be nullified.<P>
|
853
|
* Since the taxon relationship concerns the classification modifications
|
854
|
* of the number of {@link #getTaxonomicChildrenCount() childrens} for <i>this</i> taxon and
|
855
|
* of the {@link #getTaxonomicParent() parent taxon} for the child taxon will be stored.
|
856
|
*
|
857
|
* @param child the taxon playing the source role in the relationship to be removed
|
858
|
* @see #removeTaxonRelation(TaxonRelationship)
|
859
|
* @see #getRelationsToThisTaxon()
|
860
|
* @see #getRelationsFromThisTaxon()
|
861
|
* @see #getTaxonomicParent()
|
862
|
* @see #getTaxonomicChildrenCount()
|
863
|
* @see eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedFrom()
|
864
|
* @see eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedTo()
|
865
|
*
|
866
|
*/
|
867
|
@Deprecated //will be removed in future versions. Use classification/TaxonNode instead
|
868
|
public void removeTaxonomicChild(Taxon child){
|
869
|
Set<TaxonRelationship> taxRels = this.getTaxonRelations();
|
870
|
for (TaxonRelationship taxRel : taxRels ){
|
871
|
if (taxRel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN())
|
872
|
&& taxRel.getFromTaxon().equals(child)){
|
873
|
this.removeTaxonRelation(taxRel);
|
874
|
}
|
875
|
}
|
876
|
}
|
877
|
|
878
|
/**
|
879
|
* Returns the taxon which is the next higher taxon (parent) of <i>this</i> taxon
|
880
|
* within the classification and which is stored in the
|
881
|
* TaxonomicParentCache attribute. Each taxon can have only one parent taxon.
|
882
|
* The child taxon and the parent taxon play the source respectively the
|
883
|
* target role in one {@link TaxonRelationship taxon relationship} with
|
884
|
* {@link TaxonRelationshipType taxon relationship type} "taxonomically included in".
|
885
|
* The {@link name.Rank rank} of the taxon name used as a parent taxon must be higher
|
886
|
* than the rank of the taxon name used as a child taxon.
|
887
|
*
|
888
|
* @see #setTaxonomicParent(Taxon, Reference, String)
|
889
|
* @see #getTaxonomicChildren()
|
890
|
* @see #getTaxonomicChildrenCount()
|
891
|
* @see #getRelationsFromThisTaxon()
|
892
|
*/
|
893
|
@Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
|
894
|
public Taxon getTaxonomicParent() {
|
895
|
return this.taxonomicParentCache;
|
896
|
}
|
897
|
|
898
|
/**
|
899
|
* Sets the taxononomic parent of <i>this</i> taxon to null.
|
900
|
* Note that this method does not handle taxonomic relationships.
|
901
|
*/
|
902
|
@Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
|
903
|
public void nullifyTaxonomicParent() {
|
904
|
this.taxonomicParentCache = null;
|
905
|
}
|
906
|
|
907
|
/**
|
908
|
* Replaces both the taxonomic parent cache with the given new parent taxon
|
909
|
* and the corresponding taxon relationship with a new {@link TaxonRelationship taxon relationship}
|
910
|
* (with {@link TaxonRelationshipType taxon relationship type} "taxonomically included in") instance.
|
911
|
* In the new taxon relationship <i>this</i> taxon plays the source role (child).
|
912
|
* This method creates and adds the new taxon relationship to the set of
|
913
|
* {@link #getRelationsFromThisTaxon() "taxon relationships from"} belonging to <i>this</i> taxon.
|
914
|
* The taxon relationship will also be added to the set of
|
915
|
* {@link #getRelationsToThisTaxon() "taxon relationships to"} belonging to the second taxon
|
916
|
* (parent) involved in the new relationship.<P>
|
917
|
* Since the taxon relationship concerns the classification modifications
|
918
|
* of the {@link #getTaxonomicParent() parent taxon} for <i>this</i> taxon and of the number of
|
919
|
* {@link #getTaxonomicChildrenCount() childrens} for the child taxon will be stored.
|
920
|
*
|
921
|
* @param newParent the taxon which plays the target role (parent) in the new taxon relationship
|
922
|
* @param citation the reference source for the new taxon relationship
|
923
|
* @param microcitation the string with the details describing the exact localisation within the reference
|
924
|
* @see #removeTaxonRelation(TaxonRelationship)
|
925
|
* @see #getTaxonomicParent()
|
926
|
* @see #addTaxonRelation(Taxon, TaxonRelationshipType, Reference, String)
|
927
|
* @see #addTaxonRelation(TaxonRelationship)
|
928
|
* @see #getTaxonRelations()
|
929
|
* @see #getRelationsFromThisTaxon()
|
930
|
* @see #getRelationsToThisTaxon()
|
931
|
* @see #getTaxonomicChildrenCount()
|
932
|
*/
|
933
|
@Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
|
934
|
public void setTaxonomicParent(Taxon newParent, Reference citation, String microcitation){
|
935
|
//remove previously existing parent relationship!!!
|
936
|
Taxon oldParent = this.getTaxonomicParent();
|
937
|
Set<TaxonRelationship> taxRels = this.getTaxonRelations();
|
938
|
for (TaxonRelationship taxRel : taxRels ){
|
939
|
if (taxRel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN()) && taxRel.getToTaxon().equals(oldParent)){
|
940
|
this.removeTaxonRelation(taxRel);
|
941
|
}
|
942
|
}
|
943
|
//add new parent
|
944
|
if (newParent != null){
|
945
|
addTaxonRelation(newParent, TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(),citation,microcitation);
|
946
|
}
|
947
|
}
|
948
|
|
949
|
/**
|
950
|
* Returns the set of taxa which have <i>this</i> taxon as next higher taxon
|
951
|
* (parent) within the classification. Each taxon can have several child
|
952
|
* taxa. The child taxon and the parent taxon play the source respectively
|
953
|
* the target role in one {@link TaxonRelationship taxon relationship} with
|
954
|
* {@link TaxonRelationshipType taxon relationship type} "taxonomically included in".
|
955
|
* The {@link name.Rank rank} of the taxon name used as a parent taxon must be higher
|
956
|
* than the rank of the taxon name used as a child taxon.
|
957
|
*
|
958
|
* @see #getTaxonomicParent()
|
959
|
* @see #addTaxonomicChild(Taxon, Reference, String)
|
960
|
* @see #getTaxonomicChildrenCount()
|
961
|
* @see #getRelationsToThisTaxon()
|
962
|
*/
|
963
|
@Transient
|
964
|
@Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
|
965
|
public Set<Taxon> getTaxonomicChildren() {
|
966
|
Set<Taxon> taxa = new HashSet<Taxon>();
|
967
|
Set<TaxonRelationship> rels = this.getRelationsToThisTaxon();
|
968
|
for (TaxonRelationship rel: rels){
|
969
|
TaxonRelationshipType tt = rel.getType();
|
970
|
TaxonRelationshipType incl = TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN();
|
971
|
if (tt.equals(incl)){
|
972
|
taxa.add(rel.getFromTaxon());
|
973
|
}
|
974
|
}
|
975
|
return taxa;
|
976
|
}
|
977
|
|
978
|
/**
|
979
|
* Returns the number of taxa which have <i>this</i> taxon as next higher taxon
|
980
|
* (parent) within the classification and the number of which is stored in
|
981
|
* the TaxonomicChildrenCount attribute. Each taxon can have several child
|
982
|
* taxa. The child taxon and the parent taxon play the source respectively
|
983
|
* the target role in one {@link TaxonRelationship taxon relationship} with
|
984
|
* {@link TaxonRelationshipType taxon relationship type} "taxonomically included in".
|
985
|
* The {@link name.Rank rank} of the taxon name used as a parent taxon must be higher
|
986
|
* than the rank of the taxon name used as a child taxon.
|
987
|
*
|
988
|
* @see #getTaxonomicChildren()
|
989
|
* @see #getRelationsToThisTaxon()
|
990
|
*/
|
991
|
@Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
|
992
|
public int getTaxonomicChildrenCount(){
|
993
|
return taxonomicChildrenCount;
|
994
|
}
|
995
|
|
996
|
/**
|
997
|
* @see #getTaxonomicChildrenCount()
|
998
|
*/
|
999
|
@Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
|
1000
|
public void setTaxonomicChildrenCount(int taxonomicChildrenCount) {
|
1001
|
this.taxonomicChildrenCount = taxonomicChildrenCount;
|
1002
|
}
|
1003
|
|
1004
|
/**
|
1005
|
* Returns the boolean value indicating whether <i>this</i> taxon has at least one
|
1006
|
* taxonomic child taxon within the classification (true) or not (false).
|
1007
|
*
|
1008
|
* @see #getTaxonomicChildrenCount()
|
1009
|
* @see #getTaxonomicChildren()
|
1010
|
*/
|
1011
|
@Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
|
1012
|
@Transient
|
1013
|
public boolean hasTaxonomicChildren(){
|
1014
|
return this.taxonomicChildrenCount > 0;
|
1015
|
}
|
1016
|
|
1017
|
@Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
|
1018
|
private int computeTaxonomicChildrenCount(){
|
1019
|
int count = 0;
|
1020
|
for (TaxonRelationship rel: this.getRelationsToThisTaxon()){
|
1021
|
if (rel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN())){
|
1022
|
count++;
|
1023
|
}
|
1024
|
}
|
1025
|
return count;
|
1026
|
}
|
1027
|
|
1028
|
|
1029
|
/**
|
1030
|
* Returns the boolean value indicating whether <i>this</i> taxon is a misaplication
|
1031
|
* (misapplied name) for at least one other taxon.
|
1032
|
*/
|
1033
|
// TODO cache as for #hasTaxonomicChildren
|
1034
|
@Transient
|
1035
|
public boolean isMisapplication(){
|
1036
|
return computeMisapliedNameRelations() > 0;
|
1037
|
}
|
1038
|
|
1039
|
/**
|
1040
|
* Counts the number of misaplied names relationships where this taxon represents the
|
1041
|
* misaplied name for another taxon.
|
1042
|
* @return
|
1043
|
*/
|
1044
|
private int computeMisapliedNameRelations(){
|
1045
|
int count = 0;
|
1046
|
for (TaxonRelationship rel: this.getRelationsFromThisTaxon()){
|
1047
|
if (rel.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
|
1048
|
count++;
|
1049
|
}
|
1050
|
}
|
1051
|
return count;
|
1052
|
}
|
1053
|
|
1054
|
/**
|
1055
|
* Returns the boolean value indicating whether <i>this</i> taxon is a related
|
1056
|
* concept for at least one other taxon.
|
1057
|
*/
|
1058
|
@Transient
|
1059
|
public boolean isRelatedConcept(){
|
1060
|
return computeConceptRelations() > 0;
|
1061
|
}
|
1062
|
|
1063
|
/**
|
1064
|
* Counts the number of concept relationships where this taxon represents the
|
1065
|
* related concept for another taxon.
|
1066
|
* @return
|
1067
|
*/
|
1068
|
private int computeConceptRelations(){
|
1069
|
int count = 0;
|
1070
|
for (TaxonRelationship rel: this.getRelationsFromThisTaxon()){
|
1071
|
TaxonRelationshipType type = rel.getType();
|
1072
|
if (type.isConceptRelationship()){
|
1073
|
count++;
|
1074
|
}
|
1075
|
}
|
1076
|
return count;
|
1077
|
}
|
1078
|
|
1079
|
/**
|
1080
|
* Returns the boolean value indicating whether <i>this</i> taxon has at least one
|
1081
|
* {@link Synonym synonym} (true) or not (false). If true the {@link #getSynonymRelations() set of synonym relationships}
|
1082
|
* belonging to <i>this</i> ("accepted/correct") taxon is not empty .
|
1083
|
*
|
1084
|
* @see #getSynonymRelations()
|
1085
|
* @see #getSynonyms()
|
1086
|
* @see #getSynonymNames()
|
1087
|
* @see #removeSynonym(Synonym)
|
1088
|
* @see SynonymRelationship
|
1089
|
*/
|
1090
|
@Transient
|
1091
|
public boolean hasSynonyms(){
|
1092
|
return this.getSynonymRelations().size() > 0;
|
1093
|
}
|
1094
|
|
1095
|
|
1096
|
/**
|
1097
|
* Returns the boolean value indicating whether <i>this</i> taxon is at least
|
1098
|
* involved in one {@link #getTaxonRelations() taxon relationship} between
|
1099
|
* two taxa (true), either as a source or as a target, or not (false).
|
1100
|
*
|
1101
|
* @see #getTaxonRelations()
|
1102
|
* @see #getRelationsToThisTaxon()
|
1103
|
* @see #getRelationsFromThisTaxon()
|
1104
|
* @see #removeTaxonRelation(TaxonRelationship)
|
1105
|
* @see TaxonRelationship
|
1106
|
*/
|
1107
|
public boolean hasTaxonRelationships(){
|
1108
|
return this.getTaxonRelations().size() > 0;
|
1109
|
}
|
1110
|
|
1111
|
/*
|
1112
|
* MISAPPLIED NAMES
|
1113
|
*/
|
1114
|
/**
|
1115
|
* Returns the set of taxa playing the source role in {@link TaxonRelationship taxon relationships}
|
1116
|
* (with {@link TaxonRelationshipType taxon relationship type} "misapplied name for") where
|
1117
|
* <i>this</i> taxon plays the target role. A misapplied name is a taxon the
|
1118
|
* {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name} of which has been erroneously used
|
1119
|
* by its {@link TaxonBase#getSec() taxon reference} to denominate the same real taxon
|
1120
|
* as the one meant by <i>this</i> ("accepted/correct") taxon.
|
1121
|
*
|
1122
|
* @see #getTaxonRelations()
|
1123
|
* @see #getRelationsToThisTaxon()
|
1124
|
* @see #addMisappliedName(Taxon, Reference, String)
|
1125
|
*/
|
1126
|
@Transient
|
1127
|
public Set<Taxon> getMisappliedNames(){
|
1128
|
Set<Taxon> taxa = new HashSet<Taxon>();
|
1129
|
Set<TaxonRelationship> rels = this.getRelationsToThisTaxon();
|
1130
|
for (TaxonRelationship rel: rels){
|
1131
|
TaxonRelationshipType tt = rel.getType();
|
1132
|
TaxonRelationshipType incl = TaxonRelationshipType.MISAPPLIED_NAME_FOR();
|
1133
|
if (tt.equals(incl)){
|
1134
|
taxa.add(rel.getFromTaxon());
|
1135
|
}
|
1136
|
}
|
1137
|
return taxa;
|
1138
|
}
|
1139
|
/**
|
1140
|
* Returns the set of taxa playing the target role in {@link TaxonRelationship taxon relationships}
|
1141
|
* (with {@link TaxonRelationshipType taxon relationship type} "misapplied name for") where
|
1142
|
* <i>this</i> taxon plays the source role. A misapplied name is a taxon the
|
1143
|
* {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name} of which has been erroneously used
|
1144
|
* by its {@link TaxonBase#getSec() taxon reference} to denominate the same real taxon
|
1145
|
* as the one meant by <i>this</i> ("accepted/correct") taxon.
|
1146
|
*
|
1147
|
* @see #getTaxonRelations()
|
1148
|
* @see #getRelationsToThisTaxon()
|
1149
|
* @see #addMisappliedName(Taxon, Reference, String)
|
1150
|
*/
|
1151
|
@Transient
|
1152
|
public Set<Taxon> getTaxonForMisappliedName(){
|
1153
|
Set<Taxon> taxa = new HashSet<Taxon>();
|
1154
|
Set<TaxonRelationship> rels = this.getRelationsFromThisTaxon();
|
1155
|
for (TaxonRelationship rel: rels){
|
1156
|
TaxonRelationshipType tt = rel.getType();
|
1157
|
TaxonRelationshipType incl = TaxonRelationshipType.MISAPPLIED_NAME_FOR();
|
1158
|
if (tt.equals(incl)){
|
1159
|
taxa.add(rel.getToTaxon());
|
1160
|
}
|
1161
|
}
|
1162
|
return taxa;
|
1163
|
}
|
1164
|
|
1165
|
|
1166
|
/*
|
1167
|
* DEALING WITH SYNONYMS
|
1168
|
*/
|
1169
|
/**
|
1170
|
* Returns the set of all {@link Synonym synonyms} of <i>this</i> ("accepted/correct") taxon.
|
1171
|
* Each synonym is the source and <i>this</i> taxon is the target of a {@link SynonymRelationship synonym relationship}
|
1172
|
* belonging to the {@link #getSynonymRelations() set of synonym relationships} assigned to <i>this</i> taxon.
|
1173
|
* For a particular synonym and for a particular ("accepted/correct") taxon
|
1174
|
* there can be several synonym relationships (if two or more
|
1175
|
* {@link SynonymRelationshipType synonym relationship types} - for instance
|
1176
|
* "pro parte synonym of" and "is homotypic synonym of" - must be combined).
|
1177
|
*
|
1178
|
* @see #getSynonymsSortedByType()
|
1179
|
* @see #getSynonymNames()
|
1180
|
* @see #getSynonymRelations()
|
1181
|
* @see #addSynonym(Synonym, SynonymRelationshipType)
|
1182
|
* @see #addSynonym(Synonym, SynonymRelationshipType, Reference, String)
|
1183
|
* @see #removeSynonymRelation(SynonymRelationship)
|
1184
|
* @see #removeSynonym(Synonym)
|
1185
|
*/
|
1186
|
@Transient
|
1187
|
public Set<Synonym> getSynonyms(){
|
1188
|
Set<Synonym> syns = new HashSet<Synonym>();
|
1189
|
for (SynonymRelationship rel: this.getSynonymRelations()){
|
1190
|
syns.add(rel.getSynonym());
|
1191
|
}
|
1192
|
return syns;
|
1193
|
}
|
1194
|
/**
|
1195
|
* Returns the set of all {@link Synonym synonyms} of <i>this</i> ("accepted/correct") taxon
|
1196
|
* sorted by the different {@link SynonymRelationshipType categories of synonym relationships}.
|
1197
|
* Each synonym is the source and <i>this</i> taxon is the target of a {@link SynonymRelationship synonym relationship}
|
1198
|
* belonging to the {@link #getSynonymRelations() set of synonym relationships} assigned to <i>this</i> taxon.
|
1199
|
*
|
1200
|
* @see #getSynonyms()
|
1201
|
* @see #getSynonymNames()
|
1202
|
* @see #getSynonymRelations()
|
1203
|
* @see #addSynonym(Synonym, SynonymRelationshipType)
|
1204
|
* @see #addSynonym(Synonym, SynonymRelationshipType, Reference, String)
|
1205
|
* @see #removeSynonymRelation(SynonymRelationship)
|
1206
|
* @see #removeSynonym(Synonym)
|
1207
|
*/
|
1208
|
@Transient
|
1209
|
public Set<Synonym> getSynonymsSortedByType(){
|
1210
|
// FIXME: need to sort synonyms according to type!!!
|
1211
|
logger.warn("getSynonymsSortedByType() not yet implemented");
|
1212
|
return getSynonyms();
|
1213
|
}
|
1214
|
/**
|
1215
|
* Returns the set of all {@link name.TaxonNameBase taxon names} used as {@link Synonym synonyms}
|
1216
|
* of <i>this</i> ("accepted/correct") taxon. Each synonym is the source and
|
1217
|
* <i>this</i> taxon is the target of a {@link SynonymRelationship synonym relationship} belonging
|
1218
|
* to the {@link #getSynonymRelations() set of synonym relationships} assigned to <i>this</i> taxon.
|
1219
|
*
|
1220
|
* @see #getSynonyms()
|
1221
|
* @see #getSynonymsSortedByType()
|
1222
|
* @see #getSynonymRelations()
|
1223
|
* @see #addSynonymName(TaxonNameBase, SynonymRelationshipType)
|
1224
|
* @see #addSynonym(Synonym, SynonymRelationshipType, Reference, String)
|
1225
|
* @see #removeSynonymRelation(SynonymRelationship)
|
1226
|
* @see #removeSynonym(Synonym)
|
1227
|
*/
|
1228
|
@Transient
|
1229
|
public Set<TaxonNameBase> getSynonymNames(){
|
1230
|
Set<TaxonNameBase> names = new HashSet<TaxonNameBase>();
|
1231
|
for (SynonymRelationship rel: this.getSynonymRelations()){
|
1232
|
names.add(rel.getSynonym().getName());
|
1233
|
}
|
1234
|
return names;
|
1235
|
}
|
1236
|
/**
|
1237
|
* Creates a new {@link SynonymRelationship synonym relationship} (with the given {@link Synonym synonym}
|
1238
|
* and with the given {@link SynonymRelationshipType synonym relationship type}), returns it and adds it
|
1239
|
* to the set of {@link #getSynonymRelations() synonym relationships} assigned to <i>this</i> taxon.
|
1240
|
* The new synonym relationship will also be added to the set of
|
1241
|
* {@link Synonym#getSynonymRelations() synonym relationships} belonging to the synonym
|
1242
|
* involved in this synonym relationship.<BR>
|
1243
|
* The returned synonym relationship allows to add further information to it.
|
1244
|
*
|
1245
|
* @param synonym the synonym involved in the relationship to be created
|
1246
|
* and added to <i>this</i> taxon's synonym relationships set
|
1247
|
* @param synonymType the synonym relationship category of the synonym
|
1248
|
* relationship to be added
|
1249
|
* @return the created synonym relationship
|
1250
|
* @see #addSynonymRelation(SynonymRelationship)
|
1251
|
* @see #addSynonym(Synonym, SynonymRelationshipType, Reference, String)
|
1252
|
* @see #addSynonymName(TaxonNameBase, SynonymRelationshipType)
|
1253
|
* @see #addSynonymName(TaxonNameBase, SynonymRelationshipType, Reference, String)
|
1254
|
* @see #addHomotypicSynonym(Synonym, Reference, String)
|
1255
|
* @see #addHomotypicSynonymName(TaxonNameBase, Reference, String)
|
1256
|
* @see #addHeterotypicSynonymName(TaxonNameBase)
|
1257
|
* @see #addHeterotypicSynonymName(TaxonNameBase, HomotypicalGroup, Reference, String)
|
1258
|
* @see #getSynonymRelations()
|
1259
|
* @see #removeSynonym(Synonym)
|
1260
|
* @see Synonym#getSynonymRelations()
|
1261
|
*/
|
1262
|
public SynonymRelationship addSynonym(Synonym synonym, SynonymRelationshipType synonymType){
|
1263
|
return addSynonym(synonym, synonymType, null, null);
|
1264
|
}
|
1265
|
/**
|
1266
|
* Creates a new {@link SynonymRelationship synonym relationship} (with the given {@link Synonym synonym},
|
1267
|
* with the given {@link SynonymRelationshipType synonym relationship type} and with the
|
1268
|
* {@link eu.etaxonomy.cdm.model.reference.Reference reference source} on which the relationship assertion is based),
|
1269
|
* returns it and adds it to the set of {@link #getSynonymRelations() synonym relationships}
|
1270
|
* assigned to <i>this</i> taxon. The new synonym relationship will also be
|
1271
|
* added to the set of {@link Synonym#getSynonymRelations() synonym relationships} belonging to the synonym
|
1272
|
* involved in this synonym relationship.<BR>
|
1273
|
* The returned synonym relationship allows to add further information to it.
|
1274
|
*
|
1275
|
* @param synonym the synonym involved in the relationship to be created
|
1276
|
* and added to <i>this</i> taxon's synonym relationships set
|
1277
|
* @param synonymType the synonym relationship category of the synonym
|
1278
|
* relationship to be added
|
1279
|
* @param citation the reference source for the new synonym relationship
|
1280
|
* @param microcitation the string with the details describing the exact localisation within the reference
|
1281
|
* @return the created synonym relationship
|
1282
|
* @see #addSynonymRelation(SynonymRelationship)
|
1283
|
* @see #addSynonym(Synonym, SynonymRelationshipType, Reference, String)
|
1284
|
* @see #addSynonymName(TaxonNameBase, SynonymRelationshipType)
|
1285
|
* @see #addSynonymName(TaxonNameBase, SynonymRelationshipType, Reference, String)
|
1286
|
* @see #addHomotypicSynonym(Synonym, Reference, String)
|
1287
|
* @see #addHomotypicSynonymName(TaxonNameBase, Reference, String)
|
1288
|
* @see #addHeterotypicSynonymName(TaxonNameBase)
|
1289
|
* @see #addHeterotypicSynonymName(TaxonNameBase, HomotypicalGroup, Reference, String)
|
1290
|
* @see #getSynonymRelations()
|
1291
|
* @see #removeSynonym(Synonym)
|
1292
|
* @see Synonym#getSynonymRelations()
|
1293
|
*/
|
1294
|
public SynonymRelationship addSynonym(Synonym synonym, SynonymRelationshipType synonymType, Reference citation, String citationMicroReference){
|
1295
|
SynonymRelationship synonymRelationship = new SynonymRelationship(synonym, this, synonymType, citation, citationMicroReference);
|
1296
|
return synonymRelationship;
|
1297
|
}
|
1298
|
|
1299
|
/**
|
1300
|
* Creates a new {@link Synonym synonym} (with the given {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name}),
|
1301
|
* a new {@link SynonymRelationship synonym relationship} (with the new synonym and with the given
|
1302
|
* {@link SynonymRelationshipType synonym relationship type}), returns the relationship and adds it
|
1303
|
* to the set of {@link #getSynonymRelations() synonym relationships} assigned to <i>this</i> taxon.
|
1304
|
* The new synonym will have the same {@link TaxonBase#getSec() concept reference}
|
1305
|
* as <i>this</i> taxon. The new synonym relationship will also be added to
|
1306
|
* the set of {@link Synonym#getSynonymRelations() synonym relationships} belonging
|
1307
|
* to the created synonym.<BR>
|
1308
|
* The returned synonym relationship allows to add further information to it.
|
1309
|
*
|
1310
|
* @param synonymName the taxon name to be used as a synonym to be added
|
1311
|
* to <i>this</i> taxon's set of synonyms
|
1312
|
* @param synonymType the synonym relationship category of the synonym
|
1313
|
* relationship to be added
|
1314
|
* @return the created synonym relationship
|
1315
|
* @see #addSynonymName(TaxonNameBase, SynonymRelationshipType, Reference, String)
|
1316
|
* @see #addSynonym(Synonym, SynonymRelationshipType)
|
1317
|
* @see #addSynonym(Synonym, SynonymRelationshipType, Reference, String)
|
1318
|
* @see #addSynonymRelation(SynonymRelationship)
|
1319
|
* @see #addHomotypicSynonym(Synonym, Reference, String)
|
1320
|
* @see #addHomotypicSynonymName(TaxonNameBase, Reference, String)
|
1321
|
* @see #addHeterotypicSynonymName(TaxonNameBase)
|
1322
|
* @see #addHeterotypicSynonymName(TaxonNameBase, HomotypicalGroup, Reference, String)
|
1323
|
* @see #getSynonymRelations()
|
1324
|
* @see #removeSynonym(Synonym)
|
1325
|
* @see Synonym#getSynonymRelations()
|
1326
|
*/
|
1327
|
public SynonymRelationship addSynonymName(TaxonNameBase synonymName, SynonymRelationshipType synonymType){
|
1328
|
return addSynonymName(synonymName, synonymType, null, null);
|
1329
|
}
|
1330
|
/**
|
1331
|
* Creates a new {@link Synonym synonym} (with the given {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name}),
|
1332
|
* a new {@link SynonymRelationship synonym relationship} (with the new synonym, with the given
|
1333
|
* {@link SynonymRelationshipType synonym relationship type} and with the {@link eu.etaxonomy.cdm.model.reference.Reference reference source}
|
1334
|
* on which the relationship assertion is based), returns the relationship
|
1335
|
* and adds it to the set of {@link #getSynonymRelations() synonym relationships} assigned
|
1336
|
* to <i>this</i> taxon. The new synonym will have the same {@link TaxonBase#getSec() concept reference}
|
1337
|
* as <i>this</i> taxon. The new synonym relationship will also be added to
|
1338
|
* the set of {@link Synonym#getSynonymRelations() synonym relationships} belonging
|
1339
|
* to the created synonym.<BR>
|
1340
|
* The returned synonym relationship allows to add further information to it.
|
1341
|
*
|
1342
|
* @param synonymName the taxon name to be used as a synonym to be added
|
1343
|
* to <i>this</i> taxon's set of synonyms
|
1344
|
* @param synonymType the synonym relationship category of the synonym
|
1345
|
* relationship to be added
|
1346
|
* @param citation the reference source for the new synonym relationship
|
1347
|
* @param microcitation the string with the details describing the exact localisation within the reference
|
1348
|
* @return the created synonym relationship
|
1349
|
* @see #addSynonymName(TaxonNameBase, SynonymRelationshipType, Reference, String)
|
1350
|
* @see #addSynonym(Synonym, SynonymRelationshipType)
|
1351
|
* @see #addSynonym(Synonym, SynonymRelationshipType, Reference, String)
|
1352
|
* @see #addSynonymRelation(SynonymRelationship)
|
1353
|
* @see #addHomotypicSynonym(Synonym, Reference, String)
|
1354
|
* @see #addHomotypicSynonymName(TaxonNameBase, Reference, String)
|
1355
|
* @see #addHeterotypicSynonymName(TaxonNameBase)
|
1356
|
* @see #addHeterotypicSynonymName(TaxonNameBase, HomotypicalGroup, Reference, String)
|
1357
|
* @see #getSynonymRelations()
|
1358
|
* @see #removeSynonym(Synonym)
|
1359
|
* @see Synonym#getSynonymRelations()
|
1360
|
*/
|
1361
|
public SynonymRelationship addSynonymName(TaxonNameBase synonymName, SynonymRelationshipType synonymType, Reference citation, String citationMicroReference){
|
1362
|
Synonym synonym = Synonym.NewInstance(synonymName, this.getSec());
|
1363
|
return addSynonym(synonym, synonymType, citation, citationMicroReference);
|
1364
|
}
|
1365
|
|
1366
|
/**
|
1367
|
* Creates a new {@link Synonym synonym} (with the given {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name}),
|
1368
|
* a new {@link SynonymRelationship synonym relationship} (with the new synonym and with the
|
1369
|
* {@link SynonymRelationshipType#HETEROTYPIC_SYNONYM_OF() "is heterotypic synonym of" relationship type}),
|
1370
|
* returns the relationship and adds it to the set of
|
1371
|
* {@link #getSynonymRelations() synonym relationships} assigned to <i>this</i> taxon.
|
1372
|
* The new synonym will have the same {@link TaxonBase#getSec() concept reference}
|
1373
|
* as <i>this</i> taxon. The new synonym relationship will also be added to
|
1374
|
* the set of {@link Synonym#getSynonymRelations() synonym relationships} belonging
|
1375
|
* to the created synonym.<BR>
|
1376
|
* The returned synonym relationship allows to add further information to it.
|
1377
|
*
|
1378
|
* @param synonymName the taxon name to be used as an heterotypic synonym
|
1379
|
* to be added to <i>this</i> taxon's set of synonyms
|
1380
|
* @return the created synonym relationship
|
1381
|
* @see #addHeterotypicSynonymName(TaxonNameBase, HomotypicalGroup, Reference, String)
|
1382
|
* @see #addSynonymName(TaxonNameBase, SynonymRelationshipType)
|
1383
|
* @see #addSynonymName(TaxonNameBase, SynonymRelationshipType, Reference, String)
|
1384
|
* @see #addSynonym(Synonym, SynonymRelationshipType)
|
1385
|
* @see #addSynonym(Synonym, SynonymRelationshipType, Reference, String)
|
1386
|
* @see #addSynonymRelation(SynonymRelationship)
|
1387
|
* @see #addHomotypicSynonym(Synonym, Reference, String)
|
1388
|
* @see #addHomotypicSynonymName(TaxonNameBase, Reference, String)
|
1389
|
* @see #getSynonymRelations()
|
1390
|
* @see #removeSynonym(Synonym)
|
1391
|
* @see Synonym#getSynonymRelations()
|
1392
|
*/
|
1393
|
public SynonymRelationship addHeterotypicSynonymName(TaxonNameBase synonymName){
|
1394
|
return addHeterotypicSynonymName(synonymName, null, null, null);
|
1395
|
}
|
1396
|
|
1397
|
/**
|
1398
|
* Creates a new {@link Synonym synonym} (with the given {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name}),
|
1399
|
* a new {@link SynonymRelationship synonym relationship} (with the new synonym, with the
|
1400
|
* {@link SynonymRelationshipType#HETEROTYPIC_SYNONYM_OF() "is heterotypic synonym of" relationship type}
|
1401
|
* and with the {@link eu.etaxonomy.cdm.model.reference.Reference reference source}
|
1402
|
* on which the relationship assertion is based), returns the relationship
|
1403
|
* and adds it to the set of {@link #getSynonymRelations() synonym relationships} assigned
|
1404
|
* to <i>this</i> taxon. The new synonym will have the same {@link TaxonBase#getSec() concept reference}
|
1405
|
* as <i>this</i> taxon. Furthermore the new synonym relationship will be
|
1406
|
* added to the set of {@link Synonym#getSynonymRelations() synonym relationships} belonging
|
1407
|
* to the created synonym and the taxon name used as synonym will be added
|
1408
|
* to the given {@link name.HomotypicalGroup homotypical group}.<BR>
|
1409
|
* The returned synonym relationship allows to add further information to it.
|
1410
|
*
|
1411
|
* @param synonymName the taxon name to be used as an heterotypic synonym
|
1412
|
* to be added to <i>this</i> taxon's set of synonyms
|
1413
|
* @param homotypicalGroup the homotypical group to which the taxon name
|
1414
|
* of the synonym will be added
|
1415
|
* @param citation the reference source for the new synonym relationship
|
1416
|
* @param microcitation the string with the details describing the exact localisation
|
1417
|
* within the reference
|
1418
|
* @return the created synonym relationship
|
1419
|
* @see #addHeterotypicSynonymName(TaxonNameBase)
|
1420
|
* @see #addSynonymName(TaxonNameBase, SynonymRelationshipType, Reference, String)
|
1421
|
* @see #addSynonymName(TaxonNameBase, SynonymRelationshipType)
|
1422
|
* @see #addSynonym(Synonym, SynonymRelationshipType)
|
1423
|
* @see #addSynonym(Synonym, SynonymRelationshipType, Reference, String)
|
1424
|
* @see #addSynonymRelation(SynonymRelationship)
|
1425
|
* @see #addHomotypicSynonym(Synonym, Reference, String)
|
1426
|
* @see #addHomotypicSynonymName(TaxonNameBase, Reference, String)
|
1427
|
* @see #getSynonymRelations()
|
1428
|
* @see #removeSynonym(Synonym)
|
1429
|
* @see Synonym#getSynonymRelations()
|
1430
|
*/
|
1431
|
public SynonymRelationship addHeterotypicSynonymName(TaxonNameBase synonymName, HomotypicalGroup homotypicalGroup, Reference citation, String microCitation){
|
1432
|
Synonym synonym = Synonym.NewInstance(synonymName, this.getSec());
|
1433
|
if (homotypicalGroup != null){
|
1434
|
homotypicalGroup.addTypifiedName(synonymName);
|
1435
|
}
|
1436
|
return addSynonym(synonym, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF(), citation, microCitation);
|
1437
|
}
|
1438
|
|
1439
|
/**
|
1440
|
* Creates a new {@link Synonym synonym} (with the given {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name}),
|
1441
|
* a new {@link SynonymRelationship synonym relationship} (with the new synonym, with the
|
1442
|
* {@link SynonymRelationshipType#HOMOTYPIC_SYNONYM_OF() "is homotypic synonym of" relationship type})
|
1443
|
* and with the {@link eu.etaxonomy.cdm.model.reference.Reference reference source}
|
1444
|
* on which the relationship assertion is based), returns the relationship
|
1445
|
* and adds it to the set of {@link #getSynonymRelations() synonym relationships} assigned
|
1446
|
* to <i>this</i> taxon. The new synonym will have the same {@link TaxonBase#getSec() concept reference}
|
1447
|
* as <i>this</i> taxon. Furthermore the new synonym relationship will be
|
1448
|
* added to the set of {@link Synonym#getSynonymRelations() synonym relationships} belonging
|
1449
|
* to the created synonym and the taxon name used as synonym will be added
|
1450
|
* to the same {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup homotypical group} to which the taxon name
|
1451
|
* of <i>this</i> taxon belongs.<BR>
|
1452
|
* The returned synonym relationship allows to add further information to it.
|
1453
|
*
|
1454
|
* @param synonymName the taxon name to be used as an homotypic synonym
|
1455
|
* to be added to <i>this</i> taxon's set of synonyms
|
1456
|
* @param citation the reference source for the new synonym relationship
|
1457
|
* @param microcitation the string with the details describing the exact localisation
|
1458
|
* within the reference
|
1459
|
* @return the created synonym relationship
|
1460
|
* @see #addHomotypicSynonym(Synonym, Reference, String)
|
1461
|
* @see #addSynonymName(TaxonNameBase, SynonymRelationshipType, Reference, String)
|
1462
|
* @see #addSynonymName(TaxonNameBase, SynonymRelationshipType)
|
1463
|
* @see #addSynonym(Synonym, SynonymRelationshipType)
|
1464
|
* @see #addSynonym(Synonym, SynonymRelationshipType, Reference, String)
|
1465
|
* @see #addSynonymRelation(SynonymRelationship)
|
1466
|
* @see #addHeterotypicSynonymName(TaxonNameBase)
|
1467
|
* @see #addHeterotypicSynonymName(TaxonNameBase, HomotypicalGroup, Reference, String)
|
1468
|
* @see #getSynonymRelations()
|
1469
|
* @see #removeSynonym(Synonym)
|
1470
|
* @see Synonym#getSynonymRelations()
|
1471
|
*/
|
1472
|
public SynonymRelationship addHomotypicSynonymName(TaxonNameBase synonymName, Reference citation, String microCitation){
|
1473
|
Synonym synonym = Synonym.NewInstance(synonymName, this.getSec());
|
1474
|
return addHomotypicSynonym(synonym, citation, microCitation);
|
1475
|
}
|
1476
|
|
1477
|
/**
|
1478
|
* Creates a new {@link SynonymRelationship synonym relationship} (with the given {@link Synonym synonym},
|
1479
|
* with the {@link SynonymRelationshipType#HOMOTYPIC_SYNONYM_OF() "is homotypic synonym of" relationship type}
|
1480
|
* and with the {@link eu.etaxonomy.cdm.model.reference.Reference reference source} on which the relationship
|
1481
|
* assertion is based), returns it and adds it to the set of
|
1482
|
* {@link #getSynonymRelations() synonym relationships} assigned to <i>this</i> taxon.
|
1483
|
* Furthermore the new synonym relationship will be added to the set of
|
1484
|
* {@link Synonym#getSynonymRelations() synonym relationships} belonging to the synonym
|
1485
|
* involved in this synonym relationship and the {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name}
|
1486
|
* used as synonym will be added to the same {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup homotypical group}
|
1487
|
* to which the taxon name of <i>this</i> taxon belongs.<BR>
|
1488
|
* The returned synonym relationship allows to add further information to it.
|
1489
|
*
|
1490
|
* @param synonym the synonym involved in the "is homotypic synonym of" relationship to be created
|
1491
|
* and added to <i>this</i> taxon's synonym relationships set
|
1492
|
* @param citation the reference source for the new synonym relationship
|
1493
|
* @param microcitation the string with the details describing the exact localisation within the reference
|
1494
|
* @return the created synonym relationship
|
1495
|
* @see #addHomotypicSynonymName(TaxonNameBase, Reference, String)
|
1496
|
* @see #addSynonym(Synonym, SynonymRelationshipType)
|
1497
|
* @see #addSynonym(Synonym, SynonymRelationshipType, Reference, String)
|
1498
|
* @see #addSynonymName(TaxonNameBase, SynonymRelationshipType, Reference, String)
|
1499
|
* @see #addSynonymName(TaxonNameBase, SynonymRelationshipType)
|
1500
|
* @see #addSynonymRelation(SynonymRelationship)
|
1501
|
* @see #addHeterotypicSynonymName(TaxonNameBase)
|
1502
|
* @see #addHeterotypicSynonymName(TaxonNameBase, HomotypicalGroup, Reference, String)
|
1503
|
* @see #getSynonymRelations()
|
1504
|
* @see #removeSynonym(Synonym)
|
1505
|
* @see Synonym#getSynonymRelations()
|
1506
|
*/
|
1507
|
public SynonymRelationship addHomotypicSynonym(Synonym synonym, Reference citation, String microCitation){
|
1508
|
if (this.getName() != null){
|
1509
|
if (this.getName().getHomotypicalGroup().getTypifiedNames().isEmpty()){
|
1510
|
this.getName().getHomotypicalGroup().getTypifiedNames().add(this.getName());
|
1511
|
|
1512
|
}
|
1513
|
this.getName().getHomotypicalGroup().addTypifiedName(synonym.getName());
|
1514
|
|
1515
|
}
|
1516
|
SynonymRelationship synRel = null;
|
1517
|
if (!this.getSynonyms().contains(synonym)){
|
1518
|
synRel = addSynonym(synonym, SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF(), citation, microCitation);
|
1519
|
} else{
|
1520
|
logger.warn("The synonym is already related to the taxon.");
|
1521
|
|
1522
|
}
|
1523
|
return synRel;
|
1524
|
}
|
1525
|
|
1526
|
/**
|
1527
|
* Like {@link #removeSynonym(Synonym, boolean)} with <code>removeSynonymNameFromHomotypicalGroup</code> set to true.
|
1528
|
* @see #removeSynonym(Synonym, boolean)
|
1529
|
*/
|
1530
|
public void removeSynonym(Synonym synonym){
|
1531
|
removeSynonym(synonym, true);
|
1532
|
}
|
1533
|
|
1534
|
/**
|
1535
|
* Removes the element(s) from the set of {@link SynonymRelationship synonym relationships}
|
1536
|
* assigned to <i>this</i> ("accepted/valid") taxon in which the given synonym is involved.
|
1537
|
* Due to bidirectionality the same synonym relationships will also be
|
1538
|
* removed from the set of synonym relationships assigned to the
|
1539
|
* {@link Synonym#getSynonymRelations() synonym} involved in the relationship. Furthermore the content of
|
1540
|
* the {@link SynonymRelationship#getAcceptedTaxon() accepted taxon} attribute and of the
|
1541
|
* {@link SynonymRelationship#getSynonym() synonym} attribute within the synonym relationships
|
1542
|
* themselves will be set to "null".
|
1543
|
*
|
1544
|
* @param synonym the synonym involved in the synonym relationship which should be deleted
|
1545
|
* @param removeSynonymNameFromHomotypicalGroup if <code>true</code> the removed synonyms
|
1546
|
* name will get a new homotypic group in case it is together with other names in a group.
|
1547
|
* @see #getSynonymRelations()
|
1548
|
* @see #addSynonym(Synonym, SynonymRelationshipType)
|
1549
|
* @see #addSynonym(Synonym, SynonymRelationshipType, Reference, String)
|
1550
|
* @see #removeSynonymRelation(SynonymRelationship)
|
1551
|
* @see #removeSynonymRelation(SynonymRelationship, boolean)
|
1552
|
*/
|
1553
|
public void removeSynonym(Synonym synonym, boolean removeSynonymNameFromHomotypicalGroup){
|
1554
|
Set<SynonymRelationship> synonymRelationships = new HashSet<SynonymRelationship>();
|
1555
|
synonymRelationships.addAll(this.getSynonymRelations());
|
1556
|
for(SynonymRelationship synonymRelationship : synonymRelationships){
|
1557
|
if (synonymRelationship.getAcceptedTaxon().equals(this) && synonymRelationship.getSynonym().equals(synonym)){
|
1558
|
this.removeSynonymRelation(synonymRelationship, removeSynonymNameFromHomotypicalGroup);
|
1559
|
}
|
1560
|
}
|
1561
|
}
|
1562
|
|
1563
|
|
1564
|
/**
|
1565
|
* Retrieves the ordered list (depending on the date of publication) of
|
1566
|
* homotypic {@link Synonym synonyms} (according to the same {@link eu.etaxonomy.cdm.model.reference.Reference reference}
|
1567
|
* as for <i>this</i> taxon) under the condition that the {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon names}
|
1568
|
* of these synonyms and the taxon name of <i>this</i> taxon belong to the
|
1569
|
* same {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup homotypical group}.
|
1570
|
*
|
1571
|
* @return the ordered list of homotypic synonyms
|
1572
|
* @see #getHomotypicSynonymsByHomotypicRelationship()
|
1573
|
* @see #getSynonyms()
|
1574
|
* @see #getHomotypicSynonymyGroups()
|
1575
|
* @see eu.etaxonomy.cdm.model.name.HomotypicalGroup
|
1576
|
* @see eu.etaxonomy.cdm.model.name.HomotypicalGroup#getSynonymsInGroup(Reference)
|
1577
|
*/
|
1578
|
@Transient
|
1579
|
public List<Synonym> getHomotypicSynonymsByHomotypicGroup(){
|
1580
|
if (this.getHomotypicGroup() == null){
|
1581
|
return null;
|
1582
|
}else{
|
1583
|
return this.getSynonymsInGroup(this.getHomotypicGroup());
|
1584
|
}
|
1585
|
}
|
1586
|
|
1587
|
/**
|
1588
|
* Retrieves the ordered list (depending on the date of publication) of
|
1589
|
* homotypic {@link Synonym synonyms} (according to the same {@link eu.etaxonomy.cdm.model.reference.Reference reference}
|
1590
|
* as for <i>this</i> taxon) under the condition that these synonyms and
|
1591
|
* <i>this</i> taxon are involved in {@link SynonymRelationship synonym relationships} with an
|
1592
|
* "is homotypic synonym of" {@link SynonymRelationshipType#HOMOTYPIC_SYNONYM_OF() synonym relationship type}.
|
1593
|
*
|
1594
|
* @return the ordered list of homotypic synonyms
|
1595
|
* @see #getHomotypicSynonymsByHomotypicGroup()
|
1596
|
* @see #getSynonyms()
|
1597
|
* @see #getHomotypicSynonymyGroups()
|
1598
|
* @see SynonymRelationshipType
|
1599
|
*/
|
1600
|
@Transient
|
1601
|
public List<Synonym> getHomotypicSynonymsByHomotypicRelationship(){
|
1602
|
Set<SynonymRelationship> synonymRelations = this.getSynonymRelations();
|
1603
|
List<Synonym> result = new ArrayList<Synonym>();
|
1604
|
for(SynonymRelationship synonymRelation : synonymRelations) {
|
1605
|
if(synonymRelation.getType().equals(SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF())){
|
1606
|
result.add(synonymRelation.getSynonym());
|
1607
|
}
|
1608
|
}
|
1609
|
return result;
|
1610
|
}
|
1611
|
|
1612
|
/**
|
1613
|
* Returns the ordered list of all {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup homotypical groups} {@link Synonym synonyms} of
|
1614
|
* <i>this</i> taxon belong to. {@link eu.etaxonomy.cdm.model.name.TaxonNameBase Taxon names} of homotypic synonyms
|
1615
|
* belong to the same homotypical group as the taxon name of <i>this</i>
|
1616
|
* taxon. Taxon names of heterotypic synonyms belong to at least one other
|
1617
|
* homotypical group. <BR>
|
1618
|
* The list returned is ordered according to the date of publication of the
|
1619
|
* first published name within each homotypical group.
|
1620
|
*
|
1621
|
* @see #getHeterotypicSynonymyGroups()
|
1622
|
* @see #getSynonyms()
|
1623
|
* @see eu.etaxonomy.cdm.model.name.HomotypicalGroup
|
1624
|
*/
|
1625
|
@Transient
|
1626
|
public List<HomotypicalGroup> getHomotypicSynonymyGroups(){
|
1627
|
List<HomotypicalGroup> result = new ArrayList<HomotypicalGroup>();
|
1628
|
result.add(this.getHomotypicGroup());
|
1629
|
for (TaxonNameBase taxonNameBase :this.getSynonymNames()){
|
1630
|
if (taxonNameBase != null) {
|
1631
|
if (!result.contains(taxonNameBase.getHomotypicalGroup())){
|
1632
|
result.add(taxonNameBase.getHomotypicalGroup());
|
1633
|
}
|
1634
|
} // TODO: give error message to user
|
1635
|
}
|
1636
|
// TODO: sort list according to date of first published name within each group
|
1637
|
return result;
|
1638
|
}
|
1639
|
|
1640
|
@Override
|
1641
|
@Transient
|
1642
|
public boolean isOrphaned() {
|
1643
|
|
1644
|
if(taxonNodes == null || taxonNodes.isEmpty()) {
|
1645
|
if(getRelationsFromThisTaxon().isEmpty() && getRelationsToThisTaxon().isEmpty()) {
|
1646
|
return true;
|
1647
|
}
|
1648
|
}
|
1649
|
return false;
|
1650
|
}
|
1651
|
|
1652
|
/**
|
1653
|
* Returns the ordered list of all {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup homotypical groups}
|
1654
|
* that contain {@link Synonym synonyms} that are heterotypic to <i>this</i> taxon.
|
1655
|
* {@link eu.etaxonomy.cdm.model.name.TaxonNameBase Taxon names} of heterotypic synonyms
|
1656
|
* belong to a homotypical group which cannot be the homotypical group to which the
|
1657
|
* taxon name of <i>this</i> taxon belongs. This method returns the same
|
1658
|
* list as the {@link #getHomotypicSynonymyGroups() getHomotypicSynonymyGroups} method
|
1659
|
* but without the homotypical group to which the taxon name of <i>this</i> taxon
|
1660
|
* belongs.<BR>
|
1661
|
* The list returned is ordered according to the date of publication of the
|
1662
|
* first published name within each homotypical group.
|
1663
|
*
|
1664
|
* @see #getHeterotypicSynonymyGroups()
|
1665
|
* @see #getSynonyms()
|
1666
|
* @see SynonymRelationshipType#HETEROTYPIC_SYNONYM_OF()
|
1667
|
* @see eu.etaxonomy.cdm.model.name.HomotypicalGroup
|
1668
|
*/
|
1669
|
@Transient
|
1670
|
public List<HomotypicalGroup> getHeterotypicSynonymyGroups(){
|
1671
|
List<HomotypicalGroup> list = getHomotypicSynonymyGroups();
|
1672
|
list.remove(this.getHomotypicGroup());
|
1673
|
//sort
|
1674
|
Map<Synonym, HomotypicalGroup> map = new HashMap<Synonym, HomotypicalGroup>();
|
1675
|
for (HomotypicalGroup homotypicalGroup: list){
|
1676
|
List<Synonym> synonymList = getSynonymsInGroup(homotypicalGroup);
|
1677
|
if (synonymList.size() > 0){
|
1678
|
map.put(synonymList.get(0), homotypicalGroup);
|
1679
|
}
|
1680
|
}
|
1681
|
List<Synonym> keyList = new ArrayList<Synonym>();
|
1682
|
keyList.addAll(map.keySet());
|
1683
|
Collections.sort(keyList, new TaxonComparator());
|
1684
|
|
1685
|
List<HomotypicalGroup> result = new ArrayList<HomotypicalGroup>();
|
1686
|
for(Synonym synonym: keyList){
|
1687
|
result.add(map.get(synonym));
|
1688
|
}
|
1689
|
//sort end
|
1690
|
return result;
|
1691
|
}
|
1692
|
|
1693
|
/**
|
1694
|
* Retrieves the ordered list (depending on the date of publication) of
|
1695
|
* {@link taxon.Synonym synonyms} (according to a given reference)
|
1696
|
* the {@link TaxonNameBase taxon names} of which belong to the homotypical group.
|
1697
|
* If other names are part of the group that are not considered synonyms of
|
1698
|
* <i>this</i> taxon, then they will not be included in
|
1699
|
* the result set.
|
1700
|
*
|
1701
|
* @param homoGroup
|
1702
|
* @see TaxonNameBase#getSynonyms()
|
1703
|
* @see TaxonNameBase#getTaxa()
|
1704
|
* @see taxon.Synonym
|
1705
|
*/
|
1706
|
@Transient
|
1707
|
public List<Synonym> getSynonymsInGroup(HomotypicalGroup homotypicGroup){
|
1708
|
List<Synonym> result = new ArrayList<Synonym>();
|
1709
|
|
1710
|
for (TaxonNameBase<?, ?>name : homotypicGroup.getTypifiedNames()){
|
1711
|
for (Synonym synonym : name.getSynonyms()){
|
1712
|
for(SynonymRelationship synRel : synonym.getSynonymRelations()){
|
1713
|
if (synRel.getAcceptedTaxon().equals(this)){
|
1714
|
result.add(synRel.getSynonym());
|
1715
|
}
|
1716
|
}
|
1717
|
}
|
1718
|
}
|
1719
|
Collections.sort(result, new TaxonComparator());
|
1720
|
return result;
|
1721
|
}
|
1722
|
|
1723
|
|
1724
|
/**
|
1725
|
* Returns the image gallery description. If no image gallery exists, a new one is created using the
|
1726
|
* defined title and adds the string "-Image Gallery" to the title.</BR>
|
1727
|
* If multiple image galleries exist an arbitrary one is choosen.
|
1728
|
* @param title
|
1729
|
* @return
|
1730
|
*/
|
1731
|
public TaxonDescription getOrCreateImageGallery(String title){
|
1732
|
return getOrCreateImageGallery(title, true, false);
|
1733
|
}
|
1734
|
|
1735
|
/**
|
1736
|
* Returns the image gallery description. If no image gallery exists, a new one is created using the
|
1737
|
* defined title.</BR>
|
1738
|
* If onlyTitle == true we look only for an image gallery with this title, create a new one otherwise.
|
1739
|
* If multiple image galleries exist that match the conditions an arbitrary one is choosen.
|
1740
|
* @param title
|
1741
|
* @param onlyTitle
|
1742
|
* @param if true, the String "Image Gallery
|
1743
|
* @return
|
1744
|
*/
|
1745
|
@Transient
|
1746
|
public TaxonDescription getOrCreateImageGallery(String title, boolean addImageGalleryToTitle, boolean onlyTitle){
|
1747
|
TaxonDescription result = null;
|
1748
|
String titleCache = (title == null) ? "Image Gallery" : title;
|
1749
|
if (title != null && addImageGalleryToTitle){
|
1750
|
titleCache = titleCache+ "-Image Gallery";
|
1751
|
}
|
1752
|
Set<TaxonDescription> descriptionSet = this.getDescriptions();
|
1753
|
for (TaxonDescription desc: descriptionSet){
|
1754
|
if (desc.isImageGallery()){
|
1755
|
if (onlyTitle && ! titleCache.equals(desc.getTitleCache())){
|
1756
|
continue;
|
1757
|
}
|
1758
|
result = desc;
|
1759
|
if (onlyTitle && titleCache.equals(desc.getTitleCache())){
|
1760
|
break;
|
1761
|
}
|
1762
|
}
|
1763
|
}
|
1764
|
if (result == null){
|
1765
|
result = TaxonDescription.NewInstance();
|
1766
|
result.setTitleCache(titleCache, true);
|
1767
|
this.addDescription(result);
|
1768
|
result.setImageGallery(true);
|
1769
|
}
|
1770
|
return result;
|
1771
|
}
|
1772
|
//*********************** CLONE ********************************************************/
|
1773
|
|
1774
|
|
1775
|
/**
|
1776
|
* Clones <i>this</i> taxon. This is a shortcut that enables to create
|
1777
|
* a new instance that differs only slightly from <i>this</i> taxon by
|
1778
|
* modifying only some of the attributes.<BR><BR>
|
1779
|
* The TaxonNodes are not cloned, the list is empty.<BR>
|
1780
|
* (CAUTION: this behaviour needs to be discussed and may change in future).<BR><BR>
|
1781
|
* The taxon relationships and synonym relationships are cloned <BR>
|
1782
|
*
|
1783
|
* @see eu.etaxonomy.cdm.model.taxon.TaxonBase#clone()
|
1784
|
* @see eu.etaxonomy.cdm.model.media.IdentifiableEntity#clone()
|
1785
|
* @see java.lang.Object#clone()
|
1786
|
*/
|
1787
|
@Override
|
1788
|
public Object clone() {
|
1789
|
Taxon result;
|
1790
|
result = (Taxon)super.clone();
|
1791
|
|
1792
|
result.setRelationsFromThisTaxon(new HashSet<TaxonRelationship>());
|
1793
|
|
1794
|
for (TaxonRelationship fromRelationship : this.getRelationsFromThisTaxon()){
|
1795
|
TaxonRelationship newRelationship = (TaxonRelationship)fromRelationship.clone();
|
1796
|
newRelationship.setRelatedFrom(result);
|
1797
|
result.relationsFromThisTaxon.add(newRelationship);
|
1798
|
}
|
1799
|
|
1800
|
result.setRelationsToThisTaxon(new HashSet<TaxonRelationship>());
|
1801
|
for (TaxonRelationship toRelationship : this.getRelationsToThisTaxon()){
|
1802
|
TaxonRelationship newRelationship = (TaxonRelationship)toRelationship.clone();
|
1803
|
newRelationship.setRelatedTo(result);
|
1804
|
result.relationsToThisTaxon.add(newRelationship);
|
1805
|
}
|
1806
|
|
1807
|
|
1808
|
result.synonymRelations = new HashSet<SynonymRelationship>();
|
1809
|
for (SynonymRelationship synRelationship : this.getSynonymRelations()){
|
1810
|
SynonymRelationship newRelationship = (SynonymRelationship)synRelationship.clone();
|
1811
|
newRelationship.setRelatedTo(result);
|
1812
|
result.synonymRelations.add(newRelationship);
|
1813
|
}
|
1814
|
|
1815
|
|
1816
|
result.taxonNodes = new HashSet<TaxonNode>();
|
1817
|
|
1818
|
/*for (TaxonNode taxonNode : this.getTaxonNodes()){
|
1819
|
TaxonNode newTaxonNode = (TaxonNode)taxonNode.clone();
|
1820
|
newTaxonNode.setTaxon(result);
|
1821
|
result.addTaxonNode(newTaxonNode);
|
1822
|
}*/
|
1823
|
|
1824
|
return result;
|
1825
|
|
1826
|
}
|
1827
|
|
1828
|
public void clearDescriptions() {
|
1829
|
this.descriptions = new HashSet<TaxonDescription>();
|
1830
|
}
|
1831
|
|
1832
|
}
|