summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main/java
diff options
context:
space:
mode:
authorniamhcore <niamh.core@est.tech>2021-10-21 15:19:04 +0100
committerniamhcore <niamh.core@est.tech>2021-10-29 09:20:39 +0100
commita1c6e6ac56f9e53f08b329ce7f5069514c62fc77 (patch)
tree124ea9506d021c70d430e213015b9e9522f0f184 /cps-ri/src/main/java
parentd5bc2ef86b68ba6e8fdc8cf808e9cc0065ce2ae2 (diff)
Add get cm handles by modules names - persistence layer
- Add sql query to anchor repository - Add sql query to yang resource repository Issue-ID: CPS-644 Signed-off-by: niamhcore <niamh.core@est.tech> Change-Id: I85ab1fcb343e6be77628695153d8d9f303dc3112
Diffstat (limited to 'cps-ri/src/main/java')
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java33
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java16
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java33
3 files changed, 73 insertions, 9 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java
index 2776c4d67d..2b63169d44 100755
--- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java
@@ -23,6 +23,7 @@
package org.onap.cps.spi.impl;
import java.util.Collection;
+import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import javax.transaction.Transactional;
@@ -30,11 +31,13 @@ import org.onap.cps.spi.CpsAdminPersistenceService;
import org.onap.cps.spi.entities.AnchorEntity;
import org.onap.cps.spi.entities.DataspaceEntity;
import org.onap.cps.spi.exceptions.AlreadyDefinedException;
+import org.onap.cps.spi.exceptions.ModuleNamesNotFoundException;
import org.onap.cps.spi.model.Anchor;
import org.onap.cps.spi.repository.AnchorRepository;
import org.onap.cps.spi.repository.DataspaceRepository;
import org.onap.cps.spi.repository.FragmentRepository;
import org.onap.cps.spi.repository.SchemaSetRepository;
+import org.onap.cps.spi.repository.YangResourceRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Component;
@@ -54,6 +57,9 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic
@Autowired
private FragmentRepository fragmentRepository;
+ @Autowired
+ private YangResourceRepository yangResourceRepository;
+
@Override
public void createDataspace(final String dataspaceName) {
try {
@@ -88,6 +94,14 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic
}
@Override
+ public Collection<Anchor> getAnchors(final String dataspaceName, final Collection<String> inputModuleNames) {
+ validateDataspaceAndModuleNames(dataspaceName, inputModuleNames);
+ final Collection<AnchorEntity> anchorEntities =
+ anchorRepository.getAnchorsByDataspaceNameAndModuleNames(dataspaceName, inputModuleNames);
+ return anchorEntities.stream().map(CpsAdminPersistenceServiceImpl::toAnchor).collect(Collectors.toSet());
+ }
+
+ @Override
public Anchor getAnchor(final String dataspaceName, final String anchorName) {
return toAnchor(getAnchorEntity(dataspaceName, anchorName));
}
@@ -112,4 +126,23 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic
.schemaSetName(anchorEntity.getSchemaSet().getName())
.build();
}
+
+ private void validateDataspaceAndModuleNames(final String dataspaceName,
+ final Collection<String> inputModuleNames) {
+ final Collection<String> retrievedModuleNames =
+ yangResourceRepository.findAllModuleReferences(dataspaceName, inputModuleNames)
+ .stream().map(module -> module.getModuleName())
+ .collect(Collectors.toList());
+ if (retrievedModuleNames.isEmpty()) {
+ dataspaceRepository.getByName(dataspaceName);
+ }
+ if (inputModuleNames.size() > retrievedModuleNames.size()) {
+ final List<String> moduleNamesNotFound = inputModuleNames.stream()
+ .filter(moduleName -> !retrievedModuleNames.contains(moduleName))
+ .collect(Collectors.toList());
+ if (!moduleNamesNotFound.isEmpty()) {
+ throw new ModuleNamesNotFoundException(dataspaceName, moduleNamesNotFound);
+ }
+ }
+ }
}
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java
index 0305555456..6d4cb3c716 100755
--- a/cps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2021 Pantheon.tech
+ * Modifications Copyright (C) 2021 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +28,8 @@ import org.onap.cps.spi.entities.DataspaceEntity;
import org.onap.cps.spi.entities.SchemaSetEntity;
import org.onap.cps.spi.exceptions.AnchorNotFoundException;
import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
public interface AnchorRepository extends JpaRepository<AnchorEntity, Integer> {
@@ -41,4 +44,17 @@ public interface AnchorRepository extends JpaRepository<AnchorEntity, Integer> {
Collection<AnchorEntity> findAllByDataspace(@NotNull DataspaceEntity dataspaceEntity);
Collection<AnchorEntity> findAllBySchemaSet(@NotNull SchemaSetEntity schemaSetEntity);
+
+ @Query(value = "SELECT DISTINCT\n"
+ + "anchor.*\n"
+ + "FROM\n"
+ + "yang_resource\n"
+ + "JOIN schema_set_yang_resources ON "
+ + "schema_set_yang_resources.yang_resource_id = yang_resource.id\n"
+ + "JOIN schema_set ON schema_set.id = schema_set_yang_resources.schema_set_id\n"
+ + "JOIN anchor ON anchor.schema_set_id = schema_set.id\n"
+ + "JOIN dataspace ON dataspace.id = anchor.dataspace_id AND dataspace.name = :dataspaceName\n"
+ + "WHERE yang_resource.module_Name IN (:moduleNames)", nativeQuery = true)
+ Collection<AnchorEntity> getAnchorsByDataspaceNameAndModuleNames(@Param("dataspaceName") String dataspaceName,
+ @Param("moduleNames") Collection<String> moduleNames);
} \ No newline at end of file
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 764e2dfc74..3f5c43decc 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
@@ -20,6 +20,7 @@
package org.onap.cps.spi.repository;
+import java.util.Collection;
import java.util.List;
import java.util.Set;
import javax.validation.constraints.NotNull;
@@ -41,11 +42,11 @@ public interface YangResourceRepository extends JpaRepository<YangResourceEntity
+ "yang_resource.module_name AS module_name,\n"
+ "yang_resource.revision AS revision\n"
+ "FROM\n"
- + "dataspace dataspace\n"
- + "JOIN schema_set schema_set ON schema_set.dataspace_id = dataspace.id\n"
- + "JOIN schema_set_yang_resources schema_set_yang_resource ON schema_set_yang_resource.schema_set_id = "
+ + "dataspace\n"
+ + "JOIN schema_set ON schema_set.dataspace_id = dataspace.id\n"
+ + "JOIN schema_set_yang_resources ON schema_set_yang_resources.schema_set_id = "
+ "schema_set.id\n"
- + "JOIN yang_resource yang_resource ON yang_resource.id = schema_set_yang_resource.yang_resource_id\n"
+ + "JOIN yang_resource ON yang_resource.id = schema_set_yang_resources.yang_resource_id\n"
+ "WHERE\n"
+ "dataspace.name = :dataspaceName", nativeQuery = true)
Set<YangResourceModuleReference> findAllModuleReferences(@Param("dataspaceName") String dataspaceName);
@@ -54,18 +55,32 @@ public interface YangResourceRepository extends JpaRepository<YangResourceEntity
+ "yang_resource.module_Name AS module_name,\n"
+ "yang_resource.revision AS revision\n"
+ "FROM\n"
- + "dataspace dataspace\n"
- + "JOIN anchor anchor ON anchor.dataspace_id = dataspace.id\n"
- + "JOIN schema_set schema_set ON schema_set.id = anchor.schema_set_id\n"
- + "JOIN schema_set_yang_resources schema_set_yang_resource ON schema_set_yang_resource.schema_set_id = "
+ + "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 yang_resource ON yang_resource.id = schema_set_yang_resource.yang_resource_id\n"
+ + "JOIN yang_resource ON yang_resource.id = schema_set_yang_resources.yang_resource_id\n"
+ "WHERE\n"
+ "dataspace.name = :dataspaceName AND\n"
+ "anchor.name =:anchorName", nativeQuery = true)
Set<YangResourceModuleReference> findAllModuleReferences(
@Param("dataspaceName") String dataspaceName, @Param("anchorName") String anchorName);
+ @Query(value = "SELECT DISTINCT\n"
+ + "yang_resource.*\n"
+ + "FROM\n"
+ + "dataspace\n"
+ + "JOIN schema_set ON schema_set.dataspace_id = dataspace.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\n"
+ + "dataspace.name = :dataspaceName and yang_resource.module_Name IN (:moduleNames)", nativeQuery = true)
+ Set<YangResourceModuleReference> findAllModuleReferences(@Param("dataspaceName") String dataspaceName,
+ @Param("moduleNames") Collection<String> moduleNames);
+
+
@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);