X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cps-service%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fcps%2Futils%2FDataMapUtils.java;h=42719d9b3cd55277d27187af754f72e1f4cdbe20;hb=ebfa4077b2e462237301e93566fed6ef2f56674c;hp=3ee6afb719a6e8e05997b74cdbd5ecc2c913052a;hpb=95843555f6a1d6b61db61ebd8cd452b63c8efbc2;p=cps.git 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 3ee6afb719..42719d9b3c 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()) @@ -58,7 +69,7 @@ public class DataMapUtils { return ImmutableMap.builder() .putAll( dataNodes.stream() - .filter(dataNode -> isListNode(dataNode.getXpath())) + .filter(dataNode -> isListElement(dataNode.getXpath())) .collect(groupingBy( dataNode -> getNodeIdentifier(dataNode.getXpath()), mapping(DataMapUtils::toDataMap, toUnmodifiableList()) @@ -86,10 +97,10 @@ public class DataMapUtils { } private static boolean isContainerNode(final String xpath) { - return !isListNode(xpath); + return !isListElement(xpath); } - private static boolean isListNode(final String xpath) { + private static boolean isListElement(final String xpath) { return xpath.endsWith("]"); } }