Align JSON DataNode for Get and Post/Put API in CPS
[cps.git] / cps-service / src / main / java / org / onap / cps / utils / DataMapUtils.java
index 71a95f1..42719d9 100644 (file)
@@ -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<String, Object> toDataMapWithIdentifier(final DataNode dataNode) {
+        return ImmutableMap.<String, Object>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<String, Object> toDataMap(final DataNode dataNode) {
         return ImmutableMap.<String, Object>builder()
             .putAll(dataNode.getLeaves())