summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main/java
diff options
context:
space:
mode:
authorRishi.Chail <rishi.chail@est.tech>2021-04-14 00:51:44 +0100
committerRishi.Chail <rishi.chail@est.tech>2021-04-26 12:58:17 +0100
commit2b7d23c2ffa067732df1ecc3879d252646dad2da (patch)
treed8ef8bcb618aeb10d2917afd49af0f6d7f0d7cd6 /cps-ri/src/main/java
parent964fc0f1f9a19e64aa45c3f3469a8f4d5079724c (diff)
Get Data under anchor using single root
Issue-ID: CPS-325 Signed-off-by: Rishi.Chail <rishi.chail@est.tech> Change-Id: Id8da3d767199c5767c625b55d175ac6791dcca48
Diffstat (limited to 'cps-ri/src/main/java')
-rwxr-xr-x[-rw-r--r--]cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java11
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java9
2 files changed, 19 insertions, 1 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 fa13c7d14d..a02b193d9e 100644..100755
--- 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
@@ -130,7 +130,12 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
final String xpath) {
final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
final AnchorEntity anchorEntity = anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName);
- return fragmentRepository.getByDataspaceAndAnchorAndXpath(dataspaceEntity, anchorEntity, xpath);
+ if (isRootXpath(xpath)) {
+ return fragmentRepository.getFirstByDataspaceAndAnchor(dataspaceEntity, anchorEntity);
+ } else {
+ return fragmentRepository.getByDataspaceAndAnchorAndXpath(dataspaceEntity, anchorEntity,
+ xpath);
+ }
}
@Override
@@ -205,4 +210,8 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
fragmentEntity.setChildFragments(Collections.emptySet());
fragmentRepository.save(fragmentEntity);
}
+
+ private boolean isRootXpath(final String xpath) {
+ return "/".equals(xpath) || "".equals(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 b896fe86d0..74d04613d9 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,6 +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);
+
+ default FragmentEntity getFirstByDataspaceAndAnchor(@NonNull DataspaceEntity dataspaceEntity,
+ @NonNull AnchorEntity anchorEntity) {
+ return findFirstByDataspaceAndAnchor(dataspaceEntity, anchorEntity)
+ .orElseThrow(() -> new DataNodeNotFoundException(dataspaceEntity.getName(), anchorEntity.getName()));
+ }
+
@Modifying
@Query("DELETE FROM FragmentEntity fe WHERE fe.anchor IN (:anchors)")
void deleteByAnchorIn(@NotNull @Param("anchors") Collection<AnchorEntity> anchorEntities);