commit bce2d0e546e3092a676180f8b7b8599a0a0f015e
Author: Katja Luther <k.luther@bgbm.org>
Date:   Tue Jun 28 11:43:59 2022 +0200

    fix 10084: fix problem with missing taxonuuid in dto

diff --git a/cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonNodeDaoHibernateImpl.java b/cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonNodeDaoHibernateImpl.java
index 33f07a0486..b754a4bfd4 100755
--- a/cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonNodeDaoHibernateImpl.java
+++ b/cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonNodeDaoHibernateImpl.java
@@ -1184,16 +1184,11 @@ public class TaxonNodeDaoHibernateImpl extends AnnotatableDaoBaseImpl<TaxonNode>
 
     public String getTaxonNodeDtoQueryWithoutParent() {
         String queryString = "SELECT new " + SortableTaxonNodeQueryResult.class.getName() + "("
-        	+	"tn.uuid, tn.id, t.titleCache"// rank "
-
-        //    + "tn.uuid, tn.id, t.uuid, t.titleCache, name.titleCache, rank, cl.uuid,  t.publish, tn.status, note "
+		+	"tn.uuid, tn.id, t.uuid, t.titleCache"// rank "
             + ") "
             + " FROM TaxonNode tn "
             + "   LEFT JOIN tn.taxon AS t "     ;
-//            + "   LEFT JOIN t.name AS name "
-//            + "   INNER JOIN tn.classification AS cl ";
-//            + "	  LEFT OUTER JOIN tn.statusNote as note ";
-      //      + "   LEFT OUTER JOIN name.rank AS rank ";
+
         return queryString;
     }
 
@@ -1256,7 +1251,7 @@ public class TaxonNodeDaoHibernateImpl extends AnnotatableDaoBaseImpl<TaxonNode>
         List<TaxonNodeDto> nodeDtos = new ArrayList<>();
         Collections.sort(result, new SortableTaxonNodeQueryResultComparator());
         for(SortableTaxonNodeQueryResult queryDTO : result){
-            TaxonNodeDto nodeDto = new TaxonNodeDto(queryDTO.getTaxonNodeUuid(), queryDTO.getTaxonNodeId(), queryDTO.getTreeIndex(), queryDTO.getNameTitleCache(), queryDTO.getTaxonTitleCache(), queryDTO.getNameRank()!= null? queryDTO.getNameRank().getOrderIndex(): null, queryDTO.getParentNodeUuid(), queryDTO.getSortIndex(), queryDTO.getClassificationUuid(), queryDTO.isTaxonIsPublish(), queryDTO.getStatus(), queryDTO.getStatusNote());
+            TaxonNodeDto nodeDto = new TaxonNodeDto(queryDTO.getTaxonNodeUuid(), queryDTO.getTaxonNodeId(), queryDTO.getTaxonUuid(), queryDTO.getTreeIndex(), queryDTO.getNameTitleCache(), queryDTO.getTaxonTitleCache(), queryDTO.getNameRank()!= null? queryDTO.getNameRank().getOrderIndex(): null, queryDTO.getParentNodeUuid(), queryDTO.getSortIndex(), queryDTO.getClassificationUuid(), queryDTO.isTaxonIsPublish(), queryDTO.getStatus(), queryDTO.getStatusNote());
             nodeDtos.add(nodeDto);
         }
         return nodeDtos;
diff --git a/cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/TaxonNodeDto.java b/cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/TaxonNodeDto.java
index 58d3e5e016..5202c350ee 100644
--- a/cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/TaxonNodeDto.java
+++ b/cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/TaxonNodeDto.java
@@ -92,13 +92,14 @@ public class TaxonNodeDto extends UuidAndTitleCache<ITaxonTreeNode> {
         super(uuid, id, nameTitleCache, taxonTitleCache);
 
     }
