ref #5448 Add new rank "forme"
[cdmlib-apps.git] / app-import / src / main / java / eu / etaxonomy / cdm / io / redlist / gefaesspflanzen / RedListGefaesspflanzenImportNames.java
index 11ca7df0edcdeaf07c3e4b7741bbc2c7c01d52a8..b3100204a04de95b6c3501ae1717f71e300b847b 100644 (file)
@@ -33,6 +33,7 @@ import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
 import eu.etaxonomy.cdm.model.common.Annotation;
 import eu.etaxonomy.cdm.model.common.AnnotationType;
 import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.common.ExtensionType;
 import eu.etaxonomy.cdm.model.common.Language;
 import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
 import eu.etaxonomy.cdm.model.description.CommonTaxonName;
@@ -49,8 +50,6 @@ 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;
-import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
-import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
 import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
 
 /**
@@ -72,32 +71,60 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
 
     private static final boolean STRICT_TITLE_CHECK = false;
 
+    private ExtensionType extensionTypeFlor;
+
+    private ExtensionType extensionTypeAtlasIdx;
+
+    private ExtensionType extensionTypeKart;
+
+    private ExtensionType extensionTypeRl2015;
+
+    private ExtensionType extensionTypeEhrd;
+
+    private ExtensionType extensionTypeWissk;
+
     public RedListGefaesspflanzenImportNames() {
         super(tableName, pluralString);
     }
 
     @Override
     protected String getIdQuery(RedListGefaesspflanzenImportState state) {
-        return "SELECT NAMNR "
+        return "SELECT SEQNUM "
                 + "FROM V_TAXATLAS_D20_EXPORT t "
-                + " ORDER BY NAMNR";
+                + " ORDER BY SEQNUM";
     }
 
     @Override
     protected String getRecordQuery(RedListGefaesspflanzenImportConfigurator config) {
         String result = " SELECT * "
                 + " FROM V_TAXATLAS_D20_EXPORT t "
-                + " WHERE t.NAMNR IN (@IDSET)";
+                + " WHERE t.SEQNUM IN (@IDSET)";
         result = result.replace("@IDSET", IPartitionedIO.ID_LIST_TOKEN);
         return result;
     }
 
     @Override
     protected void doInvoke(RedListGefaesspflanzenImportState state) {
+        makeExtensionTypes();
         super.doInvoke(state);
     }
 
 
+    private void makeExtensionTypes() {
+        extensionTypeFlor = ExtensionType.NewInstance(RedListUtil.FLOR, RedListUtil.FLOR, "");
+        extensionTypeAtlasIdx = ExtensionType.NewInstance(RedListUtil.ATLAS_IDX, RedListUtil.ATLAS_IDX, "");
+        extensionTypeKart = ExtensionType.NewInstance(RedListUtil.KART, RedListUtil.KART, "");
+        extensionTypeRl2015 = ExtensionType.NewInstance(RedListUtil.RL2015, RedListUtil.RL2015, "");
+        extensionTypeEhrd = ExtensionType.NewInstance(RedListUtil.EHRD, RedListUtil.EHRD, "");
+        extensionTypeWissk = ExtensionType.NewInstance(RedListUtil.WISSK, RedListUtil.WISSK, "");
+        getTermService().saveOrUpdate(extensionTypeFlor);
+        getTermService().saveOrUpdate(extensionTypeAtlasIdx);
+        getTermService().saveOrUpdate(extensionTypeKart);
+        getTermService().saveOrUpdate(extensionTypeRl2015);
+        getTermService().saveOrUpdate(extensionTypeEhrd);
+        getTermService().saveOrUpdate(extensionTypeWissk);
+    }
+
     @Override
     public boolean doPartition(ResultSetPartitioner partitioner, RedListGefaesspflanzenImportState state) {
         ResultSet rs = partitioner.getResultSet();
@@ -120,7 +147,6 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
     private void makeSingleNameAndTaxon(RedListGefaesspflanzenImportState state, ResultSet rs, Set<TaxonNameBase> namesToSave, Set<TaxonBase> taxaToSave)
             throws SQLException {
         long id = rs.getLong(RedListUtil.NAMNR);
-        String clTaxonString = rs.getString(RedListUtil.CL_TAXON);
         String relationE = rs.getString(RedListUtil.E);
         String relationW = rs.getString(RedListUtil.W);
         String relationK = rs.getString(RedListUtil.K);
@@ -140,7 +166,7 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
         //---TAXON---
         TaxonBase<?> taxonBase = importTaxon(rs, name, state);
         if(taxonBase==null){
-            RedListUtil.logMessage(id, "Taxon for name "+name+" could not be created.", logger);
+            RedListUtil.logMessage(id, "!SERIOUS ERROR! Taxon for name "+name+" could not be created!", logger);
             return;
         }
 
@@ -154,18 +180,6 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
         cloneTaxon(taxonBase, relationR, RedListUtil.CLASSIFICATION_NAMESPACE_R, taxaToSave, id, state);
         cloneTaxon(taxonBase, relationO, RedListUtil.CLASSIFICATION_NAMESPACE_O, taxaToSave, id, state);
         cloneTaxon(taxonBase, relationS, RedListUtil.CLASSIFICATION_NAMESPACE_S, taxaToSave, id, state);
-        //checklist
-        TaxonBase<?> checklistTaxon = null;
-        if(CdmUtils.isNotBlank(clTaxonString) && !clTaxonString.trim().equals("-")){
-            checklistTaxon = (TaxonBase<?>) taxonBase.clone();
-            if(checklistTaxon.isInstanceOf(Taxon.class)){
-                TaxonRelationship relation = HibernateProxyHelper.deproxy(checklistTaxon, Taxon.class).addTaxonRelation(HibernateProxyHelper.deproxy(taxonBase, Taxon.class), TaxonRelationshipType.CONGRUENT_TO(), null, null);
-                relation.setDoubtful(true);
-            }
-
-            ImportHelper.setOriginalSource(checklistTaxon, state.getTransactionalSourceReference(), id, RedListUtil.TAXON_CHECKLISTE_NAMESPACE);
-            taxaToSave.add(checklistTaxon);
-        }
 
         //NOTE: the source has to be added after cloning or otherwise the clone would also get the source
         ImportHelper.setOriginalSource(taxonBase, state.getTransactionalSourceReference(), id, RedListUtil.TAXON_GESAMTLISTE_NAMESPACE);
@@ -195,6 +209,9 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
 
         long id = rs.getLong(RedListUtil.NAMNR);
         String taxNameString = rs.getString(RedListUtil.TAXNAME);
+        String epi1String = rs.getString(RedListUtil.EPI1);
+        String epi2String = rs.getString(RedListUtil.EPI2);
+        String epi3String = rs.getString(RedListUtil.EPI3);
         String gueltString = rs.getString(RedListUtil.GUELT);
         String trivialString = rs.getString(RedListUtil.TRIVIAL);
         String authorBasiString = rs.getString(RedListUtil.AUTOR_BASI);
@@ -218,6 +235,7 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
             taxonBase = Synonym.NewInstance(name, null);
         }
         else{
+            RedListUtil.logMessage(id, "Taxon was not created!! Unknown value for "+RedListUtil.GUELT+"!", logger);
             return null;
         }
 
@@ -229,24 +247,18 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
         }
 
         //add annotations
-        addAnnotation(RedListUtil.FLOR+": "+florString, taxonBase);
-        addAnnotation(RedListUtil.ATLAS_IDX+": "+atlasIdxString, taxonBase);
-        addAnnotation(RedListUtil.KART+": "+kartString, taxonBase);
-        addAnnotation(RedListUtil.RL2015+": "+rl2015String, taxonBase);
-        addAnnotation(RedListUtil.EHRD+": "+ehrdString, taxonBase);
-        addAnnotation(RedListUtil.WISSK+": "+wisskString, taxonBase);
+        taxonBase.addExtension(florString, extensionTypeFlor);
+        taxonBase.addExtension(atlasIdxString, extensionTypeAtlasIdx);
+        taxonBase.addExtension(kartString, extensionTypeKart);
+        taxonBase.addExtension(rl2015String, extensionTypeRl2015);
+        taxonBase.addExtension(ehrdString, extensionTypeEhrd);
+        taxonBase.addExtension(wisskString, extensionTypeWissk);
 
         //check taxon name consistency
-        checkTaxonConsistency(id, taxNameString, hybString, taxonBase, state);
+        checkTaxonConsistency(id, taxNameString, hybString, epi1String, epi2String, epi3String, taxonBase, state);
         return taxonBase;
     }
 
-    private void addAnnotation(String string, TaxonBase<?> taxonBase) {
-        if(CdmUtils.isNotBlank(string)){
-            taxonBase.addAnnotation(Annotation.NewInstance(string, AnnotationType.TECHNICAL(), Language.GERMAN()));
-        }
-    }
-
     private void importAuthors(RedListGefaesspflanzenImportState state, ResultSet rs, NonViralName<?> name) throws SQLException {
 
         long id = rs.getLong(RedListUtil.NAMNR);
@@ -259,22 +271,16 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
 
         //combination author
         if(authorKombString.contains(RedListUtil.EX)){
-            //TODO: what happens with multiple ex authors??
-            String[] kombSplit = authorKombString.split(RedListUtil.EX);
-            if(kombSplit.length!=2){
-                RedListUtil.logMessage(id, "Multiple ex combination authors found", logger);
-            }
-            for (int i = 0; i < kombSplit.length; i++) {
-                if(i==0){
-                    //first author is ex author
-                    TeamOrPersonBase<?> authorKomb = (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, kombSplit[i]);
-                    name.setExCombinationAuthorship(authorKomb);
-                }
-                else{
-                    TeamOrPersonBase<?> authorKomb = (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, kombSplit[i]);
-                    name.setCombinationAuthorship(authorKomb);
-                }
-            }
+            // multiple ex authors will be reduced to only the last one
+            // e.g. Almq. ex Sternström ex Dahlst. -> Almq. ex Dahlst.
+            //first author is ex combination author
+            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 = RedListUtil.getAuthorOfExAuthorshipString(authorKombString);
+            TeamOrPersonBase<?> combAuthor = (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, authorString);
+            name.setCombinationAuthorship(combAuthor);
         }
         else if(authorKombString.trim().contains(RedListUtil.AUCT)){
             RedListUtil.logMessage(id, "AUCT information in "+RedListUtil.AUTOR_KOMB+" column", logger);
@@ -285,29 +291,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)){
@@ -343,7 +339,7 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
         }
 
         NonViralName<?> name = null;
-        Rank rank = makeRank(id, state, rangString, ep3String!=null);
+        Rank rank = makeRank(id, state, rangString, CdmUtils.isNotBlank(ep3String));
         //cultivar
         if(rank!= null && rank.equals(Rank.CULTIVAR())){
             CultivarPlantName cultivar = CultivarPlantName.NewInstance(rank);
@@ -381,7 +377,7 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
                     NomenclaturalStatus status = NomenclaturalStatus.NewInstance(statusType);
                     //special case for invalid names where the DB entry contains
                     //additional information in brackets e.g. "nom. inval. (sine basion.)"
-                    if(statusType.equals(NomenclaturalStatusType.INVALID())){
+                    if(statusType.equals(NomenclaturalStatusType.INVALID()) || statusType.equals(NomenclaturalStatusType.REJECTED()) ){
                         Pattern pattern = Pattern.compile("\\((.*?)\\)");
                         Matcher matcher = pattern.matcher(nomZusatzString);
                         if (matcher.find()){
@@ -393,12 +389,6 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
             }
             //hybrid
             if(CdmUtils.isNotBlank(hybString)){
-                //save hybrid formula
-                if(CdmUtils.isNotBlank(formelString)){
-                    Annotation annotation = Annotation.NewDefaultLanguageInstance(formelString);
-                    annotation.setAnnotationType(AnnotationType.TECHNICAL());
-                    name.addAnnotation(annotation);
-                }
                 //more than two hybrids not yet handled by name parser
                 //TODO: use parser when implemented to fully support hybrids
                 if(taxNameString.split(RedListUtil.HYB_SIGN).length>2){
@@ -411,34 +401,10 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
                 else if(hybString.equals(RedListUtil.HYB_G)){
                     name.setMonomHybrid(true);
                 }
-                else if(hybString.equals(RedListUtil.HYB_XF) || hybString.equals(RedListUtil.HYB_NF) ){
+                else if(hybString.equals(RedListUtil.HYB_XF) || hybString.equals(RedListUtil.HYB_XU)){
                     name.setHybridFormula(true);
-                    if(ep1String.contains(RedListUtil.HYB_SIGN)){
-                        RedListUtil.logMessage(id, "EPI1 has hybrid signs but with flag: "+RedListUtil.HYB_XF, logger);
-                    }
-                    else if(ep2String.contains(RedListUtil.HYB_SIGN)){
-                        String[] split = ep2String.split(RedListUtil.HYB_SIGN);
-                        String hybridFormula1 = ep1String+" "+split[0].trim();
-                        String hybridFormula2 = ep1String+" "+split[1].trim();
-                        //check if the specific epithets are from the same genus or not like e.g. EPI2 = pratensis × Lolium multiflorum
-                        String[] secondHybrid = split[1].trim().split(" ");
-                        if(secondHybrid.length>1 && secondHybrid[0].matches("[A-Z].*")){
-                            hybridFormula2 = split[1];
-                        }
-                        if(CdmUtils.isNotBlank(ep3String)){
-                            hybridFormula1 += " "+ep3String;
-                            hybridFormula2 += " "+ep3String;
-                        }
-                        String fullFormula = hybridFormula1+" "+RedListUtil.HYB_SIGN+" "+hybridFormula2;
-                        name = NonViralNameParserImpl.NewInstance().parseFullName(fullFormula, NomenclaturalCode.ICNAFP, rank);
-                    }
-                    else if(ep3String.contains(RedListUtil.HYB_SIGN)){
-                        String[] split = ep3String.split(RedListUtil.HYB_SIGN);
-                        String hybridFormula1 = ep1String+" "+ep2String+" "+split[0];
-                        String hybridFormula2 = ep1String+" "+ep2String+" "+split[1];
-                        String fullFormula = hybridFormula1+" "+RedListUtil.HYB_SIGN+" "+hybridFormula2;
-                        name = NonViralNameParserImpl.NewInstance().parseFullName(fullFormula, NomenclaturalCode.ICNAFP, rank);
-                    }
+                    String fullFormula = buildHybridFormula(ep1String, ep2String, ep3String, rank);
+                    name = NonViralNameParserImpl.NewInstance().parseFullName(fullFormula, NomenclaturalCode.ICNAFP, rank);
                 }
                 else if(hybString.equals(RedListUtil.HYB_N)){
                     name = NonViralNameParserImpl.NewInstance().parseFullName(taxNameString, NomenclaturalCode.ICNAFP, rank);
@@ -457,8 +423,15 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
                 else{
                     logger.error("HYB value "+hybString+" not yet handled");
                 }
+                //save hybrid formula
+                if(CdmUtils.isNotBlank(formelString)){
+                    Annotation annotation = Annotation.NewDefaultLanguageInstance(formelString);
+                    annotation.setAnnotationType(AnnotationType.TECHNICAL());
+                    name.addAnnotation(annotation);
+                }
             }
         }
+
         //add source
         ImportHelper.setOriginalSource(name, state.getTransactionalSourceReference(), id, RedListUtil.NAME_NAMESPACE);
 
@@ -466,6 +439,48 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
         return name;
     }
 
+    private String buildHybridFormula(String ep1String, String ep2String, String ep3String, Rank rank) {
+        String fullFormula = null;
+        if(ep1String.contains(RedListUtil.HYB_SIGN)){
+            fullFormula = ep1String;
+        }
+        else if(ep2String.contains(RedListUtil.HYB_SIGN)){
+            String[] split = ep2String.split(RedListUtil.HYB_SIGN);
+            String hybridFormula1 = ep1String+" "+split[0].trim();
+            String hybridFormula2 = ep1String+" "+split[1].trim();
+            //check if the genus is mentioned in EP2 or not
+            String[] secondHybrid = split[1].trim().split(" ");
+            //check if the genus is abbreviated like e.g. Centaurea jacea × C. decipiens
+            if(secondHybrid.length>1 && secondHybrid[0].matches("[A-Z]\\.")){
+                hybridFormula2 = ep1String+" "+split[1].trim().substring(3);
+            }
+            else if(secondHybrid.length>1 && secondHybrid[0].matches("[A-Z].*")){
+                hybridFormula2 = split[1].trim();
+            }
+            if(CdmUtils.isNotBlank(ep3String)){
+                hybridFormula1 += " "+rank.getAbbreviation()+" "+ep3String;
+                hybridFormula2 += " "+rank.getAbbreviation()+" "+ep3String;
+            }
+            fullFormula = hybridFormula1+" "+RedListUtil.HYB_SIGN+" "+hybridFormula2;
+        }
+        else if(ep3String.contains(RedListUtil.HYB_SIGN)){
+            String[] split = ep3String.split(RedListUtil.HYB_SIGN);
+            String hybridFormula1 = ep1String+" "+ep2String+" "+rank.getAbbreviation()+" "+split[0].trim();
+            String hybridFormula2 = ep1String+" "+ep2String+" "+rank.getAbbreviation()+" "+split[1].trim();
+            //check if the genus is mentioned in EP3 or not
+            String[] secondHybrid = split[1].trim().split(" ");
+            //check if the genus is abbreviated like e.g. Centaurea jacea jacea × C. jacea subsp. decipiens
+            if(secondHybrid.length>1 && secondHybrid[0].matches("[A-Z]\\.")){
+                hybridFormula2 = ep1String+" "+split[1].trim().substring(3);
+            }
+            else if(secondHybrid.length>1 && secondHybrid[0].matches("[A-Z].*")){
+                hybridFormula2 = split[1].trim();
+            }
+            fullFormula = hybridFormula1+" "+RedListUtil.HYB_SIGN+" "+hybridFormula2;
+        }
+        return fullFormula;
+    }
+
     private void checkNameConsistency(long id, String nomZusatzString, String taxZusatzString,
             String zusatzString, String authorString, String hybString, NonViralName<?> name) {
         String authorshipCache = name.getAuthorshipCache();
@@ -490,6 +505,9 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
         if(authorString.equals(RedListUtil.AUCT)){
             authorString = "";
         }
+        if(!STRICT_TITLE_CHECK && authorString.matches(".*ex.*ex.*")){
+            return;
+        }
         if(STRICT_TITLE_CHECK){
             if(!authorString.equals(authorshipCache)){
                 RedListUtil.logMessage(id, "Authorship inconsistent! name.authorhshipCache <-> Column "+RedListUtil.AUTOR+": "+authorshipCache+" <-> "+authorString, logger);
@@ -502,16 +520,19 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
         }
     }
 
-    private void checkTaxonConsistency(long id, String taxNameString, String hybString, TaxonBase<?> taxonBase, RedListGefaesspflanzenImportState state) {
+    private void checkTaxonConsistency(long id, String taxNameString, String hybString, String epi1String, String epi2String, String epi3String, TaxonBase<?> taxonBase, RedListGefaesspflanzenImportState state) {
+        if(taxNameString.split(RedListUtil.HYB_SIGN).length>2){
+            RedListUtil.logInfoMessage(id, "multiple hybrid signs. No name check for "+taxNameString, logger);
+            return;
+        }
+
         String nameCache = HibernateProxyHelper.deproxy(taxonBase.getName(), NonViralName.class).getNameCache().trim();
         taxNameString = taxNameString.trim();
         taxNameString = taxNameString.replaceAll(" +", " ");
 
-        if(taxNameString.endsWith("agg.")){
-            taxNameString = taxNameString.replace("agg.", "aggr.");
-        }
 
-        if(hybString.equals(RedListUtil.HYB_X) || hybString.equals(RedListUtil.HYB_N)){
+        if((hybString.equals(RedListUtil.HYB_X) || hybString.equals(RedListUtil.HYB_N))
+                && nameCache.matches(".*\\s"+RedListUtil.HYB_SIGN+"\\w.*")){
             taxNameString = taxNameString.replace(" "+RedListUtil.HYB_SIGN+" ", " "+RedListUtil.HYB_SIGN);//hybrid sign has no space after it in titleCache for binomial hybrids
             taxNameString = taxNameString.replace(" x ", " "+RedListUtil.HYB_SIGN);//in some cases a standard 'x' is used
         }
@@ -519,7 +540,19 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
             taxNameString = taxNameString.replace("X ", RedListUtil.HYB_SIGN);
         }
         else if(hybString.equals(RedListUtil.HYB_GF)){
-            taxNameString = taxNameString.replace(" "+RedListUtil.HYB_SIGN, " x");
+            taxNameString = taxNameString.replace(" "+RedListUtil.HYB_SIGN+" ", " "+RedListUtil.HYB_SIGN);
+        }
+        else if(hybString.equals(RedListUtil.HYB_XF)){
+            nameCache = taxonBase.getName().getTitleCache();
+            if(nameCache.contains("sec")){
+                nameCache = nameCache.substring(0, nameCache.indexOf("sec"));
+            }
+            if(!STRICT_TITLE_CHECK){
+                taxNameString = buildHybridFormula(epi1String, epi2String, epi3String, taxonBase.getName().getRank());
+            }
+            if(taxNameString.split(RedListUtil.HYB_SIGN).length==1){
+                taxNameString = taxNameString.replace(RedListUtil.HYB_SIGN+" ", RedListUtil.HYB_SIGN);
+            }
         }
 
         if(taxNameString.endsWith("- Gruppe")){
@@ -529,7 +562,9 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
             taxNameString = taxNameString.replaceAll("- group", "species group");
         }
 
+        taxNameString = taxNameString.replace("agg.", "aggr.");
         taxNameString = taxNameString.replace("[ranglos]", "[unranked]");
+
         if(taxonBase.getName().getRank()!=null){
             if(taxonBase.getName().getRank().equals(Rank.PROLES())){
                 taxNameString = taxNameString.replace("proles", "prol.");
@@ -556,7 +591,8 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
             if(rankStr.equals("ORA")){
                 //special handling for ORA because of two possibilities
                 if(hasSpecificEpithet){
-                    return Rank.UNRANKED_INFRASPECIFIC();
+                    //re-load term because the representation was changed before
+                    return (Rank) getTermService().load(Rank.uuidInfraspecificTaxon);
                 }
                 else{
                     return Rank.UNRANKED_INFRAGENERIC();
@@ -565,6 +601,24 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
             else if(rankStr.equals("SAM")){
                 return getRank(state, RedListUtil.uuidRankCollectionSpecies, "Collective Species", "Collective Species", "\"Coll. Species\"", (OrderedTermVocabulary<Rank>) Rank.GENUS().getVocabulary(), null, RankClass.SpeciesGroup);
             }
+            else if(rankStr.equals("SPR")){
+                return getRank(state, RedListUtil.uuidRankSubproles, "Subproles", "Subproles", "subproles", (OrderedTermVocabulary<Rank>) Rank.GENUS().getVocabulary(), null, RankClass.Infraspecific);
+            }
+            else if(rankStr.equals("MOD")){
+                return getRank(state, RedListUtil.uuidRankModification, "Modification", "Modification", "modificatio", (OrderedTermVocabulary<Rank>) Rank.GENUS().getVocabulary(), null, RankClass.Infraspecific);
+            }
+            else if(rankStr.equals("LUS")){
+                return getRank(state, RedListUtil.uuidRankLusus, "Lusus", "Lusus", "lusus", (OrderedTermVocabulary<Rank>) Rank.GENUS().getVocabulary(), null, RankClass.Infraspecific);
+            }
+            else if(rankStr.equals("SPI")){
+                return getRank(state, RedListUtil.uuidRankSubspeciesPrincipes, "Subspecies principes", "Subspecies principes", "subsp. princ.", (OrderedTermVocabulary<Rank>) Rank.GENUS().getVocabulary(), null, RankClass.Infraspecific);
+            }
+            else if(rankStr.equals("KMB")){
+                return getRank(state, RedListUtil.uuidRankCombination, "Combination", "Combination", "", (OrderedTermVocabulary<Rank>) Rank.GENUS().getVocabulary(), null, RankClass.Infraspecific);
+            }
+            else if(rankStr.equals("'FO")){
+                return getRank(state, RedListUtil.uuidRankForme, "Forme'", "Forme'", "", (OrderedTermVocabulary<Rank>) Rank.GENUS().getVocabulary(), null, RankClass.Infraspecific);
+            }
             else{
                 rank = state.getTransformer().getRankByKey(rankStr);
             }