summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ri/src/main/java')
-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.java28
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 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);