ref #10322, ref #9524 allow loading annotations without type
authorAndreas Müller <a.mueller@bgbm.org>
Wed, 29 May 2024 16:34:33 +0000 (18:34 +0200)
committerAndreas Müller <a.mueller@bgbm.org>
Wed, 29 May 2024 16:34:46 +0000 (18:34 +0200)
cdmlib-api/src/main/java/eu/etaxonomy/cdm/api/dto/portal/config/DistributionInfoConfiguration.java
cdmlib-api/src/main/java/eu/etaxonomy/cdm/api/dto/portal/config/TaxonPageDtoConfiguration.java
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/AnnotationDtoLoader.java
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/portal/AnnotatableDtoLoader.java
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/portal/TaxonPageDtoLoaderBase.java
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/portal/TaxonPageDtoLoaderTest.java

index 769bbac99a735cb12c5fbfe4472f49342f8bee1f..b7b156bc9297729b78edc4b4fa5a3800c2bb8753 100644 (file)
@@ -175,6 +175,9 @@ public class DistributionInfoConfiguration implements IAnnotatableLoaderConfigur
     public Set<UUID> getAnnotationTypes() {
         return annotationTypes;
     }
+    public void addAnnotationType(UUID annotationType) {
+        annotationTypes.add(annotationType);
+    }
     public void setAnnotationTypes(Set<UUID> annotationTypes) {
         this.annotationTypes = annotationTypes;
     }
index 2b9e5fe09815ec663c660de4ea0ad54818218e6e..5946c1149b192ad3ca4d13ff9b738adb9e96bd75 100644 (file)
@@ -227,6 +227,11 @@ public class TaxonPageDtoConfiguration implements IAnnotatableLoaderConfiguratio
         this.distributionInfoConfiguration.setAnnotationTypes(annotationTypes);
     }
 
+    public void addAnnotationType(UUID annotationType) {
+        this.annotationTypes.add(annotationType);
+        this.distributionInfoConfiguration.addAnnotationType(annotationType);
+    }
+
     public boolean isUseDtoLoading() {
         return useDtoLoading;
     }
