Skip to content

Commit

Permalink
Work on #14.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjordan committed Dec 18, 2018
1 parent faaa385 commit 5a39c3c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
3 changes: 2 additions & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ parameters:
app.plugins.fetchresourcelist.from.drupal.content_types: ['islandora_object']
app.plugins.fetchresourcelist.from.drupal.media_tags: ['/taxonomy/term/15']
app.plugins.fetchresourcelist.from.drupal.gemini_endpoint: 'http://localhost:8000/gemini'
app.plugins.fetchresourcelist.from.drupal.gemini_jwt_token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE1NDQ1NTQxMDYsImV4cCI6MTU0NDU2MTMwNiwid2ViaWQiOiIxIiwiaXNzIjoiaHR0cHM6XC9cL2xvY2FsaG9zdDo4MDAwIiwic3ViIjoiYWRtaW4iLCJyb2xlcyI6WyJhdXRoZW50aWNhdGVkIiwiYWRtaW5pc3RyYXRvciJdfQ.TQdGHkJC_X5XCj5_3-jdASN_7K0C9E_ayMRvz6XudDq7w-An8GM-QcuXc92OjbwgSmzicVKDjwfPWLoluALR2CQLSr9aWG0FoZdCHKXC04iz8Zd-JAHz9sXv3lQ047Nrv7eL9-cwDNSurT0ja2tSOH5OZyRX1krhv9hkwQNoEucsvaTYtDrxJwiIffxfLPqk53aSdPyGXHp2Z0UC8G_0IAigXNfWxqoHPvf0mfYOp0NrOnRtdzwt9EtBfh1uGQHFzkkjCilVCSXmP4-7tCBc9NP4g-kf3c5egNrqDLB0SRSCy3POsIEE08qS97fcYO-QItDXm8ngr4QapCajBcMTsQ'
# For now, will need to be replaced pending outcome of https://github.com/mjordan/riprap/issues/21.
app.plugins.fetchresourcelist.from.drupal.gemini_auth_header: 'Bearer islandora'

# To not register any fetchdigest plugins, use app.plugins.fetchdigest [].
# Currently we only allow one fetchdigest plugin per fixity event (i.e., this
Expand Down
35 changes: 27 additions & 8 deletions src/Command/PluginFetchResourceListFromDrupal.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(
$this->media_tags = $this->params->get('app.plugins.fetchresourcelist.from.drupal.media_tags');
$this->use_fedora_urls = $this->params->get('app.plugins.fetchresourcelist.from.drupal.use_fedora_urls');
$this->gemini_endpoint = $this->params->get('app.plugins.fetchresourcelist.from.drupal.gemini_endpoint');
$this->gemini_jwt_token = $this->params->get('app.plugins.fetchresourcelist.from.drupal.gemini_jwt_token');
$this->gemini_auth_header = $this->params->get('app.plugins.fetchresourcelist.from.drupal.gemini_auth_header');

$this->logger = $logger;
$this->event_detail = $event_detail;
Expand All @@ -58,15 +58,24 @@ protected function execute(InputInterface $input, OutputInterface $output)
$response = $client->request('GET', $url, [
'http_errors' => false,
'headers' => [$this->jsonapi_authorization_headers[0]], // @todo: Loop through this array and add each header.
'query' => ['page[offset]' => '1', 'page[limit]' => '50']
'query' => ['page[offset]' => '0', 'page[limit]' => '50']
]);
$status_code = $response->getStatusCode();
$node_list = (string) $response->getBody();
$node_list_array = json_decode($node_list, true);

if (count($node_list_array['data']) == 0) {
if ($this->logger) {
$this->logger->warning("PluginFetchResourceListFromDrupal retrieved an empty node list from Drupal",
array(
'HTTP response code' => $status_code
)
);
}
}

foreach ($node_list_array['data'] as $node) {
$nid = $node['attributes']['nid'];
// var_dump($nid);
$nid = $node['attributes']['nid'];
// Get the media associated with this node using the Islandora-supplied Manage Media View.
$media_client = new \GuzzleHttp\Client();
$media_url = $this->drupal_base_url . '/node/' . $nid . '/media';
Expand All @@ -85,18 +94,29 @@ protected function execute(InputInterface $input, OutputInterface $output)
foreach ($media['field_media_use'] as $term) {
if (in_array($term['url'], $this->media_tags)) {
if ($this->use_fedora_urls) {
// @todo: getFedoraUrl() returns false on failure, so build in logic here to account for that.
// @todo: getFedoraUrl() returns false on failure, so build in logic here to log that
// the resource ID / URL cannot be found. (But, http responses are already logged in
// getFedoraUrl() so maybe we don't need to log here?)
if (isset($media['field_media_image'])) {
$fedora_url = $this->getFedoraUrl($media['field_media_image'][0]['target_uuid']);
// This is a string containing one resource ID (URL) per line;
// $output->writeln($fedora_url);
var_dump($fedora_url);
// var_dump($media['field_media_image'][0]['target_uuid']);
} else {
$fedora_url = $this->getFedoraUrl($media['field_media_file'][0]['target_uuid']);
// This is a string containing one resource ID (URL) per line;
// $output->writeln($fedora_url);
var_dump($fedora_url);
}
} else {
if (isset($media['field_media_image'])) {
// This is a string containing one resource ID (URL) per line;
// $output->writeln($media['field_media_image'][0]['url']);
var_dump($media['field_media_image'][0]['url']);
} else {
// This is a string containing one resource ID (URL) per line;
// $output->writeln($media['field_media_file'][0]['url']);
var_dump($media['field_media_file'][0]['url']);
}
}
Expand All @@ -111,7 +131,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->logger->info("PluginFetchResourceListFromDrupal executed");
}

// !!!!! during development, so downstream plugins aren't fired. !!!!!!SSS
// !!!!! during development, so downstream plugins aren't fired. !!!!!!
exit;
}

Expand All @@ -127,11 +147,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
private function getFedoraUrl($uuid)
{
try {
$auth = 'Bearer ' . $this->gemini_jwt_token;
$client = new \GuzzleHttp\Client();
$options = [
'http_errors' => false,
'headers' => ['Authorization' => $auth],
'headers' => ['Authorization' => $this->gemini_auth_header],
];
$url = $this->gemini_endpoint . '/' . $uuid;
$response = $client->request('GET', $url, $options);
Expand Down

0 comments on commit 5a39c3c

Please sign in to comment.