Skip to content

Commit

Permalink
Cleanup; started work on #5.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjordan committed Nov 28, 2018
1 parent 2154dbb commit 987736c
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 24 deletions.
2 changes: 1 addition & 1 deletion islandora_riprap.module
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function islandora_riprap_theme($existing, $type, $theme, $path) {
'variables' => ['content' => null, 'outcome' => null, 'mid' => null],
],
'islandora_riprap_report' => [
'variables' => ['report' => null],
'variables' => ['report' => null, 'mid' => null],
],
];
}
Expand Down
10 changes: 10 additions & 0 deletions islandora_riprap.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ islandora_riprap.riprap:
_permission: 'administer site configuration'
media: \d+

islandora_riprap.premis:
path: '/media/{media}/premis'
defaults:
_controller: '\Drupal\islandora_riprap\Controller\IslandoraRiprapPremisController::main'
# _title: 'Fixity Events'
requirements:
# _permission: 'administer site configuration'
_permission: 'access content'
media: \d+

islandora_riprap.settings:
path: '/admin/config/islandora_riprap/settings'
defaults:
Expand Down
8 changes: 5 additions & 3 deletions src/Controller/IslandoraRiprapController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public function main() {
$mid = $path_args[2];
$output = $this->queryRiprap($mid);

$header = ['Event UUID', 'Event type', 'Timestamp', 'Digest algorithm', 'Digest value', 'Event detail', 'Event outcome', 'Note'];
$header = [t('Event UUID'), t('Resource URI'), t('Event type'), t('Timestamp'),
t('Digest algorithm'), t('Digest value'), t('Event detail'), t('Event outcome'), t('Note')];
$rows = array();
foreach ($output as &$event) {
unset($event['resource_id']);
$rows[] = array_values($event);
}

Expand All @@ -40,9 +40,11 @@ public function main() {
'#rows' => $rows,
];

drupal_set_message(t('This is sample data!'), 'warning');
return [
'#theme' => 'islandora_riprap_report',
'#report' => $output,
'#mid' => $mid,
];
}

