Initial Findings
It was found that the V1 of Get Data Node API would always return the first data node under an anchor. So if there are multiple data nodes stored under an anchor, when the Get operation was performed to retrieve all data nodes(by setting the xPath as root node xPath"/"), then only the first data node in the stack would be returned.
Also when the get operation is performed to retrieve individual parent data nodes under an anchor, the data nodes are retrieved successfully. Hence proving that even when multiple data nodes exist under an anchor, only one of them can be retrieved at a time and when trying to retrieve all of them by using root node xPath the operation only returns the first data node.
Decisions
After team discussion based on the findings mentioned below, it was decided to release V2 of Get Data Node API, where in the response body was to be updated to be a JSON array. And within this array individual data trees would be returned.
JSON Data Stored in CPS DB using POST operation
The following JSON data was first stored in CPS DB, then to test the GET operation:
{ "first-container": { "a-leaf": "a-Value" }, "last-container": { "x-leaf": "x-value" } }
Analysis of Get a Node API
Currently after multiple data trees are stored in CPS DB. On performing the GET operation on the same data, with xpath set as root "/", the first data tree is returned by the Get Data Node API. This data tree is returned in form of a JSON Object as follows:
CURL Request:
curl --location 'http://localhost:8080/cps/api/v1/dataspaces/testDataspace/anchors/sample/node?xpath=%2F' \ --header 'Accept: application/json' \ --header 'Authorization: Basic Y3BzdXNlcjpjcHNyMGNrcyE='
Response:
Expected Outcome
After the GET API is updated, we want all the data trees to be returned when the xpath is set to root "/" and when a specific xpath is provided we want the functionality to remain as is.
Based on the existing GET request there are two possible responses we can get here:
Data returned as a JSON array, with the array containing individual data trees (This approach was finalized to be implemented in V2 of get API)
Data Returned as a JSON object, with all data trees in a single object