diff options
author | rajesh.kumar <rk00747546@techmahindra.com> | 2022-09-14 05:11:32 +0000 |
---|---|---|
committer | rajesh.kumar <rk00747546@techmahindra.com> | 2022-12-09 09:57:44 +0000 |
commit | 71e4f8339e0240f90ad0a42a9360be52553f0d82 (patch) | |
tree | 8fe47799cde6365d40ee84de568b224fcdff22f5 /cps-service | |
parent | fdaccbf398d84b7b19a95e11c017b5c6d2019ffe (diff) |
Added API to get all schema sets for a given dataspace.
Issue-ID: CPS-1187
Change-ID: I73f97f986a817d423f93a8d922dcd9647b0914aa
Signed-off-by: rajesh.kumar <rk00747546@techmahindra.com>
Diffstat (limited to 'cps-service')
5 files changed, 58 insertions, 0 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 6b17e820c4..b1f90d686b 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 @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2020-2022 Nordix Foundation * Modifications Copyright (C) 2020-2021 Pantheon.tech + * Modifications Copyright (C) 2022 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -66,6 +67,14 @@ public interface CpsModuleService { SchemaSet getSchemaSet(String dataspaceName, String schemaSetName); /** + * Retrieve all schema sets in the given dataspace. + * + * @param dataspaceName dataspace name + * @return all SchemaSets + */ + Collection<SchemaSet> getSchemaSets(String dataspaceName); + + /** * Deletes Schema Set. * * @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 b4890f4a71..a04dd2af5b 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 @@ -3,6 +3,7 @@ * Copyright (C) 2020-2022 Nordix Foundation * Modifications Copyright (C) 2020-2021 Pantheon.tech * Modifications Copyright (C) 2022 Bell Canada + * Modifications Copyright (C) 2022 TechMahindra Ltd * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,6 +36,7 @@ import org.onap.cps.spi.model.ModuleDefinition; import org.onap.cps.spi.model.ModuleReference; import org.onap.cps.spi.model.SchemaSet; import org.onap.cps.spi.utils.CpsValidator; +import org.onap.cps.yang.YangTextSchemaSourceSet; import org.onap.cps.yang.YangTextSchemaSourceSetBuilder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -78,6 +80,15 @@ public class CpsModuleServiceImpl implements CpsModuleService { } @Override + public Collection<SchemaSet> getSchemaSets(final String dataspaceName) { + cpsValidator.validateNameCharacters(dataspaceName); + final Collection<SchemaSet> schemaSets = + cpsModulePersistenceService.getSchemaSetsByDataspaceName(dataspaceName); + schemaSets.forEach(schemaSet -> setModuleReferences(schemaSet, dataspaceName)); + return schemaSets; + } + + @Override @Transactional public void deleteSchemaSet(final String dataspaceName, final String schemaSetName, final CascadeDeleteAllowed cascadeDeleteAllowed) { @@ -124,4 +135,9 @@ public class CpsModuleServiceImpl implements CpsModuleService { return CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED == cascadeDeleteAllowed; } + private void setModuleReferences(final SchemaSet schemaSet, final String dataspaceName) { + final YangTextSchemaSourceSet yangTextSchemaSourceSet = yangTextSchemaSourceSetCache + .get(dataspaceName, schemaSet.getName()); + schemaSet.setModuleReferences(yangTextSchemaSourceSet.getModuleReferences()); + } } 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 aaf6b38af4..f5dc8ac3a3 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 @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2020-2022 Nordix Foundation * Modifications Copyright (C) 2020-2022 Bell Canada. + * Modifications Copyright (C) 2022 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +26,7 @@ import java.util.Collection; import java.util.Map; import org.onap.cps.spi.model.ModuleDefinition; import org.onap.cps.spi.model.ModuleReference; +import org.onap.cps.spi.model.SchemaSet; /** * Service to manage modules. @@ -52,6 +54,14 @@ public interface CpsModulePersistenceService { Map<String, String> newModuleNameToContentMap, Collection<ModuleReference> allModuleReferences); /** + * Get all schema sets for a given dataspace. + * + * @param dataspaceName dataspace name. + * @return List of schema sets + */ + Collection<SchemaSet> getSchemaSetsByDataspaceName(String dataspaceName); + + /** * Deletes Schema Set. * * @param dataspaceName dataspace name diff --git a/cps-service/src/main/java/org/onap/cps/spi/exceptions/SchemaSetNotFoundException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/SchemaSetNotFoundException.java index cf63f924fd..218918fcb6 100644 --- a/cps-service/src/main/java/org/onap/cps/spi/exceptions/SchemaSetNotFoundException.java +++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/SchemaSetNotFoundException.java @@ -38,4 +38,5 @@ public class SchemaSetNotFoundException extends CpsAdminException { super("Schema Set not found.", String.format("Schema Set with name %s was not found for dataspace %s.", schemaSetName, dataspaceName)); } + } diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy index 690578ea05..358a6fb3f3 100644 --- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy @@ -3,6 +3,7 @@ * Copyright (C) 2020-2022 Nordix Foundation * Modifications Copyright (C) 2020-2021 Pantheon.tech * Modifications Copyright (C) 2020-2022 Bell Canada. + * Modifications Copyright (C) 2022 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +31,8 @@ import org.onap.cps.spi.exceptions.SchemaSetInUseException import org.onap.cps.spi.utils.CpsValidator import org.onap.cps.spi.model.Anchor import org.onap.cps.spi.model.ModuleReference +import org.onap.cps.spi.model.SchemaSet +import org.onap.cps.yang.YangTextSchemaSourceSet import org.onap.cps.yang.YangTextSchemaSourceSetBuilder import spock.lang.Specification import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED @@ -91,6 +94,25 @@ class CpsModuleServiceImplSpec extends Specification { 1 * mockCpsValidator.validateNameCharacters('someDataspace', 'someSchemaSet') } + def 'Get schema sets by dataspace name.'() { + given: 'two already present schema sets' + def moduleReference = new ModuleReference('sample1', '2022-12-07') + def sampleSchemaSet1 = new SchemaSet('testSchemaSet1', 'testDataspace', [moduleReference]) + def sampleSchemaSet2 = new SchemaSet('testSchemaSet2', 'testDataspace', [moduleReference]) + and: 'the persistence service returns the created schema sets' + mockCpsModulePersistenceService.getSchemaSetsByDataspaceName('testDataspace') >> [sampleSchemaSet1, sampleSchemaSet2] + and: 'yang resource cache always returns a schema source set' + def mockYangTextSchemaSourceSet = Mock(YangTextSchemaSourceSet) + mockYangTextSchemaSourceSetCache.get('testDataspace', _) >> mockYangTextSchemaSourceSet + when: 'get schema sets method is invoked' + def result = objectUnderTest.getSchemaSets('testDataspace') + then: 'the correct schema sets are returned' + assert result.size() == 2 + assert result.containsAll(sampleSchemaSet1, sampleSchemaSet2) + and: 'the Cps Validator is called on the dataspaceName' + 1 * mockCpsValidator.validateNameCharacters('testDataspace') + } + def 'Delete schema-set when cascade is allowed.'() { given: '#numberOfAnchors anchors are associated with schemaset' def associatedAnchors = createAnchors(numberOfAnchors) |