Versions Compared

Key

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

...

#

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....

Replied below


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

...

The reason for this being that the particular child/grandchild is in itself a unique data node and can be queried with its own xpath and hence any operation on the particular child/grandchild should be treated as an operation on the particular node rather than an operation on its parent.

Proposed Algorithm

The JSON data stored in CPS can be retrieved as Maps, And using this we can find the delta between two anchors retrieved as two separate Maps. The result can be stored in an JSON array with appropriate notations for action, xpath and payload.

Algorithm:

  1. Create an empty JSON Array, to store the result
    • The JSON array will contain the following: action, xpath, payload as individual JSON objects each object representing a singular operation.
  2. Fetch the data from two anchors and store in two separate Maps
  3. Iterate over the entries of first map
  4. For each entry of first map, check if the key is present in second map.
  5. If the key is not found in second map, it means that the key-value pair has been removed from the second map. Create a JSON Object with DELETE action, the xpath to deleted node and payload. Add the Object to the JSON Array.
  6. If the key is present in the second map, compare the values associated with the keys in both maps.
  7. If the values are instance of Map, recursively call the comparision algorithm to compare all nested maps. Add all the necessary fields into a JSON object and put the object into the JSON Array
  8. If the values are not equal, it means the key-value pair was updated. Create a JSON Object with UPDATE action, the xpath to updated nodes and payload. Add the Object to the JSON Array.
  9. Iterate over the keys of second map and find the keys not present in first map. These keys were added as new entries. Create a JSON Object with ADD action, the xpath to added node and payload. Add the Object to the JSON Array.
  10. Return the JSON Array