#5448 Import cultivar as CultivarPlantName
[cdmlib-apps.git] / app-import / src / main / java / eu / etaxonomy / cdm / io / redlist / gefaesspflanzen / RedListGefaesspflanzenImportNames.java
index 0d7e047de440b2cba03d4f23f11d14608d5a2f9e..52979ad33df907d2cbb73af907991ed05017ebb8 100644 (file)
@@ -15,6 +15,8 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
@@ -28,11 +30,14 @@ import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
 import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
 import eu.etaxonomy.cdm.model.agent.AgentBase;
 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.Language;
 import eu.etaxonomy.cdm.model.description.CommonTaxonName;
 import eu.etaxonomy.cdm.model.description.TaxonDescription;
 import eu.etaxonomy.cdm.model.name.BotanicalName;
+import eu.etaxonomy.cdm.model.name.CultivarPlantName;
 import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
 import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
 import eu.etaxonomy.cdm.model.name.NonViralName;
@@ -62,6 +67,8 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
 
     private static final String pluralString = "names";
 
+    private static final boolean STRICT_TITLE_CHECK = false;
+
     public RedListGefaesspflanzenImportNames() {
         super(tableName, pluralString);
     }
@@ -109,23 +116,7 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
 
     private void makeSingleNameAndTaxon(RedListGefaesspflanzenImportState state, ResultSet rs, Set<TaxonNameBase> namesToSave, Set<TaxonBase> taxaToSave)
             throws SQLException {
-        //cell values
         long id = rs.getLong(RedListUtil.NAMNR);
-        String taxNameString = rs.getString(RedListUtil.TAXNAME);
-        String gueltString = rs.getString(RedListUtil.GUELT);
-        String rangString = rs.getString(RedListUtil.RANG);
-        String ep1String = rs.getString(RedListUtil.EPI1);
-        String ep2String = rs.getString(RedListUtil.EPI2);
-        String ep3String = rs.getString(RedListUtil.EPI3);
-        String nomZusatzString = rs.getString(RedListUtil.NOM_ZUSATZ);
-        String taxZusatzString = rs.getString(RedListUtil.TAX_ZUSATZ);
-        String zusatzString = rs.getString(RedListUtil.ZUSATZ);
-        String nonString = rs.getString(RedListUtil.NON);
-        String sensuString = rs.getString(RedListUtil.SENSU);
-        String trivialString = rs.getString(RedListUtil.TRIVIAL);
-        String authorKombString = rs.getString(RedListUtil.AUTOR_KOMB);
-        String authorBasiString = rs.getString(RedListUtil.AUTOR_BASI);
-        String hybString = rs.getString(RedListUtil.HYB);
         String clTaxonString = rs.getString(RedListUtil.CL_TAXON);
         String relationE = rs.getString(RedListUtil.E);
         String relationW = rs.getString(RedListUtil.W);
@@ -137,88 +128,82 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
         String relationS = rs.getString(RedListUtil.S);
 
         //---NAME---
-        NonViralName name = importName(state, id, taxNameString, rangString, ep1String, ep2String, ep3String,
-                nomZusatzString, hybString, namesToSave);
+        NonViralName<?> name = importName(state, rs, namesToSave);
 
 
         //--- AUTHORS ---
-        importAuthors(state, rs, id, nomZusatzString, taxZusatzString, zusatzString, authorKombString,
-                authorBasiString, name);
+        importAuthors(state, rs, name);
 
         //---TAXON---
-        TaxonBase taxonBase = importTaxon(id, taxNameString, gueltString, authorBasiString, hybString, trivialString, name);
+        TaxonBase<?> taxonBase = importTaxon(rs, name);
         if(taxonBase==null){
             RedListUtil.logMessage(id, "Taxon for name "+name+" could not be created.", logger);
             return;
         }
-        taxonBase.setSec(state.getConfig().getSourceReference());
 
         //---CONCEPT RELATIONSHIPS---
-        /*check if taxon/synonym also exists in other classification
-         * 1. create new taxon with the same name (in that classification)
-         * 2. create concept relationship between both
-         */
+        //E, W, K, AW, AO, R, O, S
+        cloneTaxon(taxonBase, relationE, RedListUtil.CLASSIFICATION_NAMESPACE_E, taxaToSave, id, state);
+        cloneTaxon(taxonBase, relationW, RedListUtil.CLASSIFICATION_NAMESPACE_W, taxaToSave, id, state);
+        cloneTaxon(taxonBase, relationK, RedListUtil.CLASSIFICATION_NAMESPACE_K, taxaToSave, id, state);
+        cloneTaxon(taxonBase, relationAW, RedListUtil.CLASSIFICATION_NAMESPACE_AW, taxaToSave, id, state);
+        cloneTaxon(taxonBase, relationAO, RedListUtil.CLASSIFICATION_NAMESPACE_AO, taxaToSave, id, state);
+        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("-")){
-            cloneTaxon(taxonBase, name, TaxonRelationshipType.CONGRUENT_TO(), taxaToSave, id, RedListUtil.TAXON_CHECKLISTE_NAMESPACE, false, true, state);
+            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);
         }
