You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

With recent developments in the CPS core API's a few inconsistencies that were observed with the Get Data Node API. The goal of this wiki is to provide the analysis of these inconsistencies, how these functional inconsistencies compare against the Query API and some possible solutions to them.

Inconsistent response when retrieving data nodes.

When a get operation is performed on Root node xpath (/) it returns an array list containing all the data nodes under the root node xpath. But if the same operation is performed for a List Data node no array list is returned instead a 404 Not Found response is returned.

Requesting data under root node xPath
/v2/dataspaces/my-dataspace/anchors/multipleTop/node?xpath=/&descendants=3
Response
[
    {
        "stores:bookstore": {
            "store-name": "My Bookstore",
            "store-owner": "James",
            "categories": [
                {
                    "name": "Test book",
                    "price": 100,
                    "stock": false,
                    "book-category": "SciFi"
                }
            ]
        }
    },
    {
        "stores:electronics-store": {
            "store-name": "My Electronics store",
            "category": [
                {
                    "status": true,
                    "address": "India",
                    "store-type": "electronics"
                }
            ]
        }
    }
]
Requesting entire List using Get Data Node API
/v2/dataspaces/my-dataspace/anchors/multipleTop/node?xpath=/bookstore/categories&descendants=3
Response
{
    "status": "404 NOT_FOUND",
    "message": "DataNode not found",
    "details": "DataNode with xpath /bookstore/categories was not found for anchor multipleTop and dataspace my-dataspace."
}


Similarly, when the comparing the Get Data Node API to Query API, it was observed that when a Query is performed on a List data node then all the list items are returned, but when the same operation is performed using Get Data Node API it returns 404 Not Found as response.

Requesting an entire List

Requesting entire List using Query API and xPath
/v2/dataspaces/my-dataspace/anchors/multipleTop/nodes/query?cps-path=/bookstore/categories&descendants=3


Response by Query API
[
    {
        "stores:categories": {
            "name": "Cook book",
            "price": 500,
            "stock": true,
            "book-category": "Cooking"
        }
    },
    {
        "stores:categories": {
            "name": "Test book",
            "price": 100,
            "stock": false,
            "book-category": "SciFi"
        }
    }
]

Reason for the inconsistency

When we look at the way the data is being stored in CPS DB we can see that when storing a List Data Node, the entire list is not stored under a single xPath referring to the list data node.

Instead, each individual list item is stored in the CPS DB with its along with its unique xPath which consists of the name of List Data node and the corresponding "key" leaf or "key" attribute.

And hence there is currently the entire list cannot be retrieved by the xPath for the List Data Node and only the individual list items can be retrieved.

"xpath"

"attributes"


"/bookstore"

"{""store-name"": ""My Bookstore"", ""store-owner"": ""James""}"

"/bookstore/categories[@book-category='SciFi']"

"{""name"": ""Test book"", ""price"": 100, ""stock"": false, ""book-category"": ""SciFi""}"

"/bookstore/categories[@book-category='Cooking']"

"{""name"": ""Cook book"", ""price"": 500, ""stock"": true, ""book-category"": ""Cooking""}"

"/electronics-store""{""store-name"": ""My Electronics store""}"

"/electronics-store/category[@store-type='electronics']"

"{""status"": true, ""address"": ""India"", ""store-type"": ""electronics""}"

In the above table we can see that the the individual list items of the list "Categories" are stored with respect to their unique xpaths and no xPath such as /bookstore/categories exists in the DB.

Possible Solutions

Using a special character in the xPath for Get Data Node API

By using a special character as part of the attribute in xPath we can implement a logic to retrieve the entire List data node.

For instance, to retrieve the entire list we can use an asterisk symbol in the attributes part of the xPath . And a logic can be implemented where if the asterisk is present in the attribute part of the xPath then CPS should return the entire list data node.

Sample Request
/v2/dataspaces/my-dataspace/anchors/multipleTop/node?xpath=/bookstore/categories[@category=*]&descendants=3

In the above request our xPath looks something looks like this:

xPath with asterisk symbol as attribute
/bookstore/categories[@type=*]
Expected Response
[
    {
        "stores:categories": {
            "name": "Cook book",
            "price": 500,
            "stock": true,
            "book-category": "Cooking"
        }
    },
    {
        "stores:categories": {
            "name": "Test book",
            "price": 100,
            "stock": false,
            "book-category": "SciFi"
        }
    }
]

Redirect request to the Query API

Another proposed approach is to redirect the request to the Query API when a list data node is requested.

Note: The problem with this approach is to identify whether the request data node is a list or not, by using the xpath provided in the Get request.

Implement a logic to retrieve all data nodes when a list is requested

Another approach could be to implement logic to retrieve all the list items when a List data node is queried, similar to the approach taken in Query API.


  • No labels