CPS Delta feature Exceptions
Where ever possible the Delta Feature will throw the same exceptions as defined in CPS core. If any new exception for the delta feature are required the following will be updated here.
Issues & Decisions
# | Issue | Notes | Decision |
---|---|---|---|
1 | Add or Delete leaves (optional leaves) handle as UPDATE or ADD/DELETE ? | The delta report proposed follows the Json Patch format of representing the differences between 2 json. Going by the general convention, referring RFC-6902:
| |
2 | How to handle multiple changes at different levels? | Example:
There could be Many more complex scenarios.... | |
3 | The above scenarios need to be explored and documented in detail. Such as handling arrays within a json. | ||
4 | Need to decide what the action/operation should be called. | Proposed: Add/Delete/Update RFC-6902: add/remove/replace |
HTTP response codes for Delta API
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- /v1/dataspaces/{dataspace-name}/delta?firstAnchor={anchor-name}?secondAnchor={anchor-name}?xpath={xpath}&descendants={descendants} Proposed method name: <decision pending> | Generate a delta report between 2 anchors in a given dataspace. |
| AnchorNotFoundException should provide the name of missing anchor from the given two anchor names. |
Request parameters:
Parameter name | In | Required | Description |
---|---|---|---|
dataspace-name | Path | Yes | Dataspace name |
firstAnchor | Query | Yes | First Anchor Name/Reference Anchor |
secondAnchor | Query | Yes | Second Anchor Name |
xpath | Query | Yes | xpath of the node |
descendants | Query | No | Number of descendants for delta comparison. |
Response Body/Delta Report Format
Mechanism for Delta generation
Additional Details
Format/Conventions to be used for Delta Report (not finalized)
There are several ways of representing the differences between JSON but here we discuss the JSON Patch format of representing these differences because the proposed Delta report closely represents JSON patch with a few differences. This approach focuses in producing another JSON document that represents the differences between the two JSON's that have been compared.
JSON Patch
JSON Patch defines a JSON document structure for expressing a sequence of operations to apply to a JavaScript Object Notation(JSON) document; it is suitable for use with the HTTP PATCH method. The "application/json-patch+json" media type is used to identify such patch documents.
But in it can also be used to get the differences between two JSON as the JSON patch document represents an array of objects. where each object represents a single operation(op), path and value.
Here the notation of operation is used as the same JSON Patch document can be used to perform HTTP Patch operations. But The operations field can be used as a reference to decide how the "action" field should function in the implementation of Delta report.
The operation "op
" field in a JSON patch document can have following values:
Operation | Description | Delta report equivalent |
---|---|---|
add | Adds the value at the target location; if the value exists in the given location, it’s replaced | if the value is not present in the source json, but was found in the comparand json, then it should be considered an "add" action |
remove | Removes the value at the target location | if a value was present at the source json, but was not found in the comparand json, then it should be considered as "delete" action |
replace | Replaces the value at the target location | if a value is present in the source json, but an updated value is present in the comparand json, then it will be considered as "update" action |
move | Removes the value at a specified location and adds it to the target location | N/A |
copy | Copies the value at a specified location to the target location | N/A |
test | Tests that a value at the target location is equal to a specified value | N/A |