Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Workbench use Drupal's built in REST interfaces for files and media #171

Closed
mjordan opened this issue Dec 9, 2020 · 8 comments
Closed
Assignees
Labels
code cleanup Clean up code, including code-level comments

Comments

@mjordan
Copy link
Owner

mjordan commented Dec 9, 2020

... instead of using Islandora's MediaSourceController. As discussed at the 2020-12-09 Islandora 8 Tech call re. Islandora/documentation#1481, this controller provides a lot of Islandora-specific plumbing that it would be disruptive and difficult to refactor. It is likely to be an order of magnitude simpler to adapt Workbench's create_media() function to use Drupal's File and Media REST resources to attach a file and then a media to a node.

@mjordan mjordan added the code cleanup Clean up code, including code-level comments label Dec 9, 2020
@mjordan mjordan self-assigned this Dec 9, 2020
@mjordan
Copy link
Owner Author

mjordan commented Jan 27, 2021

Probably wait until Islandora ships with Drupal 9.1 to implement this, since creating media via REST suffered from https://www.drupal.org/project/drupal/issues/3072076. After that is fixed, the following should work:

curl -v -X POST -uadmin:islandora -H'Accept: application/vnd.api+json' -H'Content-Type: application/octet-stream' -H'Content-Disposition: file; filename="test.jpg"' --data-binary @bcp3356.jpg  "http://localhost:8000/jsonapi/media/image/field_media_image"

then PATCH with field data like:

 curl -v -X PATCH -uadmin:islandora -H'Accept: application/vnd.api+json' -H'Content-Type:application/vnd.api+json' --data '{"data":{"type": "media--image", "id":"f6b36617-3982-4746-b5cc-8e14f60519d4","attributes":{"name":"My New Name"}}}' "http://localhost:8000/jsonapi/media/image/f6b36617-3982-4746-b5cc-8e14f60519d4"

@mjordan
Copy link
Owner Author

mjordan commented Mar 25, 2021

OK, back in business. In Drupal 9.2.0-dev, the issue linked above is resolved.

This now works for creating file:

curl -v -X POST -uadmin:islandora -H'Accept: application/vnd.api+json' -H'Content-Type: application/octet-stream' -H'Content-Disposition: file; filename="test.jpg"' --data-binary @test.jpg "http://localhost:8000/jsonapi/media/image/field_media_image"

Then, for creating the file's media:

curl -v -X POST -uadmin:islandora -H'Accept: application/vnd.api+json' -H'Content-type: application/vnd.api+json' --data @media.json "http://localhost:8000/jsonapi/media/image"

with the following as the --data @media.json:

{
  "data":{
     "type":"media--image",
     "attributes":{
        "name":"My media"
     },
     "relationships":{
        "field_media_of":{
           "data":{
              "type":"node--islandora_object",
              "id":"fa12d7ce-f66c-494f-b149-d95c3c201210"         // 'type' and 'id' are available in the node HTTP response.
           }
        },
        "field_media_image":{
           "data":{
              "type":"file--file",              
              "id":"5060c33a-789f-4850-a2f9-2f6e05e2dd65"      // 'type' and 'id' are available in the file HTTP response.
           }
        },
        "field_media_use":{
           "data":{
              "type":"taxonomy_term--islandora_media_use",
              "id":"cc5e6f00-be2f-4d07-b047-be39cd9b7387"
           }
        }
     }
  }
}

@mjordan
Copy link
Owner Author

mjordan commented Apr 5, 2021

Some preliminary tasks:

First, to create files, Workbench will need a media type -> media field mapping like this:

'file': 'field_media_file',
'document': 'field_media_document',
'image': 'field_media_image',
'audio': 'field_media_audio_file',
'video': 'field_media_video_file'

and this will need to be extensible via configuration, to accommodate custom media types.

Second, to create media, we'll need to be able to get UUIDs for instances of nodes, files, and taxo terms, as illustrated abobe.

mjordan added a commit that referenced this issue Apr 5, 2021
@mjordan
Copy link
Owner Author

mjordan commented Apr 5, 2021

config['media_file_fields'] option added in 58d239e. If present in config file, allows adding/overriding which field is used for a media bundle's file. Format in config file is:

media_file_fields:
 - video: field_foo
 - image: field_bar

To do: validate that the media bundle has the indicated field.

mjordan added a commit that referenced this issue Apr 6, 2021
mjordan added a commit that referenced this issue Apr 6, 2021
@mjordan
Copy link
Owner Author

mjordan commented Apr 6, 2021

get_term_uuid(config, term_id) added in 2c52434.

@mjordan
Copy link
Owner Author

mjordan commented Apr 7, 2021

#254 adds code to check version of Drupal core. Depends on islandora_workbench_integration commit 638d172b2589463c36b2032c6400f62063fc932d. Note to self: to put this into production, uncomment # check_drupal_core_version(config) in workbench_utils.py.

mjordan added a commit that referenced this issue Apr 9, 2021
mjordan added a commit that referenced this issue Apr 9, 2021
mjordan added a commit that referenced this issue Apr 9, 2021
mjordan added a commit that referenced this issue Apr 11, 2021
mjordan added a commit that referenced this issue Apr 12, 2021
mjordan added a commit that referenced this issue Apr 12, 2021
mjordan added a commit that referenced this issue Apr 13, 2021
mjordan added a commit to mjordan/islandora_workbench_integration that referenced this issue Apr 13, 2021
…ndency on JSON:API; added install configuration for File Upload REST endpoint.
mjordan added a commit that referenced this issue Apr 13, 2021
@mjordan
Copy link
Owner Author

mjordan commented Apr 13, 2021

Noteworthy changes to Workbench resulting from development on this issue:

mjordan added a commit that referenced this issue Apr 14, 2021
mjordan added a commit that referenced this issue Apr 17, 2021
@mjordan
Copy link
Owner Author

mjordan commented Apr 18, 2021

Merged into main with b37f353.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code cleanup Clean up code, including code-level comments
Projects
None yet
Development

No branches or pull requests

1 participant