Revision fd992c0d
Added by Niels Hoffmann over 13 years ago
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImpl.java | ||
---|---|---|
13 | 13 |
import java.util.ArrayList; |
14 | 14 |
import java.util.Collections; |
15 | 15 |
import java.util.Comparator; |
16 |
import java.util.HashSet; |
|
16 | 17 |
import java.util.List; |
18 |
import java.util.Set; |
|
17 | 19 |
import java.util.UUID; |
18 | 20 |
|
19 | 21 |
import org.apache.log4j.Logger; |
... | ... | |
22 | 24 |
import org.springframework.transaction.annotation.Propagation; |
23 | 25 |
import org.springframework.transaction.annotation.Transactional; |
24 | 26 |
|
27 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
|
28 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
|
29 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
|
30 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
31 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
|
32 |
import eu.etaxonomy.cdm.model.taxon.SynonymRelationship; |
|
33 |
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType; |
|
34 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
25 | 35 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
36 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; |
|
26 | 37 |
import eu.etaxonomy.cdm.persistence.dao.BeanInitializer; |
27 | 38 |
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonNodeDao; |
28 | 39 |
|
... | ... | |
67 | 78 |
protected void setDao(ITaxonNodeDao dao) { |
68 | 79 |
this.dao = dao; |
69 | 80 |
} |
81 |
|
|
82 |
/* (non-Javadoc) |
|
83 |
* @see eu.etaxonomy.cdm.api.service.ITaxonService#makeTaxonSynonym(eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.model.taxon.Taxon) |
|
84 |
*/ |
|
85 |
@Transactional(readOnly = false) |
|
86 |
public Synonym makeTaxonNodeASynonymOfAnotherTaxonNode(TaxonNode oldTaxonNode, TaxonNode newAcceptedTaxonNode, SynonymRelationshipType synonymRelationshipType, Reference citation, String citationMicroReference) { |
|
87 |
|
|
88 |
// TODO at the moment this method only moves synonym-, concept relations and descriptions to the new accepted taxon |
|
89 |
// in a future version we also want to move cdm data like annotations, marker, so., but we will need a policy for that |
|
90 |
if (oldTaxonNode == null || newAcceptedTaxonNode == null || oldTaxonNode.getTaxon().getName() == null){ |
|
91 |
throw new IllegalArgumentException("A mandatory parameter was null."); |
|
92 |
} |
|
93 |
|
|
94 |
if(oldTaxonNode.equals(newAcceptedTaxonNode)){ |
|
95 |
throw new IllegalArgumentException("Taxon can not be made synonym of its own."); |
|
96 |
} |
|
97 |
|
|
98 |
Taxon oldTaxon = (Taxon) HibernateProxyHelper.deproxy(oldTaxonNode.getTaxon()); |
|
99 |
Taxon newAcceptedTaxon = (Taxon) HibernateProxyHelper.deproxy(newAcceptedTaxonNode.getTaxon()); |
|
100 |
|
|
101 |
// Move oldTaxon to newTaxon |
|
102 |
TaxonNameBase<?,?> synonymName = oldTaxon.getName(); |
|
103 |
if (synonymRelationshipType == null){ |
|
104 |
if (synonymName.isHomotypic(newAcceptedTaxon.getName())){ |
|
105 |
synonymRelationshipType = SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF(); |
|
106 |
}else{ |
|
107 |
synonymRelationshipType = SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF(); |
|
108 |
} |
|
109 |
} |
|
110 |
SynonymRelationship synonmyRelationship = newAcceptedTaxon.addSynonymName(synonymName, synonymRelationshipType, citation, citationMicroReference); |
|
111 |
|
|
112 |
//Move Synonym Relations to new Taxon |
|
113 |
for(SynonymRelationship synRelation : oldTaxon.getSynonymRelations()){ |
|
114 |
newAcceptedTaxon.addSynonym(synRelation.getSynonym(), synRelation.getType(), |
|
115 |
synRelation.getCitation(), synRelation.getCitationMicroReference()); |
|
116 |
} |
|
117 |
|
|
118 |
|
|
119 |
// CHILD NODES |
|
120 |
if(oldTaxonNode.getChildNodes() != null && oldTaxonNode.getChildNodes().size() != 0){ |
|
121 |
for(TaxonNode childNode : oldTaxonNode.getChildNodes()){ |
|
122 |
newAcceptedTaxonNode.addChildNode(childNode, childNode.getReference(), childNode.getMicroReference(), childNode.getSynonymToBeUsed()); |
|
123 |
} |
|
124 |
} |
|
125 |
|
|
126 |
//Move Taxon RelationShips to new Taxon |
|
127 |
Set<TaxonRelationship> obsoleteTaxonRelationships = new HashSet<TaxonRelationship>(); |
|
128 |
for(TaxonRelationship taxonRelationship : oldTaxon.getTaxonRelations()){ |
|
129 |
Taxon fromTaxon = (Taxon) HibernateProxyHelper.deproxy(taxonRelationship.getFromTaxon()); |
|
130 |
Taxon toTaxon = (Taxon) HibernateProxyHelper.deproxy(taxonRelationship.getToTaxon()); |
|
131 |
if (fromTaxon == oldTaxon){ |
|
132 |
newAcceptedTaxon.addTaxonRelation(taxonRelationship.getToTaxon(), taxonRelationship.getType(), |
|
133 |
taxonRelationship.getCitation(), taxonRelationship.getCitationMicroReference()); |
|
134 |
|
|
135 |
}else if(toTaxon == oldTaxon){ |
|
136 |
taxonRelationship.getFromTaxon().addTaxonRelation(newAcceptedTaxon, taxonRelationship.getType(), |
|
137 |
taxonRelationship.getCitation(), taxonRelationship.getCitationMicroReference()); |
|
138 |
|
|
139 |
}else{ |
|
140 |
logger.warn("Taxon is not part of its own Taxonrelationship"); |
|
141 |
} |
|
142 |
// Remove old relationships |
|
143 |
taxonRelationship.setToTaxon(null); |
|
144 |
taxonRelationship.setFromTaxon(null); |
|
145 |
} |
|
146 |
|
|
147 |
//Move descriptions to new taxon |
|
148 |
for(TaxonDescription description : oldTaxon.getDescriptions()){ |
|
149 |
description.setTitleCache("Description copied from former accepted taxon: " + oldTaxon.getTitleCache() + "(Old title: " + description.getTitleCache() + ")"); |
|
150 |
newAcceptedTaxon.addDescription(description); |
|
151 |
} |
|
152 |
|
|
153 |
oldTaxonNode.delete(); |
|
154 |
|
|
155 |
return synonmyRelationship.getSynonym(); |
|
156 |
} |
|
70 | 157 |
} |
Also available in: Unified diff
Refactoring of taxon business logic methods and started to write tests for these methods. The tests are far from finished.