You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 19 Next »

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

1Add 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:

  • Add: If the target location in the source document specifies an object member that does not already exist, and a new member is added to the object, then its an add operation
  • Remove: if the target location in the source document already had a member and the member was removed from the target document then its remove operation
  • Replace/Update: If the target location specifies an object member that does exist, and that member's value is replaced, then its a replace operation
  • Here target location is equivalent to the path of particular leaf
  • So, there it should be Add/Delete.
  • Discussed in detail below
Add/Delete as per notes on the left
2How to handle multiple changes at different levels?Example: 
  • if you compare multiple levels and say a grandchild of a the node you are comparing has been added or deleted is that an UPDATE  or just a ADD/DELETE at that level

There could be Many more complex scenarios....


3More scenarios need to be explored and documented in detail. Such as handling arrays within a json, handling child/grandchild changes.

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 InterfaceMethodScenario

HTTP Response codes

to be implemented

Notes
1Data

Proposed API:

GET- /v1/dataspaces/{dataspace-name}/delta?anchor1={anchor-name}?anchor2={anchor-name}?xpath={xpath}&descendants={descendants}

Proposed method name:  <decision pending>

Generate a delta report between 2 anchors in a given dataspace.

  • 200 (OK)
    • success
  • 400
    • dataspace not found
      DataspaceNotFoundException
    • anchor not found
      AnchorNotFoundException
    • Data node not found
      DataNodeNotFoundException
    • invalid xpath
      CpsPathException
  • 500
    • unexpected error
AnchorNotFoundException should provide the name of missing anchor from the given two anchor names.

Request parameters:

Parameter nameInRequiredDescription
dataspace-namePathYesDataspace name
anchor1QueryYesFirst Anchor Name/Reference Anchor
anchor2QueryYesSecond Anchor Name
xpathQueryYesxpath of the node
descendantsQueryNoLevel of descendants for delta comparison. 

Response Body/Delta Report Format

Response body should contain anchors delta report (added/deleted/modified configuration) as below.
[
  {
    "action": "ADD",
    "xpath": "/bookstore/categories/[@code=3]",
    "payload": {
      "code": 3,
      "name": "kidz"
    }
  },
  {
    "action": "DELETE",
    "xpath": "/bookstore/categories/[@code=1]",
    "payload": {
      "code": 1,
      "name": "Fiction"
    }
  },
  {
    "action": "UPDATE",
    "xpath": "/bookstore/categories/[@code=2]",
    "payload": {
      "name": "Comic"
    }
  }
]

Mechanism for Delta generation

CPS Delta Flowchart

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:

OperationDescriptionDelta report equivalent
addAdds the value at the target location; if the value exists in the given location, it’s replacedif the value is not present in the source json, but was found in the comparand json, then it should be considered an "add" action
removeRemoves the value at the target locationif a value was present at the source json, but was not found in the comparand json, then it should be considered as "delete" action
replaceReplaces the value at the target locationif 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
moveRemoves the value at a specified location and adds it to the target locationN/A
copyCopies the value at a specified location to the target locationN/A
testTests that a value at the target location is equal to a specified valueN/A
Sample JSON Patch
[
     { "op": "test", "path": "/a/b/c", "value": "foo" },
     { "op": "remove", "path": "/a/b/c" },
     { "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] },
     { "op": "replace", "path": "/a/b/c", "value": 42 },
     { "op": "move", "from": "/a/b/c", "path": "/a/b/d" },
     { "op": "copy", "from": "/a/b/d", "path": "/a/b/e" }
   ]
  • No labels