From d427ccf02e817e3780044f8e454b8c1c7b534a8b Mon Sep 17 00:00:00 2001 From: Gerard Nugent Date: Mon, 20 Oct 2025 10:45:08 +0000 Subject: [PATCH] Revert "(Bug) Ensure clean up process also removes orphaned data in fragmenttable" This reverts commit 15e20fdf691556fd1c6a8d581dbd06716c02b06d. Reason for revert: Previous revert patch makes this incorrect. Issue-ID: CPS-3006 Change-Id: I366cc5fa23aa89295f6c3a5b88068d91478e6cb3 Signed-off-by: egernug --- .../cps/rest/controller/AdminRestController.java | 1 - .../cps/ri/CpsAdminPersistenceServiceImpl.java | 18 +----------- .../onap/cps/ri/repository/AnchorRepository.java | 4 +-- .../onap/cps/ri/repository/FragmentRepository.java | 14 +--------- .../java/org/onap/cps/api/CpsDataspaceService.java | 9 +----- .../org/onap/cps/impl/CpsDataspaceServiceImpl.java | 5 ---- .../onap/cps/spi/CpsAdminPersistenceService.java | 7 ----- .../cps/impl/CpsDataspaceServiceImplSpec.groovy | 9 +----- .../cps/DataspaceServiceIntegrationSpec.groovy | 32 +--------------------- .../test/resources/data/bookstore/bookstore.yang | 11 -------- 10 files changed, 6 insertions(+), 104 deletions(-) diff --git a/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java b/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java index 8bbd9d5ca5..ca7d374949 100755 --- a/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java +++ b/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java @@ -192,7 +192,6 @@ public class AdminRestController implements CpsAdminApi { @Override public ResponseEntity cleanDataspace(final String apiVersion, final String dataspaceName) { cpsModuleService.deleteAllUnusedYangModuleData(dataspaceName); - cpsDataspaceService.deleteAllOrphanedData(dataspaceName); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } diff --git a/cps-ri/src/main/java/org/onap/cps/ri/CpsAdminPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/ri/CpsAdminPersistenceServiceImpl.java index ccd2fca961..27dd48d38c 100755 --- a/cps-ri/src/main/java/org/onap/cps/ri/CpsAdminPersistenceServiceImpl.java +++ b/cps-ri/src/main/java/org/onap/cps/ri/CpsAdminPersistenceServiceImpl.java @@ -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 anchorEntities = anchorRepository.getAnchorEntitiesByDataspace(dataspaceEntity); - final Set 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); diff --git a/cps-ri/src/main/java/org/onap/cps/ri/repository/AnchorRepository.java b/cps-ri/src/main/java/org/onap/cps/ri/repository/AnchorRepository.java index b3e8b3a805..aa6367dff2 100755 --- a/cps-ri/src/main/java/org/onap/cps/ri/repository/AnchorRepository.java +++ b/cps-ri/src/main/java/org/onap/cps/ri/repository/AnchorRepository.java @@ -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 { @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 getAnchorEntitiesByDataspace(DataspaceEntity dataspaceEntity); } diff --git a/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentRepository.java b/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentRepository.java index c9957430db..d95d322d37 100755 --- a/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentRepository.java +++ b/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentRepository.java @@ -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. @@ -23,10 +23,8 @@ 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, @Query(value = "SELECT * FROM fragment WHERE anchor_id = :anchorId AND parent_id IS NULL", nativeQuery = true) List 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 anchorIds); } diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsDataspaceService.java b/cps-service/src/main/java/org/onap/cps/api/CpsDataspaceService.java index f493eb73b0..32d57d44a6 100644 --- a/cps-service/src/main/java/org/onap/cps/api/CpsDataspaceService.java +++ b/cps-service/src/main/java/org/onap/cps/api/CpsDataspaceService.java @@ -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 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); - } diff --git a/cps-service/src/main/java/org/onap/cps/impl/CpsDataspaceServiceImpl.java b/cps-service/src/main/java/org/onap/cps/impl/CpsDataspaceServiceImpl.java index 0abc97b0b2..ac55b81bdc 100644 --- a/cps-service/src/main/java/org/onap/cps/impl/CpsDataspaceServiceImpl.java +++ b/cps-service/src/main/java/org/onap/cps/impl/CpsDataspaceServiceImpl.java @@ -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); - } } diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java index b43bb5a145..62b26622de 100755 --- a/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java +++ b/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java @@ -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); } diff --git a/cps-service/src/test/groovy/org/onap/cps/impl/CpsDataspaceServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/impl/CpsDataspaceServiceImplSpec.groovy index 75b8948a80..97f6fba4d3 100644 --- a/cps-service/src/test/groovy/org/onap/cps/impl/CpsDataspaceServiceImplSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/impl/CpsDataspaceServiceImplSpec.groovy @@ -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') - } - } diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/functional/cps/DataspaceServiceIntegrationSpec.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/functional/cps/DataspaceServiceIntegrationSpec.groovy index b25f07c4ce..ba456ea904 100644 --- a/integration-test/src/test/groovy/org/onap/cps/integration/functional/cps/DataspaceServiceIntegrationSpec.groovy +++ b/integration-test/src/test/groovy/org/onap/cps/integration/functional/cps/DataspaceServiceIntegrationSpec.groovy @@ -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. @@ -20,18 +20,11 @@ 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') - } - } diff --git a/integration-test/src/test/resources/data/bookstore/bookstore.yang b/integration-test/src/test/resources/data/bookstore/bookstore.yang index 9951decf31..0d093ea36c 100644 --- a/integration-test/src/test/resources/data/bookstore/bookstore.yang +++ b/integration-test/src/test/resources/data/bookstore/bookstore.yang @@ -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; -- 2.16.6