Merge "CPS-1526 Fix response message for PATCH operation"
authorLuke Gleeson <luke.gleeson@est.tech>
Mon, 20 Mar 2023 15:27:38 +0000 (15:27 +0000)
committerGerrit Code Review <gerrit@onap.org>
Mon, 20 Mar 2023 15:27:38 +0000 (15:27 +0000)
cps-rest/docs/openapi/cpsData.yml
cps-service/src/main/java/org/onap/cps/api/CpsDataService.java
cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java
cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy
docs/api/swagger/cps/openapi.yaml
docs/release-notes.rst

index 1d60e1f..0a032e4 100644 (file)
@@ -131,7 +131,8 @@ nodesByDataspaceAndAnchor:
       '500':
         $ref: 'components.yml#/components/responses/InternalServerError'
   patch:
-    description: Update a data node leaves for a given dataspace and anchor and a parent node xpath
+    description: Update a data node leaves for a given dataspace and anchor and a parent node xpath. This operation
+                  is currently supported for one top level data node only.
     tags:
       - cps-data
     summary: Update node leaves
index 39fa45a..fc00868 100644 (file)
@@ -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
index cd14795..51e31f0 100755 (executable)
@@ -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<DataNode> 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);
     }
 
index faa5d2e..be397b9 100644 (file)
@@ -240,6 +240,17 @@ class CpsDataServiceImplSpec extends Specification {
             'one leaf'        | '{"name": "some-name"}'
     }
 
+    def 'Update multiple data nodes' () {
+        given: 'schema set for given dataspace and anchor refers multipleDataTree model'
+            setupSchemaSetMocks('multipleDataTree.yang')
+        and: 'json string with multiple data trees'
+            def updatedJsonData = '{"first-container":{"a-leaf":"a-new-Value"},"last-container":{"x-leaf":"x-new-value"}}'
+        when: 'update operation is performed on multiple data nodes'
+            objectUnderTest.updateNodeLeaves(dataspaceName, anchorName, '/', updatedJsonData, observedTimestamp)
+        then: 'expected exception is thrown'
+            thrown(DataValidationException)
+    }
+
     def 'Update Bookstore node leaves' () {
         given: 'a DMI registry model'
             setupSchemaSetMocks('bookstore.yang')
index edbf878..57b9962 100644 (file)
@@ -1720,8 +1720,8 @@ paths:
       tags:
         - cps-data
       summary: Update node leaves
-      description: Update a data node leaves for a given dataspace and anchor and
-        a parent node xpath
+      description: Update a data node leaves for a given dataspace and anchor and a parent node xpath. This
+        operation is currently supported for one top level data node only.
       operationId: updateNodeLeaves
       parameters:
         - name: apiVersion
index 12e485a..d52e729 100755 (executable)
@@ -39,7 +39,7 @@ Release Data
 Bug Fixes
 ---------
 3.2.6
-    - None
+    - `CPS-1526 <https://jira.onap.org/browse/CPS-1526>`_ Fix response message for PATCH operation
 
 Features
 --------
@@ -229,6 +229,9 @@ Known Limitations, Issues and Workarounds
 For upgrading, CPS uses Liquibase for database upgrades. CPS/NCMP currently only supports upgrading from Liquibase changelog 11 to Liquibase changelog 16.
 This is from commit CPS-506: List all known modules and revision to CPS-1312: Default CMHandles to READY during upgrade or from ONAP release Honolulu to Kohn.
 
+CPS core Patch operation currently supports updating data of one top level data node. When performing Patch on multiple top level data nodes at once
+a 400 Bad Request is sent as response. This is part of commit CPS-1526.
+
 ..      ====================
 ..      * * *   KOHN   * * *
 ..      ====================