Berlin Model import ->in and import state class
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / taxonx / TaxonXNomenclatureImport.java
index 869b12f4305e32340bd1ace440f15540739a433d..8a30910a180d01b772caa6b2dbd9518e0d7b3016 100644 (file)
@@ -24,16 +24,17 @@ import eu.etaxonomy.cdm.api.service.ICommonService;
 import eu.etaxonomy.cdm.api.service.INameService;\r
 import eu.etaxonomy.cdm.api.service.ITaxonService;\r
 import eu.etaxonomy.cdm.common.CdmUtils;\r
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;\r
 import eu.etaxonomy.cdm.io.common.CdmIoBase;\r
 import eu.etaxonomy.cdm.io.common.ICdmIO;\r
 import eu.etaxonomy.cdm.io.common.IImportConfigurator;\r
 import eu.etaxonomy.cdm.io.common.MapWrapper;\r
-import eu.etaxonomy.cdm.model.agent.Agent;\r
+import eu.etaxonomy.cdm.model.agent.AgentBase;\r
 import eu.etaxonomy.cdm.model.agent.Person;\r
 import eu.etaxonomy.cdm.model.common.CdmBase;\r
 import eu.etaxonomy.cdm.model.name.NonViralName;\r
 import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
-import eu.etaxonomy.cdm.model.name.TypeDesignationStatus;\r
+import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;\r
 import eu.etaxonomy.cdm.model.occurrence.Specimen;\r
 import eu.etaxonomy.cdm.model.reference.ReferenceBase;\r
 import eu.etaxonomy.cdm.model.taxon.Synonym;\r
@@ -114,8 +115,14 @@ public class TaxonXNomenclatureImport extends CdmIoBase<IImportConfigurator> imp
                unlazySynonym(config, taxon);\r
                Set<Synonym> synList = taxon.getSynonyms();\r
                for (Synonym syn : synList){\r
-                       if (syn.getName() != null && ((NonViralName<?>)syn.getName()).getNameCache().equals(synName)){\r
-                               return syn;  //only first synonym is returned\r
+                       TaxonNameBase<?,?> nameBase = syn.getName();\r
+                       if (nameBase != null){\r
+                               if (nameBase.isInstanceOf(NonViralName.class)){\r
+                                       NonViralName<?> nonViralName = nameBase.deproxy(nameBase, NonViralName.class);\r
+                                       if (nonViralName.getNameCache().equals(synName)){\r
+                                               return syn;  //only first synonym is returned\r
+                                       }\r
+                               }\r
                        }\r
                }\r
                logger.warn("Synonym ("+synName+ ")not found for taxon " + taxon.getTitleCache() + getBracketSourceName(config));\r
@@ -182,17 +189,17 @@ public class TaxonXNomenclatureImport extends CdmIoBase<IImportConfigurator> imp
                        }//elType\r
                        \r
                        //typeLoc\r
-                       HashMap<Specimen, TypeDesignationStatus> typeLocMap = null; \r
+                       HashMap<Specimen, SpecimenTypeDesignationStatus> typeLocMap = null; \r
                        if (elTypeLoc != null){\r
                                typeLocMap = doElTypeLoc(elTypeLoc, simpleSpecimen, taxonName, config);\r
                        }\r
                        if (typeLocMap != null && typeLocMap.size() >0){\r
                                for (Specimen specimen : typeLocMap.keySet()){\r
-                                       TypeDesignationStatus status = typeLocMap.get(specimen);\r
+                                       SpecimenTypeDesignationStatus status = typeLocMap.get(specimen);\r
                                        taxonName.addSpecimenTypeDesignation(specimen, status, citation, citationMicroReference, originalNameString, isNotDesignated, addToAllHomotypicNames);\r
                                }\r
                        }else{ // no type_loc\r
-                               TypeDesignationStatus status = null;\r
+                               SpecimenTypeDesignationStatus status = null;\r
                                taxonName.addSpecimenTypeDesignation(simpleSpecimen.getSpecimen(), status, citation, citationMicroReference, originalNameString, isNotDesignated, addToAllHomotypicNames);\r
                        }\r
                        return true;\r
