diff options
Diffstat (limited to 'cps-service/src/main')
4 files changed, 47 insertions, 6 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java b/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java index b1f90d686b..5ff08c9ac8 100644 --- a/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java +++ b/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2020-2022 Nordix Foundation + * Copyright (C) 2020-2023 Nordix Foundation * Modifications Copyright (C) 2020-2021 Pantheon.tech * Modifications Copyright (C) 2022 TechMahindra Ltd. * ================================================================================ @@ -80,13 +80,21 @@ public interface CpsModuleService { * @param dataspaceName dataspace name * @param schemaSetName schema set name * @param cascadeDeleteAllowed indicates the allowance to remove associated anchors and data if exist - * @throws DataInUseException if cascadeDeleteAllowed is set to CASCADE_DELETE_PROHIBITED and there - * is associated anchor record exists in database + * @throws DataInUseException if cascadeDeleteAllowed is set to CASCADE_DELETE_PROHIBITED and there + * is associated anchor record exists in database */ void deleteSchemaSet(String dataspaceName, String schemaSetName, CascadeDeleteAllowed cascadeDeleteAllowed); /** + * Deletes Schema Sets with cascade. + * + * @param dataspaceName dataspace name + * @param schemaSetNames schema set names + */ + void deleteSchemaSetsWithCascade(String dataspaceName, Collection<String> schemaSetNames); + + /** * Retrieve module references for the given dataspace name. * * @param dataspaceName dataspace name diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java index ccd0fcc289..e71e6ce662 100644 --- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java +++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java @@ -95,7 +95,7 @@ public class CpsModuleServiceImpl implements CpsModuleService { @Override @Transactional public void deleteSchemaSet(final String dataspaceName, final String schemaSetName, - final CascadeDeleteAllowed cascadeDeleteAllowed) { + final CascadeDeleteAllowed cascadeDeleteAllowed) { cpsValidator.validateNameCharacters(dataspaceName, schemaSetName); final Collection<Anchor> anchors = cpsAdminService.getAnchors(dataspaceName, schemaSetName); if (!anchors.isEmpty() && isCascadeDeleteProhibited(cascadeDeleteAllowed)) { @@ -110,6 +110,24 @@ public class CpsModuleServiceImpl implements CpsModuleService { } @Override + @Transactional + public void deleteSchemaSetsWithCascade(final String dataspaceName, final Collection<String> schemaSetNames) { + cpsValidator.validateNameCharacters(dataspaceName); + cpsValidator.validateNameCharacters(schemaSetNames); + for (final String schemaSetName : schemaSetNames) { + final Collection<Anchor> anchors = cpsAdminService.getAnchors(dataspaceName, schemaSetName); + for (final Anchor anchor : anchors) { + cpsAdminService.deleteAnchor(dataspaceName, anchor.getName()); + } + } + cpsModulePersistenceService.deleteUnusedYangResourceModules(); + cpsModulePersistenceService.deleteSchemaSets(dataspaceName, schemaSetNames); + for (final String schemaSetName : schemaSetNames) { + yangTextSchemaSourceSetCache.removeFromCache(dataspaceName, schemaSetName); + } + } + + @Override public Collection<ModuleReference> getYangResourceModuleReferences(final String dataspaceName) { cpsValidator.validateNameCharacters(dataspaceName); return cpsModulePersistenceService.getYangResourceModuleReferences(dataspaceName); diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java index f5dc8ac3a3..40d4002b97 100755 --- a/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java +++ b/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2020-2022 Nordix Foundation + * Copyright (C) 2020-2023 Nordix Foundation * Modifications Copyright (C) 2020-2022 Bell Canada. * Modifications Copyright (C) 2022 TechMahindra Ltd. * ================================================================================ @@ -70,6 +70,14 @@ public interface CpsModulePersistenceService { void deleteSchemaSet(String dataspaceName, String schemaSetName); /** + * Deletes Schema Sets. + * + * @param dataspaceName dataspace name + * @param schemaSetNames schema set names + */ + void deleteSchemaSets(String dataspaceName, Collection<String> schemaSetNames); + + /** * Returns YANG resources per specific dataspace / schemaSetName. * * @param dataspaceName dataspace name diff --git a/cps-service/src/main/java/org/onap/cps/spi/utils/CpsValidator.java b/cps-service/src/main/java/org/onap/cps/spi/utils/CpsValidator.java index c7ce8fc926..231094cf16 100644 --- a/cps-service/src/main/java/org/onap/cps/spi/utils/CpsValidator.java +++ b/cps-service/src/main/java/org/onap/cps/spi/utils/CpsValidator.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation + * Copyright (C) 2022-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. @@ -28,4 +28,11 @@ public interface CpsValidator { * @param names names of data to be validated */ void validateNameCharacters(final String... names); + + /** + * Validate characters in names within cps. + * + * @param names names of data to be validated + */ + void validateNameCharacters(final Iterable<String> names); } |