From 4c52e1a31c1424a954b2a1540117b4fbb443c578 Mon Sep 17 00:00:00 2001 From: shivasubedi Date: Thu, 12 Aug 2021 12:00:57 +0100 Subject: CPS-508: Create anchor/schemaset from new modules and existing modules Issue-ID: CPS-508 Signed-off-by: shivasubedi Change-Id: I8023a093334b77d0220f7c7d94de66863f5ba6dd --- .../src/main/java/org/onap/cps/api/CpsModuleService.java | 12 ++++++++++++ .../java/org/onap/cps/api/impl/CpsModuleServiceImpl.java | 9 +++++++++ .../java/org/onap/cps/spi/CpsAdminPersistenceService.java | 1 - .../java/org/onap/cps/spi/CpsModulePersistenceService.java | 12 ++++++++++++ .../org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy | 13 ++++++++++++- 5 files changed, 45 insertions(+), 2 deletions(-) (limited to 'cps-service/src') 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 fee4daa51a..d174085263 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 @@ -45,6 +45,18 @@ public interface CpsModuleService { void createSchemaSet(@NonNull String dataspaceName, @NonNull String schemaSetName, @NonNull Map yangResourcesNameToContentMap); + /** + * Create a schema set from new modules and existing modules. + * + * @param dataspaceName Dataspace name + * @param schemaSetName schema set name + * @param newYangResourcesModuleNameToContentMap YANG resources map where key is a module name and value is content + * @param moduleReferenceList List of YANG resources module references + */ + void createSchemaSetFromModules(@NonNull String dataspaceName, @NonNull String schemaSetName, + @NonNull Map newYangResourcesModuleNameToContentMap, + @NonNull List moduleReferenceList); + /** * Read schema set in the given dataspace. * 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 34735f8482..c65f827816 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 @@ -50,6 +50,15 @@ public class CpsModuleServiceImpl implements CpsModuleService { yangTextSchemaSourceSetCache.updateCache(dataspaceName, schemaSetName, yangTextSchemaSourceSet); } + @Override + public void createSchemaSetFromModules(final String dataspaceName, final String schemaSetName, + final Map newYangResourcesModuleNameToContentMap, + final List moduleReferenceList) { + cpsModulePersistenceService.storeSchemaSetFromModules(dataspaceName, schemaSetName, + newYangResourcesModuleNameToContentMap, moduleReferenceList); + + } + @Override public SchemaSet getSchemaSet(final String dataspaceName, final String schemaSetName) { final var yangTextSchemaSourceSet = yangTextSchemaSourceSetCache 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 f71ff0b3be..b05385fbf4 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 @@ -49,7 +49,6 @@ public interface CpsAdminPersistenceService { */ void createAnchor(@NonNull String dataspaceName, @NonNull String schemaSetName, @NonNull String anchorName); - /** * Read all anchors in the given a dataspace. * 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 bc62a23c52..7ad109d815 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 @@ -42,6 +42,18 @@ public interface CpsModulePersistenceService { void storeSchemaSet(@NonNull String dataspaceName, @NonNull String schemaSetName, @NonNull Map yangResourcesNameToContentMap); + /** + * Stores a schema set from new modules and existing modules. + * + * @param dataspaceName Dataspace name + * @param schemaSetName Schema set name + * @param newYangResourcesModuleNameToContentMap YANG resources map where key is a module name and value is content + * @param moduleReferenceList List of YANG resources module references + */ + void storeSchemaSetFromModules(@NonNull String dataspaceName, @NonNull String schemaSetName, + @NonNull Map newYangResourcesModuleNameToContentMap, + @NonNull List moduleReferenceList); + /** * Deletes Schema Set. * 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 b8bfd4593e..d719b3d24e 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 @@ -52,7 +52,7 @@ class CpsModuleServiceImplSpec extends Specification { @Autowired CpsModuleServiceImpl objectUnderTest - def 'Create schema set'() { + def 'Create schema set.'() { given: 'Valid yang resource as name-to-content map' def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap('bookstore.yang') when: 'Create schema set method is invoked' @@ -61,6 +61,17 @@ class CpsModuleServiceImplSpec extends Specification { 1 * mockModuleStoreService.storeSchemaSet('someDataspace', 'someSchemaSet', yangResourcesNameToContentMap) } + def 'Create schema set from new modules and existing modules.'() { + given: 'a list of existing modules module reference' + def moduleReferenceForExistingModule = new ModuleReference("test", "test.org", "2021-10-12") + def listOfExistingModulesModuleReference = [moduleReferenceForExistingModule] + when: 'create schema set from modules method is invoked' + objectUnderTest.createSchemaSetFromModules("someDataspaceName", "someSchemaSetName", [newModule: "newContent"], listOfExistingModulesModuleReference) + then: 'processing is delegated to persistence service' + 1 * mockModuleStoreService.storeSchemaSetFromModules("someDataspaceName", "someSchemaSetName", [newModule: "newContent"], listOfExistingModulesModuleReference) + + } + def 'Create schema set from invalid resources'() { given: 'Invalid yang resource as name-to-content map' def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap('invalid.yang') -- cgit 1.2.3-korg