Revert "(Bug) Ensure clean up process also removes orphaned data in fragmenttable" 67/141867/1
authorGerard Nugent <gerard.nugent@est.tech>
Mon, 20 Oct 2025 10:45:08 +0000 (10:45 +0000)
committerGerard Nugent <gerard.nugent@est.tech>
Mon, 20 Oct 2025 10:45:08 +0000 (10:45 +0000)
This reverts commit 15e20fdf691556fd1c6a8d581dbd06716c02b06d.

Reason for revert: Previous revert patch makes this incorrect.

Issue-ID: CPS-3006
Change-Id: I366cc5fa23aa89295f6c3a5b88068d91478e6cb3
Signed-off-by: egernug <gerard.nugent@est.tech>
cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java
cps-ri/src/main/java/org/onap/cps/ri/CpsAdminPersistenceServiceImpl.java
cps-ri/src/main/java/org/onap/cps/ri/repository/AnchorRepository.java
cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentRepository.java
cps-service/src/main/java/org/onap/cps/api/CpsDataspaceService.java
cps-service/src/main/java/org/onap/cps/impl/CpsDataspaceServiceImpl.java
cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java
cps-service/src/test/groovy/org/onap/cps/impl/CpsDataspaceServiceImplSpec.groovy
integration-test/src/test/groovy/org/onap/cps/integration/functional/cps/DataspaceServiceIntegrationSpec.groovy
integration-test/src/test/resources/data/bookstore/bookstore.yang

