ref #7589 Improve description search when adding specimens to the matrix
authorPatrick Plitzner <p.plitzner@bgbm.org>
Fri, 27 Jul 2018 09:31:48 +0000 (11:31 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Fri, 27 Jul 2018 14:09:44 +0000 (16:09 +0200)
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/DescriptiveDataSetService.java

index 9ed2428dc14d628bb88ef4c88be88b04659a722f..a4e07478f943b6e0dc3250d7eb2643532633650d 100644 (file)
@@ -205,8 +205,14 @@ public class DescriptiveDataSetService
 
         for (SpecimenDescription specimenDescription : (Set<SpecimenDescription>) specimen.getDescriptions()) {
             specimenDescription = (SpecimenDescription) descriptionService.load(specimenDescription.getUuid());
-            Set<Feature> specimenDescriptionFeatures = new HashSet<>();
+
+            //check if description is already added to data set
+            if(dataSet.getDescriptions().contains(specimenDescription)){
+                return specimenDescription;
+            }
+
             //gather specimen description features and check for match with dataset features
+            Set<Feature> specimenDescriptionFeatures = new HashSet<>();
             for (DescriptionElementBase specimenDescriptionElement : specimenDescription.getElements()) {
                 Feature feature = specimenDescriptionElement.getFeature();
                 specimenDescriptionFeatures.add(feature);
@@ -214,14 +220,10 @@ public class DescriptiveDataSetService
                     matchingDescriptionElements.add(specimenDescriptionElement);
                 }
             }
-            //if description with the exact same features is found return the description
-            if(specimenDescriptionFeatures.equals(datasetFeatures)){
-                return specimenDescription;
-            }
         }
-        //Create new specimen description if no match was found
+        //Create new specimen description if description has not already been added to the dataset
         SpecimenDescription newDesription = SpecimenDescription.NewInstance(specimen);
-        newDesription.setTitleCache("Dataset"+dataSet.getLabel()+": "+newDesription.generateTitle(), true); //$NON-NLS-2$
+        newDesription.setTitleCache("Dataset "+dataSet.getLabel()+": "+newDesription.generateTitle(), true); //$NON-NLS-2$
 
         //check for equals description element (same feature and same values)
         Map<Feature, List<DescriptionElementBase>> featureToElementMap = new HashMap<>();