summaryrefslogtreecommitdiffstats
path: root/cps-ri/src
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ri/src')
-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
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy10
3 files changed, 43 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"
diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy
index c4cfa3d50b..8a43e5125d 100644
--- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy
+++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy
@@ -26,9 +26,11 @@ import org.onap.cps.spi.entities.YangResourceEntity
import org.onap.cps.spi.exceptions.AlreadyDefinedException
import org.onap.cps.spi.exceptions.DataspaceNotFoundException
import org.onap.cps.spi.exceptions.SchemaSetNotFoundException
+import org.onap.cps.spi.model.ModuleDefinition
import org.onap.cps.spi.model.ModuleReference
import org.onap.cps.spi.repository.AnchorRepository
import org.onap.cps.spi.repository.SchemaSetRepository
+import org.onap.cps.spi.repository.YangResourceRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.context.jdbc.Sql
@@ -214,6 +216,14 @@ class CpsModulePersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase
yangResourceRepository.findById(sharedResourceId).isPresent()
}
+ @Sql([CLEAR_DATA, SET_DATA])
+ def 'Retrieving all yang resources module definition for the given dataspace and anchor name.'() {
+ when: 'all yang resources module definitions are retrieved for the given dataspace and anchor name'
+ def result = objectUnderTest.getYangResourceDefinitions('DATASPACE-001', 'ANCHOR3')
+ then: 'the correct module definitions (moduleName, revision and yang resource content) are returned'
+ result.sort() == [new ModuleDefinition('MODULE-NAME-004', 'REVISION-004', 'CONTENT-004')]
+ }
+
def assertSchemaSetPersisted(expectedDataspaceName,
expectedSchemaSetName,
expectedYangResourceName,