Project

General

Profile

« Previous | Next » 

Revision be6b41e5

Added by Andreas Müller over 4 years ago

cleanup

View differences:

cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/out/PesiTaxonExport.java
511 511
	}
512 512

  
513 513

  
514
	// 2nd Round: Add ParentTaxonFk, TreeIndex to each Taxon
515
	private boolean doPhase02_OLD(PesiExportState state) {
516
		boolean success = true;
517
		boolean includeUnpublished = false;
518
		if (! state.getConfig().isDoTreeIndex()){
519
			logger.info ("Ignore PHASE 2: ParentTaxonFk and TreeIndex");
520
			return success;
521
		}
522

  
523
		List<Classification> classificationList = null;
524
		logger.info("PHASE 2: Add ParenTaxonFk and TreeIndex...");
525

  
526
		// Specify starting ranks for tree traversing
527
		rankList.add(Rank.KINGDOM());
528
		rankList.add(Rank.GENUS());
529

  
530
		// Specify where to stop traversing (value) when starting at a specific Rank (key)
531
		rank2endRankMap.put(Rank.GENUS(), null); // Since NULL does not match an existing Rank, traverse all the way down to the leaves
532
		rank2endRankMap.put(Rank.KINGDOM(), Rank.GENUS()); // excludes rank genus
533

  
534
		StringBuffer treeIndex = new StringBuffer();
535

  
536
		// Retrieve list of classifications
537
		TransactionStatus txStatus = startTransaction(true);
538
		logger.info("Started transaction for parentFk and treeIndex. Fetching all classifications...");
539
		classificationList = getClassificationService().listClassifications(null, 0, null, null);
540
		commitTransaction(txStatus);
541
		logger.debug("Committed transaction.");
542

  
543
		logger.info("Fetched " + classificationList.size() + " classification(s).");
544

  
545
		setTreeIndexAnnotationType(getAnnotationType(uuidTreeIndex, "TreeIndex", "TreeIndex", "TI"));
546
		List<TaxonNode> rankSpecificRootNodes;
547
		for (Classification classification : classificationList) {
548
			for (Rank rank : rankList) {
549

  
550
				txStatus = startTransaction(true);
551
				logger.info("Started transaction to fetch all rootNodes specific to Rank " + rank.getLabel() + " ...");
552

  
553
				rankSpecificRootNodes = getClassificationService().listRankSpecificRootNodes(classification,
554
				        null, rank, includeUnpublished, null, null, null);
555
				logger.info("Fetched " + rankSpecificRootNodes.size() + " RootNodes for Rank " + rank.getLabel());
556

  
557
				commitTransaction(txStatus);
558
				logger.debug("Committed transaction.");
559

  
560
				for (TaxonNode rootNode : rankSpecificRootNodes) {
561
					txStatus = startTransaction(false);
562
					Rank endRank = rank2endRankMap.get(rank);
563
					if (endRank != null) {
564
						logger.debug("Started transaction to traverse childNodes of rootNode (" + rootNode.getUuid() + ") till Rank " + endRank.getLabel() + " ...");
565
					} else {
566
						logger.debug("Started transaction to traverse childNodes of rootNode (" + rootNode.getUuid() + ") till leaves are reached ...");
567
					}
568

  
569
					TaxonNode newNode = getTaxonNodeService().load(rootNode.getUuid());
570

  
571
					if (isPesiTaxon(newNode.getTaxon())){
572
						TaxonNode parentNode = newNode.getParent();
573
						if (rank.equals(Rank.KINGDOM())) {
574
							treeIndex = new StringBuffer();
575
							treeIndex.append("#");
576
						} else {
577
							// Get treeIndex from parentNode
578
							if (parentNode != null) {
579
								boolean annotationFound = false;
580
								Set<Annotation> annotations = parentNode.getAnnotations();
581
								for (Annotation annotation : annotations) {
582
									AnnotationType annotationType = annotation.getAnnotationType();
583
									if (annotationType != null && annotationType.equals(getTreeIndexAnnotationType())) {
584
										treeIndex = new StringBuffer(CdmUtils.Nz(annotation.getText()));
585
										annotationFound = true;
586
	//									logger.error("treeIndex: " + treeIndex);
587
										break;
588
									}
589
								}
590
								if (!annotationFound) {
591
									// This should not happen because it means that the treeIndex was not set correctly as an annotation to parentNode
592
									logger.error("TreeIndex could not be read from annotation of TaxonNode: " + parentNode.getUuid() + ", Taxon: " + parentNode.getTaxon().getUuid());
593
									treeIndex = new StringBuffer();
594
									treeIndex.append("#");
595
								}
596
							} else {
597
								// TreeIndex could not be determined, but it's unclear how to proceed to generate a correct treeIndex if the parentNode is NULL
598
								logger.error("ParentNode for RootNode is NULL. TreeIndex could not be determined: " + newNode.getUuid());
599
								treeIndex = new StringBuffer(); // This just prevents growing of the treeIndex in a wrong manner
600
								treeIndex.append("#");
601
							}
602
						}
603
						nomenclaturalCode = newNode.getTaxon().getName().getNameType();
604
						kingdomFk = PesiTransformer.nomenclaturalCode2Kingdom(nomenclaturalCode);
605
						traverseTree(newNode, parentNode, treeIndex, endRank, state);
606
						parentNode =null;
607
					}else{
608
						logger.debug("Taxon is not a PESI taxon: " + newNode.getTaxon().getUuid());
609
					}
610

  
611
					newNode = null;
612

  
613
					try {
614
						commitTransaction(txStatus);
615
						logger.debug("Committed transaction.");
616
					} catch (Exception e) {
617
						logger.error(e.getMessage());
618
						e.printStackTrace();
619
					}
620

  
621
				}
622
				rankSpecificRootNodes = null;
623
			}
624

  
625
		}
626

  
627
		logger.warn("Taking snapshot at the end of phase 2 of taxonExport");
628
		//ProfilerController.memorySnapshot();
629
		return success;
630
	}
