diff options
author | 2021-09-01 17:12:28 +0100 | |
---|---|---|
committer | 2021-09-06 14:06:16 +0000 | |
commit | d0422226b45f752086c9920bdead753c644d9289 (patch) | |
tree | 219118e284927589ad69dc4ded6d520e76e77530 /cps-ri/src/main/java/org/onap | |
parent | c27465347d10b573e7a211c0b11b7c8a6fd792c0 (diff) |
P1 - Get module name and revision persistence layer
Rename ModuleReference to ExtendedModuleReference
Create new ModuleReference class (moduleName and revision)
Update existing sync model flow to use new module reference class
Create native query to get module name and revision
Issue-ID: CPS-485
Signed-off-by: niamhcore <niamh.core@est.tech>
Change-Id: I0d0da7742ceef3a68e83a5dd4852091e6adf138b
Diffstat (limited to 'cps-ri/src/main/java/org/onap')
-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 | 28 |
2 files changed, 48 insertions, 13 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 1c7828f32..d7b882f6e 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 0b48eaaf6..b16b284a2 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); |