Refactor duplicate code
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 21 Mar 2016 16:56:20 +0000 (17:56 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 21 Mar 2016 16:56:20 +0000 (17:56 +0100)
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportAuthor.java
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportClassification.java
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportNames.java
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListUtil.java [moved from app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/Namespace.java with 83% similarity]

index f352022927df20c199ca30904c234342858d901d..1c64fe4610df7f929097d30db610a2148ea12e61 100644 (file)
@@ -34,6 +34,7 @@ import eu.etaxonomy.cdm.model.common.CdmBase;
 @Component
 @SuppressWarnings("serial")
 public class RedListGefaesspflanzenImportAuthor extends DbImportBase<RedListGefaesspflanzenImportState, RedListGefaesspflanzenImportConfigurator> {
+
     private static final Logger logger = Logger.getLogger(RedListGefaesspflanzenImportAuthor.class);
 
     private static final String tableName = "Rote Liste Gefäßpflanzen";
@@ -94,7 +95,7 @@ public class RedListGefaesspflanzenImportAuthor extends DbImportBase<RedListGefa
 
     private void makePerson(RedListGefaesspflanzenImportState state, String authorName) {
         //check if misapplied name
-        if(authorName.trim().equals("auct.")){
+        if(authorName.trim().equals(RedListUtil.AUCT)){
             return;
         }
         TeamOrPersonBase teamOrPerson;
index f460a0889f3c755f6cb4c593471d74ec5e43cf9d..36258f6926455e97f85eaf58fe1aee45237fb40a 100644 (file)
@@ -97,14 +97,14 @@ public class RedListGefaesspflanzenImportClassification extends DbImportBase<Red
         String parentId = String.valueOf(rs.getLong("LOWER"));
         String gueltString = rs.getString("GUELT");
 
-        TaxonBase taxonBase = state.getRelatedObject(Namespace.TAXON_NAMESPACE, id, TaxonBase.class);
-        Taxon parent = (Taxon) state.getRelatedObject(Namespace.TAXON_NAMESPACE, parentId, TaxonBase.class);
+        TaxonBase taxonBase = state.getRelatedObject(RedListUtil.TAXON_NAMESPACE, id, TaxonBase.class);
+        Taxon parent = (Taxon) state.getRelatedObject(RedListUtil.TAXON_NAMESPACE, parentId, TaxonBase.class);
 
         //taxon
         if(taxonBase.isInstanceOf(Taxon.class)){
             //misapplied name
             String appendedPhrase = taxonBase.getName().getAppendedPhrase();
-            if(appendedPhrase!=null && appendedPhrase.contains("auct.")){
+            if(appendedPhrase!=null && appendedPhrase.contains(RedListUtil.AUCT)){
                 parent.addMisappliedName((Taxon) taxonBase, null, null);
             }
             else{
@@ -140,8 +140,8 @@ public class RedListGefaesspflanzenImportClassification extends DbImportBase<Red
         } catch (SQLException e) {
             e.printStackTrace();
         }
-        Map<String, TaxonBase> taxonMap = (Map<String, TaxonBase>) getCommonService().getSourcedObjectsByIdInSource(TaxonBase.class, idSet, Namespace.TAXON_NAMESPACE);
-        result.put(Namespace.TAXON_NAMESPACE, taxonMap);
+        Map<String, TaxonBase> taxonMap = (Map<String, TaxonBase>) getCommonService().getSourcedObjectsByIdInSource(TaxonBase.class, idSet, RedListUtil.TAXON_NAMESPACE);
+        result.put(RedListUtil.TAXON_NAMESPACE, taxonMap);
         return result;
     }
 
index b3ba5489c4ae0bf473af66508b6af61ab4e125b1..84d94c69f0f2300af4b08780a97f36bc7f0ab47c 100644 (file)
@@ -149,20 +149,20 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
             for (int i = 0; i < kombSplit.length; i++) {
                 if(i==0){
                     //first author is ex author
-                    TeamOrPersonBase authorKomb = (TeamOrPersonBase) state.getRelatedObject(Namespace.AUTHOR_NAMESPACE, kombSplit[i]);
+                    TeamOrPersonBase authorKomb = (TeamOrPersonBase) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, kombSplit[i]);
                     name.setExCombinationAuthorship(authorKomb);
                 }
                 else{
-                    TeamOrPersonBase authorKomb = (TeamOrPersonBase) state.getRelatedObject(Namespace.AUTHOR_NAMESPACE, kombSplit[i]);
+                    TeamOrPersonBase authorKomb = (TeamOrPersonBase) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, kombSplit[i]);
                     name.setCombinationAuthorship(authorKomb);
                 }
             }
         }
-        else if(authorKombString.trim().equals("auct.")){
+        else if(authorKombString.trim().equals(RedListUtil.AUCT)){
             logger.warn("NAMNR: "+id+" AUCT information in AUTOR_KOMB column");
         }
         else if(!CdmUtils.isBlank(authorKombString)){
-            TeamOrPersonBase authorKomb = (TeamOrPersonBase) state.getRelatedObject(Namespace.AUTHOR_NAMESPACE, authorKombString);
+            TeamOrPersonBase authorKomb = (TeamOrPersonBase) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, authorKombString);
             name.setCombinationAuthorship(authorKomb);
         }
         //basionym author
@@ -173,7 +173,7 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
                     logger.error("NAMNR: "+id+" Multiple ex basionymn authors found");
                 }
                 if(i==0){
-                    TeamOrPersonBase authorBasi= (TeamOrPersonBase) state.getRelatedObject(Namespace.AUTHOR_NAMESPACE, basiSplit[i]);
+                    TeamOrPersonBase authorBasi= (TeamOrPersonBase) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, basiSplit[i]);
                     if(CdmUtils.isBlank(authorKombString)){
                         name.setExCombinationAuthorship(authorBasi);
                     }
@@ -182,7 +182,7 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
                     }
                 }
                 else{
-                    TeamOrPersonBase authorBasi= (TeamOrPersonBase) state.getRelatedObject(Namespace.AUTHOR_NAMESPACE, basiSplit[i]);
+                    TeamOrPersonBase authorBasi= (TeamOrPersonBase) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, basiSplit[i]);
                     if(CdmUtils.isBlank(authorKombString)){
                         name.setCombinationAuthorship(authorBasi);
                     }
