summaryrefslogtreecommitdiffstats
path: root/cps-service
diff options
context:
space:
mode:
Diffstat (limited to 'cps-service')
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsDataService.java4
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java12
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy11
3 files changed, 23 insertions, 4 deletions
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<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);
}
diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy
index faa5d2edbd..be397b92cd 100644
--- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy
@@ -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')