From 2b4c48824947478f12c7b2e7b962aeb6b46ae4fc Mon Sep 17 00:00:00 2001 From: arpitsingh Date: Fri, 3 Mar 2023 21:38:57 +0530 Subject: CPS-1526 Fix response message for PATCH operation - Fixed the Response code and message when trying to update multiple data trees at once - Response code changed to 400 - Since the patch operation across multiple data trees is not supported when xpath is set to root node xpath, appropriate message is returned in response - Existing functionality of updating one data node with root node xpath remains as it is. - Updated API documentation and release notes Issue-ID: CPS-1526 Signed-off-by: arpitsingh Change-Id: I5d25a06bb5d407316ccfb2f85877cbe56a9f6f31 --- .../src/main/java/org/onap/cps/api/CpsDataService.java | 4 +++- .../main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java | 12 +++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'cps-service/src/main/java') diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java b/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java index 39fa45ac1a..fc008685c1 100644 --- a/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java +++ b/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java @@ -138,7 +138,9 @@ public interface CpsDataService { FetchDescendantsOption fetchDescendantsOption); /** - * Updates data node for given dataspace and anchor using xpath to parent node. + * Updates data node for given dataspace and anchor using xpath to parent node. This method can currently + * update only one top level data node. The method will throw DataValidationException when more than one top level + * data nodes are provided in jsonData * * @param dataspaceName dataspace name * @param anchorName anchor name 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 cd14795ad5..51e31f08c8 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 @@ -160,9 +160,15 @@ public class CpsDataServiceImpl implements CpsDataService { final String jsonData, final OffsetDateTime observedTimestamp) { cpsValidator.validateNameCharacters(dataspaceName, anchorName); final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName); - final DataNode dataNode = buildDataNode(anchor, parentNodeXpath, jsonData, ContentType.JSON); - cpsDataPersistenceService.updateDataLeaves(dataspaceName, anchorName, dataNode.getXpath(), - dataNode.getLeaves()); + final Collection dataNodesInPatch = buildDataNodes(anchor, parentNodeXpath, jsonData, + ContentType.JSON); + if (dataNodesInPatch.size() > 1) { + throw new DataValidationException("Operation is not supported for multiple data nodes", + "Number of data nodes present: " + dataNodesInPatch.size()); + } + cpsDataPersistenceService.updateDataLeaves(dataspaceName, anchorName, + dataNodesInPatch.iterator().next().getXpath(), + dataNodesInPatch.iterator().next().getLeaves()); processDataUpdatedEventAsync(anchor, parentNodeXpath, UPDATE, observedTimestamp); } -- cgit 1.2.3-korg