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.indexFungorum;
|
11
|
|
12
|
import java.sql.ResultSet;
|
13
|
import java.util.HashMap;
|
14
|
import java.util.Map;
|
15
|
|
16
|
import org.apache.log4j.Logger;
|
17
|
import org.springframework.stereotype.Component;
|
18
|
import org.springframework.transaction.TransactionStatus;
|
19
|
|
20
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
21
|
import eu.etaxonomy.cdm.io.pesi.out.PesiTransformer;
|
22
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
23
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
24
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
25
|
import eu.etaxonomy.cdm.model.name.Rank;
|
26
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
27
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
28
|
|
29
|
|
30
|
/**
|
31
|
* @author a.mueller
|
32
|
* @created 27.02.2012
|
33
|
*/
|
34
|
@Component
|
35
|
public class IndexFungorumSupraGeneraImport extends IndexFungorumImportBase {
|
36
|
private static final Logger logger = Logger.getLogger(IndexFungorumSupraGeneraImport.class);
|
37
|
|
38
|
private static final String pluralString = "Supragenera";
|
39
|
private static final String dbTableName = "tblSupragenericNames";
|
40
|
|
41
|
public IndexFungorumSupraGeneraImport(){
|
42
|
super(pluralString, dbTableName, null);
|
43
|
}
|
44
|
|
45
|
|
46
|
@Override
|
47
|
protected String getRecordQuery(IndexFungorumImportConfigurator config) {
|
48
|
String strRecordQuery =
|
49
|
" SELECT * " +
|
50
|
" FROM [tblSupragenericNames] " +
|
51
|
// " WHERE ( dr.id IN (" + ID_LIST_TOKEN + ") )";
|
52
|
"";
|
53
|
return strRecordQuery;
|
54
|
}
|
55
|
|
56
|
|
57
|
@Override
|
58
|
protected void doInvoke(IndexFungorumImportState state) {
|
59
|
|
60
|
|
61
|
//handle source reference first
|
62
|
Reference sourceReference = state.getConfig().getSourceReference();
|
63
|
getReferenceService().save(sourceReference);
|
64
|
|
65
|
//query
|
66
|
String sql = getRecordQuery(state.getConfig());
|
67
|
ResultSet rs = state.getConfig().getSource().getResultSet(sql);
|
68
|
|
69
|
//transaction and related objects
|
70
|
TransactionStatus tx = startTransaction();
|
71
|
state.setRelatedObjects((Map)getRelatedObjectsForPartition(null, state));
|
72
|
sourceReference = state.getRelatedObject(NAMESPACE_REFERENCE, SOURCE_REFERENCE, Reference.class);
|
73
|
|
74
|
try {
|
75
|
while (rs.next()){
|
76
|
|
77
|
//TODO
|
78
|
//DisplayName, NomRefCache
|
79
|
|
80
|
Integer id = (Integer)rs.getObject("RECORD_NUMBER");
|
81
|
|
82
|
String supragenericNames = rs.getString("SupragenericNames");
|
83
|
String preferredName = rs.getString("PreferredName");
|
84
|
Integer rankFk = rs.getInt("PESI_RankFk");
|
85
|
|
86
|
//name
|
87
|
Rank rank = state.getTransformer().getRankByKey(String.valueOf(rankFk));
|
88
|
NonViralName<?> name = BotanicalName.NewInstance(rank);
|
89
|
name.setGenusOrUninomial(supragenericNames);
|
90
|
if (preferredName != null && !preferredName.equals(supragenericNames)){
|
91
|
logger.warn("Suprageneric names and preferredName is not equal. This case is not yet handled by IF import. I take SupragenericNames for import. RECORD_NUMBER" + CdmUtils.Nz(id));
|
92
|
}
|
93
|
|
94
|
//taxon
|
95
|
Taxon taxon = Taxon.NewInstance(name, sourceReference);
|
96
|
//author + nom.ref.
|
97
|
makeAuthorAndPublication(state, rs, name);
|
98
|
//source
|
99
|
makeSource(state, taxon, id, NAMESPACE_SUPRAGENERIC_NAMES );
|
100
|
|
101
|
getTaxonService().saveOrUpdate(taxon);
|
102
|
}
|
103
|
|
104
|
|
105
|
} catch (Exception e) {
|
106
|
e.printStackTrace();
|
107
|
logger.error(e.getMessage());
|
108
|
tx.setRollbackOnly();
|
109
|
state.setSuccess(false);
|
110
|
}
|
111
|
commitTransaction(tx);
|
112
|
return;
|
113
|
|
114
|
}
|
115
|
|
116
|
|
117
|
private Taxon makeTaxon(IndexFungorumImportState state, String uninomial, Rank rank) {
|
118
|
NonViralName<?> name = BotanicalName.NewInstance(rank);
|
119
|
name.setGenusOrUninomial(uninomial);
|
120
|
return Taxon.NewInstance(name, state.getConfig().getSourceReference());
|
121
|
}
|
122
|
|
123
|
|
124
|
@Override
|
125
|
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, IndexFungorumImportState state) {
|
126
|
HashMap<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String,? extends CdmBase>>(); //not needed here
|
127
|
|
128
|
//sourceReference
|
129
|
Reference<?> sourceReference = getReferenceService().find(PesiTransformer.uuidSourceRefIndexFungorum);
|
130
|
Map<String, Reference> referenceMap = new HashMap<String, Reference>();
|
131
|
referenceMap.put(SOURCE_REFERENCE, sourceReference);
|
132
|
result.put(NAMESPACE_REFERENCE, referenceMap);
|
133
|
|
134
|
return result;
|
135
|
}
|
136
|
|
137
|
@Override
|
138
|
protected boolean doCheck(IndexFungorumImportState state){
|
139
|
return true;
|
140
|
}
|
141
|
|
142
|
@Override
|
143
|
protected boolean isIgnore(IndexFungorumImportState state){
|
144
|
return ! state.getConfig().isDoTaxa();
|
145
|
}
|
146
|
|
147
|
|
148
|
|
149
|
|
150
|
|
151
|
}
|