summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main/java/org
diff options
context:
space:
mode:
authoremaclee <lee.anjella.macabuhay@est.tech>2022-06-17 17:42:56 +0100
committeremaclee <lee.anjella.macabuhay@est.tech>2022-06-30 12:08:14 +0100
commite1f73e264e2dca1f10c273620653f541c2f25d69 (patch)
treef9adc065420549de0368842ae1f4e7df30c4effe /cps-ri/src/main/java/org
parentf7c7848d4cd7654ab94d9c31b62a71ed2bc4b9e8 (diff)
Add method to get YANG module sources for CM handle
- part of this commit includes renaming the enum SyncState to DataStoreSyncState Issue-ID: CPS-1064 Signed-off-by: emaclee <lee.anjella.macabuhay@est.tech> Change-Id: I6bf419141a1b33f09871946445cdfff422c8c354
Diffstat (limited to 'cps-ri/src/main/java/org')
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java26
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java11
2 files changed, 33 insertions, 4 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 cbeb1b76f7..806e7ccaba 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
@@ -53,6 +53,7 @@ import org.onap.cps.spi.entities.YangResourceModuleReference;
import org.onap.cps.spi.exceptions.AlreadyDefinedException;
import org.onap.cps.spi.exceptions.DuplicatedYangResourceException;
import org.onap.cps.spi.exceptions.ModelValidationException;
+import org.onap.cps.spi.model.ModuleDefinition;
import org.onap.cps.spi.model.ModuleReference;
import org.onap.cps.spi.repository.DataspaceRepository;
import org.onap.cps.spi.repository.ModuleReferenceRepository;
@@ -114,12 +115,22 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
@Override
public Collection<ModuleReference> getYangResourceModuleReferences(final String dataspaceName,
- final String anchorName) {
+ final String anchorName) {
final Set<YangResourceModuleReference> yangResourceModuleReferenceList =
- yangResourceRepository
- .findAllModuleReferencesByDataspaceAndAnchor(dataspaceName, anchorName);
+ yangResourceRepository
+ .findAllModuleReferencesByDataspaceAndAnchor(dataspaceName, anchorName);
return yangResourceModuleReferenceList.stream().map(CpsModulePersistenceServiceImpl::toModuleReference)
- .collect(Collectors.toList());
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public Collection<ModuleDefinition> getYangResourceDefinitions(final String dataspaceName,
+ final String anchorName) {
+ final Set<YangResourceEntity> yangResourceEntities =
+ yangResourceRepository
+ .findAllModuleDefinitionsByDataspaceAndAnchor(dataspaceName, anchorName);
+ return yangResourceEntities.stream().map(CpsModulePersistenceServiceImpl::toModuleDefinition)
+ .collect(Collectors.toList());
}
@Override
@@ -343,4 +354,11 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
.revision(yangResourceModuleReference.getRevision())
.build();
}
+
+ private static ModuleDefinition toModuleDefinition(final YangResourceEntity yangResourceEntity) {
+ return new ModuleDefinition(
+ yangResourceEntity.getModuleName(),
+ yangResourceEntity.getRevision(),
+ yangResourceEntity.getContent());
+ }
}
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 5e9c47429b..98306d8684 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
@@ -67,6 +67,17 @@ public interface YangResourceRepository extends JpaRepository<YangResourceEntity
Set<YangResourceModuleReference> findAllModuleReferencesByDataspaceAndAnchor(
@Param("dataspaceName") String dataspaceName, @Param("anchorName") String anchorName);
+ @Query(value = "SELECT DISTINCT yang_resource.*\n"
+ + "FROM dataspace\n"
+ + "JOIN anchor ON anchor.dataspace_id = dataspace.id\n"
+ + "JOIN schema_set ON schema_set.id = anchor.schema_set_id\n"
+ + "JOIN schema_set_yang_resources ON schema_set_yang_resources.schema_set_id = schema_set.id\n"
+ + "JOIN yang_resource ON yang_resource.id = schema_set_yang_resources.yang_resource_id\n"
+ + "WHERE dataspace.name = :dataspaceName "
+ + "AND anchor.name =:anchorName", nativeQuery = true)
+ Set<YangResourceEntity> findAllModuleDefinitionsByDataspaceAndAnchor(
+ @Param("dataspaceName") String dataspaceName, @Param("anchorName") String anchorName);
+
@Query(value = "SELECT DISTINCT\n"
+ "yang_resource.*\n"
+ "FROM\n"