cleanup and minor
authorAndreas Müller <a.mueller@bgbm.org>
Wed, 6 Oct 2021 16:24:37 +0000 (18:24 +0200)
committerAndreas Müller <a.mueller@bgbm.org>
Wed, 6 Oct 2021 16:24:37 +0000 (18:24 +0200)
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/DescriptionServiceImpl.java
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IDescriptionService.java
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/description/DistributionAggregationTest.java

index 7409e8b506064b8ad1a94ba18d9bf58f96e7eba1..5d55f1f251524c73844624e7c3e9df8a8d613063 100644 (file)
@@ -663,14 +663,14 @@ public class DescriptionServiceImpl
 
     @Override
     @Transactional(readOnly = false)
-    public DeleteResult deleteDescription(DescriptionBase description) {
+    public DeleteResult deleteDescription(DescriptionBase<?> description) {
 
         DeleteResult deleteResult = new DeleteResult();
         if (description == null){
             return deleteResult;
         }
-        description = load(description.getId(), Arrays.asList("descriptiveDataSets"));
         //avoid lazy init exception
+        description = load(description.getId(), Arrays.asList("descriptiveDataSets"));
 
         deleteResult = isDeletable(description.getUuid());
         if (deleteResult.getRelatedObjects() != null && deleteResult.getRelatedObjects().size() == 1){
@@ -697,9 +697,8 @@ public class DescriptionServiceImpl
                    deleteResult.addUpdatedObject(specimen);
                }
 
-               Set<DescriptiveDataSet> descriptiveDataSets = description.getDescriptiveDataSets();
-               for (Iterator<DescriptiveDataSet> iterator = descriptiveDataSets.iterator(); iterator.hasNext();) {
-                   iterator.next().removeDescription(description);
+               for (DescriptiveDataSet dataset : description.getDescriptiveDataSets()) {
+                   dataset.removeDescription(description);
             }
 
                dao.delete(description);
@@ -728,20 +727,17 @@ public class DescriptionServiceImpl
             return result;
         }
         for (CdmBase ref: references){
-            String message = null;
-            if (description instanceof TaxonDescription && ref instanceof Taxon && ((TaxonDescription)description).getTaxon().equals(ref)){
+            if (description instanceof TaxonDescription && ref instanceof Taxon && ref.equals(((TaxonDescription)description).getTaxon())){
                 continue;
-            } else if (description instanceof TaxonNameDescription && ref instanceof TaxonName && ((TaxonNameDescription)description).getTaxonName().equals(ref)){
+            } else if (description instanceof TaxonNameDescription && ref instanceof TaxonName && ref.equals(((TaxonNameDescription)description).getTaxonName())){
                 continue;
-            } else if (description instanceof SpecimenDescription && ref instanceof SpecimenOrObservationBase && ((SpecimenDescription)description).getDescribedSpecimenOrObservation().equals(ref)){
+            } else if (description instanceof SpecimenDescription && ref instanceof SpecimenOrObservationBase && ref.equals(((SpecimenDescription)description).getDescribedSpecimenOrObservation())){
                 continue;
             } else if (ref instanceof DescriptionElementBase){
                 continue;
             }else {
-                message = "The description can't be completely deleted because it is referenced by " + ref.getUserFriendlyTypeName() ;
+                String message = "The description can't be completely deleted because it is referenced by " + ref.getUserFriendlyTypeName() ;
                 result.setAbort();
-            }
-            if (message != null){
                 result.addException(new ReferencedObjectUndeletableException(message));
                 result.addRelatedObject(ref);
             }
index 5321fab0cd75385222940ffe4b401ee887c3d00c..eca307212055a291e7a14a0cc4f33dea59cc1461 100644 (file)
@@ -6,7 +6,6 @@
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
-
 package eu.etaxonomy.cdm.api.service;
 
 import java.util.Collection;
@@ -531,86 +530,36 @@ public interface IDescriptionService extends IIdentifiableEntityService<Descript
     public Pager<TermDto> pageNamedAreasInUse(boolean includeAllParents, Integer pageSize,
             Integer pageNumber);
 
-       public DeleteResult deleteDescription(DescriptionBase description);
+       /**
+        * Deletes the description and prior removes it from taxon, specimen or descriptive dataset.
+        */
+       public DeleteResult deleteDescription(DescriptionBase<?> description);
 
        public DeleteResult deleteDescription(UUID descriptionUuid);
 
-    /**
-     * @param sourceTaxon
-     * @param targetTaxon
-     * @return
-     */
     public UpdateResult moveTaxonDescriptions(Taxon sourceTaxon, Taxon targetTaxon, boolean setNameInSource);
 
-    /**
-     * @param sourceTaxonUuid
-     * @param targetTaxonUuid
-     * @return
-     */
     public UpdateResult moveTaxonDescriptions(UUID sourceTaxonUuid, UUID targetTaxonUuid, boolean setNameInSource);
 
-
-    /**
-     * @param descriptionElementUUIDs
-     * @param targetDescriptionUuid
-     * @param isCopy
-     * @return
-     */
     public UpdateResult moveDescriptionElementsToDescription(Set<UUID> descriptionElementUUIDs, UUID targetDescriptionUuid,
             boolean isCopy, boolean setNameInSource);
 
-    /**
-     * @param descriptionElementUUIDs
-     * @param targetTaxonUuid
-     * @param moveMessage
-     * @param isCopy
-     * @return
-     */
     public UpdateResult moveDescriptionElementsToDescription(Set<UUID> descriptionElementUUIDs, UUID targetTaxonUuid,
             String moveMessage, boolean isCopy, boolean setNameInSource);
 
-    /**
-     * @param descriptionUUID
-     * @param targetTaxonUuid
-     * @return
-     */
     public UpdateResult moveTaxonDescription(UUID descriptionUuid, UUID targetTaxonUuid, boolean setNameInSource);
 
-    /**
-     * @param descriptionElements
-     * @param returnTransientEntity
-     * @return
-     */
     public List<MergeResult<DescriptionBase>> mergeDescriptionElements(Collection<TaxonDistributionDTO> descriptionElements,
             boolean returnTransientEntity);
 
-    /**
-     * @param descriptions
-     * @param returnTransientEntity
-     * @return
-     */
     public UpdateResult mergeDescriptions(Collection<DescriptionBaseDto> descriptions, UUID descriptiveDataSetUuid);
 
-
-    /**
-     * @param descriptionElementUUIDs
-     * @param targetDescription
-     * @param isCopy
-     * @return
-     */
-    UpdateResult moveDescriptionElementsToDescription(Set<UUID> descriptionElementUUIDs,
+    public UpdateResult moveDescriptionElementsToDescription(Set<UUID> descriptionElementUUIDs,
             DescriptionBase targetDescription, boolean isCopy, boolean setNameInSource);
 
     public DeleteResult isDeletable(UUID descriptionUuid);
 
     public DescriptionBaseDto loadDto(UUID descriptionUuid);
 
-    /**
-     * @param taxonUuid
-     * @return
-     */
-    List<DescriptionBaseDto> loadDtosForTaxon(UUID taxonUuid);
-
-
-
-}
+    public List<DescriptionBaseDto> loadDtosForTaxon(UUID taxonUuid);
+}
\ No newline at end of file
index 457a6cfef98893601852b70a5c01d275fac61f62..4bbf405581ed9b2a40ec1a66ec16dd49083f3102 100644 (file)
@@ -327,32 +327,32 @@ public class DistributionAggregationTest extends CdmTransactionalIntegrationTest
         UUID yugDistributionUuid = null;
         UUID yug_mn_DistributionUuid = null;
         for (DescriptionElementBase element : lapsanaAggregatedDescription.getElements()){
-            Distribution labsanaDistribution = (Distribution)element;
-            if(labsanaDistribution.getArea().equals(yug)){
+            Distribution lapsanaDistribution = (Distribution)element;
+            if(lapsanaDistribution.getArea().equals(yug)){
                 numExpectedFound++;
-                assertEquals("Aggregated status of area YUG is wrong", PresenceAbsenceTerm.NATIVE(), labsanaDistribution.getStatus());
-                assertEquals(2, labsanaDistribution.getSources().size());
+                assertEquals("Aggregated status of area YUG is wrong", PresenceAbsenceTerm.NATIVE(), lapsanaDistribution.getStatus());
+                assertEquals(2, lapsanaDistribution.getSources().size());
                 // should contain source_LCA_yug_ma and source_LCA_yug_ko, testing the microreference which is unique in the tests
-                assertTrue(sourceExists(labsanaDistribution.getSources(), book_a, "2"));
-                assertTrue(sourceExists(labsanaDistribution.getSources(), book_a, "4"));
-                yugDistributionUuid = labsanaDistribution.getUuid(); //for later
+                assertTrue(sourceExists(lapsanaDistribution.getSources(), book_a, "2"));
+                assertTrue(sourceExists(lapsanaDistribution.getSources(), book_a, "4"));
+                yugDistributionUuid = lapsanaDistribution.getUuid(); //for later
             }
-            if(labsanaDistribution.getArea().equals(yug_mn)){
+            if(lapsanaDistribution.getArea().equals(yug_mn)){
                 numExpectedFound++;
-                assertEquals("Aggregated status of area YUG-MN is wrong", PresenceAbsenceTerm.CULTIVATED(), labsanaDistribution.getStatus());
-                assertEquals(2, labsanaDistribution.getSources().size());
+                assertEquals("Aggregated status of area YUG-MN is wrong", PresenceAbsenceTerm.CULTIVATED(), lapsanaDistribution.getStatus());
+                assertEquals(2, lapsanaDistribution.getSources().size());
                 // should contain source_LCA_yug_ma and source_LCA_yug_ko, testing the microreference which is unique in the tests
-                assertTrue(sourceExists(labsanaDistribution.getSources(), book_a, "1"));
-                assertTrue(sourceExists(labsanaDistribution.getSources(), book_a, "3"));
-                yug_mn_DistributionUuid = labsanaDistribution.getUuid();  //for reaggregation test
+                assertTrue(sourceExists(lapsanaDistribution.getSources(), book_a, "1"));
+                assertTrue(sourceExists(lapsanaDistribution.getSources(), book_a, "3"));
+                yug_mn_DistributionUuid = lapsanaDistribution.getUuid();  //for reaggregation test
             }
-            if(labsanaDistribution.getArea().equals(yug_ko)){
+            if(lapsanaDistribution.getArea().equals(yug_ko)){
                 numExpectedFound++;
-                assertEquals("aggregated status of area YUG-KO wrong", PresenceAbsenceTerm.NATIVE(), labsanaDistribution.getStatus());
-                assertEquals(2, labsanaDistribution.getSources().size());
+                assertEquals("aggregated status of area YUG-KO wrong", PresenceAbsenceTerm.NATIVE(), lapsanaDistribution.getStatus());
+                assertEquals(2, lapsanaDistribution.getSources().size());
                 // should contain source_LCA_yug_ma and source_LCA_yug_ko, testing the microreference which is unique in the tests
-                assertTrue(sourceExists(labsanaDistribution.getSources(), book_a, "2"));
-                assertTrue(sourceExists(labsanaDistribution.getSources(), book_a, "4"));
+                assertTrue(sourceExists(lapsanaDistribution.getSources(), book_a, "2"));
+                assertTrue(sourceExists(lapsanaDistribution.getSources(), book_a, "4"));
             }
         }
         assertEquals("All three expected areas should have been found before", numExpectedFound, 3);