1 |
38e84b8e
|
Andreas Müller
|
/**
|
2 |
|
|
* Copyright (C) 2007 EDIT
|
3 |
51688d00
|
Andreas Müller
|
* European Distributed Institute of Taxonomy
|
4 |
38e84b8e
|
Andreas Müller
|
* http://www.e-taxonomy.eu
|
5 |
51688d00
|
Andreas Müller
|
*
|
6 |
38e84b8e
|
Andreas Müller
|
* 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.io.pesi.faunaEuropaea;
|
11 |
|
|
|
12 |
|
|
import java.util.Collection;
|
13 |
|
|
import java.util.HashSet;
|
14 |
|
|
import java.util.List;
|
15 |
|
|
import java.util.Set;
|
16 |
|
|
|
17 |
|
|
import org.apache.log4j.Logger;
|
18 |
|
|
import org.springframework.stereotype.Component;
|
19 |
|
|
import org.springframework.transaction.TransactionStatus;
|
20 |
|
|
|
21 |
|
|
import eu.etaxonomy.cdm.io.common.CdmImportBase;
|
22 |
|
|
import eu.etaxonomy.cdm.io.common.ICdmImport;
|
23 |
|
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
24 |
|
|
import eu.etaxonomy.cdm.model.name.NameRelationship;
|
25 |
51688d00
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
26 |
38e84b8e
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
27 |
|
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
28 |
|
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
29 |
|
|
|
30 |
|
|
/**
|
31 |
51688d00
|
Andreas Müller
|
* This class creates heterotypic synonymy relationships to the accepted taxon for
|
32 |
|
|
* basionym synonyms.
|
33 |
|
|
*
|
34 |
38e84b8e
|
Andreas Müller
|
* @author a.babadshanjan
|
35 |
|
|
* @created 22.09.2009
|
36 |
|
|
* @version 1.0
|
37 |
|
|
*/
|
38 |
|
|
@Component
|
39 |
|
|
public class FaunaEuropaeaHeterotypicSynonymImport extends CdmImportBase<FaunaEuropaeaImportConfigurator, FaunaEuropaeaImportState>
|
40 |
|
|
implements ICdmImport<FaunaEuropaeaImportConfigurator, FaunaEuropaeaImportState> {
|
41 |
|
|
private static final Logger logger = Logger
|
42 |
|
|
.getLogger(FaunaEuropaeaHeterotypicSynonymImport.class);
|
43 |
|
|
|
44 |
|
|
/* (non-Javadoc)
|
45 |
|
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IoStateBase)
|
46 |
|
|
*/
|
47 |
|
|
@Override
|
48 |
|
|
protected boolean doCheck(FaunaEuropaeaImportState state) {
|
49 |
|
|
logger.warn("Checking for heterotypic synonyms for basionyms not yet implemented");
|
50 |
|
|
return false;
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
/* (non-Javadoc)
|
54 |
|
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#doInvoke(eu.etaxonomy.cdm.io.common.IoStateBase)
|
55 |
|
|
*/
|
56 |
|
|
@Override
|
57 |
c59ecc4a
|
Andreas Müller
|
protected void doInvoke(FaunaEuropaeaImportState state) {
|
58 |
51688d00
|
Andreas Müller
|
|
59 |
38e84b8e
|
Andreas Müller
|
TransactionStatus txStatus = null;
|
60 |
|
|
List<Synonym> synonymList = null;
|
61 |
|
|
Set<Taxon> taxonSet = null;
|
62 |
|
|
int i = 0;
|
63 |
|
|
int start = 0;
|
64 |
|
|
|
65 |
|
|
int limit = state.getConfig().getLimitSave();
|
66 |
|
|
int nbrOfSynonyms = getTaxonService().count(Synonym.class);
|
67 |
|
|
if (logger.isInfoEnabled()) {
|
68 |
|
|
logger.info("Number of synonyms = " + nbrOfSynonyms);
|
69 |
|
|
}
|
70 |
a399b702
|
U-BGBM\k.luther
|
if(state.getConfig().isDoHeterotypicSynonyms()){
|
71 |
38e84b8e
|
Andreas Müller
|
while (i < nbrOfSynonyms) {
|
72 |
|
|
|
73 |
|
|
try {
|
74 |
|
|
if ((i++ % limit) == 0) {
|
75 |
|
|
|
76 |
|
|
start = (i == 1) ? 0 : i;
|
77 |
|
|
if (logger.isInfoEnabled()) {
|
78 |
|
|
logger.info("Retrieving synonyms starting from: " + start);
|
79 |
|
|
}
|
80 |
|
|
txStatus = startTransaction();
|
81 |
ba8ecd5d
|
Andreas Müller
|
synonymList = getTaxonService().list(Synonym.class, limit, start, null, null);
|
82 |
38e84b8e
|
Andreas Müller
|
taxonSet = new HashSet<Taxon>(limit);
|
83 |
|
|
}
|
84 |
|
|
|
85 |
51688d00
|
Andreas Müller
|
if (((i % limit) == 0 && i != 1 ) || i == nbrOfSynonyms) {
|
86 |
38e84b8e
|
Andreas Müller
|
|
87 |
|
|
HomotypicalGroup homotypicalGroup = null;
|
88 |
51688d00
|
Andreas Müller
|
Set<TaxonName> basionyms = null;
|
89 |
38e84b8e
|
Andreas Müller
|
Set<NameRelationship> nameRelations = null;
|
90 |
51688d00
|
Andreas Müller
|
TaxonName basionym = null;
|
91 |
|
|
Set<Taxon> taxonBases = null;
|
92 |
38e84b8e
|
Andreas Müller
|
Taxon acceptedTaxon = null;
|
93 |
51688d00
|
Andreas Müller
|
TaxonName synonymName = null;
|
94 |
38e84b8e
|
Andreas Müller
|
NameRelationship nameRelation = null;
|
95 |
51688d00
|
Andreas Müller
|
TaxonName acceptedName = null;
|
96 |
|
|
|
97 |
2d481abb
|
Katja Luther
|
for (TaxonBase synonym : synonymList) {
|
98 |
38e84b8e
|
Andreas Müller
|
synonymName = synonym.getName();
|
99 |
|
|
if (synonymName.isGroupsBasionym()) {
|
100 |
|
|
nameRelations = synonymName.getNameRelations();
|
101 |
|
|
if (nameRelations != null && nameRelations.iterator().hasNext()) {
|
102 |
|
|
nameRelation = nameRelations.iterator().next();
|
103 |
|
|
acceptedName = nameRelation.getToName();
|
104 |
78aaa6cb
|
Katja Luther
|
logger.debug("SynonymName: " + synonymName + " titleCache of synonym: "+synonym.getTitleCache() + " name of acceptedTaxon: " + acceptedName.getTitleCache());
|
105 |
38e84b8e
|
Andreas Müller
|
if (logger.isTraceEnabled()) {
|
106 |
|
|
logger.trace("toName: " + acceptedName);
|
107 |
|
|
logger.trace("fromName: " + nameRelation.getFromName());
|
108 |
|
|
}
|
109 |
|
|
taxonBases = acceptedName.getTaxa();
|
110 |
|
|
if (taxonBases != null && taxonBases.iterator().hasNext()) {
|
111 |
51688d00
|
Andreas Müller
|
acceptedTaxon = taxonBases.iterator().next();
|
112 |
38e84b8e
|
Andreas Müller
|
Set <Synonym> synonyms = acceptedTaxon.getSynonyms();
|
113 |
|
|
if (!synonyms.contains(synonym)){
|
114 |
|
|
//TODO: Achtung!!!!! dies wird auch bei homotypischen Synonymen aufgerufen! Dadurch wird ein weiteres Synonym erzeugt
|
115 |
|
|
acceptedTaxon.addHeterotypicSynonymName(synonymName);
|
116 |
|
|
taxonSet.add(acceptedTaxon);
|
117 |
|
|
}
|
118 |
|
|
}
|
119 |
|
|
}
|
120 |
|
|
}
|
121 |
|
|
}
|
122 |
51688d00
|
Andreas Müller
|
|
123 |
38e84b8e
|
Andreas Müller
|
getTaxonService().save((Collection)taxonSet);
|
124 |
|
|
taxonSet = null;
|
125 |
|
|
synonymList = null;
|
126 |
|
|
commitTransaction(txStatus);
|
127 |
51688d00
|
Andreas Müller
|
if(logger.isInfoEnabled()) {
|
128 |
|
|
logger.info("i = " + i + " - Transaction committed");
|
129 |
38e84b8e
|
Andreas Müller
|
}
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
} catch (Exception e) {
|
133 |
|
|
logger.warn("An exception occurred when creating heterotypic synonym relationship # " + i );
|
134 |
|
|
e.printStackTrace();
|
135 |
|
|
}
|
136 |
|
|
}
|
137 |
a399b702
|
U-BGBM\k.luther
|
}
|
138 |
c59ecc4a
|
Andreas Müller
|
return;
|
139 |
38e84b8e
|
Andreas Müller
|
}
|
140 |
|
|
|
141 |
|
|
/* (non-Javadoc)
|
142 |
|
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IoStateBase)
|
143 |
|
|
*/
|
144 |
|
|
@Override
|
145 |
|
|
protected boolean isIgnore(FaunaEuropaeaImportState state) {
|
146 |
|
|
return !(state.getConfig().isDoHeterotypicSynonymsForBasionyms());
|
147 |
|
|
}
|
148 |
c2c69eb8
|
Andreas Kohlbecker
|
}
|