@@ -192,12 +192,12 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
                 }
             }
         }
-        else if(authorBasiString.trim().equals("auct.")){
+        else if(authorBasiString.trim().equals(RedListUtil.AUCT)){
             name.setAppendedPhrase(authorBasiString);
         }
         else if(!CdmUtils.isBlank(authorBasiString)){
             //this seems to be a convention in the source database: When there is only a single author then only the "AUTOR_BASI" column is used
-            TeamOrPersonBase authorBasi= (TeamOrPersonBase) state.getRelatedObject(Namespace.AUTHOR_NAMESPACE, authorBasiString);
+            TeamOrPersonBase authorBasi= (TeamOrPersonBase) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, authorBasiString);
             if(CdmUtils.isBlank(authorKombString)){
                 name.setCombinationAuthorship(authorBasi);
             }
@@ -216,7 +216,7 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
 //        if(CdmUtils.isBlank(authorKombString) && !CdmUtils.isBlank(authorBasiString)){
 //            authorString = "("+authorString+")";
 //        }
-        if(authorString.equals("auct.")){
+        if(authorString.equals(RedListUtil.AUCT)){
             authorString = "";
         }
         if(!authorString.equals(authorshipCache)){
@@ -224,14 +224,14 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
         }
 
         //id
-        ImportHelper.setOriginalSource(name, state.getTransactionalSourceReference(), id, Namespace.NAME_NAMESPACE);
+        ImportHelper.setOriginalSource(name, state.getTransactionalSourceReference(), id, RedListUtil.NAME_NAMESPACE);
         state.getNameMap().put(id, name.getUuid());
 
         namesToSave.add(name);
 
         //---TAXON---
         TaxonBase taxonBase = null;
-        if(gueltString.equals("1") || (name.getAppendedPhrase()!=null && name.getAppendedPhrase().equals("auct."))){
+        if(gueltString.equals("1") || (name.getAppendedPhrase()!=null && name.getAppendedPhrase().equals(RedListUtil.AUCT))){
             taxonBase = Taxon.NewInstance(name, null);
         }
         else if(gueltString.equals("x") || gueltString.equals("b")){
@@ -245,7 +245,7 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
         taxaToSave.add(taxonBase);
 
         //id
-        ImportHelper.setOriginalSource(taxonBase, state.getTransactionalSourceReference(), id, Namespace.TAXON_NAMESPACE);
+        ImportHelper.setOriginalSource(taxonBase, state.getTransactionalSourceReference(), id, RedListUtil.TAXON_NAMESPACE);
         state.getTaxonMap().put(id, taxonBase.getUuid());
     }
 
@@ -303,7 +303,7 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
         } catch (SQLException e) {
             e.printStackTrace();
         }
-        result.put(Namespace.AUTHOR_NAMESPACE, authorMap);
+        result.put(RedListUtil.AUTHOR_NAMESPACE, authorMap);
 
         return result;
     }
similarity index 83%
rename from app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/Namespace.java
rename to app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListUtil.java
index 4e268ed0d9b7dfb341c3e8b3216a9bb5c181ba57..ca8a320d3ccf4a5f685f4297d227c514543a5a2a 100644 (file)
@@ -14,9 +14,14 @@ package eu.etaxonomy.cdm.io.redlist.gefaesspflanzen;
  * @date Mar 7, 2016
  *
  */
-public interface Namespace {
+public class RedListUtil {
 
     public static final String NAME_NAMESPACE = "name";
     public static final String TAXON_NAMESPACE = "taxon";
     public static final String AUTHOR_NAMESPACE = "author";
+    public static final String AUCT = "auct.";
+
+    public static logError(){
+
+    }
 }