Versions Compared

Key

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

...


Code Block
titleData Originally Stored
collapsetrue
{
  "book-store:bookstore": {
    "bookstore-name": "Easons",
    "categories": [
      {
        "code": "1",
        "name": "Children",
        "books": [
          {
            "title": "Matilda",
            "lang": "English",
            "price": 20
          },
          {
            "title": "The Gruffalo",
            "lang": "English",
            "price": 15
          }
        ]
      }
    ]
  }
}


Response when querying the list directly.

Code Block
titleCurrent output
collapsetrue
[
  {
    "books": {
      "title": "Matilda",
      "lang": "English",
      "price": 20
    }
  },
  {
    "books": {
      "title": "The Gruffalo",
      "lang": "English",
      "price": 15
    }
  }
]



Code Block
titleExpected Result
collapsetrue
[
  {
    "books": [
      {
        "title": "Matilda",
        "lang": "English",
        "price": 20
      },
      {
        "title": "The Gruffalo",
        "lang": "English",
        "price": 15
      }
    ]
  }
]


This behavior extends to list items stored under root node as well. So, this case needs to be taken into consideration as well

Initial setup to try the sample requests up ahead

To tryout the sample curl requests below please create a simple bookstore entry in your local CPS deployment. Or just execute the following curl request

Code Block
collapsetrue
curl --location 'http://localhost:8883/cps/api/v2/dataspaces/my-dataspace/anchors/bookstore-example/nodes?xpath=%2F' --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: ••••••' --data '{ "bookstore": { "bookstore-name": "Easons", "premises": { "addresses": [ { "house-number": 2, "street": "Main Street", "town": "Maynooth", "county": "Kildare" } ] }, "categories": [ { "code": 1, "name": "Children", "books" : [ { "title": "Matilda", "lang": "English", "authors": ["Roald Dahl"], "editions": [1988, 2000], "price": 20 }, { "title": "The Gruffalo", "lang": "English", "authors": ["Julia Donaldson"], "editions": [1999], "price": 15 } ] }, { "code": 2, "name": "Thriller", "books" : [ { "title": "Annihilation", "lang": "English", "authors": ["Jeff VanderMeer"], "editions": [2014], "price": 15 } ] } ] } } '

Update node leaves

Problem Description

...

Update operation can only be done on one node at a time and when trying to update parent child in one request, then only the parent node is updated.






Code Block
titleOriginal JSON data
collapsetrue
{
  "categories": {
    "code": "1",
    "name": "Children",
    "books": [
      {
	 	"title": "Matilda",
        "lang": "English",
        "price": 200,
        "authors":["Roald Dahl"],
        "editions": [1988,2000]
      }
    ]
  }
}



Code Block
titleJSON to be updated
collapsetrue
{
  "categories": {
    "code": 1,
    "name": "Kids",
    "books": [
      {
        "title": "Matilda",
	 	"price": 20,
		"editions": 
		[1988, 2000, 2022]
      }
    ]
  }
}



Code Block
titleUpdated JSON data
collapsetrue
{
  "categories": {
    "code": "1",
    "name": "Kids",
    "books": [
      {
        "title": "Matilda", 
     	"lang": "English",
        "price": 200,
        "authors": ["Roald Dahl"],
		"editions": [1988,2000]        }
    ]
  }
}


  • The request is executed successfully but only a partial update takes place in the database.
  • So, either the API should reject any request containing multiple nodes or support updating multiple nodes at once.

Replace a node with descendants

...