ref #10271 add error handling and avoid NPE for unhandled name relationship types
authorAndreas Müller <a.mueller@bgbm.org>
Tue, 9 Jan 2024 21:47:05 +0000 (22:47 +0100)
committerAndreas Müller <a.mueller@bgbm.org>
Tue, 9 Jan 2024 21:47:23 +0000 (22:47 +0100)
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/coldp/ColDpClassificationExport.java
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/coldp/ColDpExportTransformer.java

index 2b08390ce0c65b38809e061617156dc399e788eb..cf51f2edba5afdca861bc46f0bf1b5fa1146ebee 100644 (file)
@@ -76,6 +76,7 @@ import eu.etaxonomy.cdm.model.media.MediaRepresentation;
 import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
 import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
 import eu.etaxonomy.cdm.model.name.NameRelationship;
+import eu.etaxonomy.cdm.model.name.NameRelationshipType;
 import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
 import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
 import eu.etaxonomy.cdm.model.name.Rank;
@@ -1493,7 +1494,8 @@ public class ColDpClassificationExport
             for (NameRelationship rel : fromRels) {
                 ColDpNameRelType coldpType = transformer.getColDpNameRelTypeByNameRelationType(rel.getType());
                 if (coldpType == null) {
-                    //TODO warning
+                    handleNoColDpNameRelType(state, rel.getType(), name);
+                    continue;
                 }else if (coldpType.getDirection() == 0) {
                     continue;  //the relation is handled the other way round if necessary
                 }
@@ -1507,7 +1509,8 @@ public class ColDpClassificationExport
             for (NameRelationship rel : toRels) {
                 ColDpNameRelType coldpType = transformer.getColDpNameRelTypeByNameRelationType(rel.getType());
                 if (coldpType == null) {
-                    //TODO warning
+                    handleNoColDpNameRelType(state, rel.getType(), name);
+                    continue;
                 }else if (coldpType.getDirection() == 1) {
                     continue;  //the relation is handled the other way round if necessary
                 }
@@ -1523,6 +1526,17 @@ public class ColDpClassificationExport
         }
     }
 
+    private void handleNoColDpNameRelType(ColDpExportState state, NameRelationshipType nameRelType, TaxonName taxonName) {
+        String warning;
+        if (nameRelType == null) {
+            warning = "Name relationship has not type for name " + taxonName.getTitleCache();
+        } else {
+            //TODO misspelling, alternative name, blocking name for, avoids homonym of, unspecific "non"
+            warning = "Name relationship type not yet handled by COL-DP: " + nameRelType.getTitleCache() + "; name: " + taxonName.getTitleCache();
+        }
+        state.getResult().addWarning(warning);
+    }
+
     private void handleRelNameCommonData(ColDpExportState state, ColDpExportTable table,
             NameRelationship rel, TaxonName name, TaxonName relatedName, ColDpNameRelType coldpType) {
 
index 16304bca36e5e2e2217246c84a334b64dcc38cbb..36d3f0a74d73b1257c7c93606b01512161c36fae 100644 (file)
@@ -212,7 +212,7 @@ public class ColDpExportTransformer extends ExportTransformerBase {
         } else {
             //TODO misspelling, alternative name, blocking name for, avoids homonym of, unspecific "non"
             String warning = "Name relationship type not yet handled by COL-DP: " + nameRelType.getTitleCache();
-            //TODO handle warning
+            //TODO handle warning, is currently handled in calling method
             Representation preferredRep = nameRelType.getPreferredRepresentation(Language.ENGLISH());
 //            if (preferredRep != null) {
 //               return preferredRep.getLabel() == null ? null :preferredRep.getLabel().toLowerCase();