Revision 008ae587
Added by Andreas Müller over 9 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/RoteListeDbTaxonImport.java | ||
---|---|---|
20 | 20 |
import org.apache.log4j.Logger; |
21 | 21 |
import org.springframework.stereotype.Component; |
22 | 22 |
|
23 |
import eu.etaxonomy.cdm.api.service.IClassificationService; |
|
24 | 23 |
import eu.etaxonomy.cdm.io.common.IOValidator; |
25 | 24 |
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner; |
26 |
import eu.etaxonomy.cdm.io.common.TdwgAreaProvider; |
|
27 | 25 |
import eu.etaxonomy.cdm.io.common.mapping.DbImportMapping; |
28 |
import eu.etaxonomy.cdm.io.common.mapping.DbImportTaxIncludedInMapper; |
|
29 | 26 |
import eu.etaxonomy.cdm.io.common.mapping.IMappingImport; |
30 | 27 |
import eu.etaxonomy.cdm.io.redlist.validation.RoteListeDbTaxonImportValidator; |
31 | 28 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
32 |
import eu.etaxonomy.cdm.model.description.Distribution; |
|
33 |
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm; |
|
34 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
|
35 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
|
36 | 29 |
import eu.etaxonomy.cdm.model.name.BotanicalName; |
37 | 30 |
import eu.etaxonomy.cdm.model.name.Rank; |
38 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
39 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
|
40 | 31 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
41 | 32 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
42 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
|
43 | 33 |
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl; |
44 | 34 |
|
45 | 35 |
|
46 | 36 |
/** |
37 |
* TODO do we still need this class? |
|
47 | 38 |
* @author a.mueller |
48 | 39 |
* @created 27.08.2012 |
49 | 40 |
*/ |
50 | 41 |
@Component |
51 | 42 |
public class RoteListeDbTaxonImport extends RoteListeDbImportBase<TaxonBase> implements IMappingImport<TaxonBase, RoteListeDbImportState>{ |
43 |
@SuppressWarnings("unused") |
|
52 | 44 |
private static final Logger logger = Logger.getLogger(RoteListeDbTaxonImport.class); |
53 | 45 |
|
54 | 46 |
private NonViralNameParserImpl parser = NonViralNameParserImpl.NewInstance(); |
... | ... | |
70 | 62 |
} |
71 | 63 |
|
72 | 64 |
|
73 |
|
|
74 |
/* (non-Javadoc) |
|
75 |
* @see eu.etaxonomy.cdm.io.erms.ErmsImportBase#getIdQuery() |
|
76 |
*/ |
|
77 | 65 |
@Override |
78 | 66 |
protected String getIdQuery() { |
79 | 67 |
String strQuery = " SELECT pk FROM " + dbTableName + |
... | ... | |
81 | 69 |
return strQuery; |
82 | 70 |
} |
83 | 71 |
|
84 |
|
|
85 |
/* (non-Javadoc) |
|
86 |
* @see eu.etaxonomy.cdm.io.erms.ErmsImportBase#getMapping() |
|
87 |
*/ |
|
72 |
@Override |
|
88 | 73 |
protected DbImportMapping getMapping() { |
89 | 74 |
if (mapping == null){ |
90 | 75 |
mapping = new DbImportMapping(); |
... | ... | |
99 | 84 |
return mapping; |
100 | 85 |
} |
101 | 86 |
|
102 |
/* (non-Javadoc) |
|
103 |
* @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#getRecordQuery(eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator) |
|
104 |
*/ |
|
105 | 87 |
@Override |
106 | 88 |
protected String getRecordQuery(RoteListeDbImportConfigurator config) { |
107 | 89 |
String strSelect = " SELECT * "; |
... | ... | |
114 | 96 |
|
115 | 97 |
@Override |
116 | 98 |
public boolean doPartition(ResultSetPartitioner partitioner, RoteListeDbImportState state) { |
117 |
// higherTaxonMap = new HashMap<UUID, Taxon>(); |
|
118 |
// Reference genevaReference = getReferenceService().find(state.getConfig().getUuidGenevaReference()); |
|
119 |
// if (genevaReference == null){ |
|
120 |
// genevaReference = makeGenevaReference(state); |
|
121 |
// getReferenceService().save(genevaReference); |
|
122 |
// } |
|
123 |
// state.setGenevaReference(genevaReference); |
|
124 | 99 |
boolean success = super.doPartition(partitioner, state); |
125 | 100 |
// higherTaxonMap = new HashMap<UUID, Taxon>(); |
126 | 101 |
// state.setGenevaReference(null); |
... | ... | |
212 | 187 |
// speciesTaxon.addSource(sourceId, REFERENCE_NAMESPACE, sourceRef, null); |
213 | 188 |
// |
214 | 189 |
// |
215 |
// //geneva id |
|
216 |
// Reference genevaReference = state.getGenevaReference(); |
|
217 |
// Object genevaId = rs.getObject("geneva_ID"); |
|
218 |
// speciesTaxon.addSource(String.valueOf(genevaId), null, genevaReference, null); |
|
219 |
// |
|
220 | 190 |
// //distribution |
221 | 191 |
// handleDistribution(rs, speciesTaxon); |
222 | 192 |
// |
... | ... | |
224 | 194 |
|
225 | 195 |
return null; |
226 | 196 |
} |
227 |
|
|
228 |
private void handleDistribution(ResultSet rs, Taxon speciesTaxon) throws SQLException { |
|
229 |
TaxonDescription description = TaxonDescription.NewInstance(speciesTaxon); |
|
230 |
|
|
231 |
Boolean isCongo = rs.getBoolean("drc"); |
|
232 |
Boolean isBurundi = rs.getBoolean("burundi"); |
|
233 |
Boolean isRwanda = rs.getBoolean("rwanda"); |
|
234 |
|
|
235 |
addDistribution(description, isCongo, "ZAI"); |
|
236 |
addDistribution(description, isBurundi, "BUR"); |
|
237 |
addDistribution(description, isRwanda, "RWA"); |
|
238 |
|
|
239 |
} |
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
/** |
|
244 |
* @param description |
|
245 |
* @param isCongo |
|
246 |
*/ |
|
247 |
private void addDistribution(TaxonDescription description, Boolean exists, String label) { |
|
248 |
if (exists == true){ |
|
249 |
NamedArea namedArea = TdwgAreaProvider.getAreaByTdwgAbbreviation(label); |
|
250 |
Distribution distribution = Distribution.NewInstance(namedArea, PresenceAbsenceTerm.PRESENT()); |
|
251 |
description.addElement(distribution); |
|
252 |
} |
|
253 |
} |
|
254 | 197 |
|
255 | 198 |
|
256 |
|
|
257 |
//TODO use Mapper |
|
258 |
private boolean makeTaxonomicallyIncluded(RoteListeDbImportState state, Integer treeRefFk, Taxon child, Taxon parent, Reference citation, String microCitation){ |
|
259 |
String treeKey; |
|
260 |
UUID treeUuid; |
|
261 |
if (treeRefFk == null){ |
|
262 |
treeKey = "1"; // there is only one tree and it gets the map key '1' |
|
263 |
treeUuid = state.getConfig().getClassificationUuid(); |
|
264 |
}else{ |
|
265 |
treeKey =String.valueOf(treeRefFk); |
|
266 |
treeUuid = state.getTreeUuidByTreeKey(treeKey); |
|
267 |
} |
|
268 |
Classification tree = (Classification)state.getRelatedObject(DbImportTaxIncludedInMapper.TAXONOMIC_TREE_NAMESPACE, treeKey); |
|
269 |
if (tree == null){ |
|
270 |
IClassificationService service = state.getCurrentIO().getClassificationService(); |
|
271 |
tree = service.find(treeUuid); |
|
272 |
if (tree == null){ |
|
273 |
String treeName = state.getConfig().getClassificationName(); |
|
274 |
tree = Classification.NewInstance(treeName); |
|
275 |
tree.setUuid(treeUuid); |
|
276 |
//FIXME tree reference |
|
277 |
//tree.setReference(ref); |
|
278 |
service.save(tree); |
|
279 |
} |
|
280 |
state.addRelatedObject(DbImportTaxIncludedInMapper.TAXONOMIC_TREE_NAMESPACE, treeKey, tree); |
|
281 |
} |
|
282 |
|
|
283 |
TaxonNode childNode = tree.addParentChild(parent, child, citation, microCitation); |
|
284 |
return (childNode != null); |
|
285 |
} |
|
286 |
|
|
287 |
|
|
288 |
// private Reference makeGenevaReference(RoteListeDbImportState state) { |
|
289 |
// Reference result = ReferenceFactory.newDatabase(); |
|
290 |
// result.setTitleCache(state.getConfig().getGenevaReferenceTitle(), true); |
|
291 |
// result.setUuid(state.getConfig().getUuidGenevaReference()); |
|
292 |
// return result; |
|
293 |
// } |
|
294 |
|
|
295 |
/* (non-Javadoc) |
|
296 |
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator) |
|
297 |
*/ |
|
298 | 199 |
@Override |
299 | 200 |
protected boolean doCheck(RoteListeDbImportState state){ |
300 | 201 |
IOValidator<RoteListeDbImportState> validator = new RoteListeDbTaxonImportValidator(); |
... | ... | |
302 | 203 |
} |
303 | 204 |
|
304 | 205 |
|
305 |
/* (non-Javadoc) |
|
306 |
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator) |
|
307 |
*/ |
|
206 |
@Override |
|
308 | 207 |
protected boolean isIgnore(RoteListeDbImportState state){ |
309 | 208 |
return ! state.getConfig().isDoTaxa(); |
310 | 209 |
} |
Also available in: Unified diff
cleanup RoteListeDbTaxonImport