@@ -208,7 +215,11 @@ public class TaxonXNomenclatureImport extends CdmIoBase<IImportConfigurator> imp
                }\r
                String[] type = text.split(";");\r
                if (type.length != 3 ){\r
-                       logger.warn("<nomenclature><type> is of unsupported format: " + elType.getTextNormalize() + getBracketSourceName(config));\r
+                       if (text.equals("")){\r
+                               logger.info("<nomenclature><type> is empty: " + getBracketSourceName(config));\r
+                       }else{\r
+                               logger.warn("<nomenclature><type> is of unsupported format: " + elType.getTextNormalize() + getBracketSourceName(config));\r
+                       }\r
                        simpleSpecimen.setTitleCache(elType.getTextNormalize());\r
                }else{\r
                        String strLocality = type[0].trim();\r
@@ -218,7 +229,7 @@ public class TaxonXNomenclatureImport extends CdmIoBase<IImportConfigurator> imp
                        \r
                        String strCollector = type[1].trim();\r
                        if (! "".equals(strCollector)){\r
-                               Agent collector = Person.NewTitledInstance(strCollector);\r
+                               AgentBase collector = Person.NewTitledInstance(strCollector);\r
 //                             simpleSpecimen.setCollector(collector);\r
                        }\r
                        \r
@@ -241,12 +252,12 @@ public class TaxonXNomenclatureImport extends CdmIoBase<IImportConfigurator> imp
         * @param config\r
         * @return\r
         */\r
-       private HashMap<Specimen, TypeDesignationStatus> doElTypeLoc(Element elTypeLoc, \r
+       private HashMap<Specimen, SpecimenTypeDesignationStatus> doElTypeLoc(Element elTypeLoc, \r
                        SimpleSpecimen simpleSpecimen, \r
                        TaxonNameBase<?,?> taxonName,\r
                        TaxonXImportConfigurator config){\r
                \r
-               HashMap<Specimen, TypeDesignationStatus> result = new HashMap<Specimen, TypeDesignationStatus>();\r
+               HashMap<Specimen, SpecimenTypeDesignationStatus> result = new HashMap<Specimen, SpecimenTypeDesignationStatus>();\r
 \r
                String typeLocFullString = elTypeLoc.getTextTrim();\r
                typeLocFullString = typeLocFullString.replace("(", "").replace(")", "");\r
@@ -259,11 +270,11 @@ public class TaxonXNomenclatureImport extends CdmIoBase<IImportConfigurator> imp
                        typeLocStatus = typeLocStatus.trim();\r
                        int pos = typeLocStatus.indexOf(" ");\r
                        if (pos == -1){\r
-                               logger.warn("Unknown format for type_loc : " + typeLocStatus + getBracketSourceName(config));\r
+                               logger.warn("Unknown format or empty type_loc : '" +typeLocStatus + "'" + getBracketSourceName(config));\r
                                result.put(originalSpecimen, null);\r
                        }else{\r
                                String statusString = typeLocStatus.substring(0,pos); \r
-                               TypeDesignationStatus status = getStatusByStatusString(statusString.trim());\r
+                               SpecimenTypeDesignationStatus status = getStatusByStatusString(statusString.trim(), config);\r
                                //TODO\r
                                //String[] collectionStrings = typeLocStatus.substring(pos).split(",");\r
                                String tmpCollString = typeLocStatus.substring(pos).trim();\r
@@ -318,7 +329,7 @@ public class TaxonXNomenclatureImport extends CdmIoBase<IImportConfigurator> imp
                if (type.length != 2 ){\r
                        logger.warn("<collecion_even><type> is of unsupported format: " + elType.getTextNormalize());\r
                }else{\r
-                       Agent collector = Person.NewTitledInstance(type[0]);\r
+                       AgentBase collector = Person.NewTitledInstance(type[0]);\r
                        simpleSpecimen.setCollector(collector);\r
                        \r
                        String collectorNumber = type[1];\r
@@ -341,7 +352,7 @@ public class TaxonXNomenclatureImport extends CdmIoBase<IImportConfigurator> imp
                                logger.warn("Unknown format: " + typeLocStatus);\r
                        }else{\r
                                String statusString = typeLocStatus.substring(0,pos); \r
-                               TypeDesignationStatus status = getStatusByStatusString(statusString.trim());\r
+                               SpecimenTypeDesignationStatus status = getStatusByStatusString(statusString.trim(), config);\r
                                String[] collectionStrings = typeLocStatus.substring(pos).split(",");\r
                                for(String collectionString : collectionStrings){\r
                                        if (taxonBase != null){\r
@@ -365,14 +376,14 @@ public class TaxonXNomenclatureImport extends CdmIoBase<IImportConfigurator> imp
        }\r
        \r
        \r
-       private static Map<String, TypeDesignationStatus> statusMap;\r
+       private static Map<String, SpecimenTypeDesignationStatus> statusMap;\r
        private static void fillTypeStatusMap(){\r
-               statusMap = new HashMap<String, TypeDesignationStatus>();\r
-               statusMap.put("holotype", TypeDesignationStatus.HOLOTYPE());\r
-               statusMap.put("isotype", TypeDesignationStatus.ISOTYPE());\r
-               statusMap.put("lectotype", TypeDesignationStatus.LECTOTYPE());\r
-               statusMap.put("syntype", TypeDesignationStatus.SYNTYPE());\r
-               statusMap.put("isolectotype", TypeDesignationStatus.ISOLECTOTYPE());\r
+               statusMap = new HashMap<String, SpecimenTypeDesignationStatus>();\r
+               statusMap.put("holotype", SpecimenTypeDesignationStatus.HOLOTYPE());\r
+               statusMap.put("isotype", SpecimenTypeDesignationStatus.ISOTYPE());\r
+               statusMap.put("lectotype", SpecimenTypeDesignationStatus.LECTOTYPE());\r
+               statusMap.put("syntype", SpecimenTypeDesignationStatus.SYNTYPE());\r
+               statusMap.put("isolectotype", SpecimenTypeDesignationStatus.ISOLECTOTYPE());\r
                statusMap.put("type", null);\r
                //TODO to be continued\r
        }\r
@@ -384,8 +395,8 @@ public class TaxonXNomenclatureImport extends CdmIoBase<IImportConfigurator> imp
         * @param statusString\r
         * @return TypeDesignationStatus\r
         */\r
-       private static TypeDesignationStatus getStatusByStatusString(String statusString){\r
-               TypeDesignationStatus result = null;\r
+       private static SpecimenTypeDesignationStatus getStatusByStatusString(String statusString, TaxonXImportConfigurator config){\r
+               SpecimenTypeDesignationStatus result = null;\r
                if (statusString == null || "".equals(statusString.trim())){\r
                        return null;\r
                }\r
@@ -400,9 +411,9 @@ public class TaxonXNomenclatureImport extends CdmIoBase<IImportConfigurator> imp
                }\r
                result = statusMap.get(statusString);\r
                if (statusString.equals("type")){\r
-                       logger.info("No type designation type");\r
+                       logger.info("No type designation type" + getBracketSourceName(config));\r
                }else if (result == null){\r
-                       logger.warn("Unknown type status string: " + statusString);\r
+                       logger.warn("Unknown type status string: " + statusString + getBracketSourceName(config));\r
                }\r
                return result;\r
        }\r
@@ -438,7 +449,7 @@ public class TaxonXNomenclatureImport extends CdmIoBase<IImportConfigurator> imp
                commitTransaction(txStatus);\r
        }\r
        \r
-       private String getBracketSourceName(TaxonXImportConfigurator config){\r
+       private static String getBracketSourceName(TaxonXImportConfigurator config){\r
                return "(" + config.getSourceNameString() + ")";\r
        }\r
 \r