...
The proposed API will be part of the CPS Data Interface. The following response codes will be returned by the API:
# | Sub Interface | Method | Scenario | HTTP Response codes to be implemented | Notes |
---|---|---|---|---|---|
1 | Data | Proposed API: GET- /v2/dataspaces/{dataspace-name}/anchors/{anchor-name}/delta?xpath={xpath}&descendants={descendants} Proposed method name: CpsDataApi.getDeltaByDataspaceAnchorAndPayload() | Generate a delta report between an anchor and JSON payload |
|
Request parameters:
Parameter name | In | Required | Description |
---|---|---|---|
dataspace-name | Path | Yes | Dataspace name |
anchor | Path | Yes | Anchor Name/Reference Anchor |
xpath | Query | Yes | xpath of the node |
descendants | Query | No | Level of descendants for delta comparison. |
Response Body/Delta Report Format
...
The problem with 2nd Delta API is that it needs to compare any JSON payload to data stored under an anchor. This JSON payload can be coming from any source and regardless of its schema a delta should be generated between the payload and the data under the anchor.
...
The most feasible alternative is to make use of JSON Nodes along with JSON path. Where JSON Nodes and JSON Path are used as a replacement for DataNodes and xPaths respectively.
Proposed Solutions
Use of JSON Nodes and JSON Path
...
Also, the existing delta algorithm can then be modified and reused for JSON path and JSON nodes.
Separation of Added Nodes from the JSON payload
Another approach to determine the delta between the anchor data and JSON payload can be implemented as follows.
- Step 1: The anchor data and JSON payload are fetched as JSON strings.
- Step 2: The JSON payload is compared to the JSON string from the anchor and all the newly added data nodes in JSON payload are extracted to a separate JSON string, while simultaneously removing this newly added data from the JSON payload.
- Step 3: After step 2 the JSON payload will be split into two JSON strings, one containing the Unmodified, Updated and Deleted data and second containing only the Added data.
- Step 4: The JSON string from anchor and the JSON string containing the Unmodified, Updated and Deleted data can then be parsed into DataNodes, as at this point, we can be sure that all the data in the particular JSON string will belong to the schema, which can then be used by the existing algorithm to find the delta. This part of delta report will contain the action, xpath and source/target data.
- Step 5: The added data can then be put in the delta report, but since this approach assumes that all the added data nodes are not part of the schema, it is not possible to determine their xpath and hence the field for xpath can be redacted for added data nodes in this approach.
Exapmle:
JSON Data from Anchor | JSON payload | Added Data | Modified JSON payload after removing added data | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
|
|
Note |
---|
Note: Open for suggestions for alternative approaches |
...