Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Jira Legacy
serverSystem ONAP Jira
columnIdsissuekey,summary,issuetype,created,updated,duedate,assignee,reporter,priority,status,resolution
columnskey,summary,type,created,updated,due,assignee,reporter,priority,status,resolution
serverId4733707d425b2b0a-2057557c-3a0f3c0c-ae5eb515-4fd8aff50176579789cceedb
keyCPS-461

Table of Contents

Introduction

Yang module used for testing

Code Block
languagexml
titlebookstore.yang
collapsetrue
module stores {
    yang-version 1.1;
    namespace "org:onap:ccsdk:sample";

    prefix book-store;

    revision "2020-09-15" {
        description
        "Sample Model";
    }

    typedef year {
        type uint16 {
            range "1000..9999";
        }
    }

    container bookstore {

        leaf bookstore-name {
            type string;
        }

    list categories {

        key "code";

        leaf code {
            type string;
        }

        leaf name {
            type string;
        }

        list books {
            key title;

            leaf title {
                type string;
            }
            leaf lang {
                type string;
            }
            leaf-list authors {
                type string;
            }
            leaf pub_year {
                type year;
            }
            leaf price {
                type uint64;
            }
        }
    }
    }
}

...

It has been noted that the json content for read and write requests in CPS-Core is inconsistent

SolutionsIssuesObtain the schema node {

{
   "bookstore-name":"Chapters",


   "categories":[

...

]

]
}

{



DescrtiptionDescriptionResponse for getDataNode body when writing (root) DataNode
OperationGETPOST/PUT
xPath//

ResponeResponse

/Body

Code Block
Code Block

{
   "bookstore":{


     "bookstore-name":"Chapters",


      "categories":[

...

] } }
wrapped using module information

r is

...

]
  }
}

NotesThe response includes the 'value' of the bookstore node ie. the leaves and childrenthe body needs to include the whole container object.


Solution

#SolutionsIssues
1Obtain the  container from the xpath of the queried node. Node xpath will be /bookstore/categories[@code='01'] where bookstore is the container name given in the module info.This should be reasonably straightforward as the top level node is named after the container name given by the module yang file.
2Create a query to obtain the schema node directly from the database using and propagate through persistence and service layers.Would need to create a new query which would parse the json data from the yang_resource content and find the container name which is very memory intensive for its use case. Also would need to pass a new schema node object to the toDataMap method which would not be used every time which it is called.

...

For the JSON output of Get DataNode we need to alter the DataMapUtils class. The function toDataMap translates a datanode object to a JSON output:


public static Map<String, Object> toDataMap(final DataNode dataNode) {
final boolean isTopLevelNode = dataNode.getXpath().lastIndexOf('/') == 0;
if (isTopLevelNode) {
String containerName = dataNode.getXpath().substring(1);
return ImmutableMap.<String, Object>builder().put(containerName,
ImmutableMap.<String, Object>builder()
.putAll(dataNode.getLeaves())
.putAll(listElementsAsMap(dataNode.getChildDataNodes()))
.putAll(containerElementsAsMap(dataNode.getChildDataNodes()))
.build()
).build();
} else {
return ImmutableMap.<String, Object>builder()
.putAll(dataNode.getLeaves())
.putAll(listElementsAsMap(dataNode.getChildDataNodes()))
.putAll(containerElementsAsMap(dataNode.getChildDataNodes()))
.build();
}
}

We only want the container name on the top level of the JSON output and as such have to distinguish between a top level node and non top level node. We create an outer map to wrap the inner map which creates the appropriate levels in the JSON output. 

This produces the following response in the Post Request output:

{
    "bookstore": {
        "bookstore-name": "Easons",
        "categories": [
            {
                "code": "01",
                "name": "SciFi"
            }
        ]
    }
}

Tests would need to be updated to accept the new JSON output which is returned. Examples would need to be updated in openapi

...