ref #9578 , ref #8889 fix duplicate handling in getTaxonDistributionDTO
authorAndreas Müller <a.mueller@bgbm.org>
Wed, 14 Apr 2021 16:57:09 +0000 (18:57 +0200)
committerAndreas Müller <a.mueller@bgbm.org>
Wed, 14 Apr 2021 16:57:09 +0000 (18:57 +0200)
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImpl.java
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImplTest.java

index a60a9097630fb111246f7573de3c1c10787bf66e..43e7c7b6b9f6a55a319225e94a86b36565df3799 100644 (file)
@@ -1134,7 +1134,7 @@ public class TaxonNodeServiceImpl
         if (openChildren){
             //TODO we could remove nodes which are children of other nodes in parentNodes list here as they are duplicates
             for (TaxonNode node: parentNodes){
-                if (node == null){
+                if (node == null || nodes.contains(node)){
                     continue;
                 }
                 nodes.add(node);
index d61d1c69c312cdb1e3615eb80a45462d64d66e23..9756dfdffcfa8716995bd97439cd7b8e3d8dca14 100644 (file)
@@ -1062,8 +1062,13 @@ public class TaxonNodeServiceImplTest extends CdmTransactionalIntegrationTest{
     public void testGetTaxonDistributionDTO(){
         List<UUID> uuidList = Arrays.asList(node1Uuid, node2Uuid, node4Uuid);
         List<TaxonDistributionDTO> dtos = this.taxonNodeService.getTaxonDistributionDTO(uuidList, null, true);
-        Assert.assertEquals("Only 1 node has a child", 1, dtos.size());  //for some reason only the children are selected but not the parent itself, this may change in future
-        Assert.assertEquals(node4Uuid, dtos.get(0).getTaxonNodeDto().getUuid());
+        Assert.assertEquals("Children should be deduplicated", 3, dtos.size());
+        //note: the following ordering is not given by definition (as the method does not guarantee a certain order)
+        //      but is used as pseudo test here for the correctnes of the algorithm as it is currently expected
+        Assert.assertEquals("First node comes first", node1Uuid, dtos.get(0).getTaxonNodeDto().getUuid());
+        Assert.assertEquals("Child of first node comes second", node4Uuid, dtos.get(1).getTaxonNodeDto().getUuid());
+        Assert.assertEquals("Second node comes third", node2Uuid, dtos.get(2).getTaxonNodeDto().getUuid());
+        //third node is child of firt node and therefore came second already
     }
 
     @Test