commit d27fae52ff1902333e6617e0a3f79285f8bd6e25
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Wed Aug 31 12:27:39 2016 +0200

    ref #5448 Reduce multiple ex authors to only two

diff --git a/app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportAuthor.java b/app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportAuthor.java
index 9433085f..2f96e54f 100644
--- a/app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportAuthor.java
+++ b/app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportAuthor.java
@@ -100,10 +100,10 @@ public class RedListGefaesspflanzenImportAuthor extends DbImportBase<RedListGefa
         TeamOrPersonBase<?> teamOrPerson;
         //check if there are ex authors
         if(authorName.contains(RedListUtil.EX)){
-            String[] split = authorName.split(RedListUtil.EX);
-            for (int i = 0; i < split.length; i++) {
-                makePerson(state, split[i].trim());
-            }
+            String author = RedListUtil.getAuthorOfExAuthorshipString(authorName);
+            String exAuthor = RedListUtil.getExAuthorOfExAuthorshipString(authorName);
+            makePerson(state, author);
+            makePerson(state, exAuthor);
         }
         //check if it is a team
         if(authorName.contains("&")){
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 77008624..7eae1ad4 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
@@ -265,13 +265,12 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
         if(authorKombString.contains(RedListUtil.EX)){
             // multiple ex authors will be reduced to only the last one
             // e.g. Almq. ex Sternström ex Dahlst. -> Almq. ex Dahlst.
-            String[] kombSplit = authorKombString.split(RedListUtil.EX);
             //first author is ex combination author
-            String exAuthorString = kombSplit[0];
+            String exAuthorString = RedListUtil.getExAuthorOfExAuthorshipString(authorKombString);
             TeamOrPersonBase<?> exAuthor = (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, exAuthorString);
             name.setExCombinationAuthorship(exAuthor);
             //the last author is the combination author
-            String authorString = kombSplit[kombSplit.length-1];
+            String authorString = RedListUtil.getAuthorOfExAuthorshipString(authorKombString);
             TeamOrPersonBase<?> combAuthor = (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, authorString);
             name.setCombinationAuthorship(combAuthor);
         }
@@ -284,29 +283,19 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
         }
         //basionym author
         if(authorBasiString.contains(RedListUtil.EX)){
-            String[] basiSplit = authorBasiString.split(RedListUtil.EX);
-            for (int i = 0; i < basiSplit.length; i++) {
-                if(basiSplit.length!=2){
-                    RedListUtil.logMessage(id, "Multiple ex basionymn authors found", logger);
-                }
-                if(i==0){
-                    TeamOrPersonBase<?> authorBasi= (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, basiSplit[i]);
-                    if(CdmUtils.isBlank(authorKombString)){
-                        name.setExCombinationAuthorship(authorBasi);
-                    }
-                    else{
-                        name.setExBasionymAuthorship(authorBasi);
-                    }
-                }
-                else{
-                    TeamOrPersonBase<?> authorBasi= (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, basiSplit[i]);
-                    if(CdmUtils.isBlank(authorKombString)){
-                        name.setCombinationAuthorship(authorBasi);
-                    }
-                    else{
-                        name.setBasionymAuthorship(authorBasi);
-                    }
-                }
+            TeamOrPersonBase<?> authorExBasi= (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, RedListUtil.getExAuthorOfExAuthorshipString(authorBasiString));
+            if(CdmUtils.isBlank(authorKombString)){
+                name.setExCombinationAuthorship(authorExBasi);
+            }
+            else{
+                name.setExBasionymAuthorship(authorExBasi);
+            }
+            TeamOrPersonBase<?> authorBasi= (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, RedListUtil.getAuthorOfExAuthorshipString(authorBasiString));
+            if(CdmUtils.isBlank(authorKombString)){
+                name.setCombinationAuthorship(authorBasi);
+            }
+            else{
+                name.setBasionymAuthorship(authorBasi);
             }
         }
         else if(CdmUtils.isNotBlank(authorBasiString)){
@@ -508,6 +497,11 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
         if(authorString.equals(RedListUtil.AUCT)){
             authorString = "";
         }
+        if(authorString.contains(RedListUtil.EX)){
+            String exAuthor = RedListUtil.getExAuthorOfExAuthorshipString(authorString);
+            String author = RedListUtil.getAuthorOfExAuthorshipString(authorString);
+            authorString = exAuthor+RedListUtil.EX+author;
+        }
         if(STRICT_TITLE_CHECK){
             if(!authorString.equals(authorshipCache)){
                 RedListUtil.logMessage(id, "Authorship inconsistent! name.authorhshipCache <-> Column "+RedListUtil.AUTOR+": "+authorshipCache+" <-> "+authorString, logger);
diff --git a/app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListUtil.java b/app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListUtil.java
index 9476dae1..f748b498 100644
--- a/app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListUtil.java
+++ b/app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListUtil.java
@@ -132,4 +132,20 @@ public class RedListUtil {
         logger.info(NAMNR+": "+id+" "+message);
     }
 
+    public static String getAuthorOfExAuthorshipString(String authorshipString){
+        return getAuthorOfExAuthorship(authorshipString, false);
+    }
+
+    public static String getExAuthorOfExAuthorshipString(String authorshipString){
+        return getAuthorOfExAuthorship(authorshipString, true);
+    }
+
+    private static String getAuthorOfExAuthorship(String authorshipString, boolean isExAuthor){
+        String[] split = authorshipString.split(EX);
+        if(split.length>0){
+            return isExAuthor?split[0].trim():split[split.length-1].trim();
+        }
+        return null;
+    }
+
 }
