Skip to content

Commit

Permalink
WIP on #39.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjordan committed Apr 23, 2021
1 parent 6d1016a commit d634ea3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion islandora_riprap.module
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/IslandoraRiprapMediaEventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/views/field/RiprapResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 32 additions & 1 deletion src/Riprap/IslandoraRiprapUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Drupal\islandora_riprap\Riprap;

use Drupal\media\Entity\Media;
use Drupal\Core\Site\Settings;
use Drupal\Core\Link;

/**
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit d634ea3

Please sign in to comment.