index 8bbd9d5..ca7d374 100755 (executable)
@@ -192,7 +192,6 @@ public class AdminRestController implements CpsAdminApi {
     @Override
     public ResponseEntity<Void> cleanDataspace(final String apiVersion, final String dataspaceName) {
         cpsModuleService.deleteAllUnusedYangModuleData(dataspaceName);
-        cpsDataspaceService.deleteAllOrphanedData(dataspaceName);
         return new ResponseEntity<>(HttpStatus.NO_CONTENT);
     }
 
index ccd2fca..27dd48d 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START=======================================================
- * Copyright (C) 2020-2025 OpenInfra Foundation Europe. All rights reserved.
+ * Copyright (C) 2020-2025 Nordix Foundation.
  * Modifications Copyright (C) 2020-2022 Bell Canada.
  * Modifications Copyright (C) 2021 Pantheon.tech
  * Modifications Copyright (C) 2022 TechMahindra Ltd.
@@ -25,9 +25,6 @@ package org.onap.cps.ri;
 
 import jakarta.transaction.Transactional;
 import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
 import java.util.stream.Collectors;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -40,7 +37,6 @@ import org.onap.cps.ri.models.DataspaceEntity;
 import org.onap.cps.ri.models.SchemaSetEntity;
 import org.onap.cps.ri.repository.AnchorRepository;
 import org.onap.cps.ri.repository.DataspaceRepository;
-import org.onap.cps.ri.repository.FragmentRepository;
 import org.onap.cps.ri.repository.SchemaSetRepository;
 import org.onap.cps.spi.CpsAdminPersistenceService;
 import org.springframework.dao.DataIntegrityViolationException;
@@ -54,7 +50,6 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic
     private final DataspaceRepository dataspaceRepository;
     private final AnchorRepository anchorRepository;
     private final SchemaSetRepository schemaSetRepository;
-    private final FragmentRepository fragmentRepository;
 
     @Override
     public void createDataspace(final String dataspaceName) {
@@ -182,17 +177,6 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic
         anchorRepository.updateAnchorSchemaSetId(schemaSetEntity.getId(), anchorEntity.getId());
     }
 
-    @Override
-    public void deleteAllOrphanedFragmentEntities(final String dataspaceName) {
-        final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
-        final List<AnchorEntity> anchorEntities = anchorRepository.getAnchorEntitiesByDataspace(dataspaceEntity);
-        final Set<Long> anchorIds = new HashSet<>();
-        for (final AnchorEntity anchorEntity : anchorEntities) {
-            anchorIds.add(anchorEntity.getId());
-        }
-        fragmentRepository.deleteOrphanedFragmentEntities(anchorIds);
-    }
-
     private AnchorEntity getAnchorEntity(final String dataspaceName, final String anchorName) {
         final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
         return anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName);
index b3e8b3a..aa6367d 100755 (executable)
@@ -1,7 +1,7 @@
 /*
  *  ============LICENSE_START=======================================================
  *  Copyright (C) 2021 Pantheon.tech
- *  Modifications Copyright (C) 2021-2025 OpenInfra Foundation Europe. All rights reserved.
+ *  Modifications Copyright (C) 2021-2024 Nordix Foundation
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
 package org.onap.cps.ri.repository;
 
 import java.util.Collection;
-import java.util.List;
 import java.util.Optional;
 import org.onap.cps.api.exceptions.AnchorNotFoundException;
 import org.onap.cps.ri.models.AnchorEntity;
@@ -109,5 +108,4 @@ public interface AnchorRepository extends JpaRepository<AnchorEntity, Long> {
     @Query(value = "UPDATE anchor SET schema_set_id =:schemaSetId WHERE id = :anchorId ", nativeQuery = true)
     void updateAnchorSchemaSetId(@Param("schemaSetId") int schemaSetId, @Param("anchorId") long anchorId);
 
-    List<AnchorEntity> getAnchorEntitiesByDataspace(DataspaceEntity dataspaceEntity);
 }
index c995743..d95d322 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START=======================================================
- * Copyright (C) 2021-2025 OpenInfra Foundation Europe. All rights reserved.
+ * Copyright (C) 2021-2024 Nordix Foundation.
  * Modifications Copyright (C) 2020-2021 Bell Canada.
  * Modifications Copyright (C) 2020-2021 Pantheon.tech.
  * Modifications Copyright (C) 2023 TechMahindra Ltd.
 
 package org.onap.cps.ri.repository;
 
-import jakarta.transaction.Transactional;
 import java.util.Collection;
 import java.util.List;
-import java.util.Set;
 import org.onap.cps.ri.models.AnchorEntity;
 import org.onap.cps.ri.models.FragmentEntity;
 import org.onap.cps.ri.utils.EscapeUtils;
@@ -108,14 +106,4 @@ public interface FragmentRepository extends JpaRepository<FragmentEntity, Long>,
     @Query(value = "SELECT * FROM fragment WHERE anchor_id = :anchorId AND parent_id IS NULL", nativeQuery = true)
     List<FragmentEntity> findRootsByAnchorId(@Param("anchorId") long anchorId);
 
-    @Modifying
-    @Transactional
-    @Query(value = "DELETE FROM fragment where anchor_id IN (:anchorIds) "
-            + "AND ("
-            + "parent_id in"
-            + " (SELECT id from fragment WHERE (LENGTH(xpath) - LENGTH(REPLACE(xpath, '/','')) > 1)"
-            + " AND parent_id is null)"
-            + " OR ((LENGTH(xpath) - LENGTH(REPLACE(xpath, '/', '')) > 1) AND parent_id is null)"
-            + ")", nativeQuery = true)
-    void deleteOrphanedFragmentEntities(@Param("anchorIds") Set<Long> anchorIds);
 }
index f493eb7..32d57d4 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  ============LICENSE_START=======================================================
- *  Copyright (C) 2020-2025 OpenInfra Foundation Europe. All rights reserved.
+ *  Copyright (C) 2020-2023 Nordix Foundation
  *  Modifications Copyright (C) 2020-2022 Bell Canada.
  *  Modifications Copyright (C) 2021 Pantheon.tech
  *  Modifications Copyright (C) 2022 TechMahindra Ltd.
@@ -63,11 +63,4 @@ public interface CpsDataspaceService {
      */
     Collection<Dataspace> getAllDataspaces();
 
-    /**
-     *  Delete orphaned data for a given dataspace name.
-     *
-     * @param dataspaceName     the name of the dataspace where the data is located.
-     */
-    void deleteAllOrphanedData(String dataspaceName);
-
 }
index 0abc97b..ac55b81 100644 (file)
@@ -61,9 +61,4 @@ public class CpsDataspaceServiceImpl implements CpsDataspaceService {
         return cpsAdminPersistenceService.getAllDataspaces();
     }
 
-    @Override
-    public void deleteAllOrphanedData(final String dataspaceName) {
-        cpsValidator.validateNameCharacters(dataspaceName);
-        cpsAdminPersistenceService.deleteAllOrphanedFragmentEntities(dataspaceName);
-    }
 }
index b43bb5a..62b2662 100755 (executable)
@@ -151,11 +151,4 @@ public interface CpsAdminPersistenceService {
      * @param schemaSetName schema set name
      */
     void updateAnchorSchemaSet(String dataspaceName, String anchorName, String schemaSetName);
-
-    /**
-     * Delete all fragment entities that have no parent.
-     *
-     * @param dataspaceName     dataspace name
-     */
-    void deleteAllOrphanedFragmentEntities(String dataspaceName);
 }