-        //E, W, K, AW, AO, R, O, S
-        addConceptRelation(relationE, RedListUtil.CLASSIFICATION_NAMESPACE_E, taxonBase, name, taxaToSave, id, state);
-        addConceptRelation(relationW, RedListUtil.CLASSIFICATION_NAMESPACE_W, taxonBase, name, taxaToSave, id, state);
-        addConceptRelation(relationK, RedListUtil.CLASSIFICATION_NAMESPACE_K, taxonBase, name, taxaToSave, id, state);
-        addConceptRelation(relationAW, RedListUtil.CLASSIFICATION_NAMESPACE_AW, taxonBase, name, taxaToSave, id, state);
-        addConceptRelation(relationAO, RedListUtil.CLASSIFICATION_NAMESPACE_AO, taxonBase, name, taxaToSave, id, state);
-        addConceptRelation(relationR, RedListUtil.CLASSIFICATION_NAMESPACE_R, taxonBase, name, taxaToSave, id, state);
-        addConceptRelation(relationO, RedListUtil.CLASSIFICATION_NAMESPACE_O, taxonBase, name, taxaToSave, id, state);
-        addConceptRelation(relationS, RedListUtil.CLASSIFICATION_NAMESPACE_S, taxonBase, name, taxaToSave, id, state);
 
         //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);
         taxaToSave.add(taxonBase);
     }
 
