2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.api
.service
;
12 import org
.apache
.log4j
.Logger
;
13 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
14 import org
.springframework
.stereotype
.Service
;
15 import org
.springframework
.transaction
.TransactionStatus
;
16 import org
.springframework
.transaction
.annotation
.Transactional
;
18 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipBase
;
19 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
20 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
21 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationship
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
29 import eu
.etaxonomy
.cdm
.persistence
.dao
.taxon
.ITaxonDao
;
30 import eu
.etaxonomy
.cdm
.persistence
.fetch
.CdmFetch
;
32 import java
.util
.Collection
;
33 import java
.util
.List
;
35 import java
.util
.UUID
;
39 @Transactional(readOnly
= true)
40 public class TaxonServiceImpl
extends ServiceBase
<TaxonBase
> implements ITaxonService
{
41 static Logger logger
= Logger
.getLogger(TaxonServiceImpl
.class);
43 private ITaxonDao taxonDao
;
46 protected void setDao(ITaxonDao dao
) {
51 public TaxonBase
getTaxonByUuid(UUID uuid
) {
52 return super.getCdmObjectByUuid(uuid
);
55 @Transactional(readOnly
= false)
56 public UUID
saveTaxon(TaxonBase taxon
) {
57 return super.saveCdmObject(taxon
);
60 //@Transactional(readOnly = false)
61 public UUID
saveTaxon(TaxonBase taxon
, TransactionStatus txStatus
) {
63 return super.saveCdmObject(taxon
);
67 @Transactional(readOnly
= false)
68 public Map
<UUID
, ?
extends TaxonBase
> saveTaxonAll(Collection
<?
extends TaxonBase
> taxonCollection
){
69 return saveCdmObjectAll(taxonCollection
);
72 @Transactional(readOnly
= false)
73 public UUID
removeTaxon(TaxonBase taxon
) {
74 return super.removeCdmObject(taxon
);
77 public List
<TaxonBase
> searchTaxaByName(String name
, ReferenceBase sec
) {
78 return taxonDao
.getTaxaByName(name
, sec
);
81 public List
<TaxonBase
> getAllTaxa(int limit
, int start
){
82 return taxonDao
.list(limit
, start
);
85 public List
<Synonym
> getAllSynonyms(int limit
, int start
) {
86 return taxonDao
.getAllSynonyms(limit
, start
);
90 * @see eu.etaxonomy.cdm.api.service.ITaxonService#getRootTaxa(eu.etaxonomy.cdm.model.reference.ReferenceBase)
92 public List
<Taxon
> getRootTaxa(ReferenceBase sec
){
93 return getRootTaxa(sec
, CdmFetch
.FETCH_CHILDTAXA(), true);
97 * @see eu.etaxonomy.cdm.api.service.ITaxonService#getRootTaxa(eu.etaxonomy.cdm.model.reference.ReferenceBase, boolean)
99 public List
<Taxon
> getRootTaxa(ReferenceBase sec
, CdmFetch cdmFetch
, boolean onlyWithChildren
) {
100 if (cdmFetch
== null){
101 cdmFetch
= CdmFetch
.NO_FETCH();
103 return taxonDao
.getRootTaxa(sec
, cdmFetch
, onlyWithChildren
);
106 public List
<RelationshipBase
> getAllRelationships(int limit
, int start
){
107 return taxonDao
.getAllRelationships(limit
, start
);
111 * @see eu.etaxonomy.cdm.api.service.ITaxonService#makeTaxonSynonym(eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.model.taxon.Taxon)
113 @Transactional(readOnly
= false)
114 public Synonym
makeTaxonSynonym(Taxon oldTaxon
, Taxon newAcceptedTaxon
, SynonymRelationshipType synonymType
, ReferenceBase citation
, String citationMicroReference
) {
115 if (oldTaxon
== null || newAcceptedTaxon
== null || oldTaxon
.getName() == null){
119 // Move oldTaxon to newTaxon
120 TaxonNameBase synonymName
= oldTaxon
.getName();
121 if (synonymType
== null){
122 if (synonymName
.isHomotypic(newAcceptedTaxon
.getName())){
123 synonymType
= SynonymRelationshipType
.HOMOTYPIC_SYNONYM_OF();
126 synonymType
= SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF();
129 SynonymRelationship synRel
= newAcceptedTaxon
.addSynonymName(synonymName
, synonymType
, citation
, citationMicroReference
);
131 //Move Synonym Relations to new Taxon
132 for(SynonymRelationship synRelation
: oldTaxon
.getSynonymRelations()){
133 //TODO citation and microcitation
134 newAcceptedTaxon
.addSynonym(synRelation
.getSynonym(), synRelation
.getType(), null, null);
137 //Move Taxon RelationShips to new Taxon
138 for(TaxonRelationship taxonRelation
: oldTaxon
.getTaxonRelations()){
140 if (taxonRelation
.getType().equals(TaxonRelationshipType
.TAXONOMICALLY_INCLUDED_IN())){
141 if (taxonRelation
.getFromTaxon() == oldTaxon
){
142 oldTaxon
.removeTaxonRelation(taxonRelation
);
143 }else if(taxonRelation
.getToTaxon() == oldTaxon
){
144 newAcceptedTaxon
.addTaxonomicChild(taxonRelation
.getFromTaxon(), taxonRelation
.getCitation(), taxonRelation
.getCitationMicroReference());
145 oldTaxon
.removeTaxonRelation(taxonRelation
);
147 logger
.warn("Taxon is not part of its own Taxonrelationship");
151 if (taxonRelation
.getType().equals(TaxonRelationshipType
.MISAPPLIED_NAME_FOR())){
152 if (taxonRelation
.getFromTaxon() == oldTaxon
){
153 newAcceptedTaxon
.addMisappliedName(taxonRelation
.getToTaxon(), taxonRelation
.getCitation(), taxonRelation
.getCitationMicroReference());
154 oldTaxon
.removeTaxonRelation(taxonRelation
);
155 }else if(taxonRelation
.getToTaxon() == oldTaxon
){
156 newAcceptedTaxon
.addMisappliedName(taxonRelation
.getFromTaxon(), taxonRelation
.getCitation(), taxonRelation
.getCitationMicroReference());
157 oldTaxon
.removeTaxonRelation(taxonRelation
);
159 logger
.warn("Taxon is not part of its own Taxonrelationship");
162 //Concept Relationships
164 // if (taxonRelation.getType().equals(TaxonRelationshipType.MISAPPLIEDNAMEFOR())){
165 // if (taxonRelation.getFromTaxon() == oldTaxon){
166 // newAcceptedTaxon.addMisappliedName(taxonRelation.getToTaxon(), taxonRelation.getCitation(), taxonRelation.getCitationMicroReference());
167 // oldTaxon.removeTaxonRelation(taxonRelation);
168 // }else if(taxonRelation.getToTaxon() == oldTaxon){
169 // newAcceptedTaxon.addMisappliedName(taxonRelation.getFromTaxon(), taxonRelation.getCitation(), taxonRelation.getCitationMicroReference());
170 // oldTaxon.removeTaxonRelation(taxonRelation);
172 // logger.warn("Taxon is not part of its own Taxonrelationship");
177 //Move Descriptions to new Taxon
178 for(TaxonDescription taxDescription
: oldTaxon
.getDescriptions()){
179 newAcceptedTaxon
.addDescription(taxDescription
);
182 this.dao
.saveOrUpdate(newAcceptedTaxon
);
184 this.dao
.delete(oldTaxon
);
188 return synRel
.getSynonym();
192 public void generateTitleCache() {
193 generateTitleCache(true);
196 public void generateTitleCache(boolean forceProtected
) {
197 logger
.warn("generateTitleCache not yet fully implemented!");
198 // for (TaxonBase tb : taxonDao.getAllTaxa(null,null)){
199 // logger.warn("Old taxon title: " + tb.getTitleCache());
200 // if (forceProtected || !tb.isProtectedTitleCache() ){
201 // tb.setTitleCache(tb.generateTitle(), false);
202 // taxonDao.update(tb);
203 // logger.warn("New title: " + tb.getTitleCache());