index 75b8948..97f6fba 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  ============LICENSE_START=======================================================
- *  Copyright (C) 2023-2025 OpenInfra Foundation Europe. All rights reserved.
+ *  Copyright (C) 2023 Nordix Foundation
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -65,11 +65,4 @@ class CpsDataspaceServiceImplSpec extends Specification {
             1 * mockCpsValidator.validateNameCharacters('someDataspace')
     }
 
-    def 'Delete all orphaned data.'(){
-        when: 'deleting all orphaned data'
-            objectUnderTest.deleteAllOrphanedData('some-dataspaceName')
-        then: 'the persistence service method to delete all orphaned fragment entities is invoked'
-            1 * mockCpsAdminPersistenceService.deleteAllOrphanedFragmentEntities('some-dataspaceName')
-    }
-
 }
index b25f07c..ba456ea 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  ============LICENSE_START=======================================================
- *  Copyright (C) 2023-2025 OpenInfra Foundation Europe. All rights reserved.
+ *  Copyright (C) 2023-2025 Nordix Foundation
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the 'License');
  *  you may not use this file except in compliance with the License.
 
 package org.onap.cps.integration.functional.cps
 
-import static org.onap.cps.api.parameters.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
-import static org.onap.cps.api.parameters.PaginationOption.NO_PAGINATION
-
 import org.onap.cps.api.CpsDataspaceService
-import java.time.OffsetDateTime
-import org.onap.cps.api.exceptions.DataNodeNotFoundException
 import org.onap.cps.integration.base.FunctionalSpecBase
 import org.onap.cps.api.exceptions.AlreadyDefinedException
 import org.onap.cps.api.exceptions.DataspaceInUseException
 import org.onap.cps.api.exceptions.DataspaceNotFoundException
-import org.onap.cps.ri.repository.FragmentRepository
-import org.onap.cps.utils.ContentType
 
 class DataspaceServiceIntegrationSpec extends FunctionalSpecBase {
 
@@ -111,27 +104,4 @@ class DataspaceServiceIntegrationSpec extends FunctionalSpecBase {
             thrown(AlreadyDefinedException)
     }
 
-    def 'Delete all orphaned data in a dataspace.'() {
-        setup: 'an anchor'
-            cpsAnchorService.createAnchor(GENERAL_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, 'testAnchor')
-        and: 'orphaned data'
-            def jsonDataMap = [:]
-            jsonDataMap.put('/bookstore/categories[@code=\'3\']', '{"books":[{"title": "Matilda"}]}')
-            jsonDataMap.put('/bookstore/categories[@code=\'3\']', '{"sub-categories":{"code":"1","additional-info":{"info-name":"sample"}}}')
-            cpsDataService.updateDataNodesAndDescendants(GENERAL_TEST_DATASPACE, 'testAnchor', jsonDataMap,  OffsetDateTime.now(), ContentType.JSON)
-            def dataNodes = cpsDataService.getDataNodes(GENERAL_TEST_DATASPACE, 'testAnchor','/', INCLUDE_ALL_DESCENDANTS)
-            assert dataNodes.size() == 1
-            assert dataNodes.childDataNodes.size() == 1
-        and: 'parent node does not exist'
-            assert cpsQueryService.queryDataNodesAcrossAnchors(GENERAL_TEST_DATASPACE, '/bookstore', INCLUDE_ALL_DESCENDANTS, NO_PAGINATION).size() == 0
-        when: 'deleting all orphaned data in a dataspace'
-            objectUnderTest.deleteAllOrphanedData(GENERAL_TEST_DATASPACE)
-        and: 'get data nodes in dataspace'
-            cpsDataService.getDataNodes(GENERAL_TEST_DATASPACE, 'testAnchor','/', INCLUDE_ALL_DESCENDANTS)
-        then: 'there will be no more data nodes available'
-            thrown(DataNodeNotFoundException)
-        cleanup: 'remove the data for this test'
-            cpsAnchorService.deleteAnchor(GENERAL_TEST_DATASPACE, 'testAnchor')
-    }
-
 }
index 9951dec..0d093ea 100644 (file)
@@ -102,17 +102,6 @@ module stores {
                 type string;
             }
 
-            container sub-categories {
-                leaf code {
-                    type string;
-                }
-                container additional-info {
-                    leaf info-name {
-                        type string;
-                    }
-                }
-            }
-
             list books {
                 key title;