-    private void addConceptRelation(String relationString, String classificationNamespace, TaxonBase taxonBase, TaxonNameBase name, Set<TaxonBase> taxaToSave, long id, RedListGefaesspflanzenImportState state){
+    private void cloneTaxon(final TaxonBase<?> gesamtListeTaxon, String relationString, String sourceNameSpace, Set<TaxonBase> taxaToSave, long id, RedListGefaesspflanzenImportState state){
         if(CdmUtils.isNotBlank(relationString) && !relationString.equals(".")){
-            String substring = relationString.substring(relationString.length()-1, relationString.length());
-            TaxonRelationshipType taxonRelationshipTypeByKey = new RedListGefaesspflanzenTransformer().getTaxonRelationshipTypeByKey(substring);
-            if(taxonRelationshipTypeByKey==null){
-                RedListUtil.logMessage(id, "Could not interpret relationship "+relationString+" for taxon "+taxonBase.generateTitle(), logger);
+            Taxon clonedTaxon = null;
+
+            if(gesamtListeTaxon.isInstanceOf(Taxon.class)){
+                clonedTaxon = HibernateProxyHelper.deproxy(gesamtListeTaxon.clone(), Taxon.class);
             }
-            //there is no type "included in" so we have to reverse the direction
-            if(substring.equals("<")){
-                cloneTaxon(taxonBase, name, taxonRelationshipTypeByKey, taxaToSave, id, classificationNamespace, true, false, state);
+            else if(gesamtListeTaxon.isInstanceOf(Synonym.class)){
+                clonedTaxon = Taxon.NewInstance(gesamtListeTaxon.getName(), gesamtListeTaxon.getSec());
             }
             else{
-                cloneTaxon(taxonBase, name, taxonRelationshipTypeByKey, taxaToSave, id, classificationNamespace, false, false, state);
+                RedListUtil.logMessage(id, "Taxon base "+gesamtListeTaxon+" is neither taxon nor synonym! Taxon could not be cloned", logger);
+                return;
             }
+            ImportHelper.setOriginalSource(clonedTaxon, state.getTransactionalSourceReference(), id, sourceNameSpace);
+            taxaToSave.add(clonedTaxon);
         }
     }
 
-    /**
-     * <b>NOTE:</b> the {@link TaxonRelationshipType} passed as parameter is
-     * directed <b>from the clone</b> to the taxon.<br>
-     * This can be changed with parameter <i>reverseRelation</i>
-     */
-    private void cloneTaxon(TaxonBase taxonBase, TaxonNameBase name, TaxonRelationshipType relationFromCloneToTaxon, Set<TaxonBase> taxaToSave, long id, String sourceNameSpace, boolean reverseRelation, boolean doubtful, RedListGefaesspflanzenImportState state){
-        TaxonBase clone = (TaxonBase) taxonBase.clone();
-        clone.setName(name);
-        if(taxonBase.isInstanceOf(Taxon.class)){
-            TaxonRelationship taxonRelation;
-            if(reverseRelation){
-                taxonRelation = ((Taxon) taxonBase).addTaxonRelation((Taxon) clone, relationFromCloneToTaxon, null, null);
-            }
-            else {
-                taxonRelation = ((Taxon) clone).addTaxonRelation((Taxon) taxonBase, relationFromCloneToTaxon, null, null);
-            }
-            taxonRelation.setDoubtful(doubtful);
-        }
-        ImportHelper.setOriginalSource(clone, state.getTransactionalSourceReference(), id, sourceNameSpace);
-        taxaToSave.add(clone);
-    }
+    private TaxonBase<?> importTaxon(ResultSet rs, NonViralName<?> name) throws SQLException {
 
-    private TaxonBase importTaxon(long id, String taxNameString, String gueltString, String authorBasiString,
-            String hybString, String trivialString, NonViralName name) {
-        TaxonBase taxonBase = null;
+        long id = rs.getLong(RedListUtil.NAMNR);
+        String taxNameString = rs.getString(RedListUtil.TAXNAME);
+        String gueltString = rs.getString(RedListUtil.GUELT);
+        String trivialString = rs.getString(RedListUtil.TRIVIAL);
+        String authorBasiString = rs.getString(RedListUtil.AUTOR_BASI);
+        String hybString = rs.getString(RedListUtil.HYB);
+        String florString = rs.getString(RedListUtil.FLOR);
+        String atlasIdxString = rs.getString(RedListUtil.ATLAS_IDX);
+        String kartString = rs.getString(RedListUtil.KART);
+        String rl2015String = rs.getString(RedListUtil.RL2015);
+        String ehrdString = rs.getString(RedListUtil.EHRD);
+        String wisskString = rs.getString(RedListUtil.WISSK);
+
+        TaxonBase<?> taxonBase = null;
         if(authorBasiString.trim().contains(RedListUtil.AUCT)){
             taxonBase = Taxon.NewInstance(name, null);
             taxonBase.setAppendedPhrase(RedListUtil.AUCT);
@@ -237,17 +222,37 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
         if(taxonBase.isInstanceOf(Taxon.class) && trivialString!=null){
             Taxon taxon = HibernateProxyHelper.deproxy(taxonBase, Taxon.class);
             TaxonDescription description = TaxonDescription.NewInstance(taxon);
-            description.addElement(CommonTaxonName.NewInstance(trivialString, Language.getDefaultLanguage()));
+            description.addElement(CommonTaxonName.NewInstance(trivialString, Language.GERMAN()));
         }
 
+        //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);
+
         //check taxon name consistency
         checkTaxonNameConsistency(id, taxNameString, hybString, taxonBase);
         return taxonBase;
     }
 
-    private void importAuthors(RedListGefaesspflanzenImportState state, ResultSet rs, long id, String nomZusatzString,
-            String taxZusatzString, String zusatzString, String authorKombString, String authorBasiString,
-            NonViralName name) throws SQLException {
+    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);
+        String nomZusatzString = rs.getString(RedListUtil.NOM_ZUSATZ);
+        String taxZusatzString = rs.getString(RedListUtil.TAX_ZUSATZ);
+        String zusatzString = rs.getString(RedListUtil.ZUSATZ);
+        String authorKombString = rs.getString(RedListUtil.AUTOR_KOMB);
+        String authorBasiString = rs.getString(RedListUtil.AUTOR_BASI);
+
         //combination author
         if(authorKombString.contains(RedListUtil.EX)){
             //TODO: what happens with multiple ex authors??
@@ -258,11 +263,11 @@ 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(RedListUtil.AUTHOR_NAMESPACE, kombSplit[i]);
+                    TeamOrPersonBase<?> authorKomb = (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, kombSplit[i]);
                     name.setExCombinationAuthorship(authorKomb);
                 }
                 else{
-                    TeamOrPersonBase authorKomb = (TeamOrPersonBase) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, kombSplit[i]);
+                    TeamOrPersonBase<?> authorKomb = (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, kombSplit[i]);
                     name.setCombinationAuthorship(authorKomb);
                 }
             }
@@ -271,7 +276,7 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
             RedListUtil.logMessage(id, "AUCT information in "+RedListUtil.AUTOR_KOMB+" column", logger);
         }
         else if(CdmUtils.isNotBlank(authorKombString)){
-            TeamOrPersonBase authorKomb = (TeamOrPersonBase) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, authorKombString);
+            TeamOrPersonBase<?> authorKomb = (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, authorKombString);
             name.setCombinationAuthorship(authorKomb);
         }
         //basionym author
@@ -282,7 +287,7 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
                     RedListUtil.logMessage(id, "Multiple ex basionymn authors found", logger);
                 }
                 if(i==0){
-                    TeamOrPersonBase authorBasi= (TeamOrPersonBase) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, basiSplit[i]);
+                    TeamOrPersonBase<?> authorBasi= (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, basiSplit[i]);
                     if(CdmUtils.isBlank(authorKombString)){
                         name.setExCombinationAuthorship(authorBasi);
                     }
