From 6804157f3ee5b1268e53ae86e4767ee267d48eec Mon Sep 17 00:00:00 2001 From: niamhcore Date: Mon, 8 Nov 2021 14:27:18 +0000 Subject: Fix for get anchor identifiers by module names Issue-ID: CPS-762 Signed-off-by: niamhcore Change-Id: Idf93f89f8427c5906c9f6b018633c8852b111821 --- .../cps/spi/impl/CpsAdminPersistenceServiceImpl.java | 5 +++-- .../org/onap/cps/spi/repository/AnchorRepository.java | 17 +++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) (limited to 'cps-ri/src/main/java/org/onap') 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 cd3c30b97b..e5df9c5cab 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 @@ -96,8 +96,9 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic @Override public Collection queryAnchors(final String dataspaceName, final Collection inputModuleNames) { validateDataspaceAndModuleNames(dataspaceName, inputModuleNames); - final Collection anchorEntities = - anchorRepository.getAnchorsByDataspaceNameAndModuleNames(dataspaceName, inputModuleNames); + final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName); + final Collection anchorEntities = anchorRepository + .getAnchorsByDataspaceIdAndModuleNames(dataspaceEntity.getId(), inputModuleNames, inputModuleNames.size()); return anchorEntities.stream().map(CpsAdminPersistenceServiceImpl::toAnchor).collect(Collectors.toSet()); } 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 6d4cb3c716..5870fd9e9b 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 @@ -45,16 +45,13 @@ public interface AnchorRepository extends JpaRepository { Collection 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" + @Query(value = "SELECT anchor.* FROM 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 getAnchorsByDataspaceNameAndModuleNames(@Param("dataspaceName") String dataspaceName, - @Param("moduleNames") Collection moduleNames); + + "WHERE schema_set.dataspace_id = :dataspaceId AND module_name IN (:moduleNames)\n" + + "GROUP BY anchor.id, anchor.name, anchor.dataspace_id, anchor.schema_set_id\n" + + "HAVING COUNT(DISTINCT module_name) = :sizeOfModuleNames", nativeQuery = true) + Collection getAnchorsByDataspaceIdAndModuleNames(@Param("dataspaceId") int dataspaceId, + @Param("moduleNames") Collection moduleNames, @Param("sizeOfModuleNames") int sizeOfModuleNames); } \ No newline at end of file -- cgit 1.2.3-korg