summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main/java
diff options
context:
space:
mode:
authorRenu Kumari <renu.kumari@bell.ca>2021-06-30 05:50:50 -0400
committerRenu Kumari <renu.kumari@bell.ca>2021-07-05 23:31:04 -0400
commitc2de0a838e6afa8cb88dee9f4665a25245148aba (patch)
tree54f1288d402b3cb9bc048c602f5ebd1a6ab0f682 /cps-ri/src/main/java
parentfd47cc2008a514269f79eb58a84cc0039e0a153d (diff)
Added parent is null condition when searching for root fragments
Issue-ID: CPS-479 Signed-off-by: Renu Kumari <renu.kumari@bell.ca> Change-Id: I25fd91936e1b08cfc3bff69c7169392e724ed156
Diffstat (limited to 'cps-ri/src/main/java')
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java2
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java11
2 files changed, 8 insertions, 5 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
index af1eca33e6..42364ead69 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
@@ -160,7 +160,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
final var anchorEntity = anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName);
if (isRootXpath(xpath)) {
- return fragmentRepository.getFirstByDataspaceAndAnchor(dataspaceEntity, anchorEntity);
+ return fragmentRepository.findFirstRootByDataspaceAndAnchor(dataspaceEntity, anchorEntity);
} else {
return fragmentRepository.getByDataspaceAndAnchorAndXpath(dataspaceEntity, anchorEntity,
xpath);
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java
index c484ae9e87..ee77b73c9f 100755
--- a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java
@@ -48,12 +48,15 @@ public interface FragmentRepository extends JpaRepository<FragmentEntity, Long>
.orElseThrow(() -> new DataNodeNotFoundException(dataspaceEntity.getName(), anchorEntity.getName(), xpath));
}
- Optional<FragmentEntity> findFirstByDataspaceAndAnchor(@NonNull DataspaceEntity dataspaceEntity,
- @NonNull AnchorEntity anchorEntity);
+ @Query(
+ value = "SELECT * FROM FRAGMENT WHERE anchor_id = :anchor AND dataspace_id = :dataspace AND parent_id is NULL",
+ nativeQuery = true)
+ List<FragmentEntity> findRootsByDataspaceAndAnchor(
+ @Param("dataspace") int dataspaceId, @Param("anchor") int anchorId);
- default FragmentEntity getFirstByDataspaceAndAnchor(@NonNull DataspaceEntity dataspaceEntity,
+ default FragmentEntity findFirstRootByDataspaceAndAnchor(@NonNull DataspaceEntity dataspaceEntity,
@NonNull AnchorEntity anchorEntity) {
- return findFirstByDataspaceAndAnchor(dataspaceEntity, anchorEntity)
+ return findRootsByDataspaceAndAnchor(dataspaceEntity.getId(), anchorEntity.getId()).stream().findFirst()
.orElseThrow(() -> new DataNodeNotFoundException(dataspaceEntity.getName(), anchorEntity.getName()));
}