Revision 39d481af
Added by Andreas Müller over 4 years ago
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/out/PesiTaxonExport.java | ||
---|---|---|
251 | 251 |
private boolean doPhase01(PesiExportState state, PesiExportMapping mapping, PesiExportMapping additionalSourceMapping){ |
252 | 252 |
int count = 0; |
253 | 253 |
int pastCount = 0; |
254 |
List<TaxonBase> list; |
|
255 | 254 |
boolean success = true; |
256 | 255 |
// Get the limit for objects to save within a single transaction. |
257 | 256 |
int limit = state.getConfig().getLimitSave(); |
... | ... | |
266 | 265 |
} |
267 | 266 |
|
268 | 267 |
int partitionCount = 0; |
268 |
List<TaxonBase<?>> list; |
|
269 | 269 |
while ((list = getNextTaxonPartition(null, limit, partitionCount++, null)) != null ) { |
270 | 270 |
|
271 | 271 |
logger.debug("Fetched " + list.size() + " " + pluralString + ". Exporting..."); |
... | ... | |
275 | 275 |
TaxonName taxonName = taxon.getName(); |
276 | 276 |
|
277 | 277 |
TaxonName nvn = CdmBase.deproxy(taxonName); |
278 |
// System.err.println(nvn.getTitleCache()); |
|
279 | 278 |
if (! nvn.isProtectedTitleCache()){ |
280 | 279 |
nvn.setTitleCache(null, false); |
281 | 280 |
} |
... | ... | |
315 | 314 |
|
316 | 315 |
// Commit transaction |
317 | 316 |
commitTransaction(txStatus); |
318 |
logger.debug("Committed transaction."); |
|
319 | 317 |
logger.info("Exported " + (count - pastCount) + " " + pluralString + ". Total: " + count + " (Phase 01)"); |
320 | 318 |
pastCount = count; |
321 |
/*logger.warn("Taking snapshot at the end of the loop of phase 1 of taxonExport"); |
|
322 |
//ProfilerController.memorySnapshot(); |
|
323 |
*/ |
|
324 |
// Start transaction |
|
319 |
|
|
320 |
// Start new transaction |
|
325 | 321 |
txStatus = startTransaction(true); |
326 | 322 |
if (logger.isDebugEnabled()) { |
327 | 323 |
logger.info("Started new transaction. Fetching some " + pluralString + " (max: " + limit + ") ..."); |
328 | 324 |
} |
329 | 325 |
|
330 | 326 |
} |
331 |
logger.info("No " + pluralString + " left to fetch.");
|
|
327 |
logger.debug("No " + pluralString + " left to fetch.");
|
|
332 | 328 |
|
333 | 329 |
// Commit transaction |
334 | 330 |
commitTransaction(txStatus); |
335 | 331 |
txStatus = null; |
336 |
logger.debug("Committed transaction."); |
|
337 |
if (logger.isDebugEnabled()){ |
|
338 |
logger.debug("Taking snapshot at the end of phase 1 of taxonExport"); |
|
339 |
// ProfilerController.memorySnapshot(); |
|
340 |
} |
|
332 |
|
|
341 | 333 |
return success; |
342 | 334 |
} |
343 | 335 |
|
344 |
|
|
345 | 336 |
private void validatePhaseOne(TaxonBase<?> taxon, TaxonName taxonName) { |
346 | 337 |
|
347 | 338 |
// Check whether some rules are violated |
... | ... | |
404 | 395 |
|
405 | 396 |
/** |
406 | 397 |
* 2nd Round: Add ParentTaxonFk to each taxon and add Biota if not exists |
407 |
* @param state |
|
408 |
* @return |
|
409 | 398 |
*/ |
410 | 399 |
private boolean doPhase02(PesiExportState state) { |
411 | 400 |
int count = 0; |
... | ... | |
416 | 405 |
return success; |
417 | 406 |
} |
418 | 407 |
|
419 |
List<Taxon> list; |
|
420 |
|
|
421 | 408 |
// Get the limit for objects to save within a single transaction. |
422 | 409 |
int limit = state.getConfig().getLimitSave(); |
423 | 410 |
|
... | ... | |
429 | 416 |
int partitionCount = 0; |
430 | 417 |
|
431 | 418 |
// ProfilerController.memorySnapshot(); |
419 |
List<Taxon> list; |
|
432 | 420 |
while ((list = getNextTaxonPartition(Taxon.class, limit, partitionCount++, null)) != null ) { |
433 | 421 |
|
434 | 422 |
if(logger.isDebugEnabled()) { |
... | ... | |
456 | 444 |
logger.info("Started new transaction. Fetching some " + pluralString + " (max: " + limit + ") ..."); |
457 | 445 |
} |
458 | 446 |
} |
459 |
logger.info("No " + pluralString + " left to fetch.");
|
|
447 |
logger.debug("No " + pluralString + " left to fetch.");
|
|
460 | 448 |
|
461 | 449 |
// Commit transaction |
462 | 450 |
commitTransaction(txStatus); |
... | ... | |
466 | 454 |
|
467 | 455 |
/** |
468 | 456 |
* Inserts the Biota Taxon if not yet exists. |
469 |
* @param state |
|
470 |
* @throws SQLException |
|
471 | 457 |
*/ |
472 | 458 |
private void insertBiota(PesiExportState state) { |
473 | 459 |
try { |
... | ... | |
484 | 470 |
} |
485 | 471 |
} |
486 | 472 |
|
487 |
// 4th round: Add TreeIndex to each taxon |
|
488 |
private boolean doPhase04(PesiExportState state) { |
|
489 |
boolean success = true; |
|
490 |
|
|
491 |
logger.info("PHASE 4: Make TreeIndex ... "); |
|
492 |
|
|
493 |
//TODO test if possible to move to phase 02 |
|
494 |
String sql = " UPDATE Taxon SET ParentTaxonFk = (SELECT TaxonId FROM Taxon WHERE RankFk = 0) " + |
|
495 |
" WHERE (RankFk = 10) and TaxonStatusFk = 1 "; |
|
496 |
state.getConfig().getDestination().update(sql); |
|
497 |
|
|
498 |
state.getConfig().getDestination().update("EXEC dbo.recalculateallstoredpaths"); |
|
499 |
|
|
500 |
logger.info("PHASE 4: Make TreeIndex DONE"); |
|
501 |
|
|
502 |
return success; |
|
503 |
|
|
504 |
} |
|
505 |
|
|
506 |
|
|
507 |
// // 2nd Round: Add ParentTaxonFk, TreeIndex to each Taxon |
|
508 |
// private boolean doPhase02_OLD(PesiExportState state) { |
|
509 |
// boolean success = true; |
|
510 |
// boolean includeUnpublished = false; |
|
511 |
// if (! state.getConfig().isDoTreeIndex()){ |
|
512 |
// logger.info ("Ignore PHASE 2: ParentTaxonFk and TreeIndex"); |
|
513 |
// return success; |
|
514 |
// } |
|
515 |
// |
|
516 |
// List<Classification> classificationList = null; |
|
517 |
// logger.info("PHASE 2: Add ParenTaxonFk and TreeIndex..."); |
|
518 |
// |
|
519 |
// // Specify starting ranks for tree traversing |
|
520 |
// rankList.add(Rank.KINGDOM()); |
|
521 |
// rankList.add(Rank.GENUS()); |
|
522 |
// |
|
523 |
// // Specify where to stop traversing (value) when starting at a specific Rank (key) |
|
524 |
// rank2endRankMap.put(Rank.GENUS(), null); // Since NULL does not match an existing Rank, traverse all the way down to the leaves |
|
525 |
// rank2endRankMap.put(Rank.KINGDOM(), Rank.GENUS()); // excludes rank genus |
|
526 |
// |
|
527 |
// StringBuffer treeIndex = new StringBuffer(); |
|
528 |
// |
|
529 |
// // Retrieve list of classifications |
|
530 |
// TransactionStatus txStatus = startTransaction(true); |
|
531 |
// logger.info("Started transaction for parentFk and treeIndex. Fetching all classifications..."); |
|
532 |
// classificationList = getClassificationService().listClassifications(null, 0, null, null); |
|
533 |
// commitTransaction(txStatus); |
|
534 |
// logger.debug("Committed transaction."); |
|
535 |
// |
|
536 |
// logger.info("Fetched " + classificationList.size() + " classification(s)."); |
|
537 |
// |
|
538 |
// setTreeIndexAnnotationType(getAnnotationType(uuidTreeIndex, "TreeIndex", "TreeIndex", "TI")); |
|
539 |
// List<TaxonNode> rankSpecificRootNodes; |
|
540 |
// for (Classification classification : classificationList) { |
|
541 |
// for (Rank rank : rankList) { |
|
542 |
// |
|
543 |
// txStatus = startTransaction(true); |
|
544 |
// logger.info("Started transaction to fetch all rootNodes specific to Rank " + rank.getLabel() + " ..."); |
|
545 |
// |
|
546 |
// rankSpecificRootNodes = getClassificationService().listRankSpecificRootNodes(classification, |
|
547 |
// null, rank, includeUnpublished, null, null, null); |
|
548 |
// logger.info("Fetched " + rankSpecificRootNodes.size() + " RootNodes for Rank " + rank.getLabel()); |
|
549 |
// |
|
550 |
// commitTransaction(txStatus); |
|
551 |
// logger.debug("Committed transaction."); |
|
552 |
// |
|
553 |
// for (TaxonNode rootNode : rankSpecificRootNodes) { |
|
554 |
// txStatus = startTransaction(false); |
|
555 |
// Rank endRank = rank2endRankMap.get(rank); |
|
556 |
// if (endRank != null) { |
|
557 |
// logger.debug("Started transaction to traverse childNodes of rootNode (" + rootNode.getUuid() + ") till Rank " + endRank.getLabel() + " ..."); |
|
558 |
// } else { |
|
559 |
// logger.debug("Started transaction to traverse childNodes of rootNode (" + rootNode.getUuid() + ") till leaves are reached ..."); |
|
560 |
// } |
|
561 |
// |
|
562 |
// TaxonNode newNode = getTaxonNodeService().load(rootNode.getUuid()); |
|
563 |
// |
|
564 |
// if (isPesiTaxon(newNode.getTaxon())){ |
|
565 |
// TaxonNode parentNode = newNode.getParent(); |
|
566 |
// if (rank.equals(Rank.KINGDOM())) { |
|
567 |
// treeIndex = new StringBuffer(); |
|
568 |
// treeIndex.append("#"); |
|
569 |
// } else { |
|
570 |
// // Get treeIndex from parentNode |
|
571 |
// if (parentNode != null) { |
|
572 |
// boolean annotationFound = false; |
|
573 |
// Set<Annotation> annotations = parentNode.getAnnotations(); |
|
574 |
// for (Annotation annotation : annotations) { |
|
575 |
// AnnotationType annotationType = annotation.getAnnotationType(); |
|
576 |
// if (annotationType != null && annotationType.equals(getTreeIndexAnnotationType())) { |
|
577 |
// treeIndex = new StringBuffer(CdmUtils.Nz(annotation.getText())); |
|
578 |
// annotationFound = true; |
|
579 |
// // logger.error("treeIndex: " + treeIndex); |
|
580 |
// break; |
|
581 |
// } |
|
582 |
// } |
|
583 |
// if (!annotationFound) { |
|
584 |
// // This should not happen because it means that the treeIndex was not set correctly as an annotation to parentNode |
|
585 |
// logger.error("TreeIndex could not be read from annotation of TaxonNode: " + parentNode.getUuid() + ", Taxon: " + parentNode.getTaxon().getUuid()); |
|
586 |
// treeIndex = new StringBuffer(); |
|
587 |
// treeIndex.append("#"); |
|
588 |
// } |
|
589 |
// } else { |
|
590 |
// // TreeIndex could not be determined, but it's unclear how to proceed to generate a correct treeIndex if the parentNode is NULL |
|
591 |
// logger.error("ParentNode for RootNode is NULL. TreeIndex could not be determined: " + newNode.getUuid()); |
|
592 |
// treeIndex = new StringBuffer(); // This just prevents growing of the treeIndex in a wrong manner |
|
593 |
// treeIndex.append("#"); |
|
594 |
// } |
|
595 |
// } |
|
596 |
// nomenclaturalCode = newNode.getTaxon().getName().getNameType(); |
|
597 |
// kingdomFk = PesiTransformer.nomenclaturalCode2Kingdom(nomenclaturalCode); |
|
598 |
// traverseTree(newNode, parentNode, treeIndex, endRank, state); |
|
599 |
// parentNode =null; |
|
600 |
// }else{ |
|
601 |
// logger.debug("Taxon is not a PESI taxon: " + newNode.getTaxon().getUuid()); |
|
602 |
// } |
|
603 |
// |
|
604 |
// newNode = null; |
|
605 |
// |
|
606 |
// try { |
|
607 |
// commitTransaction(txStatus); |
|
608 |
// logger.debug("Committed transaction."); |
|
609 |
// } catch (Exception e) { |
|
610 |
// logger.error(e.getMessage()); |
|
611 |
// e.printStackTrace(); |
|
612 |
// } |
|
613 |
// |
|
614 |
// } |
|
615 |
// rankSpecificRootNodes = null; |
|
616 |
// } |
|
617 |
// |
|
618 |
// } |
|
619 |
// |
|
620 |
// logger.warn("Taking snapshot at the end of phase 2 of taxonExport"); |
|
621 |
// //ProfilerController.memorySnapshot(); |
|
622 |
// return success; |
|
623 |
// } |
|
624 |
|
|
625 | 473 |
//PHASE 3: Add Rank data, KingdomFk, TypeNameFk, expertFk and speciesExpertFk... |
626 | 474 |
private boolean doPhase03(PesiExportState state) { |
627 | 475 |
int count = 0; |
... | ... | |
634 | 482 |
// Get the limit for objects to save within a single transaction. |
635 | 483 |
int limit = state.getConfig().getLimitSave(); |
636 | 484 |
|
637 |
List<TaxonBase> list; |
|
638 | 485 |
logger.info("PHASE 3: Add Rank data, KingdomFk, TypeNameFk, expertFk and speciesExpertFk..."); |
639 | 486 |
// Be sure to add rank information, KingdomFk, TypeNameFk, expertFk and speciesExpertFk to every taxonName |
640 | 487 |
|
... | ... | |
644 | 491 |
logger.info("Started new transaction for rank, kingdom, typeName, expertFk and speciesExpertFK. Fetching some " + pluralString + " (max: " + limit + ") ..."); |
645 | 492 |
} |
646 | 493 |
int partitionCount = 0; |
494 |
List<TaxonBase> list; |
|
647 | 495 |
while ((list = getNextTaxonPartition(TaxonBase.class, limit, partitionCount++, null)) != null) { |
648 | 496 |
|
649 | 497 |
if (logger.isDebugEnabled()) { |
... | ... | |
683 | 531 |
logger.info("Started new transaction for rank, kingdom, typeName, expertFk and speciesExpertFK. Fetching some " + pluralString + " (max: " + limit + ") ..."); |
684 | 532 |
} |
685 | 533 |
} |
686 |
logger.info("No " + pluralString + " left to fetch.");
|
|
534 |
logger.debug("No " + pluralString + " left to fetch.");
|
|
687 | 535 |
|
688 | 536 |
// Commit transaction |
689 | 537 |
commitTransaction(txStatus); |
... | ... | |
696 | 544 |
return success; |
697 | 545 |
} |
698 | 546 |
|
547 |
// 4th round: Add TreeIndex to each taxon |
|
548 |
private boolean doPhase04(PesiExportState state) { |
|
549 |
boolean success = true; |
|
550 |
|
|
551 |
logger.info("PHASE 4: Make TreeIndex ... "); |
|
552 |
|
|
553 |
//TODO test if possible to move to phase 02 |
|
554 |
String sql = " UPDATE Taxon SET ParentTaxonFk = (SELECT TaxonId FROM Taxon WHERE RankFk = 0) " + |
|
555 |
" WHERE (RankFk = 10) and TaxonStatusFk = 1 "; |
|
556 |
state.getConfig().getDestination().update(sql); |
|
557 |
|
|
558 |
state.getConfig().getDestination().update("EXEC dbo.recalculateallstoredpaths"); |
|
559 |
|
|
560 |
logger.info("PHASE 4: Make TreeIndex DONE"); |
|
561 |
|
|
562 |
return success; |
|
563 |
} |
|
564 |
|
|
699 | 565 |
private static Integer findKingdomIdFromTreeIndex(TaxonBase<?> taxonBase,PesiExportState state) { |
700 | 566 |
Taxon taxon; |
701 | 567 |
if (taxonBase instanceof Synonym){ |
... | ... | |
824 | 690 |
if (logger.isDebugEnabled()) { |
825 | 691 |
logger.info("Started new transaction. Fetching some " + parentPluralString + " first (max: " + limit + ") ..."); |
826 | 692 |
} |
827 |
List<TaxonBase> taxonList = null; |
|
828 | 693 |
|
694 |
List<TaxonBase> taxonList = null; |
|
829 | 695 |
while ((taxonList = getTaxonService().listTaxaByName(Taxon.class, "*", "*", "*", "*", "*", Rank.SPECIES(), pageSize, pageNumber)).size() > 0) { |
830 | 696 |
|
831 | 697 |
Map<Integer, TaxonName> inferredSynonymsDataToBeSaved = new HashMap<>(); |
... | ... | |
906 | 772 |
return success; |
907 | 773 |
} |
908 | 774 |
|
909 |
/** |
|
910 |
* @param state |
|
911 |
* @param mapping |
|
912 |
* @param synRelMapping |
|
913 |
* @param currentTaxonId |
|
914 |
* @param taxonList |
|
915 |
* @param inferredSynonymsDataToBeSaved |
|
916 |
* @return |
|
917 |
*/ |
|
918 | 775 |
private Map<Integer, TaxonName> createInferredSynonymsForTaxonList(PesiExportState state, |
919 | 776 |
PesiExportMapping mapping, PesiExportMapping synRelMapping, List<TaxonBase> taxonList) { |
920 | 777 |
|
... | ... | |
1040 | 897 |
mapping.initialize(state); |
1041 | 898 |
int count = 0; |
1042 | 899 |
int pastCount = 0; |
1043 |
List<TaxonName> list; |
|
1044 | 900 |
success = true; |
1045 | 901 |
// Get the limit for objects to save within a single transaction. |
1046 | 902 |
int limit = state.getConfig().getLimitSave(); |
... | ... | |
1051 | 907 |
logger.info("Started new transaction for Pure Names. Fetching some " + pluralString + " (max: " + limit + ") ..."); |
1052 | 908 |
|
1053 | 909 |
int partitionCount = 0; |
910 |
List<TaxonName> list; |
|
1054 | 911 |
while ((list = getNextPureNamePartition(null, limit, partitionCount++)) != null ) { |
1055 | 912 |
|
1056 | 913 |
logger.info("Fetched " + list.size() + " names without taxa. Exporting..."); |
... | ... | |
1176 | 1033 |
return annotationType; |
1177 | 1034 |
} |
1178 | 1035 |
|
1179 |
/** |
|
1180 |
* Traverses the classification recursively and stores determined values for every Taxon. |
|
1181 |
* @param childNode The {@link TaxonNode TaxonNode} to process. |
|
1182 |
* @param parentNode The parent {@link TaxonNode TaxonNode} of the childNode. |
|
1183 |
* @param treeIndex The TreeIndex at the current level. |
|
1184 |
* @param fetchLevel Rank to stop fetching at. |
|
1185 |
* @param state The {@link PesiExportState PesiExportState}. |
|
1186 |
*/ |
|
1187 |
private void traverseTree(TaxonNode childNode, TaxonNode parentNode, StringBuffer treeIndex, Rank fetchLevel, PesiExportState state) { |
|
1188 |
// Traverse all branches from this childNode until specified fetchLevel is reached. |
|
1189 |
StringBuffer localTreeIndex = new StringBuffer(treeIndex); |
|
1190 |
Taxon childTaxon = childNode.getTaxon(); |
|
1191 |
if (childTaxon != null) { |
|
1192 |
if (isPesiTaxon(childTaxon)){ |
|
1193 |
Integer taxonId = state.getDbId(childTaxon); |
|
1194 |
TaxonName childName = childTaxon.getName(); |
|
1195 |
if (taxonId != null) { |
|
1196 |
Rank childRank = childName.getRank(); |
|
1197 |
if (childRank != null) { |
|
1198 |
if (! childRank.equals(fetchLevel)) { |
|
1199 |
|
|
1200 |
localTreeIndex.append(taxonId + "#"); |
|
1201 |
|
|
1202 |
saveData(childNode, parentNode, localTreeIndex, state, taxonId); |
|
1203 |
|
|
1204 |
// Store treeIndex as annotation for further use |
|
1205 |
Annotation annotation = Annotation.NewInstance(localTreeIndex.toString(), getTreeIndexAnnotationType(), Language.DEFAULT()); |
|
1206 |
childNode.addAnnotation(annotation); |
|
1207 |
|
|
1208 |
for (TaxonNode newNode : childNode.getChildNodes()) { |
|
1209 |
if (newNode.getTaxon() != null && isPesiTaxon(newNode.getTaxon())){ |
|
1210 |
traverseTree(newNode, childNode, localTreeIndex, fetchLevel, state); |
|
1211 |
} |
|
1212 |
} |
|
1213 |
|
|
1214 |
} else { |
|
1215 |
// logger.debug("Target Rank " + fetchLevel.getLabel() + " reached"); |
|
1216 |
return; |
|
1217 |
} |
|
1218 |
} else { |
|
1219 |
logger.error("Rank is NULL. FetchLevel can not be checked: " + childName.getUuid() + " (" + childName.getTitleCache() + ")"); |
|
1220 |
} |
|
1221 |
} else { |
|
1222 |
logger.error("Taxon can not be found in state: " + childTaxon.getUuid() + " (" + childTaxon.getTitleCache() + ")"); |
|
1223 |
} |
|
1224 |
}else{ |
|
1225 |
if (logger.isDebugEnabled()){ |
|
1226 |
logger.debug("Taxon is not a PESI taxon: " + childTaxon.getUuid()); |
|
1227 |
} |
|
1228 |
} |
|
1229 |
} else { |
|
1230 |
logger.error("Taxon is NULL for TaxonNode: " + childNode.getUuid()); |
|
1231 |
} |
|
1232 |
} |
|
1233 |
|
|
1234 |
/** |
|
1235 |
* Stores values in database for every recursive round. |
|
1236 |
* @param childNode The {@link TaxonNode TaxonNode} to process. |
|
1237 |
* @param parentNode The parent {@link TaxonNode TaxonNode} of the childNode. |
|
1238 |
* @param treeIndex The TreeIndex at the current level. |
|
1239 |
* @param state The {@link PesiExportState PesiExportState}. |
|
1240 |
* @param currentTaxonFk The TaxonFk to store the values for. |
|
1241 |
*/ |
|
1242 |
private void saveData(TaxonNode childNode, TaxonNode parentNode, StringBuffer treeIndex, PesiExportState state, Integer currentTaxonFk) { |
|
1243 |
// We are differentiating kingdoms by the nomenclatural code for now. |
|
1244 |
// This needs to be handled in a better way as soon as we know how to differentiate between more kingdoms. |
|
1245 |
Taxon childTaxon = childNode.getTaxon(); |
|
1246 |
if (isPesiTaxon(childTaxon)) { |
|
1247 |
TaxonBase<?> parentTaxon = null; |
|
1248 |
if (parentNode != null) { |
|
1249 |
parentTaxon = parentNode.getTaxon(); |
|
1250 |
} |
|
1251 |
|
|
1252 |
invokeParentTaxonFkAndTreeIndex(state.getDbId(parentTaxon), currentTaxonFk, treeIndex); |
|
1253 |
} |
|
1254 |
} |
|
1255 |
|
|
1256 |
/** |
|
1257 |
* Inserts values into the Taxon database table. |
|
1258 |
* |
|
1259 |
* @param taxonName The {@link TaxonNameBase TaxonName}. |
|
1260 |
* @param state The {@link PesiExportState PesiExportState}. |
|
1261 |
* @param stmt The prepared statement. |
|
1262 |
* @return Whether save was successful or not. |
|
1263 |
*/ |
|
1264 |
protected boolean invokeParentTaxonFkAndTreeIndex(Integer parentTaxonFk, Integer currentTaxonFk, StringBuffer treeIndex) { |
|
1265 |
try { |
|
1266 |
if (parentTaxonFk != null) { |
|
1267 |
parentTaxonFk_TreeIndex_KingdomFkStmt.setInt(1, parentTaxonFk); |
|
1268 |
} else { |
|
1269 |
parentTaxonFk_TreeIndex_KingdomFkStmt.setObject(1, null); |
|
1270 |
} |
|
1271 |
|
|
1272 |
if (treeIndex != null) { |
|
1273 |
parentTaxonFk_TreeIndex_KingdomFkStmt.setString(2, treeIndex.toString()); |
|
1274 |
} else { |
|
1275 |
parentTaxonFk_TreeIndex_KingdomFkStmt.setObject(2, null); |
|
1276 |
} |
|
1277 |
|
|
1278 |
if (currentTaxonFk != null) { |
|
1279 |
parentTaxonFk_TreeIndex_KingdomFkStmt.setInt(3, currentTaxonFk); |
|
1280 |
} else { |
|
1281 |
parentTaxonFk_TreeIndex_KingdomFkStmt.setObject(3, null); |
|
1282 |
} |
|
1283 |
|
|
1284 |
parentTaxonFk_TreeIndex_KingdomFkStmt.executeUpdate(); |
|
1285 |
return true; |
|
1286 |
} catch (SQLException e) { |
|
1287 |
logger.error("ParentTaxonFk (" + (parentTaxonFk ==null? "-":parentTaxonFk) + ") and TreeIndex could not be inserted into database for taxon "+ (currentTaxonFk == null? "-" :currentTaxonFk) + ": " + e.getMessage()); |
|
1288 |
e.printStackTrace(); |
|
1289 |
return false; |
|
1290 |
} |
|
1291 |
} |
|
1292 |
|
|
1293 |
protected boolean invokeParentTaxonFk(Integer parentId, Integer childId) { |
|
1036 |
private boolean invokeParentTaxonFk(Integer parentId, Integer childId) { |
|
1294 | 1037 |
try { |
1295 | 1038 |
parentTaxonFkStmt.setInt(1, parentId); |
1296 | 1039 |
parentTaxonFkStmt.setInt(2, childId); |
... | ... | |
1442 | 1185 |
// Clear Taxon |
1443 | 1186 |
sql = "DELETE FROM " + dbTableName; |
1444 | 1187 |
destination.update(sql); |
1445 |
return true; |
|
1446 |
} |
|
1447 | 1188 |
|
1448 |
/** |
|
1449 |
* Creates the kingdom fk. |
|
1450 |
* @param taxonName |
|
1451 |
* @return |
|
1452 |
*/ |
|
1453 |
@SuppressWarnings("unused") //used by mapper |
|
1454 |
private static Integer getKingdomFk(TaxonName taxonName){ |
|
1455 |
return PesiTransformer.nomenclaturalCode2Kingdom(taxonName.getNameType()); |
|
1456 |
} |
|
1189 |
//TODO due to foreign keys we should also delete all tables linking to Taxon table |
|
1457 | 1190 |
|
1458 |
/** |
|
1459 |
* Creates the parent fk. |
|
1460 |
* @param taxonName |
|
1461 |
* @return |
|
1462 |
*/ |
|
1463 |
@SuppressWarnings("unused") //used by mapper |
|
1464 |
private static Integer getParentTaxonFk(TaxonBase<?> taxonBase, PesiExportState state){ |
|
1465 |
if (taxonBase.isInstanceOf(Taxon.class)){ |
|
1466 |
Taxon taxon = CdmBase.deproxy(taxonBase, Taxon.class); |
|
1467 |
if (! isMisappliedName(taxon)){ |
|
1468 |
Set<TaxonNode> nodes = taxon.getTaxonNodes(); |
|
1469 |
if (nodes.size() == 0){ |
|
1470 |
if (taxon.getName().getRank().isLower(Rank.KINGDOM())){ |
|
1471 |
logger.warn("Accepted taxon has no parent. " + taxon.getTitleCache() + ", " + taxon.getUuid()); |
|
1472 |
} |
|
1473 |
}else if (nodes.size() > 1){ |
|
1474 |
logger.warn("Taxon has more than 1 node attached. This is not supported by PESI export." + taxon.getTitleCache() + ", " + taxon.getUuid()); |
|
1475 |
}else{ |
|
1476 |
Taxon parent =nodes.iterator().next().getParent().getTaxon(); |
|
1477 |
return state.getDbId(parent); |
|
1478 |
} |
|
1479 |
} |
|
1480 |
} |
|
1481 |
return null; |
|
1191 |
return true; |
|
1482 | 1192 |
} |
1483 | 1193 |
|
1484 | 1194 |
/** |
... | ... | |
1492 | 1202 |
return getRankFk(taxonName, taxonName.getNameType()); |
1493 | 1203 |
} |
1494 | 1204 |
|
1495 |
|
|
1496 | 1205 |
/** |
1497 | 1206 |
* Returns the <code>RankFk</code> attribute. |
1498 | 1207 |
* @param taxonName The {@link TaxonNameBase TaxonName}. |
... | ... | |
1521 | 1230 |
return result; |
1522 | 1231 |
} |
1523 | 1232 |
|
1524 |
/** |
|
1525 |
* Returns the rank cache for the taxon name based on the names nomenclatural code. |
|
1526 |
* You may not use this method for kingdoms other then Animalia, Plantae and Bacteria. |
|
1527 |
*/ |
|
1528 |
@SuppressWarnings("unused") //used by mapper |
|
1529 | 1233 |
private static String getRankCache(TaxonName taxonName, PesiExportState state) { |
1530 | 1234 |
return getRankCache(taxonName, taxonName.getNameType(), state); |
1531 | 1235 |
} |
1532 | 1236 |
|
1237 |
|
|
1533 | 1238 |
/** |
1534 | 1239 |
* Returns the <code>RankCache</code> attribute. |
1535 | 1240 |
* @param taxonName The {@link TaxonNameBase TaxonName}. |
... | ... | |
1552 | 1257 |
} |
1553 | 1258 |
} |
1554 | 1259 |
|
1555 |
/** |
|
1556 |
* @param taxonName |
|
1557 |
* @return |
|
1558 |
*/ |
|
1559 | 1260 |
private static List<TaxonNode> getTaxonNodes(TaxonName taxonName) { |
1560 | 1261 |
List<TaxonNode> result = new ArrayList<>(); |
1561 | 1262 |
for (TaxonBase<?> tb:taxonName.getTaxonBases()){ |
... | ... | |
1684 | 1385 |
return result; |
1685 | 1386 |
} |
1686 | 1387 |
|
1687 |
|
|
1688 | 1388 |
/** |
1689 | 1389 |
* Returns the <code>WebShowName</code> attribute for a taxon. |
1690 | 1390 |
* @param taxonName The {@link TaxonNameBase TaxonName}. |
... | ... | |
1720 | 1420 |
} |
1721 | 1421 |
} |
1722 | 1422 |
|
1723 |
|
|
1724 | 1423 |
/** |
1725 | 1424 |
* Returns the <code>WebSearchName</code> attribute. |
1726 | 1425 |
* @param taxonName The {@link NonViralName NonViralName}. |
... | ... | |
1735 | 1434 |
return result; |
1736 | 1435 |
} |
1737 | 1436 |
|
1738 |
|
|
1739 | 1437 |
/** |
1740 | 1438 |
* Returns the <code>FullName</code> attribute. |
1741 | 1439 |
* @param taxonName The {@link NonViralName NonViralName}. |
... | ... | |
1781 | 1479 |
return null; |
1782 | 1480 |
} |
1783 | 1481 |
|
1784 |
|
|
1785 |
|
|
1786 |
/** |
|
1787 |
* Returns the <code>FullName</code> attribute. |
|
1788 |
* @param taxon The {@link TaxonBase taxon}. |
|
1789 |
* @return The <code>FullName</code> attribute. |
|
1790 |
* @see MethodMapper |
|
1791 |
*/ |
|
1792 |
/*@SuppressWarnings("unused") |
|
1793 |
private static String getFullName(TaxonBase taxon) { |
|
1794 |
//TODO extensions? |
|
1795 |
TaxonNameBase name = taxon.getName(); |
|
1796 |
String result = getFullName(name); |
|
1797 |
if (isMisappliedName(taxon)){ |
|
1798 |
result = result + " " + getAuthorString(taxon); |
|
1799 |
} |
|
1800 |
|
|
1801 |
return result; |
|
1802 |
} |
|
1803 |
*/ |
|
1804 |
|
|
1805 | 1482 |
/** |
1806 | 1483 |
* Returns the nomenclatural reference which is the reference |
1807 | 1484 |
* including the detail (microreference). |
... | ... | |
1838 | 1515 |
return result; |
1839 | 1516 |
} |
1840 | 1517 |
|
1841 |
|
|
1842 | 1518 |
/** |
1843 | 1519 |
* Returns the <code>NameStatusFk</code> attribute. |
1844 | 1520 |
* @param taxonName The {@link TaxonNameBase TaxonName}. |
... | ... | |
1873 | 1549 |
return result; |
1874 | 1550 |
} |
1875 | 1551 |
|
1876 |
|
|
1877 | 1552 |
private static NomenclaturalStatus getNameStatus(TaxonName taxonName) { |
1878 | 1553 |
try { |
1879 | 1554 |
if (taxonName != null) { |
... | ... | |
1928 | 1603 |
return state.getTransformer().getTaxonStatusCacheByKey(getTaxonStatusFk(taxon, state)); |
1929 | 1604 |
} |
1930 | 1605 |
|
1606 |
/** |
|
1607 |
* Returns the <code>TaxonFk1</code> attribute. It corresponds to a CDM <code>TaxonRelationship</code>. |
|
1608 |
* @param relationship The {@link RelationshipBase Relationship}. |
|
1609 |
* @param state The {@link PesiExportState PesiExportState}. |
|
1610 |
* @return The <code>TaxonFk1</code> attribute. |
|
1611 |
* @see MethodMapper |
|
1612 |
*/ |
|
1613 |
@SuppressWarnings("unused") |
|
1614 |
private static Integer getSynonym(Synonym synonym, PesiExportState state) { |
|
1615 |
return state.getDbId(synonym); |
|
1616 |
} |
|
1617 |
|
|
1931 | 1618 |
/** |
1932 | 1619 |
* Returns the <code>TypeNameFk</code> attribute. |
1933 | 1620 |
* @param taxonName The {@link TaxonNameBase TaxonName}. |
... | ... | |
2115 | 1802 |
* @see MethodMapper |
2116 | 1803 |
*/ |
2117 | 1804 |
@SuppressWarnings("unused") |
2118 |
private static String getIdInSource(IdentifiableEntity taxonName) { |
|
1805 |
private static String getIdInSource(IdentifiableEntity<?> taxonName) {
|
|
2119 | 1806 |
String result = null; |
2120 | 1807 |
|
2121 | 1808 |
try { |
... | ... | |
2139 | 1826 |
}else if (refUuid.equals(PesiTransformer.uuidSourceRefIndexFungorum)){ //Index Fungorum |
2140 | 1827 |
result = idInSource != null ? ("if_id: " + source.getIdInSource()) : null; |
2141 | 1828 |
}else{ |
2142 |
if (logger.isDebugEnabled()){logger.debug("Not a PESI source");};
|
|
1829 |
if (logger.isDebugEnabled()){logger.debug("Not a PESI source");} |
|
2143 | 1830 |
} |
2144 | 1831 |
|
2145 | 1832 |
String sourceIdNameSpace = source.getIdNamespace(); |
... | ... | |
2174 | 1861 |
* @param taxonName The {@link TaxonNameBase TaxonName}. |
2175 | 1862 |
* @return The idInSource. |
2176 | 1863 |
*/ |
2177 |
private static String getIdInSourceOnly(IdentifiableEntity identEntity) { |
|
1864 |
private static String getIdInSourceOnly(IdentifiableEntity<?> identEntity) {
|
|
2178 | 1865 |
String result = null; |
2179 | 1866 |
|
2180 | 1867 |
// Get the sources first |
... | ... | |
2343 | 2030 |
* @see MethodMapper |
2344 | 2031 |
*/ |
2345 | 2032 |
@SuppressWarnings({ "unused" }) |
2346 |
private static DateTime getLastActionDate(IdentifiableEntity identEntity) { |
|
2033 |
private static DateTime getLastActionDate(IdentifiableEntity<?> identEntity) {
|
|
2347 | 2034 |
DateTime result = null; |
2348 | 2035 |
try { |
2349 | 2036 |
Set<Extension> extensions = identEntity.getExtensions(); |
... | ... | |
2458 | 2145 |
private static Integer getRelTaxonQualifierFk(RelationshipBase<?, ?, ?> relationship) { |
2459 | 2146 |
return PesiTransformer.taxonRelation2RelTaxonQualifierFk(relationship); |
2460 | 2147 |
} |
2148 |
|
|
2461 | 2149 |
@SuppressWarnings("unused") |
2462 | 2150 |
private static String getSynonymTypeCache(Synonym synonym, PesiExportState state) { |
2463 | 2151 |
String result = null; |
... | ... | |
2472 | 2160 |
return result; |
2473 | 2161 |
} |
2474 | 2162 |
|
2163 |
// ********************************** MAPPINGS ********************************/ |
|
2475 | 2164 |
|
2476 | 2165 |
/** |
2477 | 2166 |
* Returns the CDM to PESI specific export mappings. |
... | ... | |
2510 | 2199 |
ExtensionType extensionTypeExpertName = (ExtensionType)getTermService().find(PesiTransformer.uuidExtExpertName); |
2511 | 2200 |
mapping.addMapper(DbExtensionMapper.NewInstance(extensionTypeExpertName, "ExpertName")); |
2512 | 2201 |
|
2202 |
//handled in Phase02 now |
|
2513 | 2203 |
// mapping.addMapper(MethodMapper.NewInstance("ParentTaxonFk", this, TaxonBase.class, PesiExportState.class)); //by AM, doesn't work, FK exception |
2514 | 2204 |
mapping.addMapper(ObjectChangeMapper.NewInstance(TaxonBase.class, TaxonName.class, "Name")); |
2515 | 2205 |
|
... | ... | |
2529 | 2219 |
|
2530 | 2220 |
mapping.addMapper(IdMapper.NewInstance("TaxonId")); |
2531 | 2221 |
|
2532 |
// mapping.addMapper(MethodMapper.NewInstance("TaxonStatusFk", this.getClass(), "getTaxonStatusFk", standardMethodParameter, PesiExportState.class)); |
|
2533 |
|
|
2534 | 2222 |
mapping.addMapper(MethodMapper.NewInstance("KingdomFk", this, TaxonName.class)); |
2535 | 2223 |
mapping.addMapper(MethodMapper.NewInstance("RankFk", this, TaxonName.class)); |
2536 | 2224 |
mapping.addMapper(MethodMapper.NewInstance("RankCache", this, TaxonName.class, PesiExportState.class)); |
... | ... | |
2552 | 2240 |
return mapping; |
2553 | 2241 |
} |
2554 | 2242 |
|
2555 |
|
|
2556 | 2243 |
private void addNameMappers(PesiExportMapping mapping) { |
2557 | 2244 |
mapping.addMapper(DbStringMapper.NewInstance("GenusOrUninomial", "GenusOrUninomial")); |
2558 | 2245 |
mapping.addMapper(DbStringMapper.NewInstance("InfraGenericEpithet", "InfraGenericEpithet")); |
... | ... | |
2562 | 2249 |
// mapping.addMapper(DbStringMapper.NewInstance("NameCache", "WebSearchName")); //does not work as we need other cache strategy |
2563 | 2250 |
mapping.addMapper(MethodMapper.NewInstance("WebSearchName", this, TaxonName.class)); |
2564 | 2251 |
|
2565 |
// mapping.addMapper(DbStringMapper.NewInstance("TitleCache", "FullName")); //does not work as we need other cache strategy |
|
2566 | 2252 |
mapping.addMapper(MethodMapper.NewInstance("FullName", this, TaxonName.class)); |
2567 | 2253 |
|
2568 | 2254 |
|
... | ... | |
2584 | 2270 |
|
2585 | 2271 |
} |
2586 | 2272 |
|
2587 |
/** |
|
2588 |
* Returns the <code>TaxonFk1</code> attribute. It corresponds to a CDM <code>TaxonRelationship</code>. |
|
2589 |
* @param relationship The {@link RelationshipBase Relationship}. |
|
2590 |
* @param state The {@link PesiExportState PesiExportState}. |
|
2591 |
* @return The <code>TaxonFk1</code> attribute. |
|
2592 |
* @see MethodMapper |
|
2593 |
*/ |
|
2594 |
@SuppressWarnings("unused") |
|
2595 |
private static Integer getSynonym(Synonym synonym, PesiExportState state) { |
|
2596 |
return state.getDbId(synonym); |
|
2597 |
} |
|
2598 |
|
|
2599 |
|
|
2600 | 2273 |
private PesiExportMapping getSynRelMapping() { |
2601 | 2274 |
PesiExportMapping mapping = new PesiExportMapping(dbTableNameSynRel); |
2602 | 2275 |
logger.warn("SynRelMapping currently not implemented. Needs to be checked"); |
Also available in: Unified diff
cleanup