-    public TaxonNodeDto(UUID uuid, Integer id, String treeIndex, String nameTitleCache, String taxonTitleCache, Integer rankOrderIndex, UUID parentUuid, Integer sortIndex, UUID classificationUuid, Boolean taxonIsPublished, TaxonNodeStatus status, List<LanguageString> statusNote){
+    public TaxonNodeDto(UUID uuid, Integer id, UUID taxonUuid, String treeIndex, String nameTitleCache, String taxonTitleCache, Integer rankOrderIndex, UUID parentUuid, Integer sortIndex, UUID classificationUuid, Boolean taxonIsPublished, TaxonNodeStatus status, List<LanguageString> statusNote){
     	this(uuid, id, treeIndex, nameTitleCache, taxonTitleCache, rankOrderIndex, parentUuid, sortIndex, classificationUuid);
     	this.status = status;
     	this.taxonIsPublish = taxonIsPublished;
     	for (LanguageString str: statusNote) {
     		this.statusNote.put(str.getLanguage(), str.getText());
     	}
+	this.taxonUuid = taxonUuid;
     }
 
     public TaxonNodeDto(UUID uuid, Integer id, String treeIndex, String nameTitleCache, String taxonTitleCache, Integer rankOrderIndex, UUID parentUuid, Integer sortIndex, UUID classificationUuid) {
diff --git a/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/DescriptiveDataSetService.java b/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/DescriptiveDataSetService.java
index e2ea93e9b0..b060ec6190 100644
--- a/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/DescriptiveDataSetService.java
+++ b/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/DescriptiveDataSetService.java
@@ -144,14 +144,14 @@ public class DescriptiveDataSetService
             }
             DescriptionBaseDto descDto = descriptionService.loadDto(description);
             RowWrapperDTO<?> rowWrapper = null;
-            if (descDto.getTaxonDto() != null &&
+            if (descDto != null && descDto.getTaxonDto() != null &&
                     (descDto.getTypes().contains(DescriptionType.DEFAULT_VALUES_FOR_AGGREGATION)
                             || descDto.getTypes().contains(DescriptionType.AGGREGATED_STRUC_DESC)
                             || descDto.getTypes().contains(DescriptionType.SECONDARY_DATA)
                             )){
                 rowWrapper = createTaxonRowWrapper(descDto, datasetDto.getUuid());
             }
-            else if (descDto.getSpecimenDto() != null && (descDto.getTypes() == null ||
+            else if (descDto != null &&descDto.getSpecimenDto() != null && (descDto.getTypes() == null ||
                     !descDto.getTypes().contains(DescriptionType.CLONE_FOR_SOURCE))){
                 rowWrapper = createSpecimenRowWrapper(descDto, descriptiveDataSetUuid);
             }
@@ -207,7 +207,7 @@ public class DescriptiveDataSetService
     private DescriptionBaseDto recurseDefaultDescription(TaxonNodeDto node, DescriptiveDataSetBaseDto dataSet){
         DescriptionBaseDto defaultDescription = null;
         if(node!=null && node.getTaxonUuid()!=null){
-            defaultDescription = getTaxonDescriptionForDescriptiveDataSetAndType(dataSet, node.getUuid(), DescriptionType.DEFAULT_VALUES_FOR_AGGREGATION);
+            defaultDescription = getTaxonDescriptionForDescriptiveDataSetAndType(dataSet, node.getTaxonUuid(), DescriptionType.DEFAULT_VALUES_FOR_AGGREGATION);
             if(defaultDescription==null && node.getParentUUID()!=null){
                 defaultDescription = recurseDefaultDescription(taxonNodeService.dto(node.getParentUUID()), dataSet);
             }
@@ -491,22 +491,36 @@ public class DescriptiveDataSetService
     @Override
     public DescriptionBaseDto getTaxonDescriptionForDescriptiveDataSetAndType(DescriptiveDataSetBaseDto dataSet, UUID taxonUuid, DescriptionType descriptionType){
         Session session = getSession();
-        String queryString = "SELECT d.uuid FROM DescriptiveDataSet a JOIN a.descriptions as d JOIN d.taxon t WHERE t.uuid = :taxonuuid AND a.uuid = :dataSetUuid and d.type = :descriptionType";
+        String queryString = "SELECT d.uuid FROM DescriptiveDataSet a JOIN a.descriptions as d JOIN d.taxon t WHERE t.uuid = :taxonuuid AND a.uuid = :dataSetUuid";// and d.type = :descriptionType";
 
         Query query;
         query = session.createQuery(queryString);
         query.setParameter("taxonuuid", taxonUuid);
         query.setParameter("dataSetUuid", dataSet.getUuid());
-        query.setParameter("descriptionType", descriptionType);
+//        query.setParameter("descriptionType", descriptionType);
 
         @SuppressWarnings("unchecked")
         List<UUID> result = query.list();
         List<DescriptionBaseDto> list = new ArrayList<>();
         list.addAll(descriptionService.loadDtos(new HashSet(result)));
+
         if (list.isEmpty()){
             return null;
+        }else {
+		List<DescriptionBaseDto> correctTypeOnly = new ArrayList<>();
+		for (DescriptionBaseDto dto: list) {
+			if (dto.getTypes().contains(descriptionType)) {
+				correctTypeOnly.add(dto);
+			}
+		}
+		if (correctTypeOnly.isEmpty()) {
+			return null;
+		}else {
+			return correctTypeOnly.get(0);
+		}
         }
-        return list.get(0);
+
+//        return list.get(0);
     }
 
     @Override
