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.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.NameRelationship;
|
24
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
25
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
26
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
27
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
28
|
|
29
|
/**
|
30
|
* This class creates heterotypic synonymy relationships to the accepted taxon for
|
31
|
* basionym synonyms.
|
32
|
*
|
33
|
* @author a.babadshanjan
|
34
|
* @since 22.09.2009
|
35
|
*/
|
36
|
@Component
|
37
|
public class FaunaEuropaeaHeterotypicSynonymImport
|
38
|
extends CdmImportBase<FaunaEuropaeaImportConfigurator, FaunaEuropaeaImportState>
|
39
|
implements ICdmImport<FaunaEuropaeaImportConfigurator, FaunaEuropaeaImportState> {
|
40
|
|
41
|
private static final long serialVersionUID = -4195183108743873247L;
|
42
|
private static final Logger logger = Logger.getLogger(FaunaEuropaeaHeterotypicSynonymImport.class);
|
43
|
|
44
|
@Override
|
45
|
protected boolean doCheck(FaunaEuropaeaImportState state) {
|
46
|
logger.warn("Checking for heterotypic synonyms for basionyms not yet implemented");
|
47
|
return false;
|
48
|
}
|
49
|
|
50
|
@Override
|
51
|
protected void doInvoke(FaunaEuropaeaImportState state) {
|
52
|
|
53
|
TransactionStatus txStatus = null;
|
54
|
List<Synonym> synonymList = null;
|
55
|
Set<Taxon> taxonSet = null;
|
56
|
int i = 0;
|
57
|
int start = 0;
|
58
|
|
59
|
int limit = state.getConfig().getLimitSave();
|
60
|
int nbrOfSynonyms = getTaxonService().count(Synonym.class);
|
61
|
if (logger.isInfoEnabled()) {
|
62
|
logger.info("Number of synonyms = " + nbrOfSynonyms);
|
63
|
}
|
64
|
if(state.getConfig().isDoHeterotypicSynonyms()){
|
65
|
while (i < nbrOfSynonyms) {
|
66
|
|
67
|
try {
|
68
|
if ((i++ % limit) == 0) {
|
69
|
|
70
|
start = (i == 1) ? 0 : i;
|
71
|
if (logger.isInfoEnabled()) {
|
72
|
logger.info("Retrieving synonyms starting from: " + start);
|
73
|
}
|
74
|
txStatus = startTransaction();
|
75
|
synonymList = getTaxonService().list(Synonym.class, limit, start, null, null);
|
76
|
taxonSet = new HashSet<Taxon>(limit);
|
77
|
}
|
78
|
|
79
|
if (((i % limit) == 0 && i != 1 ) || i == nbrOfSynonyms) {
|
80
|
|
81
|
Set<NameRelationship> nameRelations = null;
|
82
|
Set<Taxon> taxonBases = null;
|
83
|
Taxon acceptedTaxon = null;
|
84
|
TaxonName synonymName = null;
|
85
|
NameRelationship nameRelation = null;
|
86
|
TaxonName acceptedName = null;
|
87
|
|
88
|
for (TaxonBase<?> synonym : synonymList) {
|
89
|
synonymName = synonym.getName();
|
90
|
if (synonymName.isGroupsBasionym()) {
|
91
|
nameRelations = synonymName.getNameRelations();
|
92
|
if (nameRelations != null && nameRelations.iterator().hasNext()) {
|
93
|
nameRelation = nameRelations.iterator().next();
|
94
|
acceptedName = nameRelation.getToName();
|
95
|
logger.debug("SynonymName: " + synonymName + " titleCache of synonym: "+synonym.getTitleCache() + " name of acceptedTaxon: " + acceptedName.getTitleCache());
|
96
|
if (logger.isTraceEnabled()) {
|
97
|
logger.trace("toName: " + acceptedName);
|
98
|
logger.trace("fromName: " + nameRelation.getFromName());
|
99
|
}
|
100
|
taxonBases = acceptedName.getTaxa();
|
101
|
if (taxonBases != null && taxonBases.iterator().hasNext()) {
|
102
|
acceptedTaxon = taxonBases.iterator().next();
|
103
|
Set <Synonym> synonyms = acceptedTaxon.getSynonyms();
|
104
|
if (!synonyms.contains(synonym)){
|
105
|
//TODO: Achtung!!!!! dies wird auch bei homotypischen Synonymen aufgerufen! Dadurch wird ein weiteres Synonym erzeugt
|
106
|
acceptedTaxon.addHeterotypicSynonymName(synonymName);
|
107
|
taxonSet.add(acceptedTaxon);
|
108
|
}
|
109
|
}
|
110
|
}
|
111
|
}
|
112
|
}
|
113
|
|
114
|
getTaxonService().save((Collection)taxonSet);
|
115
|
taxonSet = null;
|
116
|
synonymList = null;
|
117
|
commitTransaction(txStatus);
|
118
|
if(logger.isInfoEnabled()) {
|
119
|
logger.info("i = " + i + " - Transaction committed");
|
120
|
}
|
121
|
}
|
122
|
|
123
|
} catch (Exception e) {
|
124
|
logger.warn("An exception occurred when creating heterotypic synonym relationship # " + i );
|
125
|
e.printStackTrace();
|
126
|
}
|
127
|
}
|
128
|
}
|
129
|
return;
|
130
|
}
|
131
|
|
132
|
@Override
|
133
|
protected boolean isIgnore(FaunaEuropaeaImportState state) {
|
134
|
return !(state.getConfig().isDoHeterotypicSynonymsForBasionyms());
|
135
|
}
|
136
|
}
|