From 541ed451d1257f6eb72517f33f470db53fdd7fb4 Mon Sep 17 00:00:00 2001 From: sourabh_sourabh Date: Tue, 5 Dec 2023 11:02:17 +0000 Subject: Introduce Schema Set upgrade method - Incl. integration test - Prod code is changed to use new method that update yand module. - updated module resource to return multiple modules. Issue-ID: CPS-1806 Signed-off-by: sourabh_sourabh Change-Id: I751d9393ce78a3be9daeaff6d0252738c02115e0 Signed-off-by: sourabh_sourabh --- .../spi/impl/CpsModulePersistenceServiceImpl.java | 33 ++++++++++++++++++++++ .../cps/spi/repository/YangResourceRepository.java | 4 +++ 2 files changed, 37 insertions(+) (limited to 'cps-ri/src/main') 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 0d77530b30..b115f9a3c7 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 @@ -34,6 +34,7 @@ import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Optional; @@ -190,6 +191,21 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ schemaSetRepository.deleteByDataspaceAndNameIn(dataspaceEntity, schemaSetNames); } + + @Override + @Transactional + public void updateSchemaSetFromModules(final String dataspaceName, final String schemaSetName, + final Map newModuleNameToContentMap, + final Collection allModuleReferences) { + final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName); + final SchemaSetEntity schemaSetEntity = + schemaSetRepository.getByDataspaceAndName(dataspaceEntity, schemaSetName); + storeAndLinkNewModules(newModuleNameToContentMap, schemaSetEntity); + updateAllModuleReferences(allModuleReferences, schemaSetEntity.getId()); + } + + + @Override @Transactional public void deleteUnusedYangResourceModules() { @@ -364,4 +380,21 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ return SchemaSet.builder().name(schemaSetEntity.getName()) .dataspaceName(schemaSetEntity.getDataspace().getName()).build(); } + + private void storeAndLinkNewModules(final Map newModuleNameToContentMap, + final SchemaSetEntity schemaSetEntity) { + final Set yangResourceEntities + = new HashSet<>(synchronizeYangResources(newModuleNameToContentMap)); + schemaSetEntity.setYangResources(yangResourceEntities); + schemaSetRepository.save(schemaSetEntity); + } + + private void updateAllModuleReferences(final Collection allModuleReferences, + final Integer schemaSetEntityId) { + yangResourceRepository.deleteSchemaSetYangResourceForSchemaSetId(schemaSetEntityId); + final List allYangResourceIds = + yangResourceRepository.getResourceIdsByModuleReferences(allModuleReferences); + yangResourceRepository.insertSchemaSetIdYangResourceId(schemaSetEntityId, allYangResourceIds); + } + } 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 e833796337..3fec462b44 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 @@ -108,6 +108,10 @@ public interface YangResourceRepository extends JpaRepository