commit 76dce3500132db2ec539e04a3680360b7a3beded
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Tue Mar 15 09:24:14 2016 +0100

    Unifiy name and taxon creation

diff --git a/app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportConfigurator.java b/app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportConfigurator.java
index b368b8d1..09e5064c 100644
--- a/app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportConfigurator.java
+++ b/app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportConfigurator.java
@@ -36,9 +36,8 @@ public class RedListGefaesspflanzenImportConfigurator extends
     @Override
     protected void makeIoClassList() {
         ioClassList = new Class[]{
-//                RedListGefaesspflanzenImportAuthor.class,
-//                RedListGefaesspflanzenImportNames.class,
-                RedListGefaesspflanzenImportTaxa.class,
+                RedListGefaesspflanzenImportAuthor.class,
+                RedListGefaesspflanzenImportNames.class,
                 RedListGefaesspflanzenImportClassification.class,
         };
     }
diff --git a/app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportNames.java b/app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportNames.java
index 4a6f2ece..26b7b6d5 100644
--- a/app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportNames.java
+++ b/app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportNames.java
@@ -31,6 +31,9 @@ import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.name.BotanicalName;
 import eu.etaxonomy.cdm.model.name.Rank;
 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
+import eu.etaxonomy.cdm.model.taxon.Synonym;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
 
 /**
  *
@@ -83,9 +86,10 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
     public boolean doPartition(ResultSetPartitioner partitioner, RedListGefaesspflanzenImportState state) {
         ResultSet rs = partitioner.getResultSet();
         Set<TaxonNameBase> namesToSave = new HashSet<TaxonNameBase>();
+        Set<TaxonBase> taxaToSave = new HashSet<TaxonBase>();
         try {
             while (rs.next()){
-                makeSingleName(state, rs, namesToSave);
+                makeSingleNameAndTaxon(state, rs, namesToSave, taxaToSave);
 
             }
         } catch (SQLException e) {
@@ -93,13 +97,15 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
         }
 
         getNameService().saveOrUpdate(namesToSave);
+        getTaxonService().saveOrUpdate(taxaToSave);
         return true;
     }
 
-    private void makeSingleName(RedListGefaesspflanzenImportState state, ResultSet rs, Set<TaxonNameBase> namesToSave)
+    private void makeSingleNameAndTaxon(RedListGefaesspflanzenImportState state, ResultSet rs, Set<TaxonNameBase> namesToSave, Set<TaxonBase> taxaToSave)
             throws SQLException {
         long id = rs.getLong("NAMNR");
         String taxNameString = rs.getString("TAXNAME");
+        String gueltString = rs.getString("GUELT");
         String rangString = rs.getString("RANG");
         String ep1String = rs.getString("EPI1");
         String ep2String = rs.getString("EPI2");
@@ -116,7 +122,6 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
         Rank rank = makeRank(state, rangString);
         if(rank==null){
             logger.error("NAMNR: "+id+" Rank could not be resolved.");
-            return;
         }
         BotanicalName name = BotanicalName.NewInstance(rank);
 
@@ -194,6 +199,28 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
         state.getNameMap().put(id, name.getUuid());
 
         namesToSave.add(name);
+
+        //---TAXON---
+        TaxonBase taxonBase = null;
+        if(gueltString.equals("1")){
+            taxonBase = Taxon.NewInstance(name, null);
+        }
+        else if(gueltString.equals("x")){
+            taxonBase = Synonym.NewInstance(name, null);
+        }
+        else if(gueltString.equals("b")){
+            taxonBase = Synonym.NewInstance(name, null);
+        }
+        if(taxonBase==null){
+            logger.error("NAMNR: "+id+" Taxon for name "+name+" could not be created.");
+            return;
+        }
+
+        taxaToSave.add(taxonBase);
+
+        //id
+        ImportHelper.setOriginalSource(taxonBase, state.getTransactionalSourceReference(), id, Namespace.TAXON_NAMESPACE);
+        state.getTaxonMap().put(id, taxonBase.getUuid());
     }
 
     private Rank makeRank(RedListGefaesspflanzenImportState state, String rankStr) {
diff --git a/app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportTaxa.java b/app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportTaxa.java
deleted file mode 100644
index 9f266584..00000000
--- a/app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportTaxa.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/**
- * Copyright (C) 2007 EDIT
- * European Distributed Institute of Taxonomy
- * http://www.e-taxonomy.eu
- *
- * The contents of this file are subject to the Mozilla Public License Version 1.1
- * See LICENSE.TXT at the top of this package for the full license terms.
- */
-
-package eu.etaxonomy.cdm.io.redlist.gefaesspflanzen;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
-import eu.etaxonomy.cdm.io.common.DbImportBase;
-import eu.etaxonomy.cdm.io.common.IPartitionedIO;
-import eu.etaxonomy.cdm.io.common.ImportHelper;
-import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
-import eu.etaxonomy.cdm.model.common.CdmBase;
-import eu.etaxonomy.cdm.model.name.BotanicalName;
-import eu.etaxonomy.cdm.model.name.Rank;
-import eu.etaxonomy.cdm.model.taxon.Synonym;
-import eu.etaxonomy.cdm.model.taxon.Taxon;
-import eu.etaxonomy.cdm.model.taxon.TaxonBase;
-
-/**
- *
- * @author pplitzner
- * @date Mar 1, 2016
- *
- */
-
-@Component
-@SuppressWarnings("serial")
-public class RedListGefaesspflanzenImportTaxa extends DbImportBase<RedListGefaesspflanzenImportState, RedListGefaesspflanzenImportConfigurator> {
-
-    private static final Logger logger = Logger.getLogger(RedListGefaesspflanzenImportTaxa.class);
-
-    private static final String tableName = "Rote Liste Gefäßpflanzen";
-
-    private static final String pluralString = "taxa";
-
-    public RedListGefaesspflanzenImportTaxa() {
-        super(tableName, pluralString);
-    }
-
-    @Override
-    protected String getIdQuery(RedListGefaesspflanzenImportState state) {
-        return "SELECT NAMNR "
-                + "FROM V_TAXATLAS_D20_EXPORT t "
-                + " ORDER BY NAMNR";
-    }
-
-    @Override
-    protected String getRecordQuery(RedListGefaesspflanzenImportConfigurator config) {
-        String result = " SELECT * "
-                + " FROM V_TAXATLAS_D20_EXPORT t "
-                + " WHERE t.NAMNR IN (@IDSET)";
-        result = result.replace("@IDSET", IPartitionedIO.ID_LIST_TOKEN);
-        return result;
-    }
-
-    @Override
-    protected void doInvoke(RedListGefaesspflanzenImportState state) {
-        super.doInvoke(state);
-    }
-
-    @Override
-    public boolean doPartition(ResultSetPartitioner partitioner, RedListGefaesspflanzenImportState state) {
-        ResultSet rs = partitioner.getResultSet();
-        Set<TaxonBase> taxaToSave = new HashSet<>();
-        try {
-            while (rs.next()){
-                makeSingleTaxon(state, rs, taxaToSave);
-
-            }
-        } catch (SQLException e) {
-            e.printStackTrace();
-        }
-
-        getTaxonService().saveOrUpdate(taxaToSave);
-        return true;
-    }
-
-    private void makeSingleTaxon(RedListGefaesspflanzenImportState state, ResultSet rs, Set<TaxonBase> taxaToSave)
-            throws SQLException {
-        long id = rs.getLong("NAMNR");
-        String gueltString = rs.getString("GUELT");
-
-//        BotanicalName name = state.getRelatedObject(Namespace.NAME_NAMESPACE,String.valueOf(id), BotanicalName.class);
-        BotanicalName name = BotanicalName.NewInstance(Rank.GENUS());
-        name.setGenusOrUninomial(String.valueOf(id));
-
-        TaxonBase taxonBase = null;
-        if(gueltString.equals("1")){
-            taxonBase = Taxon.NewInstance(name, null);
-        }
-        else if(gueltString.equals("x")){
-            taxonBase = Synonym.NewInstance(name, null);
-        }
-        else if(gueltString.equals("b")){
-            taxonBase = Synonym.NewInstance(name, null);
-        }
-        if(taxonBase==null){
-            logger.error("NAMNR: "+id+" Taxon for name "+name+" could not be created.");
-            return;
-        }
-
-        taxaToSave.add(taxonBase);
-
-        //id
-        ImportHelper.setOriginalSource(taxonBase, state.getTransactionalSourceReference(), id, Namespace.TAXON_NAMESPACE);
-        state.getTaxonMap().put(id, taxonBase.getUuid());
-    }
-
-    @Override
-    public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs,
-            RedListGefaesspflanzenImportState state) {
-        Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
-//        Map<String, BotanicalName> nameMap = new HashMap<String, BotanicalName>();
-//        try {
-//            while (rs.next()){
-//                long id = rs.getLong("NAMNR");
-//                nameMap.put(String.valueOf(id), (BotanicalName) getNameService().load(state.getNameMap().get(id)));
-//            }
-//        } catch (SQLException e) {
-//            e.printStackTrace();
-//        }
-//        result.put(Namespace.NAME_NAMESPACE, nameMap);
-
-        return result;
-    }
-
-    @Override
-    protected boolean doCheck(RedListGefaesspflanzenImportState state) {
-        return false;
-    }
-
-    @Override
-    protected boolean isIgnore(RedListGefaesspflanzenImportState state) {
-        return false;
-    }
-
-}
