From d634ea312d74ecf6d4aff071c2d2bc4f9ec589fd Mon Sep 17 00:00:00 2001 From: Mark Jordan Date: Fri, 23 Apr 2021 15:50:32 +0000 Subject: [PATCH] WIP on #39. --- islandora_riprap.module | 2 +- .../IslandoraRiprapMediaEventsController.php | 2 +- src/Plugin/views/field/RiprapResults.php | 2 +- src/Riprap/IslandoraRiprapUtils.php | 33 ++++++++++++++++++- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/islandora_riprap.module b/islandora_riprap.module index 7a023fc..0e2562c 100644 --- a/islandora_riprap.module +++ b/islandora_riprap.module @@ -172,7 +172,7 @@ function islandora_riprap_islandora_premis_turtle_alter($nid, &$turtle) { $binary_resource_url = $islandora_riprap_utils->getLocalUrl($medium->id()); } else { - $binary_resource_url = $islandora_riprap_utils->getFedoraUrl($file->uuid()); + $binary_resource_url = $islandora_riprap_utils->getFedoraUrl($medium->id()); } // Create the graph from existing Turtle. diff --git a/src/Controller/IslandoraRiprapMediaEventsController.php b/src/Controller/IslandoraRiprapMediaEventsController.php index a6fc873..947c1be 100644 --- a/src/Controller/IslandoraRiprapMediaEventsController.php +++ b/src/Controller/IslandoraRiprapMediaEventsController.php @@ -39,7 +39,7 @@ public function main() { $binary_resource_url = $utils->getLocalUrl($mid); } else { - $binary_resource_url = $utils->getFedoraUrl($binary_resource_uuid); + $binary_resource_url = $utils->getFedoraUrl($mid); } $riprap_output = $riprap->getEvents(['output_format' => 'json', 'resource_id' => $binary_resource_url]); diff --git a/src/Plugin/views/field/RiprapResults.php b/src/Plugin/views/field/RiprapResults.php index f5ce845..6887ab0 100644 --- a/src/Plugin/views/field/RiprapResults.php +++ b/src/Plugin/views/field/RiprapResults.php @@ -41,7 +41,7 @@ public function render(ResultRow $value) { $binary_resource_url = $utils->getLocalUrl($mid); } else { - $binary_resource_url = $utils->getFedoraUrl($binary_resource_uuid); + $binary_resource_url = $utils->getFedoraUrl($mid); } $num_events = $config->get('number_of_events') ?: 10; diff --git a/src/Riprap/IslandoraRiprapUtils.php b/src/Riprap/IslandoraRiprapUtils.php index 618a92f..f564739 100644 --- a/src/Riprap/IslandoraRiprapUtils.php +++ b/src/Riprap/IslandoraRiprapUtils.php @@ -3,6 +3,7 @@ namespace Drupal\islandora_riprap\Riprap; use Drupal\media\Entity\Media; +use Drupal\Core\Site\Settings; use Drupal\Core\Link; /** @@ -68,7 +69,37 @@ public function getFileUuid($mid) { * @return string * The Fedora URL corresponding to the UUID, or a message. */ - public function getFedoraUrl($uuid) { + public function getFedoraUrl($mid) { + $media = Media::load($mid); + $media_source_service = \Drupal::service('islandora.media_source_service'); + $source_file = $media_source_service->getSourceFile($media); + $uri = $source_file->getFileUri(); + $scheme = \Drupal::service('stream_wrapper_manager')->getScheme($uri); + $flysystem_config = Settings::get('flysystem'); + + $mapper = \Drupal::service('islandora.entity_mapper'); + if (isset($flysystem_config[$scheme]) && $flysystem_config[$scheme]['driver'] == 'fedora') { + $parts = parse_url($uri); + $path = $parts['host'] . $parts['path']; + } + else { + $path = $mapper->getFedoraPath($source_file->uuid()); + } + $path = trim($path, '/'); + $fedora_uri = "$fedora_root/$path"; + return($fedora_uri); + } + + /** + * Get a Fedora URL for a File entity from Gemini. + * + * @param string $uuid + * The File entity's UUID. + * + * @return string + * The Fedora URL corresponding to the UUID, or a message. + */ + public function _getFedoraUrl($uuid) { try { $container = \Drupal::getContainer(); $jwt = $container->get('jwt.authentication.jwt');