Expand All @@ -56,7 +58,7 @@ public function main() {
* The JSON response from Riprap.
*/
private function queryRiprap($mid) {
$sample_riprap_output = '[{"event_uuid":"cdecb9ac-5938-4992-b5b7-8ef9e4e94c62","resource_id":"http:\/\/localhost:8000\/mockrepository\/rest\/11","event_type":"fix","timestamp":"2018-10-20T07:35:04-0800","digest_algorithm":"SHA-1","digest_value":"339e2ebc99d2a81e7786a466b5cbb9f8b3b81377","event_detail":"","event_outcome":"suc","event_outcome_detail_note":"Fedora says hi."},{"event_uuid":"f26ed6cc-e6e2-4ebe-9607-5ad7a2e4b857","resource_id":"http:\/\/localhost:8000\/mockrepository\/rest\/11","event_type":"fix","timestamp":"2018-10-29T07:35:04-0800","digest_algorithm":"SHA-1","digest_value":"339e2ebc99d2a81e7786a466b5cbb9f8b3b81377","event_detail":"","event_outcome":"suc","event_outcome_detail_note":"Fedora says hi."},{"event_uuid":"af60c8d5-7504-4be0-a355-06177855b8b8","resource_id":"http:\/\/localhost:8000\/mockrepository\/rest\/11","event_type":"ing","timestamp":"2018-11-20T07:35:04-0800","digest_algorithm":"SHA-1","digest_value":"339e2ebc99d2a81e7786a466b5cbb9f8b3b81377","event_detail":"","event_outcome":"suc","event_outcome_detail_note":""}]';
$sample_riprap_output = '[{"event_uuid":"cdecb9ac-5938-4992-b5b7-8ef9e4e94c62","resource_id":"http:\/\/localhost:8000\/mockrepository\/rest\/11","event_type":"fix","timestamp":"2018-10-20T07:35:04-0800","digest_algorithm":"SHA-1","digest_value":"339e2ebc99d2a81e7786a466b5cbb9f8b3b81377","event_detail":"","event_outcome":"suc","event_outcome_detail_note":"Fedora says hi."},{"event_uuid":"f26ed6cc-e6e2-4ebe-9607-5ad7a2e4b857","resource_id":"http:\/\/localhost:8000\/mockrepository\/rest\/11","event_type":"fix","timestamp":"2018-10-29T07:35:04-0800","digest_algorithm":"SHA-1","digest_value":"339e2ebc99d2a81e7786a466b5cbb9f8b3b81377","event_detail":"","event_outcome":"suc","event_outcome_detail_note":"Fedora says hi."},{"event_uuid":"af60c8d5-7504-4be0-a355-06177855b8b8","resource_id":"http:\/\/localhost:8000\/mockrepository\/rest\/11","event_type":"fix","timestamp":"2018-11-20T07:35:04-0800","digest_algorithm":"SHA-1","digest_value":"339e2ebc99d2a81e7786a466b5cbb9f8b3b81377","event_detail":"","event_outcome":"suc","event_outcome_detail_note":""}]';
$sample_riprap_output_array = json_decode($sample_riprap_output, true);
return $sample_riprap_output_array;
}
Expand Down
40 changes: 40 additions & 0 deletions src/Controller/IslandoraRiprapPremisController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Drupal\islandora_riprap\Controller;

use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\Response;

/**
* Controller.
*/
class IslandoraRiprapPremisController extends ControllerBase {
public function __construct() {
$config = \Drupal::config('islandora_riprap.settings');
$this->riprap_endpoint = $config->get('riprap_rest_endpoint') ?: 'http://localhost:8000/api/fixity';
$this->number_of_events = $config->get('number_of_events') ?: 10;
$this->use_drupal_urls = $config->get('use_drupal_urls') ?: FALSE;
$this->gemini_endpoint = $config->get('gemini_rest_endpoint') ?: 'http://localhost:8000/gemini';
}

/**
* Get the Riprap data for the current Media entity and render it as Turtle.
*
* @return string
*/
public function main() {
$current_path = \Drupal::service('path.current')->getPath();
$path_args = explode('/', $current_path);
$mid = $path_args[2];

$output = '@prefix premis: <http://www.loc.gov/premis/rdf/v3/> .' . "\n";
$output .= "\n";
$output .= '<http://example.com/a/resource/uri>';

$response = new Response($output, 200);
$response->headers->set("Content-Type", 'text/turtle');
return $response;
}

}

20 changes: 1 addition & 19 deletions src/Plugin/views/field/RiprapResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private function getFedoraUrl($uuid) {
* A Media ID.
*
* @return string
* The local URL of the file associated with the incoming Media entity.
* The local Drupal URL of the file associated with the incoming Media entity.
*/
public function getLocalUrl($mid) {
$media_fields = array(
Expand Down Expand Up @@ -198,21 +198,3 @@ private function queryRiprap($url) {
}

}

/*
$sample_riprap_output = '[{"event_uuid":"cdecb9ac-5938-4992-b5b7-8ef9e4e94c62","resource_id":"http:\/\/localhost:8000\/mockrepository\/rest\/11","event_type":"fix","timestamp":"2018-10-20T07:35:04-0800","digest_algorithm":"SHA-1","digest_value":"339e2ebc99d2a81e7786a466b5cbb9f8b3b81377","event_detail":"","event_outcome":"suc","event_outcome_detail_note":"Fedora says hi."},{"event_uuid":"f26ed6cc-e6e2-4ebe-9607-5ad7a2e4b857","resource_id":"http:\/\/localhost:8000\/mockrepository\/rest\/11","event_type":"fix","timestamp":"2018-10-29T07:35:04-0800","digest_algorithm":"SHA-1","digest_value":"339e2ebc99d2a81e7786a466b5cbb9f8b3b81377","event_detail":"","event_outcome":"suc","event_outcome_detail_note":"Fedora says hi."},{"event_uuid":"af60c8d5-7504-4be0-a355-06177855b8b8","resource_id":"http:\/\/localhost:8000\/mockrepository\/rest\/11","event_type":"ing","timestamp":"2018-11-20T07:35:04-0800","digest_algorithm":"SHA-1","digest_value":"339e2ebc99d2a81e7786a466b5cbb9f8b3b81377","event_detail":"","event_outcome":"fail","event_outcome_detail_note":""}]';
$riprap_output_as_array = json_decode($sample_riprap_output, true);
$successful_events = 0;
$failed_events = 0;
foreach ($riprap_output_as_array as $event) {
if ($event['event_outcome'] == 'suc') {
$successful_events++;
}
if ($event['event_outcome'] == 'fail') {
$failed_events++;
}
}
$output = "Report from sample Riprap data (3 events): $successful_events successful events, $failed_events failed events.";
*/

2 changes: 1 addition & 1 deletion templates/islandora-riprap-report.html.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div {{ attributes }}>
<div class="islandora_riprap_report">
<h4>Sample Riprap output - does not correspond to current media</h4>
<p>Fixity events for resource associated with Media {{ mid }}.</p>
<pre>{{ report }}</pre>
</div>
</div>

0 comments on commit 987736c

Please sign in to comment.