Revision 531fc7bc
Added by Andreas Müller almost 8 years ago
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaTaxExport.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2007 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
... | ... | |
52 | 52 |
|
53 | 53 |
private static final String ROW_TYPE = "http://rs.tdwg.org/dwc/terms/Taxon"; |
54 | 54 |
private static final String fileName = "coreTax.txt"; |
55 |
|
|
55 |
|
|
56 | 56 |
/** |
57 |
*
|
|
57 |
* |
|
58 | 58 |
*/ |
59 | 59 |
public DwcaTaxExport() { |
60 | 60 |
super(); |
... | ... | |
64 | 64 |
/** Retrieves data from a CDM DB and serializes the CDM to XML. |
65 | 65 |
* Starts with root taxa and traverses the classification to retrieve children taxa, synonyms and relationships. |
66 | 66 |
* Taxa that are not part of the classification are not found. |
67 |
*
|
|
67 |
* |
|
68 | 68 |
* @param exImpConfig |
69 | 69 |
* @param dbname |
70 | 70 |
* @param filename |
... | ... | |
73 | 73 |
protected void doInvoke(DwcaTaxExportState state){ |
74 | 74 |
DwcaTaxExportConfigurator config = state.getConfig(); |
75 | 75 |
TransactionStatus txStatus = startTransaction(true); |
76 |
|
|
76 |
|
|
77 | 77 |
DwcaMetaDataRecord metaRecord = new DwcaMetaDataRecord(true, fileName, ROW_TYPE); |
78 | 78 |
state.addMetaRecord(metaRecord); |
79 |
|
|
79 |
|
|
80 | 80 |
Set<UUID> classificationUuidSet = config.getClassificationUuids(); |
81 | 81 |
List<Classification> classificationList = getClassificationService().find(classificationUuidSet); |
82 | 82 |
Set<Classification> classificationSet = new HashSet<Classification>(); |
83 | 83 |
classificationSet.addAll(classificationList); |
84 |
|
|
85 |
|
|
84 |
|
|
85 |
|
|
86 | 86 |
PrintWriter writer = null; |
87 | 87 |
try { |
88 |
|
|
88 |
|
|
89 | 89 |
writer = createPrintWriter(fileName, state); |
90 | 90 |
|
91 | 91 |
List<TaxonNode> allNodes = getAllNodes(classificationSet); |
... | ... | |
94 | 94 |
i++; |
95 | 95 |
Taxon taxon = CdmBase.deproxy(node.getTaxon(), Taxon.class); |
96 | 96 |
DwcaTaxRecord record = new DwcaTaxRecord(metaRecord, config); |
97 |
|
|
97 |
|
|
98 | 98 |
NonViralName<?> name = CdmBase.deproxy(taxon.getName(), NonViralName.class); |
99 | 99 |
Taxon parent = node.getParent() == null ? null : node.getParent().getTaxon(); |
100 | 100 |
TaxonNameBase<?, ?> basionym = name.getBasionym(); |
... | ... | |
104 | 104 |
record.write(writer); |
105 | 105 |
this.addExistingRecord(taxon); |
106 | 106 |
} |
107 |
|
|
107 |
|
|
108 | 108 |
node.getClassification().getName(); |
109 | 109 |
//synonyms |
110 | 110 |
handleSynonyms(taxon, writer, classification, metaRecord, config); |
111 |
|
|
111 |
|
|
112 | 112 |
//misapplied names |
113 | 113 |
handleMisapplication(taxon, writer, classification, metaRecord, config); |
114 |
|
|
114 |
|
|
115 | 115 |
writer.flush(); |
116 |
|
|
116 |
|
|
117 | 117 |
} |
118 | 118 |
} catch (FileNotFoundException e) { |
119 | 119 |
e.printStackTrace(); |
... | ... | |
129 | 129 |
} |
130 | 130 |
commitTransaction(txStatus); |
131 | 131 |
return; |
132 |
|
|
132 |
|
|
133 | 133 |
} |
134 | 134 |
|
135 | 135 |
private void handleSynonyms(Taxon taxon, PrintWriter writer, Classification classification, DwcaMetaDataRecord metaRecord, DwcaTaxExportConfigurator config) { |
... | ... | |
147 | 147 |
//???? |
148 | 148 |
Taxon parent = null; |
149 | 149 |
TaxonNameBase<?, ?> basionym = name.getBasionym(); |
150 |
|
|
150 |
|
|
151 | 151 |
if (! this.recordExists(synonym)){ |
152 | 152 |
handleTaxonBase(record, synonym, name, taxon, parent, basionym, classification, type, isProParte, isPartial, config); |
153 | 153 |
record.write(writer); |
154 | 154 |
this.addExistingRecord(synonym); |
155 | 155 |
} |
156 |
|
|
156 |
|
|
157 | 157 |
} |
158 |
|
|
158 |
|
|
159 | 159 |
} |
160 |
|
|
160 |
|
|
161 | 161 |
|
162 | 162 |
private void handleMisapplication(Taxon taxon, PrintWriter writer, Classification classification, DwcaMetaDataRecord metaRecord, DwcaTaxExportConfigurator config) { |
163 | 163 |
Set<Taxon> misappliedNames = taxon.getMisappliedNames(); |
... | ... | |
168 | 168 |
//???? |
169 | 169 |
Taxon parent = null; |
170 | 170 |
TaxonNameBase<?, ?> basionym = name.getBasionym(); |
171 |
|
|
171 |
|
|
172 | 172 |
if (! this.recordExists(misappliedName)){ |
173 | 173 |
handleTaxonBase(record, misappliedName, name, taxon, parent, basionym, classification, relType, false, false, config); |
174 | 174 |
record.write(writer); |
175 | 175 |
this.addExistingRecord(misappliedName); |
176 | 176 |
} |
177 |
}
|
|
177 |
} |
|
178 | 178 |
} |
179 | 179 |
|
180 | 180 |
/** |
... | ... | |
184 | 184 |
* @param acceptedTaxon |
185 | 185 |
* @param parent |
186 | 186 |
* @param basionym |
187 |
* @param isPartial
|
|
188 |
* @param isProParte
|
|
189 |
* @param config
|
|
187 |
* @param isPartial |
|
188 |
* @param isProParte |
|
189 |
* @param config |
|
190 | 190 |
* @param type |
191 | 191 |
*/ |
192 |
private void handleTaxonBase(DwcaTaxRecord record, TaxonBase<?> taxonBase, NonViralName<?> name,
|
|
193 |
Taxon acceptedTaxon, Taxon parent, TaxonNameBase<?, ?> basionym, Classification classification,
|
|
192 |
private void handleTaxonBase(DwcaTaxRecord record, TaxonBase<?> taxonBase, NonViralName<?> name, |
|
193 |
Taxon acceptedTaxon, Taxon parent, TaxonNameBase<?, ?> basionym, Classification classification, |
|
194 | 194 |
RelationshipTermBase<?> relType, boolean isProParte, boolean isPartial, DwcaTaxExportConfigurator config) { |
195 | 195 |
record.setId(taxonBase.getId()); |
196 | 196 |
record.setUuid(taxonBase.getUuid()); |
197 |
|
|
197 |
|
|
198 | 198 |
//maybe wrong as according to the DwC-A documentation only resolvable ids are allowed, this differs from DwC documentation |
199 | 199 |
record.setScientificNameId(name); |
200 | 200 |
record.setScientificName(name.getTitleCache()); |
201 |
|
|
201 |
|
|
202 | 202 |
record.setAcceptedNameUsageId(acceptedTaxon.getUuid()); |
203 | 203 |
record.setAcceptedNameUsage(acceptedTaxon.getName() == null? acceptedTaxon.getTitleCache() : acceptedTaxon.getName().getTitleCache()); |
204 |
|
|
204 |
|
|
205 | 205 |
//parentNameUsage |
206 | 206 |
if (parent != null){ |
207 | 207 |
record.setParentNameUsageId(parent.getUuid()); |
208 | 208 |
record.setParentNameUsage(parent.getTitleCache()); |
209 | 209 |
} |
210 |
|
|
210 |
|
|
211 | 211 |
//originalNameUsage |
212 | 212 |
// ??? - is not a name usage (concept) |
213 | 213 |
if (basionym != null){ |
... | ... | |
216 | 216 |
record.setOriginalNameUsageId(null); |
217 | 217 |
record.setOriginalNameUsage(basionym.getTitleCache()); |
218 | 218 |
} |
219 |
|
|
219 |
|
|
220 | 220 |
//nameAccordingTo |
221 |
Reference<?> sec = taxonBase.getSec();
|
|
221 |
Reference sec = taxonBase.getSec(); |
|
222 | 222 |
if (sec == null){ |
223 | 223 |
String message = "There is a taxon without sec " + taxonBase.getTitleCache() + "( " + taxonBase.getId() + ")"; |
224 | 224 |
logger.warn(message); |
... | ... | |
226 | 226 |
record.setNameAccordingToId(taxonBase.getSec().getUuid()); |
227 | 227 |
record.setNameAccordingTo(taxonBase.getSec().getTitleCache()); |
228 | 228 |
} |
229 |
|
|
229 |
|
|
230 | 230 |
//namePublishedIn |
231 | 231 |
// ??? is not a nameUsage (concept) |
232 | 232 |
if (name.getNomenclaturalReference() != null){ |
233 | 233 |
record.setNamePublishedInId(name.getNomenclaturalReference().getUuid()); |
234 | 234 |
record.setNamePublishedIn(name.getNomenclaturalReference() == null ? null : name.getNomenclaturalReference().getTitleCache()); |
235 | 235 |
} |
236 |
|
|
236 |
|
|
237 | 237 |
// what is the exact difference to id and acceptedNameUsageId |
238 | 238 |
record.setTaxonConceptId(taxonBase.getUuid()); |
239 |
|
|
239 |
|
|
240 | 240 |
//Classification |
241 | 241 |
if (config.isWithHigherClassification()){ |
242 | 242 |
//FIXME all classification and rank specific fields are meant to represent the classification |
... | ... | |
247 | 247 |
//... higher ranks |
248 | 248 |
handleUninomialOrGenus(record, name); |
249 | 249 |
if (name.getRank() != null && name.getRank().equals(Rank.SUBGENUS())){ |
250 |
record.setSubgenus(name.getNameCache());
|
|
250 |
record.setSubgenus(name.getNameCache()); |
|
251 | 251 |
} |
252 | 252 |
//record.setSubgenus(name.getInfraGenericEpithet()); |
253 | 253 |
} |
... | ... | |
257 | 257 |
record.setGenusPart(name.getGenusOrUninomial()); |
258 | 258 |
} |
259 | 259 |
record.setInfraGenericEpithet(name.getInfraGenericEpithet()); |
260 |
|
|
260 |
|
|
261 | 261 |
record.setSpecificEpithet(name.getSpecificEpithet()); |
262 | 262 |
record.setInfraspecificEpithet(name.getInfraSpecificEpithet()); |
263 |
|
|
263 |
|
|
264 | 264 |
record.setTaxonRank(name.getRank()); |
265 | 265 |
if (name.getRank() != null){ |
266 | 266 |
record.setVerbatimTaxonRank(name.getRank().getAbbreviation()); |
... | ... | |
268 | 268 |
String message = "No rank available for " + name.getTitleCache() + "(" + name.getId() + ")"; |
269 | 269 |
logger.warn(message); |
270 | 270 |
} |
271 |
|
|
271 |
|
|
272 | 272 |
record.setScientificNameAuthorship(name.getAuthorshipCache()); |
273 |
|
|
273 |
|
|
274 | 274 |
// ??? - use for TextData common names? |
275 | 275 |
record.setVernacularName(null); |
276 |
|
|
276 |
|
|
277 | 277 |
record.setNomenclaturalCode(name.getNomenclaturalCode()); |
278 | 278 |
// ??? TODO Misapplied Names, inferred synonyms |
279 | 279 |
handleTaxonomicStatus(record, name, relType, isProParte, isPartial); |
280 | 280 |
handleNomStatus(record, taxonBase, name); |
281 |
|
|
281 |
|
|
282 | 282 |
// TODO we need to differentiate technical |
283 | 283 |
String taxonRemarks = ""; |
284 | 284 |
for (Annotation annotation : taxonBase.getAnnotations()){ |
... | ... | |
294 | 294 |
if (StringUtils.isNotBlank(taxonRemarks)){ |
295 | 295 |
record.setTaxonRemarks(taxonRemarks); |
296 | 296 |
} |
297 |
|
|
297 |
|
|
298 | 298 |
// TODO which date is needed here (taxon, name, sec, ... ?) |
299 | 299 |
record.setModified(taxonBase.getUpdated()); |
300 |
|
|
300 |
|
|
301 | 301 |
// ??? |
302 | 302 |
record.setLanguage(null); |
303 |
|
|
303 |
|
|
304 | 304 |
record.setRights(taxonBase.getRights()); |
305 |
|
|
305 |
|
|
306 | 306 |
//TODO |
307 | 307 |
record.setRightsHolder(null); |
308 | 308 |
record.setAccessRights(null); |
309 |
|
|
309 |
|
|
310 | 310 |
//TODO currently only via default value |
311 | 311 |
record.setBibliographicCitation(null); |
312 | 312 |
record.setInformationWithheld(null); |
313 |
|
|
313 |
|
|
314 | 314 |
record.setDatasetId(classification); |
315 | 315 |
record.setDatasetName(classification.getTitleCache()); |
316 |
|
|
316 |
|
|
317 | 317 |
//TODO |
318 | 318 |
record.setSource(null); |
319 |
|
|
319 |
|
|
320 | 320 |
return; |
321 | 321 |
} |
322 | 322 |
|
... | ... | |
324 | 324 |
* @param record |
325 | 325 |
* @param name |
326 | 326 |
* @param type |
327 |
* @param isPartial
|
|
328 |
* @param isProParte
|
|
327 |
* @param isPartial |
|
328 |
* @param isProParte |
|
329 | 329 |
*/ |
330 | 330 |
private void handleTaxonomicStatus(DwcaTaxRecord record, |
331 | 331 |
NonViralName<?> name, RelationshipTermBase<?> type, boolean isProParte, boolean isPartial) { |
... | ... | |
347 | 347 |
logger.warn(message); |
348 | 348 |
status = "partialSynonym"; |
349 | 349 |
} |
350 |
|
|
350 |
|
|
351 | 351 |
record.setTaxonomicStatus(status); |
352 | 352 |
} |
353 | 353 |
} |
... | ... | |
363 | 363 |
Rank rank = name.getRank(); |
364 | 364 |
if (rank != null){ |
365 | 365 |
if (rank.isLower(Rank.GENUS())){ |
366 |
record.setGenus(firstEpi);
|
|
366 |
record.setGenus(firstEpi); |
|
367 | 367 |
}else if (rank.equals(Rank.GENUS())){ |
368 |
record.setGenus(firstEpi);
|
|
368 |
record.setGenus(firstEpi); |
|
369 | 369 |
}else if (rank.equals(Rank.KINGDOM())){ |
370 |
record.setKingdom(firstEpi);
|
|
370 |
record.setKingdom(firstEpi); |
|
371 | 371 |
}else if (rank.equals(Rank.PHYLUM())){ |
372 |
record.setPhylum(firstEpi);
|
|
372 |
record.setPhylum(firstEpi); |
|
373 | 373 |
}else if (rank.equals(Rank.CLASS())){ |
374 |
record.setClazz(firstEpi);
|
|
374 |
record.setClazz(firstEpi); |
|
375 | 375 |
}else if (rank.equals(Rank.ORDER())){ |
376 |
record.setOrder(firstEpi);
|
|
376 |
record.setOrder(firstEpi); |
|
377 | 377 |
}else if (rank.equals(Rank.FAMILY())){ |
378 |
record.setFamily(firstEpi);
|
|
378 |
record.setFamily(firstEpi); |
|
379 | 379 |
}else{ |
380 | 380 |
// !!! |
381 | 381 |
String message = "Rank not covered. Set uninomial as genus instead: " + rank.getLabel(); |
382 | 382 |
logger.warn(message); |
383 |
// record.setGenus(firstEpi);
|
|
384 |
}
|
|
385 |
|
|
383 |
// record.setGenus(firstEpi); |
|
384 |
} |
|
385 |
|
|
386 | 386 |
} |
387 | 387 |
} |
388 | 388 |
} |
... | ... | |
421 | 421 |
protected boolean isIgnore(DwcaTaxExportState state) { |
422 | 422 |
return ! state.getConfig().isDoTaxa(); |
423 | 423 |
} |
424 |
|
|
424 |
|
|
425 | 425 |
} |
Also available in: Unified diff
Remove generics from Reference in cdmlib (except for cdmlib-model) #5830