...
NormalizedNodeResult | NormalizedNodeContainerBuilder | ||||
---|---|---|---|---|---|
|
| ||||
|
|
Impact analysis on
...
remaining CPS core API's
After updating the post operation to support multiple data trees. the following problems issues were noticed with the GET APIremaining API's in CPS
Get a node
When passing the xpath value as root(/) in the query parameter, the expected response should return all the data trees stored under a particular, But currently the Get API only returns the first data tree under the particular anchorCode Block //Expected Response with xpath= / as query parameter { "first-container": { "a-leaf": "a-Value" }, "last-container": { "x-leaf": "x-value" } }
Code Block //Response received { "multipleDataTree:first-container": { "a-leaf": "a-Value" } }
Code Block //Confirmation test to check that all data trees exist under the particular anchor by passing individual container names // Response when xpath=/first-container in query parameter { "multipleDataTree:first-container": { "a-leaf": "a-Value" } } // Response when xpath=/last-container in query parameter { "multipleDataTree:first-container": { "a-leaf": "a-Value" } }
Update a node
The update node API performs update operation on a single data tree. In order to perform the update operation on an existing data tree the update API first performs a get operation using the following method:Code Block public void updateDataNodeAndDescendants(final String dataspaceName, final String anchorName, final DataNode dataNode) { //performing a Get operation to retrieve a Fragment entity final FragmentEntity fragmentEntity = getFragmentWithoutDescendantsByXpath(dataspaceName, anchorName, dataNode.getXpath()); updateFragmentEntityAndDescendantsWithDataNode(fragmentEntity, dataNode); try { fragmentRepository.save(fragmentEntity); } catch (final StaleStateException staleStateException) { throw new ConcurrencyException("Concurrent Transactions", String.format("dataspace :'%s', Anchor : '%s' and xpath: '%s' is updated by another transaction.", dataspaceName, anchorName, dataNode.getXpath())); } }
The getFragmentWithoutDescendantsByXpath() used to method used to return a single FragmentEntity using the getFragmentByXpath() method.
- The same method was also used by the GET API to get a single data tree,
- But now that we have support for multiple data tress under a single Anchor the getFragmentByXpath() returns multiple FragmentEntities, each for the respective data tree when the xpath is set to root(/).
- Now since getFragmentWithoutDescendantsByXpath() also uses getFragmentByXpath() to get FragmentEntities, it now returns a list of Fragment Entities
- But it is to be noted that this operation will not be feasible for Update operation with xpath set to root(/)
- For instance
- If there are 10 data trees stored under an Anchor
- An update operation is to be performed on any 2 of the data trees
- Then it is not feasible to get all the data trees by passing the xpath as root and then updating only the desired number of data trees (here in this example 2 data trees)
- Rather it will be better to update the data trees individually
- An argument can be made, what if there is a need to update all data trees or majority of data trees.
- An update operation with xpath as root in such case can be feasible. But the probability of such scenario is something to be thought upon
- Also in such a scenario where a major chunk of old data trees is changed, a fresh data node can be created containing the updated data trees and the old data trees can be deleted.