commit 9ff7f3d8faa813ee9ed4695f810410dec8f79a9d
Author: Katja Luther <k.luther@bgbm.org>
Date:   Fri Oct 25 13:00:15 2019 +0200

    merging fauna Eu - Erms -continue

diff --git a/cdm-pesi/src/main/java/eu/etaxonomy/cdm/app/pesi/merging/FaunaEuErmsFindIdenticalNamesActivator.java b/cdm-pesi/src/main/java/eu/etaxonomy/cdm/app/pesi/merging/FaunaEuErmsFindIdenticalNamesActivator.java
index 0dae4f73..96c84649 100644
--- a/cdm-pesi/src/main/java/eu/etaxonomy/cdm/app/pesi/merging/FaunaEuErmsFindIdenticalNamesActivator.java
+++ b/cdm-pesi/src/main/java/eu/etaxonomy/cdm/app/pesi/merging/FaunaEuErmsFindIdenticalNamesActivator.java
@@ -95,7 +95,8 @@ public class FaunaEuErmsFindIdenticalNamesActivator {
 		resultOK = resultOK && sc.writeSameNamesdifferentAuthorToCsv(mergingObjects, sFileName + "_authors.csv");
 		resultOK = resultOK &&sc.writeSameNamesdifferentStatusToCsv(mergingObjects, sFileName + "_status.csv");
 		resultOK = resultOK &&sc.writeSameNamesToCsVFile(mergingObjects, sFileName + "_names.csv");
-		resultOK = resultOK &&sc.writeSameNamesdifferentPhylumToCsv(mergingObjects, sFileName + "_phylum.csv");
+		//do not create the phylum file, explanation inside the method writeSameNamesdifferentPhylumToCsv
+		//resultOK = resultOK &&sc.writeSameNamesdifferentPhylumToCsv(mergingObjects, sFileName + "_phylum.csv");
 		resultOK = resultOK &&sc.writeSameNamesDifferentParentToCsv(mergingObjects, sFileName + "parent.csv");
 
 		System.err.println("End merging Fauna Europaea and Erms" + resultOK);
@@ -125,6 +126,7 @@ public class FaunaEuErmsFindIdenticalNamesActivator {
 	private boolean writeSameNamesdifferentPhylumToCsv(List<FaunaEuErmsMerging> mergingObjects, String sfileName){
 		try
 		{
+			//do we really need this?? it is a taxon needed merged like all others? for erms only one taxon has different phylum. (Valencia, but these are not the same taxa -> fish and ribbon worms)
 		    FileWriter writer = new FileWriter(sfileName);
 
 		    //create Header
@@ -133,11 +135,11 @@ public class FaunaEuErmsFindIdenticalNamesActivator {
 
 			//write data
 			for (FaunaEuErmsMerging merging : mergingObjects){
-		    	//TODO
+		    	//TODO the phyllum is always different doing it this way, maybe we need to merge the phylum taxa first and then 
 				if ((merging.getPhylumInErms()== null )^ (merging.getPhylumInFaunaEu()== null)){
 					writeCsvLine(writer, merging) ;
 				}else if(!((merging.getPhylumInErms()==null) && (merging.getPhylumInFaunaEu()==null))){
-					if(!merging.getPhylumInErms().equals(merging.getPhylumInFaunaEu())){
+					if(!merging.getPhylumInErms().getNameTitleCache().equals(merging.getPhylumInFaunaEu().getNameTitleCache())){
 						writeCsvLine(writer, merging) ;
 					}
 				}
@@ -214,38 +216,38 @@ public class FaunaEuErmsFindIdenticalNamesActivator {
 			writer.append(';');
 			writer.append("id in Fauna Europaea");
 			writer.append(';');
-			writer.append("name");
+			writer.append("name in FE");
 			writer.append(';');
-			writer.append("author");
+			writer.append("author in FE");
 			writer.append(';');
-			writer.append("rank");
+			writer.append("rank in FE");
 			writer.append(';');
-			writer.append("state");
+			writer.append("state in FE");
 			writer.append(';');
-			writer.append("phylum");
+			writer.append("phylum in FE");
 			writer.append(';');
-			writer.append("parent");
+			writer.append("parent in FE");
 			writer.append(';');
-			writer.append("parent rank");
+			writer.append("parent rank in FE");
 			writer.append(';');
 
 			writer.append("uuid in Erms");
 			writer.append(';');
 			writer.append("id in Erms");
 			writer.append(';');
-			writer.append("name");
+			writer.append("name in Erms");
 			writer.append(';');
-			writer.append("author");
+			writer.append("author in Erms");
 			writer.append(';');
-			writer.append("rank");
+			writer.append("rank in Erms");
 			writer.append(';');
-			writer.append("state");
+			writer.append("state in Erms");
 			writer.append(';');
-			writer.append("phylum");
+			writer.append("phylum in Erms");
 			writer.append(';');
-			writer.append("parent");
+			writer.append("parent in Erms");
 			writer.append(';');
-			writer.append("parent rank");
+			writer.append("parent rank in Erms");
 			writer.append('\n');
 	}
 
@@ -348,7 +350,7 @@ public class FaunaEuErmsFindIdenticalNamesActivator {
 		}
 
 		writer.append(';');
-		writer.append(merging.getPhylumInErms() != null? merging.getPhylumInErms().getTaxonTitleCache():"");
+		writer.append(merging.getPhylumInErms() != null? merging.getPhylumInErms().getTitleCache():"");
 		writer.append(';');
 		writer.append(merging.getParentStringInErms());
 		writer.append(';');
@@ -537,33 +539,10 @@ public class FaunaEuErmsFindIdenticalNamesActivator {
 			mergeObject.setRankInErms(ermsName.getRank().getLabel());
 			mergeObject.setRankInFaunaEu(faunaEuName.getRank().getLabel());
 
-			//set parent informations
-
-
-			/*
-			Set<HybridRelationship> parentRelations = zooName.getParentRelationships();
-			Iterator parentIterator = parentRelations.iterator();
-			HybridRelationship parentRel;
-			ZoologicalName parentName;
-			while (parentIterator.hasNext()){
-				parentRel = (HybridRelationship)parentIterator.next();
-				parentName = (ZoologicalName)parentRel.getParentName();
-				mergeObject.setParentRankStringInErms(parentName.getRank().getLabel());
-				mergeObject.setParentStringInErms(parentName.getNameCache());
-			}
-
-			parentRelations = zooName2.getParentRelationships();
-			parentIterator = parentRelations.iterator();
-
-			while (parentIterator.hasNext()){
-				parentRel = (HybridRelationship)parentIterator.next();
-				parentName = (ZoologicalName)parentRel.getParentName();
-				mergeObject.setParentRankStringInFaunaEu(parentName.getRank().getLabel());
-				mergeObject.setParentStringInFaunaEu(parentName.getNameCache());
-			}*/
+		
 			merge.add(mergeObject);
 		}
-//		}
+
 
 		return merge;
 
diff --git a/cdm-pesi/src/main/java/eu/etaxonomy/cdm/app/pesi/merging/FaunaEuErmsMergeActivator.java b/cdm-pesi/src/main/java/eu/etaxonomy/cdm/app/pesi/merging/FaunaEuErmsMergeActivator.java
index 53cc4258..ecb94eb2 100644
--- a/cdm-pesi/src/main/java/eu/etaxonomy/cdm/app/pesi/merging/FaunaEuErmsMergeActivator.java
+++ b/cdm-pesi/src/main/java/eu/etaxonomy/cdm/app/pesi/merging/FaunaEuErmsMergeActivator.java
@@ -19,7 +19,6 @@ import eu.etaxonomy.cdm.api.application.CdmApplicationController;
 import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
 import eu.etaxonomy.cdm.api.service.pager.Pager;
 import eu.etaxonomy.cdm.app.common.CdmDestinations;
-
 import eu.etaxonomy.cdm.database.DbSchemaValidation;
 import eu.etaxonomy.cdm.database.ICdmDataSource;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
@@ -36,6 +35,7 @@ import eu.etaxonomy.cdm.model.name.IZoologicalName;
 import eu.etaxonomy.cdm.model.name.NameRelationship;
 import eu.etaxonomy.cdm.model.name.Rank;
 import eu.etaxonomy.cdm.model.reference.Reference;
+import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.model.taxon.Synonym;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
@@ -50,6 +50,8 @@ public class FaunaEuErmsMergeActivator {
 	static final int ermsUuid = 9;
 	static final int rankFaunaEu = 4;
 	static final int rankErms = 13;
+	Classification faunaEuClassification;
+	Classification ermsClassification;
 
 	CdmApplicationController appCtrInit;
 
@@ -71,7 +73,7 @@ public class FaunaEuErmsMergeActivator {
 		FaunaEuErmsMergeActivator sc = new FaunaEuErmsMergeActivator();
 
 		sc.initDb(faunaEuropaeaSource);
-//we also need to merge names completely identical!
+		//we also need to merge names completely identical!
 		sc.mergeAuthors();
 
 		//set the ranks of Agnatha and Gnathostomata to 50 instead of 45
@@ -203,10 +205,11 @@ public class FaunaEuErmsMergeActivator {
 
 		TaxonBase<?> taxonFaunaEu;
 		TaxonBase<?> taxonErms;
-
+		List<String> propertyPaths = new ArrayList<>();
+		propertyPaths.add("taxonBases.nodes.*");
 		for (List<String> row: sameStatus){
-			taxonFaunaEu = appCtrInit.getTaxonService().find(UUID.fromString(row.get(faunaEuUuid)));
-			taxonErms = appCtrInit.getTaxonService().find(UUID.fromString(row.get(ermsUuid)));
+			taxonFaunaEu = appCtrInit.getTaxonService().load(UUID.fromString(row.get(faunaEuUuid)), propertyPaths);
+			taxonErms = appCtrInit.getTaxonService().load(UUID.fromString(row.get(ermsUuid)), propertyPaths);
 			moveAllInformationsFromFaunaEuToErms(taxonFaunaEu, taxonErms);
 			if (taxonErms instanceof Taxon){
 				moveFaunaEuSynonymsToErmsTaxon((Taxon)taxonFaunaEu, (Taxon)taxonErms);
@@ -450,6 +453,20 @@ public class FaunaEuErmsMergeActivator {
 		for (Credit credit: credits){
 			erms.addCredit(credit);
 		}
+		//move children to erms taxon
+		if (faunaEu instanceof Taxon && ((Taxon)faunaEu).getTaxonNode(faunaEuClassification).hasChildNodes()) {
+			Taxon acceptedErmsTaxon;
+			if (erms instanceof Synonym) {
+				acceptedErmsTaxon = ((Synonym)erms).getAcceptedTaxon();
+			}else {
+				acceptedErmsTaxon = (Taxon)erms;
+			}
+			TaxonNode node = ((Taxon)acceptedErmsTaxon).getTaxonNode(ermsClassification);
+			for (TaxonNode child:((Taxon)faunaEu).getTaxonNode(faunaEuClassification).getChildNodes()) {
+				//add pesi reference as reference??
+				node.addChildNode(child, null, null);
+			}
+		}
 	}
 
 	//if name, rank, and status (accepted) are the same, then move the synonyms of faunaEu taxon to the erms taxon
@@ -474,7 +491,8 @@ public class FaunaEuErmsMergeActivator {
 	//merged taxon should have a new sec reference
 	private void addNewSecForMergedTaxon(Taxon taxon, Reference sec){
 		taxon.setSec(sec);
-		taxon.setUuid(UUID.randomUUID());
+		//this does not work!!
+		//taxon.setUuid(UUID.randomUUID());
 	}
 
 	// ----------- methods for merging Erms synonyms and Fauna Europaea Taxon
