Versions Compared

Key

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

...

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

  • 200 (OK)
    • success
  • 400
    • dataspace not found
      DataspaceNotFoundException
    • anchor not found
      AnchorNotFoundException
    • Data node not found
      DataNodeNotFoundException
    • invalid xpath
      CpsPathException
  • 500
    • unexpected error

Request parameters:

Parameter nameInRequiredDescription
dataspace-namePathYesDataspace name
anchorPathYesAnchor Name/Reference Anchor
xpathQueryYesxpath of the node
descendantsQueryNoLevel 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 AnchorJSON payloadAdded DataModified JSON payload after removing added data


Code Block
collapsetrue
{
  "test:bookstore": {
    "bookstore-name": "Chapters/Easons",
    "categories": [
      {
        "code": "01/1",
        "name": "SciFi",
        "books": [
          {
            "authors": [
              "Iain M. Banks"
            ],
            "lang": "en/it",
            "price": "895",
            "pub_year": "1994",
            "title": "Feersum Endjinn/Endjinn Feersum"
          },{
            "authors": [
              "Ursula K. Le Guin"
            ],
            "lang": "en",
            "price": "1099",
            "pub_year": "1999",
            "title": "Far Horizons"
          }
        ]
      },{
        "name": "Horror",
        "code": "03",
        "books": [
          {
            "authors": [
              "ABC"
            ],
            "lang": "en",
            "price": "699",
            "pub_year": "1995",
            "title": "Horror Book"
          }
        ]
      }
    ],
  }
}



Code Block
collapsetrue
{
  "test:bookstore": {
    "bookstore-name": "Chapters/Easons",
    "categories": [
      {
        "code": "01/1",
        "name": "SciFi",
        "books": [
          {
            "authors": [
              "Iain M. Banks"
            ],
            "lang": "en/it",
            "price": "895",
            "pub_year": "1994",
            "title": "Feersum Endjinn/Endjinn Feersum"
          },
          {
            "authors": [
              "Ursula K. Le Guin"
            ],
            "lang": "en",
            "price": "1099",
            "pub_year": "1999",
            "title": "Far Horizons"
          }
        ]
      },
      {
        "name": "kids",
        "code": "02",
        "books": [
          {
            "authors": [
              "Philip Pullman"
            ],
            "lang": "en",
            "price": "699",
            "pub_year": "1995",
            "title": "The Golden Compass"
          }
        ]
      },
      {
        "name": "Horror",
        "code": "03",
        "books": [
          {
            "authors": [
              "ABC"
            ],
            "lang": "en",
            "price": "699",
            "pub_year": "1995",
            "title": "Horror Book"
          }
        ]
      }
    ],
    "bookstore-phone": "123",
    "bookstore-emp": { }
  },
  "test:bookstore2": {
    "bookstore-name": "Test"
  }
}



Code Block
collapsetrue
{
  "test:bookstore" : {
    "categories" : [ {
      "name" : "kids",
      "code" : "02",
      "books" : [ {
        "authors" : [ "Philip Pullman" ],
        "lang" : "en",
        "price" : "699",
        "pub_year" : "1995",
        "title" : "The Golden Compass"
      } ]
    } ],
    "bookstore-phone" : "123",
    "bookstore-emp" : { }
  },
  "test:bookstore2" : {
    "bookstore-name" : "Test"
  }
}



Code Block
collapsetrue
{
  "test:bookstore": {
    "bookstore-name": "Chapters/Easons",
    "categories": [
      {
        "code": "01/1",
        "name": "SciFi",
        "books": [
          {
            "authors": [
              "Iain M. Banks"
            ],
            "lang": "en/it",
            "price": "895",
            "pub_year": "1994",
            "title": "Feersum Endjinn/Endjinn Feersum"
          },
          {
            "authors": [
              "Ursula K. Le Guin"
            ],
            "lang": "en",
            "price": "1099",
            "pub_year": "1999",
            "title": "Far Horizons"
          }
        ]
      },
      {
        "name": "Horror",
        "code": "03",
        "books": [
          {
            "authors": [
              "ABC"
            ],
            "lang": "en",
            "price": "699",
            "pub_year": "1995",
            "title": "Horror Book"
          }
        ]
      }
    ]
  }
}



Note
Note: Open for suggestions for alternative approaches

...