@@ -291,7 +296,7 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
                     }
                 }
                 else{
-                    TeamOrPersonBase authorBasi= (TeamOrPersonBase) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, basiSplit[i]);
+                    TeamOrPersonBase<?> authorBasi= (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, basiSplit[i]);
                     if(CdmUtils.isBlank(authorKombString)){
                         name.setCombinationAuthorship(authorBasi);
                     }
@@ -303,7 +308,7 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
         }
         else if(CdmUtils.isNotBlank(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(RedListUtil.AUTHOR_NAMESPACE, authorBasiString);
+            TeamOrPersonBase<?> authorBasi= (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, authorBasiString);
             if(CdmUtils.isBlank(authorKombString)){
                 name.setCombinationAuthorship(authorBasi);
             }
@@ -318,86 +323,141 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
         checkAuthorShipConsistency(id, nomZusatzString, taxZusatzString, zusatzString, authorString, authorshipCache);
     }
 
-    private NonViralName importName(RedListGefaesspflanzenImportState state, long id, String taxNameString,
-            String rangString, String ep1String, String ep2String, String ep3String, String nomZusatzString,
-            String hybString, Set<TaxonNameBase> namesToSave) {
+    private NonViralName<?> importName(RedListGefaesspflanzenImportState state, ResultSet rs, Set<TaxonNameBase> namesToSave) throws SQLException {
+
+        long id = rs.getLong(RedListUtil.NAMNR);
+        String taxNameString = rs.getString(RedListUtil.TAXNAME);
+        String rangString = rs.getString(RedListUtil.RANG);
+        String ep1String = rs.getString(RedListUtil.EPI1);
+        String ep2String = rs.getString(RedListUtil.EPI2);
+        String ep3String = rs.getString(RedListUtil.EPI3);
+        String nomZusatzString = rs.getString(RedListUtil.NOM_ZUSATZ);
+        String hybString = rs.getString(RedListUtil.HYB);
+        String formelString = rs.getString(RedListUtil.FORMEL);
+
         if(CdmUtils.isBlank(taxNameString) && CdmUtils.isBlank(ep1String)){
             RedListUtil.logMessage(id, "No name found!", logger);
         }
 
-        Rank rank = makeRank(id, state, rangString);
-        NonViralName name = BotanicalName.NewInstance(rank);
-
-        //ep1 should always be present
-        if(CdmUtils.isBlank(ep1String)){
-            RedListUtil.logMessage(id, RedListUtil.EPI1+" is empty!", logger);
-        }
-        name.setGenusOrUninomial(ep1String);
-        if(CdmUtils.isNotBlank(ep2String)){
-            name.setSpecificEpithet(ep2String);
+        NonViralName<?> name = null;
+        Rank rank = makeRank(id, state, rangString, ep3String!=null);
+        //cultivar
+        if(rank!= null && rank.equals(Rank.CULTIVAR())){
+            CultivarPlantName cultivar = CultivarPlantName.NewInstance(rank);
+            cultivar.setGenusOrUninomial(ep1String);
+            cultivar.setSpecificEpithet(ep2String);
+            cultivar.setCultivarName(ep3String);
+            name = cultivar;
         }
-        if(CdmUtils.isNotBlank(ep3String)){
-            name.setInfraSpecificEpithet(ep3String);
-        }
-        //nomenclatural status
-        if(CdmUtils.isNotBlank(nomZusatzString)){
-            NomenclaturalStatusType status = makeNomenclaturalStatus(id, state, nomZusatzString);
-            if(status!=null){
-                name.addStatus(NomenclaturalStatus.NewInstance(status));
+        //botanical names
+        else{
+            name = BotanicalName.NewInstance(rank);
+
+            //ep1 should always be present
+            if(CdmUtils.isBlank(ep1String)){
+                RedListUtil.logMessage(id, RedListUtil.EPI1+" is empty!", logger);
+            }
+            name.setGenusOrUninomial(ep1String);
+            if(CdmUtils.isNotBlank(ep2String)){
+                if(rank!=null && rank.isInfraGenericButNotSpeciesGroup()){
+                    name.setInfraGenericEpithet(ep2String);
+                }
+                else{
+                    name.setSpecificEpithet(ep2String);
+                }
             }
         }
         //hybrid
         if(CdmUtils.isNotBlank(hybString)){
+            //save hybrid formula
+            if(CdmUtils.isNotBlank(formelString)){
+                Annotation annotation = Annotation.NewDefaultLanguageInstance(formelString);
+                annotation.setAnnotationType(AnnotationType.TECHNICAL());
+                name.addAnnotation(annotation);
+            }
+
             if(hybString.equals(RedListUtil.HYB_X)){
                 name.setBinomHybrid(true);
-            }
-            else if(hybString.equals(RedListUtil.HYB_G)){
-                name.setMonomHybrid(true);
-            }
-            else if(hybString.equals(RedListUtil.HYB_XF)){
-                name.setHybridFormula(true);
-                if(ep1String.contains(RedListUtil.HYB_SIGN)){
-                    RedListUtil.logMessage(id, "EPI1 has hybrid signs but with flag: "+RedListUtil.HYB_XF, logger);
+                if(CdmUtils.isNotBlank(ep3String)){
+                    name.setInfraSpecificEpithet(ep3String);
                 }
-                else if(ep2String.contains(RedListUtil.HYB_SIGN)){
-                    String[] split = ep2String.split(RedListUtil.HYB_SIGN);
-                    if(split.length!=2){
-                        RedListUtil.logMessage(id, "Multiple hybrid signs found in "+ep2String, logger);
-                    }
-                    String hybridFormula1 = ep1String+" "+split[0].trim();
-                    String hybridFormula2 = ep1String+" "+split[1].trim();
-                    if(CdmUtils.isNotBlank(ep3String)){
-                        hybridFormula1 += " "+ep3String;
-                        hybridFormula2 += " "+ep3String;
+                //nomenclatural status
+                if(CdmUtils.isNotBlank(nomZusatzString)){
+                    NomenclaturalStatusType statusType = makeNomenclaturalStatus(id, state, nomZusatzString);
+                    if(statusType!=null){
+                        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())){
+                            Pattern pattern = Pattern.compile("\\((.*?)\\)");
+                            Matcher matcher = pattern.matcher(nomZusatzString);
+                            if (matcher.find()){
+                                status.setRuleConsidered(matcher.group(1));
+                            }
+                        }
+                        name.addStatus(status);
                     }
-                    String fullFormula = hybridFormula1+" "+RedListUtil.HYB_SIGN+" "+hybridFormula2;
-                    name = NonViralNameParserImpl.NewInstance().parseFullName(fullFormula);
                 }
-                else if(ep3String.contains(RedListUtil.HYB_SIGN)){
-                    String[] split = ep3String.split(RedListUtil.HYB_SIGN);
-                    if(split.length!=2){
-                        RedListUtil.logMessage(id, "Multiple hybrid signs found in "+ep3String, logger);
+                //hybrid
+                if(CdmUtils.isNotBlank(hybString)){
+                    if(hybString.equals(RedListUtil.HYB_X)){
+                        name.setBinomHybrid(true);
+                    }
+                    else if(hybString.equals(RedListUtil.HYB_G)){
+                        name.setMonomHybrid(true);
+                    }
+                    else if(hybString.equals(RedListUtil.HYB_XF)){
+                        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);
+                            if(split.length!=2){
+                                RedListUtil.logMessage(id, "Multiple hybrid signs found in "+ep2String, logger);
+                            }
+                            String hybridFormula1 = ep1String+" "+split[0].trim();
+                            String hybridFormula2 = ep1String+" "+split[1].trim();
+                            if(CdmUtils.isNotBlank(ep3String)){
+                                hybridFormula1 += " "+ep3String;
+                                hybridFormula2 += " "+ep3String;
+                            }
+                            String fullFormula = hybridFormula1+" "+RedListUtil.HYB_SIGN+" "+hybridFormula2;
+                            name = NonViralNameParserImpl.NewInstance().parseFullName(fullFormula);
+                        }
+                        else if(ep3String.contains(RedListUtil.HYB_SIGN)){
+                            String[] split = ep3String.split(RedListUtil.HYB_SIGN);
+                            if(split.length!=2){
+                                RedListUtil.logMessage(id, "Multiple hybrid signs found in "+ep3String, logger);
+                            }
+                            String hybridFormula1 = ep1String+" "+ep2String+" "+split[0];
+                            String hybridFormula2 = ep1String+" "+ep2String+" "+split[1];
+                            String fullFormula = hybridFormula1+" "+RedListUtil.HYB_SIGN+" "+hybridFormula2;
+                            name = NonViralNameParserImpl.NewInstance().parseFullName(fullFormula);
+                        }
+                    }
+                    else if(hybString.equals(RedListUtil.HYB_N)){
+                        name = NonViralNameParserImpl.NewInstance().parseFullName(ep1String+" "+ep2String+" nothosubsp. "+ep3String);
+                    }
+                    else if(hybString.equals(RedListUtil.HYB_GF)){
+                        if(ep1String.contains(RedListUtil.HYB_SIGN)){
+                            name = NonViralNameParserImpl.NewInstance().parseFullName(ep1String);
+                        }
+                        else{
+                            RedListUtil.logMessage(id, "HYB is "+hybString+" but "+RedListUtil.HYB+" does not contain "+RedListUtil.HYB_SIGN, logger);
+                        }
+                    }
+                    else if(hybString.equals(RedListUtil.HYB_XS)){
+                        //nothing to do
+                    }
+                    else{
+                        logger.error("HYB value "+hybString+" not yet handled");
                     }
-                    String hybridFormula1 = ep1String+" "+ep2String+" "+split[0];
-                    String hybridFormula2 = ep1String+" "+ep2String+" "+split[1];
-                    String fullFormula = hybridFormula1+" "+RedListUtil.HYB_SIGN+" "+hybridFormula2;
-                    name = NonViralNameParserImpl.NewInstance().parseFullName(fullFormula);
-                }
-            }
-            else if(hybString.equals(RedListUtil.HYB_N)){
-                name = NonViralNameParserImpl.NewInstance().parseFullName(ep1String+" "+ep2String+" nothosubsp. "+ep3String);
-            }
-            else if(hybString.equals(RedListUtil.HYB_GF)){
-                if(ep1String.contains(RedListUtil.HYB_SIGN)){
-                    name = NonViralNameParserImpl.NewInstance().parseFullName(ep1String);
                 }
                 else{
-                    RedListUtil.logMessage(id, "HYB is "+hybString+" but "+RedListUtil.HYB+" does not contain "+RedListUtil.HYB_SIGN, logger);
+                    logger.error("HYB value "+hybString+" not yet handled");
                 }
             }
-            else{
-                logger.error("HYB value "+hybString+" not yet handled");
-            }
         }
         //add source
         ImportHelper.setOriginalSource(name, state.getTransactionalSourceReference(), id, RedListUtil.NAME_NAMESPACE);
@@ -420,15 +480,22 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
         if(authorString.equals(RedListUtil.AUCT)){
             authorString = "";
         }
-        if(!authorString.equals(authorshipCache)){
-            RedListUtil.logMessage(id, "Authorship inconsistent! name.authorhshipCache <-> Column "+RedListUtil.AUTOR+": "+authorshipCache+" <-> "+authorString, logger);
+        if(STRICT_TITLE_CHECK){
+            if(!authorString.equals(authorshipCache)){
+                RedListUtil.logMessage(id, "Authorship inconsistent! name.authorhshipCache <-> Column "+RedListUtil.AUTOR+": "+authorshipCache+" <-> "+authorString, logger);
+            }
+        }
+        else{
+            if(CdmUtils.isNotBlank(authorString) && !authorString.startsWith(authorshipCache)){
+                RedListUtil.logMessage(id, "Authorship inconsistent! name.authorhshipCache <-> Column "+RedListUtil.AUTOR+": "+authorshipCache+" <-> "+authorString, logger);
+            }
         }
     }
 
-    private void checkTaxonNameConsistency(long id, String taxNameString, String hybString, TaxonBase taxonBase) {
+    private void checkTaxonNameConsistency(long id, String taxNameString, String hybString, TaxonBase<?> taxonBase) {
         if(hybString.equals(RedListUtil.HYB_XF)){
             if(HibernateProxyHelper.deproxy(taxonBase.getName(),NonViralName.class).getHybridChildRelations().isEmpty()){
-                RedListUtil.logMessage(id, "Hybrid name but no hybrid child relations", logger);
+                RedListUtil.logMessage(id, "Hybrid name but no hybrid child relations: "+taxonBase.getTitleCache(), logger);
                 return;
             }
             return;
@@ -436,28 +503,59 @@ public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefae
 
 
         String nameCache = HibernateProxyHelper.deproxy(taxonBase.getName(), NonViralName.class).getNameCache().trim();
+        taxNameString = taxNameString.trim();
+        taxNameString.replaceAll(" +", " ");
 
         if(taxNameString.endsWith("agg.")){
             taxNameString = taxNameString.replace("agg.", "aggr.");
         }
+
         if(hybString.equals(RedListUtil.HYB_X)){
-            taxNameString = taxNameString.replace(RedListUtil.HYB_SIGN+" ", RedListUtil.HYB_SIGN);//hybrid sign has no space after it in titleCache for binomial hybrids
+            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
+        }
+        else if(hybString.equals(RedListUtil.HYB_G)){
+            taxNameString = taxNameString.replace("X ", RedListUtil.HYB_SIGN);
         }
-        if(taxNameString.endsWith("- Gruppe")){
-            taxNameString.replaceAll("- Gruppe", "species group");
+        else if(hybString.equals(RedListUtil.HYB_GF)){
+            taxNameString = taxNameString.replace(" "+RedListUtil.HYB_SIGN, " x");
+        }
+
+        if(taxNameString.endsWith("- Gruppe")){String a ="Festuca ×xx Lolium <-> Festuca ×× Lolium";
+            taxNameString = taxNameString.replaceAll("- Gruppe", "species group");
         }
         if(taxNameString.endsWith("- group")){
-            taxNameString.replaceAll("- group", "species group");
+            taxNameString = taxNameString.replaceAll("- group", "species group");
         }
-        if(!taxNameString.trim().equals(nameCache)){
-            RedListUtil.logMessage(id, "Taxon name inconsistent! taxon.titleCache <-> Column "+RedListUtil.TAXNAME+": "+nameCache+" <-> "+taxNameString, logger);
+
+        taxNameString = taxNameString.replace("[ranglos]", "[unranked]");
+        if(STRICT_TITLE_CHECK){
+            if(!taxNameString.trim().equals(nameCache)){
+                RedListUtil.logMessage(id, "Taxon name inconsistent! taxon.titleCache <-> Column "+RedListUtil.TAXNAME+": "+nameCache+" <-> "+taxNameString, logger);
+            }
+        }
+        else{
+            if(!taxNameString.startsWith(nameCache)){
+                RedListUtil.logMessage(id, "Taxon name inconsistent! taxon.titleCache <-> Column "+RedListUtil.TAXNAME+": "+nameCache+" <-> "+taxNameString, logger);
+            }
         }
     }
 
-    private Rank makeRank(long id, RedListGefaesspflanzenImportState state, String rankStr) {
+    private Rank makeRank(long id, RedListGefaesspflanzenImportState state, String rankStr, boolean hasSpecificEpithet) {
         Rank rank = null;
         try {
-            rank = state.getTransformer().getRankByKey(rankStr);
+            if(rankStr.equals("ORA")){
+                //special handling for ORA because of two possibilities
+                if(hasSpecificEpithet){
+                    return Rank.UNRANKED_INFRASPECIFIC();
+                }
+                else{
+                    return Rank.UNRANKED_INFRAGENERIC();
+                }
+            }
+            else{
+                rank = state.getTransformer().getRankByKey(rankStr);
+            }
         } catch (UndefinedTransformerMethodException e) {
             e.printStackTrace();
         }