CenterForDigitalHumanities / TPEN-services

Services required by TPEN interfaces in order to interact with data
1 stars 0 forks source link

Create new Project Layers in databases #95

Open thehabes opened 3 months ago

thehabes commented 3 months ago

An Annotation Collection is a collection of Annotation Pages from the Web Annotation standard. Each Project has at least one Layer, which is encoded as an Annotation Collection, saved to RERUM (db driver "tiny"). This Linked Data standard adds a few requirements and a minimal example will look like this:

{
  "@context": "http://www.w3.org/ns/anno.jsonld",
  "id": "https://store.rerum.io/v1/id/collectionHex",
  "type": "AnnotationCollection",
  "label": "Project - Layer Title",
  "creator": "https://store.rerum.io/v1/id/agentHex",
  "total": 2,
  "first": "http://example.org/page1",
  "last": "http://example.org/page42",
  "partOf": "https://static.t-pen.org/hex/project.json"
}

In this document, @context, type, and @id are required and will be constant values. The label is provided by the Interface (User input or generated), creator is the authenticated User agent. The list of items provided by the request will determine the values for total (a count), and first and last. The accessory partOf property holds a public pointer back to the TPEN project built from the Project stub or hexString portion of the Project _id and the static TPEN cache.

The @id of this object will be the reference recorded into the Project record in the local "mongo" database. The hex portion of the @id can be generated ahead of time so that you do not have to wait for all the create actions to complete. #93 shows what the Project looks like and updating it can be stubbed and is not in scope for this.

The API expects to save a list of Annotation Pages, aligning with Canvases from the linked Manifest(s) on the Project.

Expected Behavior

The API will be waiting for a POST at /project/{:id}/addLayer with :id as the stub or _id hexString with an effective payload like:

{
  "label" : "Project - Layer Title",
  "creator" : "https://store.rerum.io/v1/id/agentHex",
  "items" : [{
    "@context": "http://www.w3.org/ns/anno.jsonld",
    "id": "https://store.rerum.io/v1/id/page1",
    "type": "AnnotationPage",
    "partOf": "https://store.rerum.io/v1/id/collection",
    "target" : "https://manifest/canvas/1",
    "next": "https://store.rerum.io/v1/id/page2",
    "items": [
      {
        "id": "https://store.rerum.io/v1/id/anno1",
        "type": "Annotation",
        "body": "http://example.net/comment1",
        "target": "http://example.com/book/chapter1"
      }, ...
    ]
  }, ... ]
}

however, since much of this is boilerplate or otherwise available to the API, it simplifies to:

{
  "label" : "Project - Layer Title",
  "items" : [{
    "id": "https://store.rerum.io/v1/id/page1",
    "target" : "https://manifest/canvas/1",
    "items": [
      {
        "id": "https://store.rerum.io/v1/id/anno1",
        "type": "Annotation",
        "body": "http://example.net/comment1",
        "target": "http://example.com/book/folio1"
      }, ...
    ]
  }, ... ]
}

Note: The target property is unusual on an Annotation Page, but is used here appropriately to link the Manifest(s) being annotated and the related Project via their member Canvas and Layer documents.

A valid Layer must have at least 1 Annotation Page, which in turn have 0 or more Annotations. Though an id can be prepopulated, it is not invalid to leave it off the API request. Similarly, a label is optional, however helpful. In this way, the minimal valid request is { "items" : [ "target" : "https://manifest/canvas/1" ] } representing an unannotated singular image without description.

The API service is responsible for building out the various documents in this Collection.

cubap commented 3 months ago

Make sure tests for these pieces stay in scope; we don't need testing all the way along, but we need to promise that invalid documents error out and that no matter what the final format meets minimum requirements.