diff options
18 files changed, 201 insertions, 91 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java index c840c0a7d4..6e1e7275bb 100755 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java @@ -349,13 +349,13 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService protected void createAnchorAndSyncModel(final PersistenceCmHandle cmHandle) { final var modulesForCmHandle = dmiOperations.getResourceFromDmi(cmHandle.getDmiServiceName(), cmHandle.getId(), "modules"); - - final List<ModuleReference> moduleReferencesFromDmiForCmHandle = getModuleReferences(modulesForCmHandle); - - final var knownModuleReferencesInCps = cpsModuleService.getAllYangResourcesModuleReferences(); - + final List<ModuleReference> moduleReferencesFromDmiForCmHandle = + getModuleReferences(modulesForCmHandle); + final var knownModuleReferencesInCps = + cpsModuleService.getAllYangResourceModuleReferences(NF_PROXY_DATASPACE_NAME); final List<ModuleReference> existingModuleReferences = new ArrayList<>(); - for (final ModuleReference moduleReferenceFromDmiForCmHandle : moduleReferencesFromDmiForCmHandle) { + for (final ModuleReference moduleReferenceFromDmiForCmHandle : + moduleReferencesFromDmiForCmHandle) { if (knownModuleReferencesInCps.contains(moduleReferenceFromDmiForCmHandle)) { existingModuleReferences.add(moduleReferenceFromDmiForCmHandle); } @@ -396,7 +396,8 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService final JsonObject convertedObject = new Gson().fromJson(response.getBody(), JsonObject.class); final JsonArray moduleReferencesAsJson = convertedObject.getAsJsonArray("schemas"); for (final JsonElement moduleReferenceAsJson : moduleReferencesAsJson) { - final ModuleReference moduleReference = toModuleReference((JsonObject) moduleReferenceAsJson); + final ModuleReference moduleReference = + toModuleReference((JsonObject) moduleReferenceAsJson); modulesFromDmiForCmHandle.add(moduleReference); } return modulesFromDmiForCmHandle; @@ -404,8 +405,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService private ModuleReference toModuleReference(final JsonObject moduleReferenceAsJson) { final var moduleReference = new ModuleReference(); - moduleReference.setName(moduleReferenceAsJson.get("moduleName").getAsString()); - moduleReference.setNamespace(NO_NAMESPACE); + moduleReference.setModuleName(moduleReferenceAsJson.get("moduleName").getAsString()); moduleReference.setRevision(moduleReferenceAsJson.get("revision").getAsString()); return moduleReference; } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy index b42db57233..ff3e0cd157 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy @@ -357,23 +357,23 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { def 'Sync model for a (new) cm handle with #scenario'() { given: 'DMI PLug-in returns a list of module references' getModulesForCmHandle() - def knownModule1 = new ModuleReference('module1', NO_NAMESPACE, '1') - def knownOtherModule = new ModuleReference('some other module', NO_NAMESPACE, 'some revision') + def knownModule1 = new ModuleReference('module1', '1') + def knownOtherModule = new ModuleReference('some other module', 'some revision') and: 'CPS-Core returns list of known modules' - mockCpsModuleService.getAllYangResourcesModuleReferences() >> [knownModule1, knownOtherModule] + mockCpsModuleService.getAllYangResourceModuleReferences(_) >> [knownModule1, knownOtherModule] and: 'DMI-Plugin returns resource(s) for "new" module(s)' def moduleResources = new ResponseEntity<String>(sdncReponseBody, HttpStatus.OK) mockDmiOperations.getResourceFromDmi(_, cmHandleForModelSync.getId(), 'moduleResources') >> moduleResources when: 'module Sync is triggered' objectUnderTest.createAnchorAndSyncModel(cmHandleForModelSync) then: 'the CPS module service is called once with the correct parameters' - 1 * mockCpsModuleService.createSchemaSetFromModules(expectedDataspaceNameForModleSync, cmHandleForModelSync.getId(), expectedYangResourceToContentMap , [knownModule1]) + 1 * mockCpsModuleService.createSchemaSetFromModules(expectedDataspaceNameForModleSync, cmHandleForModelSync.getId(), expectedYangResourceToContentMap, [knownModule1]) and: 'admin service create anchor method has been called with correct parameters' 1 * mockCpsAdminService.createAnchor(expectedDataspaceNameForModleSync, cmHandleForModelSync.getId(), cmHandleForModelSync.getId()) where: 'the following responses are recieved from SDNC' - scenario | sdncReponseBody || expectedYangResourceToContentMap + scenario | sdncReponseBody || expectedYangResourceToContentMap 'one unknown module' | '[{"moduleName" : "someModule", "revision" : "1","yangSource": "someResource"}]' || [someModule: 'someResource'] - 'no unknown module' | '[]' || [:] + 'no unknown module' | '[]' || [:] } def getModulesForCmHandle() { diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/moduleReferenceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/moduleReferenceSpec.groovy index d6cb4635d8..9f161a9e53 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/moduleReferenceSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/moduleReferenceSpec.groovy @@ -1,14 +1,14 @@ package org.onap.cps.ncmp.api.models -import org.onap.cps.spi.model.ModuleReference +import org.onap.cps.spi.model.ExtendedModuleReference import spock.lang.Specification class moduleReferenceSpec extends Specification { def 'lombok data annotation correctly implements toString() and hashCode() methods'() { given: 'two moduleReference objects' - def moduleReference1 = new ModuleReference('module1', "some namespace", '1') - def moduleReference2 = new ModuleReference('module1', "some namespace", '1') + def moduleReference1 = new ExtendedModuleReference('module1', "some namespace", '1') + def moduleReference2 = new ExtendedModuleReference('module1', "some namespace", '1') when: 'lombok generated methods are called' then: 'the methods exist and behaviour is accurate' assert moduleReference1.toString() == moduleReference2.toString() diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java index 1c7828f32e..d7b882f6ee 100755 --- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java +++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java @@ -116,11 +116,21 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ } @Override - public List<ModuleReference> getAllYangResourcesModuleReferences() { - final List<YangResourceModuleReference> yangResourceModuleReferenceList = - yangResourceRepository.findAllModuleNameAndRevision(); + public Collection<ModuleReference> getAllYangResourceModuleReferences(final String dataspaceName) { + final Set<YangResourceModuleReference> yangResourceModuleReferenceList = + yangResourceRepository.findAllModuleReferences(dataspaceName); return yangResourceModuleReferenceList.stream().map(CpsModulePersistenceServiceImpl::toModuleReference) - .collect(Collectors.toList()); + .collect(Collectors.toList()); + } + + @Override + public Collection<ModuleReference> getAllYangResourceModuleReferences(final String dataspaceName, + final String anchorName) { + final Set<YangResourceModuleReference> yangResourceModuleReferenceList = + yangResourceRepository + .findAllModuleReferences(dataspaceName, anchorName); + return yangResourceModuleReferenceList.stream().map(CpsModulePersistenceServiceImpl::toModuleReference) + .collect(Collectors.toList()); } @Override @@ -148,15 +158,15 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ @Transactional public void storeSchemaSetFromModules(final String dataspaceName, final String schemaSetName, final Map<String, String> newYangResourcesModuleNameToContentMap, - final List<ModuleReference> moduleReferenceList) { + final List<ModuleReference> moduleReferences) { storeSchemaSet(dataspaceName, schemaSetName, newYangResourcesModuleNameToContentMap); final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName); final var schemaSetEntity = schemaSetRepository.getByDataspaceAndName(dataspaceEntity, schemaSetName); final List<Long> listOfYangResourceIds = new ArrayList<>(); - moduleReferenceList.forEach(moduleReference -> + moduleReferences.forEach(moduleReference -> listOfYangResourceIds.add(yangResourceRepository.getIdByModuleNameAndRevision( - moduleReference.getName(), moduleReference.getRevision()))); + moduleReference.getModuleName(), moduleReference.getRevision()))); yangResourceRepository.insertSchemaSetIdYangResourceId(schemaSetEntity.getId(), listOfYangResourceIds); } @@ -325,10 +335,11 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ return checksum; } - private static ModuleReference toModuleReference(final YangResourceModuleReference yangResourceModuleReference) { + private static ModuleReference toModuleReference( + final YangResourceModuleReference yangResourceModuleReference) { return ModuleReference.builder() - .name(yangResourceModuleReference.getModuleName()) - .revision(yangResourceModuleReference.getRevision()) - .build(); + .moduleName(yangResourceModuleReference.getModuleName()) + .revision(yangResourceModuleReference.getRevision()) + .build(); } } diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java index 0b48eaaf63..b16b284a2a 100644 --- a/cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java +++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java @@ -37,8 +37,32 @@ public interface YangResourceRepository extends JpaRepository<YangResourceEntity List<YangResourceEntity> findAllByChecksumIn(@NotNull Set<String> checksum); - @Query(value = "SELECT module_name, revision FROM yang_resource", nativeQuery = true) - List<YangResourceModuleReference> findAllModuleNameAndRevision(); + @Query(value = "SELECT DISTINCT\n" + + "yr.module_name AS module_name,\n" + + "yr.revision AS revision\n" + + "FROM\n" + + "dataspace d\n" + + "JOIN schema_set ss ON ss.dataspace_id = d.id\n" + + "JOIN schema_set_yang_resources ssyr ON ssyr.schema_set_id = ss.id\n" + + "JOIN yang_resource yr ON yr.id = ssyr.yang_resource_id\n" + + "WHERE\n" + + "d.name = :dataspaceName", nativeQuery = true) + Set<YangResourceModuleReference> findAllModuleReferences(@Param("dataspaceName") String dataspaceName); + + @Query(value = "SELECT DISTINCT\n" + + "yr.module_Name AS module_name,\n" + + "yr.revision AS revision\n" + + "FROM\n" + + "dataspace d\n" + + "JOIN anchor a ON a.dataspace_id = d.id\n" + + "JOIN schema_set ss ON ss.dataspace_id = a.dataspace_id\n" + + "JOIN schema_set_yang_resources ssyr ON ssyr.schema_set_id = ss.id\n" + + "JOIN yang_resource yr ON yr.id = ssyr.yang_resource_id\n" + + "WHERE\n" + + "d.name = :dataspaceName AND\n" + + "a.name =:anchorName", nativeQuery = true) + Set<YangResourceModuleReference> findAllModuleReferences( + @Param("dataspaceName") String dataspaceName, @Param("anchorName") String anchorName); @Query(value = "SELECT id FROM yang_resource WHERE module_name=:name and revision=:revision", nativeQuery = true) Long getIdByModuleNameAndRevision(@Param("name") String moduleName, @Param("revision") String revision); diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy index 7a16a97d4b..a139830a2b 100644 --- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy +++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy @@ -20,22 +20,23 @@ */ package org.onap.cps.spi.impl -import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED -import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED - import org.onap.cps.spi.CpsAdminPersistenceService import org.onap.cps.spi.CpsModulePersistenceService import org.onap.cps.spi.entities.YangResourceEntity -import org.onap.cps.spi.exceptions.DataspaceNotFoundException import org.onap.cps.spi.exceptions.AlreadyDefinedException +import org.onap.cps.spi.exceptions.DataspaceNotFoundException import org.onap.cps.spi.exceptions.SchemaSetInUseException import org.onap.cps.spi.exceptions.SchemaSetNotFoundException import org.onap.cps.spi.model.ModuleReference +import org.onap.cps.spi.model.ExtendedModuleReference import org.onap.cps.spi.repository.AnchorRepository import org.onap.cps.spi.repository.SchemaSetRepository import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.context.jdbc.Sql +import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED +import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED + class CpsModulePersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase { @Autowired @@ -71,13 +72,13 @@ class CpsModulePersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase static final String NEW_RESOURCE_CHECKSUM = 'b13faef573ed1374139d02c40d8ce09c80ea1dc70e63e464c1ed61568d48d539' static final String NEW_RESOURCE_MODULE_NAME = 'stores' static final String NEW_RESOURCE_REVISION = '2020-09-15' - static final ModuleReference newModuleReference = ModuleReference.builder().name(NEW_RESOURCE_MODULE_NAME) + static final ExtendedModuleReference newModuleReference = ExtendedModuleReference.builder().name(NEW_RESOURCE_MODULE_NAME) .revision(NEW_RESOURCE_REVISION).build() def newYangResourcesNameToContentMap = [(NEW_RESOURCE_NAME):NEW_RESOURCE_CONTENT] - def allYangResourcesModuleAndRevisionList = [ModuleReference.builder().build(),ModuleReference.builder().build(), - ModuleReference.builder().build(),ModuleReference.builder().build(), - ModuleReference.builder().build(), newModuleReference] + def allYangResourcesModuleAndRevisionList = [new ExtendedModuleReference(name: 'MODULE-NAME-002',namespace:null, revision: 'REVISION-002'), new ExtendedModuleReference(name: 'MODULE-NAME-003',namespace:null, revision: 'REVISION-003'), + new ExtendedModuleReference(name: 'MODULE-NAME-004',namespace:null, revision: 'REVISION-004'), ExtendedModuleReference.builder().build(), + ExtendedModuleReference.builder().build(), newModuleReference] def dataspaceEntity def setup() { @@ -109,7 +110,7 @@ class CpsModulePersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase def 'Store and retrieve new schema set from new modules and existing modules.'() { given: 'map of new modules, a list of existing modules, module reference' def mapOfNewModules = [newModule1: 'module newmodule { yang-version 1.1; revision "2021-10-12" { } }'] - def moduleReferenceForExistingModule = new ModuleReference("test","test.org","2021-10-12") + def moduleReferenceForExistingModule = new ModuleReference("test","2021-10-12") def listOfExistingModulesModuleReference = [moduleReferenceForExistingModule] def mapOfExistingModule = [test: 'module test { yang-version 1.1; revision "2021-10-12" { } }'] objectUnderTest.storeSchemaSet(DATASPACE_NAME, "someSchemaSetName", mapOfExistingModule) @@ -135,13 +136,27 @@ class CpsModulePersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase } @Sql([CLEAR_DATA, SET_DATA]) - def 'Retrieving all yang resources module references.'() { - given: 'a new schema set is stored' - objectUnderTest.storeSchemaSet(DATASPACE_NAME, SCHEMA_SET_NAME_NEW, newYangResourcesNameToContentMap) - when: 'all yang resources module references are retrieved' - def result = objectUnderTest.getAllYangResourcesModuleReferences() + def 'Retrieving all yang resources module references for the given dataspace.'() { + given: 'a dataspace name' + def dataspaceName = 'DATASPACE-002' + when: 'all yang resources module references are retrieved for the given dataspace name' + def result = objectUnderTest.getAllYangResourceModuleReferences(dataspaceName) then: 'the correct resources are returned' - result.sort() == allYangResourcesModuleAndRevisionList.sort() + result.sort() == [new ModuleReference(moduleName: 'MODULE-NAME-005', revision: 'REVISION-002'), + new ModuleReference(moduleName: 'MODULE-NAME-006', revision: 'REVISION-006')] + } + + @Sql([CLEAR_DATA, SET_DATA]) + def 'Retrieving module names and revisions for the given anchor.'() { + given: 'a dataspace name and anchor name' + def dataspaceName = 'DATASPACE-001' + def anchorName = 'ANCHOR1' + when: 'all yang resources module references are retrieved for the given anchor' + def result = objectUnderTest.getAllYangResourceModuleReferences(dataspaceName, anchorName) + then: 'the correct module names and revisions are returned' + result.sort() == [new ModuleReference(moduleName: null, revision: null), new ModuleReference(moduleName: 'MODULE-NAME-002', revision: 'REVISION-002'), + new ModuleReference(moduleName: 'MODULE-NAME-003', revision: 'REVISION-002'), + new ModuleReference(moduleName: 'MODULE-NAME-004', revision: 'REVISION-004')] } @Sql([CLEAR_DATA, SET_DATA]) diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsPersistenceSpecBase.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsPersistenceSpecBase.groovy index 5132632452..8ec5c90e9c 100644 --- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsPersistenceSpecBase.groovy +++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsPersistenceSpecBase.groovy @@ -55,6 +55,7 @@ class CpsPersistenceSpecBase extends Specification { static final String CLEAR_DATA = '/data/clear-all.sql' static final String DATASPACE_NAME = 'DATASPACE-001' + static final String DATASPACE_NAME2 = 'DATASPACE-002' static final String SCHEMA_SET_NAME1 = 'SCHEMA-SET-001' static final String SCHEMA_SET_NAME2 = 'SCHEMA-SET-002' static final String ANCHOR_NAME1 = 'ANCHOR-001' diff --git a/cps-ri/src/test/resources/data/schemaset.sql b/cps-ri/src/test/resources/data/schemaset.sql index adfcfa172e..61600356b9 100644 --- a/cps-ri/src/test/resources/data/schemaset.sql +++ b/cps-ri/src/test/resources/data/schemaset.sql @@ -24,26 +24,32 @@ INSERT INTO DATASPACE (ID, NAME) VALUES (1001, 'DATASPACE-001'), (1002, 'DATASPACE-002'); INSERT INTO SCHEMA_SET (ID, NAME, DATASPACE_ID) VALUES - (2001, 'SCHEMA-SET-001', 1001), (2002, 'SCHEMA-SET-002', 1001), + (2001, 'SCHEMA-SET-001', 1001), + (2002, 'SCHEMA-SET-002', 1001), (2100, 'SCHEMA-SET-100', 1001), -- for removal, not referenced by anchors - (2101, 'SCHEMA-SET-101', 1001); -- for removal, having anchor and data associated - -INSERT INTO YANG_RESOURCE (ID, NAME, CONTENT, CHECKSUM) VALUES - (3001, 'module1@2020-02-02.yang', 'CONTENT-001', 'e8bdda931099310de66532e08c3fafec391db29f55c81927b168f6aa8f81b73b'), - (3002, 'module2@2020-02-02.yang', 'CONTENT-002', '7e7d48afbe066ed0a890a09081859046d3dde52300dfcdb13be5b20780353a11'), - (3003, 'module3@2020-02-02.yang', 'CONTENT-003', 'ca20c45fec8547633f05ff8905c48ffa7b02b94ec3ad4ed79922e6ba40779df3'), - (3004, 'module4@2020-02-02.yang', 'CONTENT-004', 'f6ed09d343562e4d4ae5140f3c6a55df9c53f6da8e30dda8cbd9eaf9cd449be0'), - (3100, 'orphan@2020-02-02.yang', 'ORPHAN', 'checksum'); -- for auto-removal as orphan + (2101, 'SCHEMA-SET-101', 1001), -- for removal, having anchor and data associated + (2003, 'SCHEMA-SET-003', 1002), + (2004, 'SCHEMA-SET-004', 1002); + +INSERT INTO YANG_RESOURCE (ID, NAME, CONTENT, CHECKSUM, MODULE_NAME, REVISION) VALUES + (3001, 'module1@2020-02-02.yang', 'CONTENT-001', 'e8bdda931099310de66532e08c3fafec391db29f55c81927b168f6aa8f81b73b',null,null), + (3002, 'module2@2020-02-02.yang', 'CONTENT-002', '7e7d48afbe066ed0a890a09081859046d3dde52300dfcdb13be5b20780353a11','MODULE-NAME-002','REVISION-002'), + (3003, 'module3@2020-02-02.yang', 'CONTENT-003', 'ca20c45fec8547633f05ff8905c48ffa7b02b94ec3ad4ed79922e6ba40779df3','MODULE-NAME-003','REVISION-002'), + (3004, 'module4@2020-02-02.yang', 'CONTENT-004', 'f6ed09d343562e4d4ae5140f3c6a55df9c53f6da8e30dda8cbd9eaf9cd449be0','MODULE-NAME-004','REVISION-004'), + (3100, 'orphan@2020-02-02.yang', 'ORPHAN', 'checksum',null,null), -- for auto-removal as orphan + (3005, 'module5@2020-02-02.yang', 'CONTENT-005', 'checksum-005','MODULE-NAME-005','REVISION-002'), + (3006, 'module6@2020-02-02.yang', 'CONTENT-006', 'checksum-006','MODULE-NAME-006','REVISION-006'); INSERT INTO SCHEMA_SET_YANG_RESOURCES (SCHEMA_SET_ID, YANG_RESOURCE_ID) VALUES (2001, 3001), (2001, 3002), (2002, 3003), (2002, 3004), (2100, 3003), (2100, 3100), -- orphan removal case - (2101, 3003), (2101, 3004); + (2101, 3003), (2101, 3004), + (2003, 3005), (2004, 3006); INSERT INTO ANCHOR (ID, NAME, DATASPACE_ID, SCHEMA_SET_ID) VALUES -- anchors for removal (6001, 'ANCHOR1', 1001, 2101), (6002, 'ANCHOR2', 1001, 2101); INSERT INTO FRAGMENT (ID, XPATH, ANCHOR_ID, DATASPACE_ID) VALUES - (7001, '/XPATH', 6001, 1001); + (7001, '/XPATH', 6001, 1001);
\ No newline at end of file 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 5c40331d74..218a236f1b 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 @@ -21,6 +21,7 @@ package org.onap.cps.api; +import java.util.Collection; import java.util.List; import java.util.Map; import org.checkerframework.checker.nullness.qual.NonNull; @@ -51,12 +52,12 @@ public interface CpsModuleService { * @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 existingModuleReferences List of YANG resources module references of the modules + * @param moduleReferences List of YANG resources module references of the modules * needed for this handle that are already in CPS */ void createSchemaSetFromModules(@NonNull String dataspaceName, @NonNull String schemaSetName, @NonNull Map<String, String> newYangResourcesModuleNameToContentMap, - @NonNull List<ModuleReference> existingModuleReferences); + @NonNull List<ModuleReference> moduleReferences); /** * Read schema set in the given dataspace. @@ -82,7 +83,8 @@ public interface CpsModuleService { /** * Retrieve all modules and revisions known by CPS for all Yang Resources. * + * @param dataspaceName dataspace name * @return a list of ModuleReference objects */ - List<ModuleReference> getAllYangResourcesModuleReferences(); + Collection<ModuleReference> getAllYangResourceModuleReferences(final String dataspaceName); } 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 0597d380a5..17ad78cbe8 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 @@ -21,6 +21,7 @@ package org.onap.cps.api.impl; +import java.util.Collection; import java.util.List; import java.util.Map; import org.onap.cps.api.CpsModuleService; @@ -53,9 +54,9 @@ public class CpsModuleServiceImpl implements CpsModuleService { @Override public void createSchemaSetFromModules(final String dataspaceName, final String schemaSetName, final Map<String, String> newYangResourcesModuleNameToContentMap, - final List<ModuleReference> existingModuleReferences) { + final List<ModuleReference> moduleReferences) { cpsModulePersistenceService.storeSchemaSetFromModules(dataspaceName, schemaSetName, - newYangResourcesModuleNameToContentMap, existingModuleReferences); + newYangResourcesModuleNameToContentMap, moduleReferences); } @@ -64,7 +65,7 @@ public class CpsModuleServiceImpl implements CpsModuleService { final var yangTextSchemaSourceSet = yangTextSchemaSourceSetCache .get(dataspaceName, schemaSetName); return SchemaSet.builder().name(schemaSetName).dataspaceName(dataspaceName) - .moduleReferences(yangTextSchemaSourceSet.getModuleReferences()).build(); + .extendedModuleReferences(yangTextSchemaSourceSet.getModuleReferences()).build(); } @Override @@ -74,8 +75,8 @@ public class CpsModuleServiceImpl implements CpsModuleService { } @Override - public List<ModuleReference> getAllYangResourcesModuleReferences() { - return cpsModulePersistenceService.getAllYangResourcesModuleReferences(); + public Collection<ModuleReference> getAllYangResourceModuleReferences(final String dataspaceName) { + return cpsModulePersistenceService.getAllYangResourceModuleReferences(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 7ad109d815..4f46c0dacb 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 @@ -21,6 +21,7 @@ package org.onap.cps.spi; +import java.util.Collection; import java.util.List; import java.util.Map; import org.checkerframework.checker.nullness.qual.NonNull; @@ -48,11 +49,11 @@ public interface CpsModulePersistenceService { * @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 + * @param moduleReferences List of YANG resources module references */ void storeSchemaSetFromModules(@NonNull String dataspaceName, @NonNull String schemaSetName, @NonNull Map<String, String> newYangResourcesModuleNameToContentMap, - @NonNull List<ModuleReference> moduleReferenceList); + @NonNull List<ModuleReference> moduleReferences); /** * Deletes Schema Set. @@ -89,9 +90,20 @@ public interface CpsModulePersistenceService { @NonNull String anchorName); /** - * Returns all YANG resources module references. + * Returns all YANG resources module references for the given dataspace name. * - * @return List of all YANG resources module information in the database + * @param dataspaceName dataspace name + * @return Collection of all YANG resources module information in the database + */ + Collection<ModuleReference> getAllYangResourceModuleReferences(final String dataspaceName); + + /** + * Get all YANG resource module references for the given anchor name and dataspace name. + * + * @param dataspaceName dataspace name + * @param anchorName anchor name + * @return a collection of module names and revisions */ - List<ModuleReference> getAllYangResourcesModuleReferences(); + Collection<ModuleReference> getAllYangResourceModuleReferences(final String dataspaceName, + final String anchorName); } diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/DataNode.java b/cps-service/src/main/java/org/onap/cps/spi/model/DataNode.java index 5773bc45c9..8e9dff873a 100644 --- a/cps-service/src/main/java/org/onap/cps/spi/model/DataNode.java +++ b/cps-service/src/main/java/org/onap/cps/spi/model/DataNode.java @@ -38,7 +38,7 @@ public class DataNode { private String dataspace; private String schemaSetName; private String anchorName; - private ModuleReference moduleReference; + private ExtendedModuleReference extendedModuleReference; private String xpath; private Map<String, Object> leaves = Collections.emptyMap(); private Collection<String> xpathsChildren; diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/ExtendedModuleReference.java b/cps-service/src/main/java/org/onap/cps/spi/model/ExtendedModuleReference.java new file mode 100644 index 0000000000..5e9c8d0cd7 --- /dev/null +++ b/cps-service/src/main/java/org/onap/cps/spi/model/ExtendedModuleReference.java @@ -0,0 +1,42 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright 2020-2021 Pantheon.tech + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.spi.model; + +import java.io.Serializable; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class ExtendedModuleReference implements Serializable { + + private static final long serialVersionUID = 1L; + + private String name; + private String namespace; + private String revision; + +} diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/ModuleReference.java b/cps-service/src/main/java/org/onap/cps/spi/model/ModuleReference.java index f9aa2b5904..9b73f8ff0f 100644 --- a/cps-service/src/main/java/org/onap/cps/spi/model/ModuleReference.java +++ b/cps-service/src/main/java/org/onap/cps/spi/model/ModuleReference.java @@ -1,7 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * Modifications Copyright 2020-2021 Pantheon.tech + * Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,10 +32,7 @@ import lombok.NoArgsConstructor; @AllArgsConstructor public class ModuleReference implements Serializable { - private static final long serialVersionUID = 1L; - - private String name; - private String namespace; + private static final long serialVersionUID = -1761408847591042599L; + private String moduleName; private String revision; - } diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/SchemaSet.java b/cps-service/src/main/java/org/onap/cps/spi/model/SchemaSet.java index caf7800d9b..4df7893e2c 100644 --- a/cps-service/src/main/java/org/onap/cps/spi/model/SchemaSet.java +++ b/cps-service/src/main/java/org/onap/cps/spi/model/SchemaSet.java @@ -35,5 +35,5 @@ public class SchemaSet implements Serializable { private static final long serialVersionUID = 1464791260718603291L; private String name; private String dataspaceName; - private List<ModuleReference> moduleReferences; + private List<ExtendedModuleReference> extendedModuleReferences; } diff --git a/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSet.java b/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSet.java index 32ee324c54..2c9d374b14 100644 --- a/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSet.java +++ b/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSet.java @@ -21,7 +21,7 @@ package org.onap.cps.yang; import java.util.List; import org.checkerframework.checker.nullness.qual.NonNull; -import org.onap.cps.spi.model.ModuleReference; +import org.onap.cps.spi.model.ExtendedModuleReference; import org.opendaylight.yangtools.yang.model.api.SchemaContext; /** @@ -35,7 +35,7 @@ public interface YangTextSchemaSourceSet { * @return list of ModuleRef */ @NonNull - List<ModuleReference> getModuleReferences(); + List<ExtendedModuleReference> getModuleReferences(); /** * Return SchemaContext for given YangSchema. diff --git a/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java b/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java index 3a65369dc7..5cbfd6222d 100644 --- a/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java +++ b/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java @@ -35,7 +35,7 @@ import java.util.stream.Collectors; import lombok.NoArgsConstructor; import org.onap.cps.spi.exceptions.CpsException; import org.onap.cps.spi.exceptions.ModelValidationException; -import org.onap.cps.spi.model.ModuleReference; +import org.onap.cps.spi.model.ExtendedModuleReference; import org.opendaylight.yangtools.yang.common.Revision; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; @@ -88,14 +88,14 @@ public final class YangTextSchemaSourceSetBuilder { } @Override - public List<ModuleReference> getModuleReferences() { + public List<ExtendedModuleReference> getModuleReferences() { return schemaContext.getModules().stream() .map(YangTextSchemaSourceSetImpl::toModuleReference) .collect(Collectors.toList()); } - private static ModuleReference toModuleReference(final Module module) { - return ModuleReference.builder() + private static ExtendedModuleReference toModuleReference(final Module module) { + return ExtendedModuleReference.builder() .name(module.getName()) .namespace(module.getQNameModule().getNamespace().toString()) .revision(module.getRevision().map(Revision::toString).orElse(null)) 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 d719b3d24e..31df479e42 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 @@ -25,7 +25,7 @@ package org.onap.cps.api.impl import org.onap.cps.TestUtils import org.onap.cps.spi.CpsModulePersistenceService import org.onap.cps.spi.exceptions.ModelValidationException -import org.onap.cps.spi.model.ModuleReference +import org.onap.cps.spi.model.ExtendedModuleReference import org.spockframework.spring.SpringBean import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest @@ -63,7 +63,7 @@ class CpsModuleServiceImplSpec extends Specification { 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 moduleReferenceForExistingModule = new ExtendedModuleReference("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) @@ -90,7 +90,7 @@ class CpsModuleServiceImplSpec extends Specification { then: 'the correct schema set is returned' result.getName().contains('someSchemaSet') result.getDataspaceName().contains('someDataspace') - result.getModuleReferences().contains(new ModuleReference('stores', 'org:onap:ccsdk:sample', '2020-09-15')) + result.getExtendedModuleReferences().contains(new ExtendedModuleReference('stores', 'org:onap:ccsdk:sample', '2020-09-15')) } def 'Schema set caching.'() { @@ -117,9 +117,9 @@ class CpsModuleServiceImplSpec extends Specification { def 'Get all yang resources module references.'(){ given: 'an already present module reference' - def moduleReferences = [new ModuleReference()] - mockModuleStoreService.getAllYangResourcesModuleReferences() >> moduleReferences + def moduleReferences = [new ExtendedModuleReference()] + mockModuleStoreService.getAllYangResourceModuleReferences('someDataspaceName') >> moduleReferences expect: 'the list provided by persistence service is returned as result' - objectUnderTest.getAllYangResourcesModuleReferences() == moduleReferences + objectUnderTest.getAllYangResourceModuleReferences('someDataspaceName') == moduleReferences } } |