3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.cdm
.io
.faunaEuropaea
;
13 import java
.util
.Collection
;
14 import java
.util
.HashSet
;
15 import java
.util
.List
;
18 import org
.apache
.log4j
.Logger
;
19 import org
.springframework
.stereotype
.Component
;
20 import org
.springframework
.transaction
.TransactionStatus
;
22 import eu
.etaxonomy
.cdm
.io
.common
.CdmImportBase
;
23 import eu
.etaxonomy
.cdm
.io
.common
.ICdmImport
;
24 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
25 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
26 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
32 * This class creates heterotypic synonymy relationships to the accepted taxon for
35 * @author a.babadshanjan
40 public class FaunaEuropaeaHeterotypicSynonymImport
extends CdmImportBase
<FaunaEuropaeaImportConfigurator
, FaunaEuropaeaImportState
>
41 implements ICdmImport
<FaunaEuropaeaImportConfigurator
, FaunaEuropaeaImportState
> {
42 private static final Logger logger
= Logger
43 .getLogger(FaunaEuropaeaHeterotypicSynonymImport
.class);
46 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IoStateBase)
49 protected boolean doCheck(FaunaEuropaeaImportState state
) {
50 logger
.warn("Checking for heterotypic synonyms for basionyms not yet implemented");
55 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doInvoke(eu.etaxonomy.cdm.io.common.IoStateBase)
58 protected boolean doInvoke(FaunaEuropaeaImportState state
) {
60 TransactionStatus txStatus
= null;
61 List
<Synonym
> synonymList
= null;
62 Set
<Taxon
> taxonSet
= null;
66 int limit
= state
.getConfig().getLimitSave();
67 int nbrOfSynonyms
= getTaxonService().count(Synonym
.class);
68 if (logger
.isInfoEnabled()) {
69 logger
.info("Number of synonyms = " + nbrOfSynonyms
);
72 while (i
< nbrOfSynonyms
) {
75 if ((i
++ % limit
) == 0) {
77 start
= (i
== 1) ?
0 : i
;
78 if (logger
.isInfoEnabled()) {
79 logger
.info("Retrieving synonyms starting from: " + start
);
81 txStatus
= startTransaction();
82 synonymList
= getTaxonService().getAllSynonyms(limit
, start
);
83 taxonSet
= new HashSet
<Taxon
>(limit
);
86 if (((i
% limit
) == 0 && i
!= 1 ) || i
== nbrOfSynonyms
) {
88 HomotypicalGroup homotypicalGroup
= null;
89 Set
<TaxonNameBase
> basionyms
= null;
90 Set
<NameRelationship
> nameRelations
= null;
91 TaxonNameBase basionym
= null;
92 Set
<TaxonBase
> taxonBases
= null;
93 TaxonBase taxonBase
= null;
94 Taxon acceptedTaxon
= null;
95 TaxonNameBase synonymName
= null;
96 NameRelationship nameRelation
= null;
97 TaxonNameBase acceptedName
= null;
99 for (Synonym synonym
: synonymList
) {
100 synonymName
= synonym
.getName();
101 if (synonymName
.isGroupsBasionym()) {
102 nameRelations
= synonymName
.getNameRelations();
103 if (nameRelations
!= null && nameRelations
.iterator().hasNext()) {
104 nameRelation
= nameRelations
.iterator().next();
105 acceptedName
= nameRelation
.getToName();
106 logger
.info("SynonymName: " + synonymName
+ " titleCache of synonym: "+synonym
.getTitleCache() + " name of acceptedTaxon: " + acceptedName
.getTitleCache());
107 if (logger
.isTraceEnabled()) {
108 logger
.trace("toName: " + acceptedName
);
109 logger
.trace("fromName: " + nameRelation
.getFromName());
111 taxonBases
= acceptedName
.getTaxa();
112 if (taxonBases
!= null && taxonBases
.iterator().hasNext()) {
113 taxonBase
= taxonBases
.iterator().next();
114 acceptedTaxon
= taxonBase
.deproxy(taxonBase
, Taxon
.class);
115 Set
<Synonym
> synonyms
= acceptedTaxon
.getSynonyms();
116 if (!synonyms
.contains(synonym
)){
117 //TODO: Achtung!!!!! dies wird auch bei homotypischen Synonymen aufgerufen! Dadurch wird ein weiteres Synonym erzeugt
118 acceptedTaxon
.addHeterotypicSynonymName(synonymName
);
119 taxonSet
.add(acceptedTaxon
);
126 getTaxonService().save((Collection
)taxonSet
);
129 commitTransaction(txStatus
);
130 if(logger
.isInfoEnabled()) {
131 logger
.info("i = " + i
+ " - Transaction committed");
135 } catch (Exception e
) {
136 logger
.warn("An exception occurred when creating heterotypic synonym relationship # " + i
);
144 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IoStateBase)
147 protected boolean isIgnore(FaunaEuropaeaImportState state
) {
148 return !(state
.getConfig().isDoHeterotypicSynonymsForBasionyms());