514
//	// 2nd Round: Add ParentTaxonFk, TreeIndex to each Taxon
515
//	private boolean doPhase02_OLD(PesiExportState state) {
516
//		boolean success = true;
517
//		boolean includeUnpublished = false;
518
//		if (! state.getConfig().isDoTreeIndex()){
519
//			logger.info ("Ignore PHASE 2: ParentTaxonFk and TreeIndex");
520
//			return success;
521
//		}
522
//
523
//		List<Classification> classificationList = null;
524
//		logger.info("PHASE 2: Add ParenTaxonFk and TreeIndex...");
525
//
526
//		// Specify starting ranks for tree traversing
527
//		rankList.add(Rank.KINGDOM());
528
//		rankList.add(Rank.GENUS());
529
//
530
//		// Specify where to stop traversing (value) when starting at a specific Rank (key)
531
//		rank2endRankMap.put(Rank.GENUS(), null); // Since NULL does not match an existing Rank, traverse all the way down to the leaves
532
//		rank2endRankMap.put(Rank.KINGDOM(), Rank.GENUS()); // excludes rank genus
533
//
534
//		StringBuffer treeIndex = new StringBuffer();
535
//
536
//		// Retrieve list of classifications
537
//		TransactionStatus txStatus = startTransaction(true);
538
//		logger.info("Started transaction for parentFk and treeIndex. Fetching all classifications...");
539
//		classificationList = getClassificationService().listClassifications(null, 0, null, null);
540
//		commitTransaction(txStatus);
541
//		logger.debug("Committed transaction.");
542
//
543
//		logger.info("Fetched " + classificationList.size() + " classification(s).");
544
//
545
//		setTreeIndexAnnotationType(getAnnotationType(uuidTreeIndex, "TreeIndex", "TreeIndex", "TI"));
546
//		List<TaxonNode> rankSpecificRootNodes;
547
//		for (Classification classification : classificationList) {
548
//			for (Rank rank : rankList) {
549
//
550
//				txStatus = startTransaction(true);
551
//				logger.info("Started transaction to fetch all rootNodes specific to Rank " + rank.getLabel() + " ...");
552
//
553
//				rankSpecificRootNodes = getClassificationService().listRankSpecificRootNodes(classification,
554
//				        null, rank, includeUnpublished, null, null, null);
555
//				logger.info("Fetched " + rankSpecificRootNodes.size() + " RootNodes for Rank " + rank.getLabel());
556
//
557
//				commitTransaction(txStatus);
558
//				logger.debug("Committed transaction.");
559
//
560
//				for (TaxonNode rootNode : rankSpecificRootNodes) {
561
//					txStatus = startTransaction(false);
562
//					Rank endRank = rank2endRankMap.get(rank);
563
//					if (endRank != null) {
564
//						logger.debug("Started transaction to traverse childNodes of rootNode (" + rootNode.getUuid() + ") till Rank " + endRank.getLabel() + " ...");
565
//					} else {
566
//						logger.debug("Started transaction to traverse childNodes of rootNode (" + rootNode.getUuid() + ") till leaves are reached ...");
567
//					}
568
//
569
//					TaxonNode newNode = getTaxonNodeService().load(rootNode.getUuid());
570
//
571
//					if (isPesiTaxon(newNode.getTaxon())){
572
//						TaxonNode parentNode = newNode.getParent();
573
//						if (rank.equals(Rank.KINGDOM())) {
574
//							treeIndex = new StringBuffer();
575
//							treeIndex.append("#");
576
//						} else {
577
//							// Get treeIndex from parentNode
578
//							if (parentNode != null) {
579
//								boolean annotationFound = false;
580
//								Set<Annotation> annotations = parentNode.getAnnotations();
581
//								for (Annotation annotation : annotations) {
582
//									AnnotationType annotationType = annotation.getAnnotationType();
583
//									if (annotationType != null && annotationType.equals(getTreeIndexAnnotationType())) {
584
//										treeIndex = new StringBuffer(CdmUtils.Nz(annotation.getText()));
585
//										annotationFound = true;
586
//	//									logger.error("treeIndex: " + treeIndex);
587
//										break;
588
//									}
589
//								}
590
//								if (!annotationFound) {
591
//									// This should not happen because it means that the treeIndex was not set correctly as an annotation to parentNode
592
//									logger.error("TreeIndex could not be read from annotation of TaxonNode: " + parentNode.getUuid() + ", Taxon: " + parentNode.getTaxon().getUuid());
593
//									treeIndex = new StringBuffer();
594
//									treeIndex.append("#");
595
//								}
596
//							} else {
597
//								// TreeIndex could not be determined, but it's unclear how to proceed to generate a correct treeIndex if the parentNode is NULL
598
//								logger.error("ParentNode for RootNode is NULL. TreeIndex could not be determined: " + newNode.getUuid());
599
//								treeIndex = new StringBuffer(); // This just prevents growing of the treeIndex in a wrong manner
600
//								treeIndex.append("#");
601
//							}
602
//						}
603
//						nomenclaturalCode = newNode.getTaxon().getName().getNameType();
604
//						kingdomFk = PesiTransformer.nomenclaturalCode2Kingdom(nomenclaturalCode);
605
//						traverseTree(newNode, parentNode, treeIndex, endRank, state);
606
//						parentNode =null;
607
//					}else{
608
//						logger.debug("Taxon is not a PESI taxon: " + newNode.getTaxon().getUuid());
609
//					}
610
//
611
//					newNode = null;
612
//
613
//					try {
614
//						commitTransaction(txStatus);
615
//						logger.debug("Committed transaction.");
616
//					} catch (Exception e) {
617
//						logger.error(e.getMessage());
618
//						e.printStackTrace();
619
//					}
620
//
621
//				}
622
//				rankSpecificRootNodes = null;
623
//			}
624
//
625
//		}
626
//
627
//		logger.warn("Taking snapshot at the end of phase 2 of taxonExport");
628
//		//ProfilerController.memorySnapshot();
629
//		return success;
630
//	}
631 631

  
632 632
	//PHASE 3: Add Rank data, KingdomFk, TypeNameFk, expertFk and speciesExpertFk...
