ref #10048 add source to distributions and handle MCL-number as identifier
authorAndreas Müller <a.mueller@bgbm.org>
Fri, 11 Nov 2022 15:48:20 +0000 (16:48 +0100)
committerAndreas Müller <a.mueller@bgbm.org>
Fri, 11 Nov 2022 15:48:20 +0000 (16:48 +0100)
app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelFactsImport.java
app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelTaxonImport.java

index 6b4848a2485ef7cfb32e125fa08d5739afea97c6..dbcb283d224bc5c4677cdc7e6ef0017277e86e3a 100644 (file)
@@ -333,92 +333,95 @@ public class BerlinModelFactsImport  extends BerlinModelImportBase {
                                                        continue;\r
                                                }\r
 \r
+                                               DescriptionElementBase deb;\r
+\r
                         if (state.getConfig().isMcl()) {\r
                             if (categoryFkInt.equals(20)) {\r
-                                handleMclState(state, taxonDescription, fact);\r
+                                deb = handleMclState(state, taxonDescription, fact);\r
                             }else if (categoryFkInt.equals(21)) {\r
-                                handleMclDistribution(state, taxonDescription, fact);\r
+                                deb = handleMclDistribution(state, taxonDescription, fact);\r
                             }else {\r
                                 throw new RuntimeException("Unhandled fact category: " + categoryFkInt);\r
                             }\r
                             continue;\r
+                        }else {\r
+\r
+                                               //textData\r
+                                               TextData textData = null;\r
+                                               boolean newTextData = true;\r
+\r
+                                               // For Cichorieae DB: If fact category is 31 (Systematics) and there is already a Systematics TextData\r
+                                               // description element append the fact text to the existing TextData\r
+                                               if(categoryFkInt.equals(31)) {\r
+                                                       Set<DescriptionElementBase> descriptionElements = taxonDescription.getElements();\r
+                                                       for (DescriptionElementBase descriptionElement : descriptionElements) {\r
+                                                               String featureString = descriptionElement.getFeature().getRepresentation(Language.DEFAULT()).getLabel();\r
+                                                               if (descriptionElement instanceof TextData && featureString.equals("Systematics")) { // TODO: test\r
+                                                                       textData = (TextData)descriptionElement;\r
+                                                                       String factTextStr = textData.getText(Language.DEFAULT());\r
+                                                                       // FIXME: Removing newlines doesn't work\r
+                                                                       if (factTextStr.contains("\\r\\n")) {\r
+                                                                               factTextStr = factTextStr.replaceAll("\\r\\n","");\r
+                                                                       }\r
+                                                                       StringBuilder factText = new StringBuilder(factTextStr);\r
+                                                                       factText.append(fact);\r
+                                                                       fact = factText.toString();\r
+                                                                       newTextData = false;\r
+                                                                       break;\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+\r
+                                               if (taxonDescription.isImageGallery()){\r
+                                                   newTextData = false;\r
+                                                   textData = (TextData)taxonDescription.getElements().iterator().next();\r
+                                               }\r
+                                               if(newTextData == true) {\r
+                                                       textData = TextData.NewInstance();\r
+                                               }else if (textData == null){\r
+                                                   throw new RuntimeException("Textdata must not be null");  //does not happen, only to avoid potential NPE warnings\r
+                                               }\r
+\r
+\r
+                                               //for diptera database\r
+                                               if (categoryFkInt.equals(99) && notes.contains("<OriginalName>")){\r
+                                                       fact = notes + ": " +  fact ;\r
+                                               }\r
+                                               //for E+M maps\r
+                                               if (categoryFkInt.equals(14) && state.getConfig().isRemoveHttpMapsAnchor() && fact.contains("<a href")){\r
+                                                       //example <a href="http://euromed.luomus.fi/euromed_map.php?taxon=280629&size=medium">distribution</a>\r
+                                                       fact = fact.replace("<a href=\"", "").replace("\">distribution</a>", "");\r
+                                               }\r
+\r
+                                               //TODO textData.putText(fact, bmiConfig.getFactLanguage());  //doesn't work because  bmiConfig.getFactLanguage() is not not a persistent Language Object\r
+                                               //throws  in thread "main" org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance - save the transient instance before flushing: eu.etaxonomy.cdm.model.common.Language; nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: eu.etaxonomy.cdm.model.common.Language\r
+\r
+                                               Language lang = Language.DEFAULT();\r
+                                               if (state.getConfig().isSalvador()){\r
+                                                   lang = getSalvadorFactLanguage(categoryFkInt);\r
+                                               }\r
+                                               if (! taxonDescription.isImageGallery()){\r
+                                                       textData.putText(lang, fact);\r
+                                                       textData.setFeature(feature);\r
+                                               }\r
+\r
+                                               deb = textData;\r
+\r
+                                               if (state.getConfig().isSalvador()){\r
+                                                   if (categoryFkInt == 306){\r
+                                                       NamedArea area = null;  // for now we do not set an area as it can not be disabled in dataportals via css yet\r
+                                                       deb = CommonTaxonName.NewInstance(fact, Language.SPANISH_CASTILIAN(), area);\r
+                                                   }else if (categoryFkInt == 307){\r
+                                                       Distribution salvadorDistribution = salvadorDistributionFromMuestrasDeHerbar(state, (Taxon)taxonBase, fact);\r
+                                                       if (salvadorDistribution != null){\r
+                                                           //id\r
+                                                           doId(state, salvadorDistribution, factId, "Fact");\r
+                                                           mergeSalvadorDistribution(taxonDescription, salvadorDistribution);\r
+                                                       }\r
+                                                   }\r
+                                               }\r
                         }\r
 \r
-                                               //textData\r
-                                               TextData textData = null;\r
-                                               boolean newTextData = true;\r
-\r
-                                               // For Cichorieae DB: If fact category is 31 (Systematics) and there is already a Systematics TextData\r
-                                               // description element append the fact text to the existing TextData\r
-                                               if(categoryFkInt.equals(31)) {\r
-                                                       Set<DescriptionElementBase> descriptionElements = taxonDescription.getElements();\r
-                                                       for (DescriptionElementBase descriptionElement : descriptionElements) {\r
-                                                               String featureString = descriptionElement.getFeature().getRepresentation(Language.DEFAULT()).getLabel();\r
-                                                               if (descriptionElement instanceof TextData && featureString.equals("Systematics")) { // TODO: test\r
-                                                                       textData = (TextData)descriptionElement;\r
-                                                                       String factTextStr = textData.getText(Language.DEFAULT());\r
-                                                                       // FIXME: Removing newlines doesn't work\r
-                                                                       if (factTextStr.contains("\\r\\n")) {\r
-                                                                               factTextStr = factTextStr.replaceAll("\\r\\n","");\r
-                                                                       }\r
-                                                                       StringBuilder factText = new StringBuilder(factTextStr);\r
-                                                                       factText.append(fact);\r
-                                                                       fact = factText.toString();\r
-                                                                       newTextData = false;\r
-                                                                       break;\r
-                                                               }\r
-                                                       }\r
-                                               }\r
-\r
-                                               if (taxonDescription.isImageGallery()){\r
-                                                   newTextData = false;\r
-                                                   textData = (TextData)taxonDescription.getElements().iterator().next();\r
-                                               }\r
-                                               if(newTextData == true) {\r
-                                                       textData = TextData.NewInstance();\r
-                                               }else if (textData == null){\r
-                                                   throw new RuntimeException("Textdata must not be null");  //does not happen, only to avoid potential NPE warnings\r
-                                               }\r
-\r
-\r
-                                               //for diptera database\r
-                                               if (categoryFkInt.equals(99) && notes.contains("<OriginalName>")){\r
-                                                       fact = notes + ": " +  fact ;\r
-                                               }\r
-                                               //for E+M maps\r
-                                               if (categoryFkInt.equals(14) && state.getConfig().isRemoveHttpMapsAnchor() && fact.contains("<a href")){\r
-                                                       //example <a href="http://euromed.luomus.fi/euromed_map.php?taxon=280629&size=medium">distribution</a>\r
-                                                       fact = fact.replace("<a href=\"", "").replace("\">distribution</a>", "");\r
-                                               }\r
-\r
-                                               //TODO textData.putText(fact, bmiConfig.getFactLanguage());  //doesn't work because  bmiConfig.getFactLanguage() is not not a persistent Language Object\r
-                                               //throws  in thread "main" org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance - save the transient instance before flushing: eu.etaxonomy.cdm.model.common.Language; nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: eu.etaxonomy.cdm.model.common.Language\r
-\r
-                                               Language lang = Language.DEFAULT();\r
-                                               if (state.getConfig().isSalvador()){\r
-                                                   lang = getSalvadorFactLanguage(categoryFkInt);\r
-                                               }\r
-                                               if (! taxonDescription.isImageGallery()){\r
-                                                       textData.putText(lang, fact);\r
-                                                       textData.setFeature(feature);\r
-                                               }\r
-\r
-                                               DescriptionElementBase deb = textData;\r
-\r
-                                               if (state.getConfig().isSalvador()){\r
-                                                   if (categoryFkInt == 306){\r
-                                                       NamedArea area = null;  // for now we do not set an area as it can not be disabled in dataportals via css yet\r
-                                                       deb = CommonTaxonName.NewInstance(fact, Language.SPANISH_CASTILIAN(), area);\r
-                                                   }else if (categoryFkInt == 307){\r
-                                                       Distribution salvadorDistribution = salvadorDistributionFromMuestrasDeHerbar(state, (Taxon)taxonBase, fact);\r
-                                                       if (salvadorDistribution != null){\r
-                                                           //id\r
-                                                           doId(state, salvadorDistribution, factId, "Fact");\r
-                                                           mergeSalvadorDistribution(taxonDescription, salvadorDistribution);\r
-                                                       }\r
-                                                   }\r
-                                               }\r
-\r
 \r
                                                //reference\r
                                                Reference citation = null;\r
@@ -500,7 +503,7 @@ public class BerlinModelFactsImport  extends BerlinModelImportBase {
                return success;\r
        }\r
 \r
-    private void handleMclDistribution(BerlinModelImportState state, TaxonDescription taxonDescription, String fact) {\r
+    private Distribution handleMclDistribution(BerlinModelImportState state, TaxonDescription taxonDescription, String fact) {\r
         String areaStr = fact.substring(0, 2);\r
         NamedArea mclArea = mclAreaUuid(state, areaStr);\r
         String statusStr = fact.substring(2);\r
@@ -508,6 +511,7 @@ public class BerlinModelFactsImport  extends BerlinModelImportBase {
 \r
         Distribution distribution = Distribution.NewInstance(mclArea, status);\r
         taxonDescription.addElement(distribution);\r
+        return distribution;\r
     }\r
 \r
     private NamedArea mclAreaUuid(BerlinModelImportState state, String areaStr) {\r
@@ -576,17 +580,18 @@ public class BerlinModelFactsImport  extends BerlinModelImportBase {
         }\r
     }\r
 \r
-    private void handleMclState(BerlinModelImportState state, TaxonDescription taxonDescription, String fact) {\r
+    private Distribution handleMclState(BerlinModelImportState state, TaxonDescription taxonDescription, String fact) {\r
         NamedArea mclArea = getNamedArea(state, UUID.fromString("f0500f01-0a59-4a6b-83cf-4070182f7266"), null, null, null, null, null, null, null, null);\r
         PresenceAbsenceTerm status;\r
         if (fact.equals("E")) {\r
             status = PresenceAbsenceTerm.ENDEMIC_FOR_THE_RELEVANT_AREA();\r
         }else {\r
             status = getPresenceTerm(state, BerlinModelTransformer.uuidStatusXenophyte,\r
-                    "Xenophyte", "Xenophyte in the overall area", "X", false, PresenceAbsenceTerm.PRESENT().getVocabulary());\r
+                    "xenophyte", "Xenophyte in the overall area", "X", false, PresenceAbsenceTerm.PRESENT().getVocabulary());\r
         }\r
         Distribution distribution = Distribution.NewInstance(mclArea, status);\r
         taxonDescription.addElement(distribution);\r
+        return distribution;\r
     }\r
 \r
     private void mergeSalvadorDistribution(TaxonDescription taxonDescription,\r
@@ -760,16 +765,10 @@ public class BerlinModelFactsImport  extends BerlinModelImportBase {
                return taxonDescription;\r
        }\r
 \r
-\r
-    /**\r
-     * @param categoryFk\r
-     * @return\r
-     */\r
     private boolean isPublicFeature(Integer categoryFk) {\r
         return ! (categoryFk == 1800 || categoryFk == 1900 || categoryFk == 2000);\r
     }\r
 \r
-\r
        @Override\r
        public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, BerlinModelImportState state) {\r
 \r
index 0c2cbb66f57260f489630cf335fbd597181528ea..493f54bdac68a77c50c47fbb5f01df5c4b111c71 100644 (file)
@@ -170,7 +170,6 @@ public class BerlinModelTaxonImport  extends BerlinModelImportBase {
                                        uuid = rs.getString("UUID");
                                }
 
-
                                TaxonName taxonName = null;
                                taxonName  = taxonNameMap.get(String.valueOf(nameFk));
 
@@ -260,13 +259,16 @@ public class BerlinModelTaxonImport  extends BerlinModelImportBase {
                                        //idInSource
                                        String idInSource = rs.getString("IdInSource");
                                        if (isNotBlank(idInSource)){
-                                               if(!state.getConfig().isEuroMed()){
+                                               if(!state.getConfig().isEuroMed() && !state.getConfig().isMcl()){
                                                    ExtensionType detailExtensionType = getExtensionType(state, BerlinModelTransformer.ID_IN_SOURCE_EXT_UUID, "Berlin Model IdInSource","Berlin Model IdInSource","BM source id");
                                                    Extension.NewInstance(taxonBase, idInSource.trim(), detailExtensionType);
-                                               }else if(isMclIdentifier(state,rs, idInSource)){
+                                               }else if(isMclIdentifier(state,rs, idInSource) || state.getConfig().isMcl()){
                                                    DefinedTerm identifierType = getIdentiferType(state, BerlinModelTransformer.uuidEM_MCLIdentifierType, "MCL identifier", "Med-Checklist identifier", "MCL ID", null);
                                                    Identifier.NewInstance(taxonBase, idInSource.trim(), identifierType);
                                                }
+                                               //maybe we want to handle it as fact in future for MCL
+//                                             if (state.getConfig().isMcl()) {
+//                                             }
                                        }
                                        //namePhrase
                                        String namePhrase = rs.getString("NamePhrase");
@@ -374,13 +376,6 @@ public class BerlinModelTaxonImport  extends BerlinModelImportBase {
                return success;
        }
 
-    /**
-     * @param state
-     * @param rs
-     * @param idInSource
-     * @return
-     * @throws SQLException
-     */
     private boolean isMclIdentifier(BerlinModelImportState state, ResultSet rs, String idInSource) throws SQLException {
         if (idInSource.contains("-")){
             return true;