diff options
author | 2021-11-22 11:44:38 +0000 | |
---|---|---|
committer | 2021-11-23 10:53:39 +0000 | |
commit | 09c6b6e1fa2684c913d7b904f7c7ad6b26b04ef1 (patch) | |
tree | 63481d02e24d1277341d74db68614e7fd3680a41 /cps-ri/src/main | |
parent | 9e09fe868b39fd5f13092a923da3474deb0f75b9 (diff) |
CPS-314: Delete Dataspace
Issue-ID: CPS-314
Change-Id: I778e2b784c7b1ff3fecc1036425708dc4ec73227
Signed-off-by: niamhcore <niamh.core@est.tech>
Diffstat (limited to 'cps-ri/src/main')
3 files changed, 21 insertions, 3 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java index b1bd03c25..9c69006ec 100755 --- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java +++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java @@ -32,6 +32,7 @@ import org.onap.cps.spi.entities.AnchorEntity; import org.onap.cps.spi.entities.DataspaceEntity; import org.onap.cps.spi.entities.YangResourceModuleReference; import org.onap.cps.spi.exceptions.AlreadyDefinedException; +import org.onap.cps.spi.exceptions.DataspaceInUseException; import org.onap.cps.spi.exceptions.ModuleNamesNotFoundException; import org.onap.cps.spi.model.Anchor; import org.onap.cps.spi.repository.AnchorRepository; @@ -71,6 +72,22 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic } @Override + public void deleteDataspace(final String dataspaceName) { + final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName); + final int numberOfAssociatedAnchors = anchorRepository.countByDataspace(dataspaceEntity); + if (numberOfAssociatedAnchors != 0) { + throw new DataspaceInUseException(dataspaceName, + String.format("Dataspace contains %d anchor(s)", numberOfAssociatedAnchors)); + } + final int numberOfAssociatedSchemaSets = schemaSetRepository.countByDataspace(dataspaceEntity); + if (numberOfAssociatedSchemaSets != 0) { + throw new DataspaceInUseException(dataspaceName, + String.format("Dataspace contains %d schemaset(s)", numberOfAssociatedSchemaSets)); + } + dataspaceRepository.delete(dataspaceEntity); + } + + @Override public void createAnchor(final String dataspaceName, final String schemaSetName, final String anchorName) { final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName); final var schemaSetEntity = diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java index 5870fd9e9..471f1758c 100755 --- a/cps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java +++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java @@ -45,6 +45,8 @@ public interface AnchorRepository extends JpaRepository<AnchorEntity, Integer> { Collection<AnchorEntity> findAllBySchemaSet(@NotNull SchemaSetEntity schemaSetEntity); + Integer countByDataspace(@NotNull DataspaceEntity dataspaceEntity); + @Query(value = "SELECT anchor.* FROM yang_resource\n" + "JOIN schema_set_yang_resources ON schema_set_yang_resources.yang_resource_id = yang_resource.id\n" + "JOIN schema_set ON schema_set.id = schema_set_yang_resources.schema_set_id\n" diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/SchemaSetRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/SchemaSetRepository.java index 7b56f9323..a15ce622c 100644 --- a/cps-ri/src/main/java/org/onap/cps/spi/repository/SchemaSetRepository.java +++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/SchemaSetRepository.java @@ -19,7 +19,6 @@ package org.onap.cps.spi.repository; -import java.util.List; import java.util.Optional; import javax.validation.constraints.NotNull; import org.onap.cps.spi.entities.DataspaceEntity; @@ -31,11 +30,11 @@ import org.springframework.stereotype.Repository; @Repository public interface SchemaSetRepository extends JpaRepository<SchemaSetEntity, Integer> { - List<SchemaSetEntity> findAllByDataspace(@NotNull DataspaceEntity dataspaceEntity); - Optional<SchemaSetEntity> findByDataspaceAndName(@NotNull DataspaceEntity dataspaceEntity, @NotNull String schemaSetName); + Integer countByDataspace(@NotNull DataspaceEntity dataspaceEntity); + /** * Gets a schema set by dataspace and schema set name. * |