sul-dlss / purl-fetcher

An HTTP API for querying and updating PURLs
0 stars 1 forks source link

Handle external identifiers for /resources controller #773

Closed jcoyne closed 2 months ago

jcoyne commented 3 months ago

When you upload a file, the cocina should be written with the correct file identifiers.

Currently the published cocina constructs a file externalIdentifier by appending the filename to the fileSets externalIdentifier (and sub(/\/fileSet\/, 'file')):

  "structural": {
    "contains": [
      {
        "type": "https://cocina.sul.stanford.edu/models/resources/image",
        "externalIdentifier": "https://cocina.sul.stanford.edu/fileSet/tc504hx8387-727eb94a-71ae-46c8-a6f5-b26a3c3992e0",
        "label": "Object 1",
        "version": 1,
        "structural": {
          "contains": [
            {
              "type": "https://cocina.sul.stanford.edu/models/file",
              "externalIdentifier": "https://cocina.sul.stanford.edu/file/tc504hx8387-727eb94a-71ae-46c8-a6f5-b26a3c3992e0/example.jp2",
              "label": "example.jp2",
              "filename": "example.jp2",
              "size": 11043,
              "version": 1,
              "hasMimeType": "image/jp2",
              "hasMessageDigests": [
                {
                  "type": "md5",
                  "digest": "8ff299eda08d7c506273840d52a03bf3"
                },
                {
                  "type": "sha1",
                  "digest": "f11c7c172a285dc9dc948fbe2934c401e5aa8200"
                }
              ],
              "access": {
                "view": "world",
                "download": "none",
                "controlledDigitalLending": false
              },
              "administrative": {
                "publish": true,
                "sdrPreserve": false,
                "shelve": true
              }
            }
          ]
        }
      }
    ],
justinlittman commented 3 months ago

I'd suggest that:

jcoyne commented 3 months ago

You are right that we have not been consistent. This is how file identifiers are constructed in SDR-API https://github.com/sul-dlss/sdr-api/blob/3a0eca315b950e31cc93fd303588da95936bb9bc/app/controllers/resources_controller.rb#L143-L145

Here is a way we do it in pre-assembly: https://github.com/sul-dlss/pre-assembly/blob/952882872743d12991f8e7f93b9dcad9a4ac7b45/app/lib/pre_assembly/file_identifier_generator.rb#L9

And yet another way in DSA: https://github.com/sul-dlss/dor-services-app/blob/main/app/services/cocina/id_generator.rb#L27-L29