index ac40e3dbd8407753c74a011596b9727abad834a4..801494fcff5f48af2118d4fa7a5684267432d8e1 100644 (file)
@@ -56,8 +56,8 @@ public class AnnotationDtoLoader {
 
 
         String hql = "SELECT new map(a.id as id, a.uuid as uuid, "
-                +     " a.text as text, a.annotationType.uuid as typeUuid) "
-                + " FROM Annotation a "
+                +     " a.text as text, at.uuid as typeUuid) "
+                + " FROM Annotation a LEFT JOIN a.annotationType at "
                 + " WHERE a.id IN :baseIds "
                 ;
 
index 2fe16932f9ec316fe054a2eae99cb424867e72e5..3e3f18bf4f1fb7677c66d228962019e26ec28d05 100644 (file)
@@ -22,6 +22,7 @@ import eu.etaxonomy.cdm.api.dto.portal.config.IAnnotatableLoaderConfiguration;
 import eu.etaxonomy.cdm.common.SetMap;
 import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
 import eu.etaxonomy.cdm.model.common.Annotation;
+import eu.etaxonomy.cdm.model.common.AnnotationType;
 import eu.etaxonomy.cdm.model.common.Marker;
 import eu.etaxonomy.cdm.persistence.dao.common.ICdmGenericDao;
 
@@ -60,11 +61,16 @@ public class AnnotatableDtoLoader {
 
         Map<String,Object> params = new HashMap<>();
         String hql = "SELECT new map(bc.id as id, a.id as annotationId) "
-                + " FROM "+baseClass.getSimpleName()+" bc JOIN bc.annotations a "
+                + " FROM "+baseClass.getSimpleName()+" bc JOIN bc.annotations a"
+                        + " LEFT JOIN a.annotationType at"
                 + " WHERE bc.id IN :baseIds";
         params.put("baseIds", baseIds);
-        if (config.getAnnotationTypes() != null) {
-            hql += " AND a.annotationType.uuid IN :annotationTypes ";
+        if (config.getAnnotationTypes() != null ) {
+            hql += " AND (at.uuid IN :annotationTypes ";
+            if (config.getAnnotationTypes().contains(AnnotationType.uuidUntyped)) {
+                hql += " OR a.id IS NOT NULL AND at IS NULL ";
+            }
+            hql += ")";
             params.put("annotationTypes", config.getAnnotationTypes());
         }
 
index 9bdfe7dae90f6c9cf7d06423ce11640c24e5294c..9831656cc9a0499897f33151d16a9b4f38983cf1 100644 (file)
@@ -119,7 +119,7 @@ public abstract class TaxonPageDtoLoaderBase {
             //annotation
             for (Annotation annotation : annotatable.getAnnotations()) {
                 if ((annotation.getAnnotationType() != null
-                        //config == null currently needs to be allowed as it is also used by DistributionInfoBuilder an
+                        //config == null currently needs to be allowed as it is also used by DistributionInfoBuilder and
                         //also for now empty annotation types needs to be interpreted as "no filter" as we do not distinguish
                         //null and empty yet, this may change in future
                         && (config == null || config.getAnnotationTypes().isEmpty()
@@ -135,7 +135,7 @@ public abstract class TaxonPageDtoLoaderBase {
                     UUID uuidAnnotationType = annotation.getAnnotationType() == null ? null :annotation.getAnnotationType().getUuid();
                     annotationDto.setTypeUuid(uuidAnnotationType);
                     //language etc. currently not yet used
-                }else if (config != null && !config.getAnnotationTypes().isEmpty() && config.getAnnotationTypes().contains(AnnotationType.uuidUntyped) &&  (annotation.getAnnotationType() == null)){
+                }else if (config != null && config.getAnnotationTypes().contains(AnnotationType.uuidUntyped) &&  (annotation.getAnnotationType() == null)){
                     AnnotationDto annotationDto = new AnnotationDto();
                     annotatableDto.addAnnotation(annotationDto);
                     //TODO id needed? but need to adapt dto and container then
index 901bafdc856086549da9959287a3f1c561bea16c..3a9495536418abd2149d572cbc1182063adcb7af 100644 (file)
@@ -58,6 +58,7 @@ import eu.etaxonomy.cdm.model.common.Annotation;
 import eu.etaxonomy.cdm.model.common.AnnotationType;
 import eu.etaxonomy.cdm.model.common.ExtendedTimePeriod;
 import eu.etaxonomy.cdm.model.common.Language;
+import eu.etaxonomy.cdm.model.common.MarkerType;
 import eu.etaxonomy.cdm.model.common.TimePeriod;
 import eu.etaxonomy.cdm.model.description.CategoricalData;
 import eu.etaxonomy.cdm.model.description.CommonTaxonName;
@@ -304,6 +305,7 @@ public class TaxonPageDtoLoaderTest extends CdmTransactionalIntegrationTest {
         cc.showAreaOfScopeLabel = true;
         config.setWithSpecimens(false);
         config.setTaxonUuid(taxonUuid);
+        config.addAnnotationType(AnnotationType.uuidUntyped);
 
         config.setUseDtoLoading(false);
         testAllFactsDo(config); //with model instance loading
@@ -524,7 +526,10 @@ public class TaxonPageDtoLoaderTest extends CdmTransactionalIntegrationTest {
         TreeNode<Set<DistributionDto>, NamedAreaDto> germanyNode = tree.getRootElement().getChildren().get(1);
         Assert.assertEquals("Germany", germanyNode.getNodeId().getLabel());
         DistributionDto germanyDistribution = germanyNode.getData().iterator().next();
-        Assert.assertEquals(1, germanyDistribution.getAnnotations().getCount());
+        Assert.assertEquals(2, germanyDistribution.getAnnotations().getCount());
+        Assert.assertEquals("Missing type annotation should exist",
+                + 1, germanyDistribution.getAnnotations().getItems().stream()
+                     .filter(a->"Missing Type Annotation".equals(a.getText())).count());
         Assert.assertEquals("There should be 1 source (even if it has no name used in source)", 1, germanyDistribution.getSources().getCount());
 
         //france
@@ -589,8 +594,9 @@ public class TaxonPageDtoLoaderTest extends CdmTransactionalIntegrationTest {
         Country.GERMANY().setSymbol("De");
         PresenceAbsenceTerm.PRESENT().setSymbol("");
         Distribution germany = Distribution.NewInstance(Country.GERMANY(), PresenceAbsenceTerm.PRESENT());
-        germany.addAnnotation(Annotation.NewEditorialDefaultLanguageInstance("Abc Annotation"));
+        germany.addAnnotation(Annotation.NewEditorialDefaultLanguageInstance("Editorial Annotation"));
         germany.addAnnotation(Annotation.NewInstance("Technical Annotation", AnnotationType.TECHNICAL(), Language.DEFAULT()));
+        germany.addAnnotation(Annotation.NewInstance("Missing Type Annotation", null, Language.DEFAULT()));
         //.... germany source
         Reference germanRef = ReferenceFactory.newArticle();
         germanRef.setInJournal(ReferenceFactory.newJournal());
@@ -677,6 +683,9 @@ public class TaxonPageDtoLoaderTest extends CdmTransactionalIntegrationTest {
         //empty text
         TextData emptyTd = TextData.NewInstance(Feature.DISCUSSION(), "", Language.DEFAULT(), null);
         taxDesc.addElements(emptyTd);
+        //annotation
+        taxDesc.addAnnotation(Annotation.NewInstance("Missing Type Annotation for empty", null, Language.DEFAULT()));
+        taxDesc.addMarker(MarkerType.IS_DOUBTFUL(), true);
 
         //common names
         CommonTaxonName cn1 = CommonTaxonName.NewInstance("My flower", Language.ENGLISH(), Country.UNITEDKINGDOMOFGREATBRITAINANDNORTHERNIRELAND());