633 633
	private boolean doPhase03(PesiExportState state) {
......
653 653

  
654 654
			logger.debug("Fetched " + list.size() + " " + pluralString + ". Exporting...");
655 655
			for (TaxonBase<?> taxon : list) {
656
				TaxonName taxonName = taxon.getName();
656
				TaxonName taxonName = CdmBase.deproxy(taxon.getName());
657 657
				// Determine expertFk
658 658
//				Integer expertFk = makeExpertFk(state, taxonName);
659 659
//
......
1349 1349
			rankTypeExpertsUpdateStmt.executeUpdate();
1350 1350
			return true;
1351 1351
		} catch (SQLException e) {
1352
			logger.error("Data could not be inserted into database: " + e.getMessage());
1352
			logger.error("Data could not be inserted into database: " + e.getMessage() + "; rankFk = " + rankFk + "; kingdomFk = " + kingdomFk );
1353 1353
			e.printStackTrace();
1354 1354
			return false;
1355 1355
		} catch (Exception e) {
1356
			logger.error("Some exception occurred: " + e.getMessage());
1356
			logger.error("Some exception occurred: " + e.getMessage() + "; rankFk = " + rankFk + "; kingdomFk = " + kingdomFk);
1357 1357
			e.printStackTrace();
1358 1358
			return false;
1359 1359
		}
......
1384 1384
	 */
1385 1385
	@SuppressWarnings("unused")  //used by mapper
1386 1386
	private static Integer getKingdomFk(TaxonName taxonName){
1387
		return PesiTransformer.nomenclaturalCode2Kingdom(taxonName.getNomenclaturalCode());
1387
		return PesiTransformer.nomenclaturalCode2Kingdom(taxonName.getNameType());
1388 1388
	}
1389 1389

  
1390 1390
	/**

Also available in: Unified diff