From d8620d2bceab3001543d795b3d44925377d00cf1 Mon Sep 17 00:00:00 2001 From: danielhanrahan Date: Thu, 28 Sep 2023 11:13:36 +0100 Subject: JSON list support when updating multiple datanodes updateDataNodesAndDescendants if supplied with a JSON list such as {"branch": [{"name":"Name1"}, {"name":"Name2"}]} would only replace the first node /test-tree/branch[@name='Name1'], and ignore any remaining list items. This is caused by the use of a legacy buildDataNode, which returns only a single DataNode from JSON, even if the JSON contained a list. Issue-ID: CPS-1889 Signed-off-by: danielhanrahan Change-Id: I257491b6bc3f047a64eb241eaac70fd457b24347 --- .../org/onap/cps/api/impl/CpsDataServiceImpl.java | 27 +++++----------------- 1 file changed, 6 insertions(+), 21 deletions(-) (limited to 'cps-service/src/main') 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 7db87e87ea..1d68450f8a 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 @@ -31,6 +31,7 @@ import static org.onap.cps.notification.Operation.UPDATE; import io.micrometer.core.annotation.Timed; import java.io.Serializable; import java.time.OffsetDateTime; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Map; @@ -321,28 +322,12 @@ public class CpsDataServiceImpl implements CpsDataService { processDataUpdatedEventAsync(anchor, listNodeXpath, DELETE, observedTimestamp); } - private DataNode buildDataNode(final Anchor anchor, final String parentNodeXpath, final String nodeData, - final ContentType contentType) { - final SchemaContext schemaContext = getSchemaContext(anchor); - - if (ROOT_NODE_XPATH.equals(parentNodeXpath)) { - final ContainerNode containerNode = timedYangParser.parseData(contentType, nodeData, schemaContext); - return new DataNodeBuilder().withContainerNode(containerNode).build(); - } - - final ContainerNode containerNode = - timedYangParser.parseData(contentType, nodeData, schemaContext, parentNodeXpath); - - return new DataNodeBuilder() - .withParentNodeXpath(parentNodeXpath) - .withContainerNode(containerNode) - .build(); - } - private Collection buildDataNodes(final Anchor anchor, final Map nodesJsonData) { - return nodesJsonData.entrySet().stream().map(nodeJsonData -> - buildDataNode(anchor, nodeJsonData.getKey(), - nodeJsonData.getValue(), ContentType.JSON)).collect(Collectors.toList()); + final Collection dataNodes = new ArrayList<>(); + for (final Map.Entry nodeJsonData : nodesJsonData.entrySet()) { + dataNodes.addAll(buildDataNodes(anchor, nodeJsonData.getKey(), nodeJsonData.getValue(), ContentType.JSON)); + } + return dataNodes; } private Collection buildDataNodes(final Anchor anchor, final String parentNodeXpath, -- cgit 1.2.3-korg