diff options
Diffstat (limited to 'cps-ri/src/main')
-rwxr-xr-x | cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java | 33 | ||||
-rw-r--r-- | cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java | 4 |
2 files changed, 37 insertions, 0 deletions
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<String, String> newModuleNameToContentMap, + final Collection<ModuleReference> 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<String, String> newModuleNameToContentMap, + final SchemaSetEntity schemaSetEntity) { + final Set<YangResourceEntity> yangResourceEntities + = new HashSet<>(synchronizeYangResources(newModuleNameToContentMap)); + schemaSetEntity.setYangResources(yangResourceEntities); + schemaSetRepository.save(schemaSetEntity); + } + + private void updateAllModuleReferences(final Collection<ModuleReference> allModuleReferences, + final Integer schemaSetEntityId) { + yangResourceRepository.deleteSchemaSetYangResourceForSchemaSetId(schemaSetEntityId); + final List<Integer> 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 @@ -109,6 +109,10 @@ public interface YangResourceRepository extends JpaRepository<YangResourceEntity } @Modifying + @Query(value = "DELETE FROM schema_set_yang_resources WHERE schema_set_id = :schemaSetId", nativeQuery = true) + void deleteSchemaSetYangResourceForSchemaSetId(@Param("schemaSetId") int schemaSetId); + + @Modifying @Query(value = "DELETE FROM yang_resource yr WHERE NOT EXISTS " + "(SELECT 1 FROM schema_set_yang_resources ssyr WHERE ssyr.yang_resource_id = yr.id)", nativeQuery = true) void deleteOrphans(); |