summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main
diff options
context:
space:
mode:
authorsourabh_sourabh <sourabh.sourabh@est.tech>2023-12-05 11:02:17 +0000
committersourabh_sourabh <sourabh.sourabh@est.tech>2023-12-13 12:53:38 +0000
commit541ed451d1257f6eb72517f33f470db53fdd7fb4 (patch)
tree28ebef126cedbda25ce315cefb0798e8b8cd2401 /cps-ri/src/main
parent7e94b26a666907cc97d692b8dda8364bb0a0ef45 (diff)
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 <sourabh.sourabh@est.tech> Change-Id: I751d9393ce78a3be9daeaff6d0252738c02115e0 Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
Diffstat (limited to 'cps-ri/src/main')
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java33
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java4
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();