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.redlist;
|
11
|
|
12
|
import java.sql.ResultSet;
|
13
|
import java.sql.SQLException;
|
14
|
import java.util.HashMap;
|
15
|
import java.util.HashSet;
|
16
|
import java.util.Map;
|
17
|
import java.util.Set;
|
18
|
import java.util.UUID;
|
19
|
|
20
|
import org.apache.log4j.Logger;
|
21
|
import org.springframework.stereotype.Component;
|
22
|
|
23
|
import eu.etaxonomy.cdm.io.common.IOValidator;
|
24
|
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
|
25
|
import eu.etaxonomy.cdm.io.common.mapping.DbImportMapping;
|
26
|
import eu.etaxonomy.cdm.io.common.mapping.IMappingImport;
|
27
|
import eu.etaxonomy.cdm.io.redlist.validation.RoteListeDbTaxonImportValidator;
|
28
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
29
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
30
|
import eu.etaxonomy.cdm.model.name.Rank;
|
31
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
32
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
33
|
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
|
34
|
|
35
|
|
36
|
/**
|
37
|
* TODO do we still need this class?
|
38
|
* @author a.mueller
|
39
|
* @created 27.08.2012
|
40
|
*/
|
41
|
@Component
|
42
|
public class RoteListeDbTaxonImport extends RoteListeDbImportBase<TaxonBase> implements IMappingImport<TaxonBase, RoteListeDbImportState>{
|
43
|
@SuppressWarnings("unused")
|
44
|
private static final Logger logger = Logger.getLogger(RoteListeDbTaxonImport.class);
|
45
|
|
46
|
private NonViralNameParserImpl parser = NonViralNameParserImpl.NewInstance();
|
47
|
|
48
|
private Map<UUID, Taxon> higherTaxonMap;
|
49
|
|
50
|
private Integer TREE_ID = null;
|
51
|
|
52
|
private DbImportMapping mapping;
|
53
|
|
54
|
private int modCount = 10000;
|
55
|
private static final String pluralString = "taxa";
|
56
|
private static final String dbTableName = "checklist";
|
57
|
private static final Class cdmTargetClass = TaxonBase.class;
|
58
|
private static final String strOrderBy = " ORDER BY family, genus, species ";
|
59
|
|
60
|
public RoteListeDbTaxonImport(){
|
61
|
super(pluralString, dbTableName, cdmTargetClass);
|
62
|
}
|
63
|
|
64
|
|
65
|
@Override
|
66
|
protected String getIdQuery() {
|
67
|
String strQuery = " SELECT pk FROM " + dbTableName +
|
68
|
strOrderBy;
|
69
|
return strQuery;
|
70
|
}
|
71
|
|
72
|
@Override
|
73
|
protected DbImportMapping getMapping() {
|
74
|
if (mapping == null){
|
75
|
mapping = new DbImportMapping();
|
76
|
|
77
|
// mapping.addMapper(DbImportObjectCreationMapper.NewInstance(this, "pk", TAXON_NAMESPACE)); //id + tu_status
|
78
|
//
|
79
|
// UUID uuidKew = RoteListeDbTransformer.uuidAcceptedKew;
|
80
|
// mapping.addMapper(DbImportMarkerMapper.NewInstance("accepted kew", uuidKew, "Accepted Kew", "Accepted Kew", "Kew", null));
|
81
|
|
82
|
}
|
83
|
|
84
|
return mapping;
|
85
|
}
|
86
|
|
87
|
@Override
|
88
|
protected String getRecordQuery(RoteListeDbImportConfigurator config) {
|
89
|
String strSelect = " SELECT * ";
|
90
|
String strFrom = " FROM checklist";
|
91
|
String strWhere = " WHERE ( pk IN (" + ID_LIST_TOKEN + ") )";
|
92
|
String strRecordQuery = strSelect + strFrom + strWhere + strOrderBy;
|
93
|
return strRecordQuery;
|
94
|
}
|
95
|
|
96
|
|
97
|
@Override
|
98
|
public boolean doPartition(ResultSetPartitioner partitioner, RoteListeDbImportState state) {
|
99
|
boolean success = super.doPartition(partitioner, state);
|
100
|
// higherTaxonMap = new HashMap<UUID, Taxon>();
|
101
|
// state.setGenevaReference(null);
|
102
|
return success;
|
103
|
}
|
104
|
|
105
|
|
106
|
@Override
|
107
|
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, RoteListeDbImportState state) {
|
108
|
String nameSpace;
|
109
|
Class<?> cdmClass;
|
110
|
Set<String> idSet;
|
111
|
Set<String> referenceIdSet = new HashSet<String>();
|
112
|
|
113
|
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>();
|
114
|
|
115
|
try{
|
116
|
while (rs.next()){
|
117
|
handleForeignKey(rs, referenceIdSet, "source");
|
118
|
}
|
119
|
|
120
|
// //reference map
|
121
|
// nameSpace = REFERENCE_NAMESPACE;
|
122
|
// cdmClass = Reference.class;
|
123
|
// idSet = referenceIdSet;
|
124
|
// Map<String, Reference> referenceMap = (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, referenceIdSet, nameSpace);
|
125
|
// result.put(REFERENCE_NAMESPACE, referenceMap);
|
126
|
|
127
|
} catch (SQLException e) {
|
128
|
throw new RuntimeException(e);
|
129
|
}
|
130
|
return result;
|
131
|
}
|
132
|
|
133
|
|
134
|
@Override
|
135
|
public TaxonBase createObject(ResultSet rs, RoteListeDbImportState state) throws SQLException {
|
136
|
BotanicalName speciesName = BotanicalName.NewInstance(Rank.SPECIES());
|
137
|
|
138
|
// Reference sec = state.getConfig().getSourceReference();
|
139
|
// getReferenceService().saveOrUpdate(sec);
|
140
|
//
|
141
|
// String familyString = rs.getString("family");
|
142
|
// String genusString = rs.getString("genus");
|
143
|
// String speciesString = rs.getString("species");
|
144
|
// String authorityString = rs.getString("authority");
|
145
|
//
|
146
|
// if (logger.isDebugEnabled()){
|
147
|
// System.out.println(familyString + " " + genusString + " " + speciesString);
|
148
|
// }
|
149
|
//
|
150
|
// Taxon speciesTaxon = Taxon.NewInstance(speciesName, sec);;
|
151
|
// speciesName.setGenusOrUninomial(genusString);
|
152
|
// speciesName.setSpecificEpithet(speciesString);
|
153
|
// parser.handleAuthors(speciesName, CdmUtils.concat(" ", new String[] {"", genusString, speciesString, authorityString}), authorityString);
|
154
|
//
|
155
|
// //family
|
156
|
// Taxon familyTaxon = null;
|
157
|
// if (StringUtils.isNotBlank(familyString)){
|
158
|
// familyTaxon = getHigherTaxon(state, familyString, null);
|
159
|
// if (familyTaxon == null){
|
160
|
// BotanicalName familyName = BotanicalName.NewInstance(Rank.FAMILY());
|
161
|
// familyName.setGenusOrUninomial(familyString);
|
162
|
// familyTaxon = Taxon.NewInstance(familyName, sec);
|
163
|
// saveHigherTaxon(state, familyTaxon, familyString, null);
|
164
|
// }
|
165
|
// getTaxonService().saveOrUpdate(familyTaxon);
|
166
|
// }
|
167
|
//
|
168
|
//
|
169
|
// //genus
|
170
|
// Taxon genusTaxon = getHigherTaxon(state, familyString, genusString);
|
171
|
// if (genusTaxon == null){
|
172
|
// BotanicalName genusName = BotanicalName.NewInstance(Rank.GENUS());
|
173
|
// genusName.setGenusOrUninomial(genusString);
|
174
|
// genusTaxon = Taxon.NewInstance(genusName, sec);
|
175
|
// saveHigherTaxon(state, genusTaxon, familyString, genusString);
|
176
|
// if (familyTaxon != null){
|
177
|
// makeTaxonomicallyIncluded(state, TREE_ID, genusTaxon, familyTaxon, null, null);
|
178
|
// }
|
179
|
// }
|
180
|
// makeTaxonomicallyIncluded(state, TREE_ID, speciesTaxon, genusTaxon, null, null);
|
181
|
// getTaxonService().saveOrUpdate(genusTaxon);
|
182
|
//
|
183
|
// String sourceString = rs.getString("source");
|
184
|
// String sourceId = rs.getString("source_id");
|
185
|
//
|
186
|
// Reference sourceRef = state.getRelatedObject(REFERENCE_NAMESPACE, sourceString, Reference.class);
|
187
|
// speciesTaxon.addSource(sourceId, REFERENCE_NAMESPACE, sourceRef, null);
|
188
|
//
|
189
|
//
|
190
|
// //distribution
|
191
|
// handleDistribution(rs, speciesTaxon);
|
192
|
//
|
193
|
// return speciesTaxon;
|
194
|
|
195
|
return null;
|
196
|
}
|
197
|
|
198
|
|
199
|
@Override
|
200
|
protected boolean doCheck(RoteListeDbImportState state){
|
201
|
IOValidator<RoteListeDbImportState> validator = new RoteListeDbTaxonImportValidator();
|
202
|
return validator.validate(state);
|
203
|
}
|
204
|
|
205
|
|
206
|
@Override
|
207
|
protected boolean isIgnore(RoteListeDbImportState state){
|
208
|
return ! state.getConfig().isDoTaxa();
|
209
|
}
|
210
|
|
211
|
|
212
|
|
213
|
}
|