From ebfa4077b2e462237301e93566fed6ef2f56674c Mon Sep 17 00:00:00 2001 From: "puthuparambil.aditya" Date: Mon, 14 Feb 2022 10:56:35 +0000 Subject: Align JSON DataNode for Get and Post/Put API in CPS Issue-ID: CPS-865 Signed-off-by: puthuparambil.aditya Change-Id: I60b1f9c94e79bdd66d60fe6a68f5fc4adc718d35 --- .../onap/cps/notification/CpsDataUpdatedEventFactory.java | 2 +- .../src/main/java/org/onap/cps/utils/DataMapUtils.java | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'cps-service/src/main') diff --git a/cps-service/src/main/java/org/onap/cps/notification/CpsDataUpdatedEventFactory.java b/cps-service/src/main/java/org/onap/cps/notification/CpsDataUpdatedEventFactory.java index e7b639d48..1013c13b7 100644 --- a/cps-service/src/main/java/org/onap/cps/notification/CpsDataUpdatedEventFactory.java +++ b/cps-service/src/main/java/org/onap/cps/notification/CpsDataUpdatedEventFactory.java @@ -89,7 +89,7 @@ public class CpsDataUpdatedEventFactory { private Data createData(final DataNode dataNode) { final var data = new Data(); - DataMapUtils.toDataMap(dataNode).forEach(data::setAdditionalProperty); + DataMapUtils.toDataMapWithIdentifier(dataNode).forEach(data::setAdditionalProperty); return data; } diff --git a/cps-service/src/main/java/org/onap/cps/utils/DataMapUtils.java b/cps-service/src/main/java/org/onap/cps/utils/DataMapUtils.java index 71a95f1ca..42719d9b3 100644 --- a/cps-service/src/main/java/org/onap/cps/utils/DataMapUtils.java +++ b/cps-service/src/main/java/org/onap/cps/utils/DataMapUtils.java @@ -36,13 +36,24 @@ import org.onap.cps.spi.model.DataNode; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class DataMapUtils { + /** + * Converts DataNode structure into a map including the root node identifier for a JSON response. + * + * @param dataNode data node object + * @return a map representing same data with the root node identifier + */ + public static Map toDataMapWithIdentifier(final DataNode dataNode) { + return ImmutableMap.builder() + .put(getNodeIdentifier(dataNode.getXpath()), toDataMap(dataNode)) + .build(); + } + /** * Converts DataNode structure into a map for a JSON response. * * @param dataNode data node object * @return a map representing same data */ - public static Map toDataMap(final DataNode dataNode) { return ImmutableMap.builder() .putAll(dataNode.getLeaves()) -- cgit 1.2.3-korg