ref #9510 adapt specimens holding description label (cont. II)
authorAndreas Müller <a.mueller@bgbm.org>
Wed, 6 Oct 2021 10:06:55 +0000 (12:06 +0200)
committerAndreas Müller <a.mueller@bgbm.org>
Wed, 6 Oct 2021 10:08:28 +0000 (12:08 +0200)
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/DescriptiveDataSetService.java
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/description/StructuredDescriptionAggregationTest.java

index 25e3c078eb1aa8b6f250f2f5986a2c9a7b957772..0714e99b634df5ca675e9be061575d47f00f8246 100644 (file)
@@ -276,7 +276,7 @@ public class DescriptiveDataSetService
                     .findFirst().orElseGet(()->{
                         TaxonDescription td = TaxonDescription.NewInstance(taxon);
                         td.addType(DescriptionType.INDIVIDUALS_ASSOCIATION);
-                        td.setTitleCache("Specimens used by " + dataSet.getTitleCache() + " for " + taxon.getTitleCache(), true);
+                        td.setTitleCache("Specimens used by " + dataSet.getTitleCache() + " for " + getTaxonLabel(taxon), true);
                         return td;});
 
             IndividualsAssociation association = IndividualsAssociation.NewInstance(specimen);
@@ -369,6 +369,14 @@ public class DescriptiveDataSetService
         return result;
     }
 
+    private String getTaxonLabel(Taxon taxon) {
+        if (taxon.getName() != null){
+            return taxon.getName().getTitleCache();
+        }else{
+            return taxon.getTitleCache();
+        }
+    }
+
     private SpecimenRowWrapperDTO createSpecimenRowWrapper(SpecimenDescription description, UUID taxonNodeUuid,
             UUID datasetUuid) {
         TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
index ca8f58d730e22006b81f194dd8a8c123d7db9345..56c5bf0a3add4432476dbcb6e0a6403248bce197 100644 (file)
@@ -548,10 +548,17 @@ public class StructuredDescriptionAggregationTest extends CdmTransactionalIntegr
 
     private SpecimenDescription createSpecimenDescription(DescriptiveDataSet dataSet, UUID taxonUuid, String specLabel, UUID specimenUuid ) {
         Taxon taxon = (Taxon)taxonService.find(taxonUuid);
-        TaxonDescription taxonDescription = TaxonDescription.NewInstance(taxon);
         DerivedUnit specimen = DerivedUnit.NewPreservedSpecimenInstance();
         specimen.setTitleCache(specLabel, true);
         specimen.setUuid(specimenUuid);
+        TaxonDescription taxonDescription = taxon.getDescriptions(DescriptionType.INDIVIDUALS_ASSOCIATION).stream()
+            .findFirst()
+            .orElseGet(()->{
+                TaxonDescription td = TaxonDescription.NewInstance(taxon);
+                td.addType(DescriptionType.INDIVIDUALS_ASSOCIATION);
+                td.setTitleCache("Specimens used by " + dataSet.getTitleCache() + " for " + getTaxonLabel(taxon), true);
+                return td;}
+             );
         IndividualsAssociation individualsAssociation = IndividualsAssociation.NewInstance(specimen);
         // TODO this has to be discussed; currently the description with the InidividualsAssociation is
         // needed in the dataset for performance reasons
@@ -563,6 +570,14 @@ public class StructuredDescriptionAggregationTest extends CdmTransactionalIntegr
         return specDesc;
     }
 
+    private String getTaxonLabel(Taxon taxon) {
+        if (taxon.getName() != null){
+            return taxon.getName().getTitleCache();
+        }else{
+            return taxon.getTitleCache();
+        }
+    }
+
     private Feature createFeature(UUID uuid, String label, boolean isQuantitative) {
         Feature feature = Feature.NewInstance("", label, null);
         feature.setUuid(uuid);