From ad61e283f7d981c3c8e307af871fb3a63e0cf4f9 Mon Sep 17 00:00:00 2001 From: Rudrangi Anupriya Date: Mon, 17 Jul 2023 20:20:34 +0530 Subject: Persisting a list element to a parent list (ep2) Post List Element does not allow for create List Element, only appends onto existing node as children -Add a check in saveListElements to see if the parent xpath is a root path ("/").If root node store list element as top node. Else add passed list element to parent xpath node. -Add test for scenario for above -Add test scenario Saving list element data fragment under Root node -Add Integration Tests Add and Delete top-level list (element) data nodes with root node -Update bookstore model with TopLevelList datanode Issue-ID: CPS-1586 Change-Id: Iaa7f59fbeebb03703626132c6d5c2afde0e7ab4b Signed-off-by: Rudrangi Anupriya --- .../main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'cps-service/src/main/java/org') diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java index 6e7c1649d7..7db87e87ea 100755 --- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java +++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java @@ -116,8 +116,12 @@ public class CpsDataServiceImpl implements CpsDataService { final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName); final Collection listElementDataNodeCollection = buildDataNodes(anchor, parentNodeXpath, jsonData, ContentType.JSON); - cpsDataPersistenceService.addListElements(dataspaceName, anchorName, parentNodeXpath, - listElementDataNodeCollection); + if (isRootNodeXpath(parentNodeXpath)) { + cpsDataPersistenceService.storeDataNodes(dataspaceName, anchorName, listElementDataNodeCollection); + } else { + cpsDataPersistenceService.addListElements(dataspaceName, anchorName, parentNodeXpath, + listElementDataNodeCollection); + } processDataUpdatedEventAsync(anchor, parentNodeXpath, UPDATE, observedTimestamp); } @@ -391,6 +395,10 @@ public class CpsDataServiceImpl implements CpsDataService { .get(anchor.getDataspaceName(), anchor.getSchemaSetName()).getSchemaContext(); } + private static boolean isRootNodeXpath(final String xpath) { + return ROOT_NODE_XPATH.equals(xpath); + } + private void processDataNodeUpdate(final Anchor anchor, final DataNode dataNodeUpdate) { cpsDataPersistenceService.batchUpdateDataLeaves(anchor.getDataspaceName(), anchor.getName(), Collections.singletonMap(dataNodeUpdate.getXpath(), dataNodeUpdate.getLeaves())); -- cgit 1.2.3-korg