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

ISSUE-14: LoD Reconciling + CSV Export + Release Improvements #31

Merged
merged 42 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
a157a20
First pass on LoD Reconciling
DiegoPino Jul 25, 2021
cd1b043
Push headers/erase old LoD reconciled when re-running
DiegoPino Jul 26, 2021
9909ff7
Wow. We got this even with LoD Fix/Edit form!!
DiegoPino Jul 28, 2021
95922b1
Because MADS RDF is case Sensitive.. add CONST mapping
DiegoPino Jul 28, 2021
07bd252
Make sure sort by PID ::getData is given so offset is consistent
DiegoPino Jul 30, 2021
579d4b5
Header normalization finally done the right way
DiegoPino Aug 3, 2021
36f53a8
use RELS_EXT_isPageNumber_literal_intDerivedFromString_l for page ord…
DiegoPino Aug 4, 2021
fd52fb6
Does less manual cleaning and trusts fputcsv() more for escaping
DiegoPino Aug 19, 2021
fb8cd17
weird left over ;
DiegoPino Aug 19, 2021
8f1cba7
Fix some silly select defaults
DiegoPino Sep 2, 2021
a1472be
New Permissions to allow export to CSV
DiegoPino Sep 2, 2021
d70a726
Small Improvements to Ami Utility Service
DiegoPino Sep 2, 2021
28969c6
This still needs more work. Webform find and replace breaks Form State
DiegoPino Sep 2, 2021
84ed6ab
Full Export Action to CSV
DiegoPino Sep 2, 2021
8fe9a34
Another pass on making LoD reconciling better
DiegoPino Sep 21, 2021
afffc75
Now that was a mistake!
DiegoPino Sep 21, 2021
6f51681
Fix direct Ingest
DiegoPino Sep 23, 2021
a25920d
Not be super-smart. Just smart-ish with JSON attempts of decoding
DiegoPino Sep 23, 2021
3758608
Persist LoD Per Page and also Globally into a CSV
DiegoPino Sep 24, 2021
583e6bc
Small cleanup and better checks on passed for IngestADOQueueWorker
DiegoPino Sep 24, 2021
c59d170
Gosh. Restored Twig Template processing
DiegoPino Sep 25, 2021
a161939
Allow (enforce) AMI Set Label to be provided during Setup
DiegoPino Sep 27, 2021
bd71514
Complete refactor of co-dependent Symfony Services
DiegoPino Sep 27, 2021
f280dad
Fix Batch Size Issue capping to hundreds and not respecting exact row…
DiegoPino Sep 27, 2021
58b0811
replace EntityChangedActionDeriver to avoid other entities to pop on …
DiegoPino Sep 30, 2021
31e70a7
This one was driving me crazy. Stuck "Direct" for ever
DiegoPino Oct 5, 2021
9a7aecc
Consistently use only lower case columns
DiegoPino Oct 5, 2021
19ea03b
Small typo on Docs
DiegoPino Oct 12, 2021
fffc059
Small fail safe update in case the queue fails for not-us reasons
DiegoPino Oct 19, 2021
d71bb08
Make ZIP upload field Private instead of tmp
DiegoPino Nov 3, 2021
d9ba478
New thing for me
DiegoPino Nov 3, 2021
2a470a4
Files distributed across multiple Queue Entries First pass
DiegoPino Nov 3, 2021
4581569
This looks better
DiegoPino Nov 4, 2021
f629a7c
New options. Force file processing as separate item can be set per SET
DiegoPino Nov 4, 2021
054c668
Enforces revisions?
DiegoPino Nov 10, 2021
e62e6ce
AMI version of Entity Preview for Format Strawberryfield
DiegoPino Nov 11, 2021
7faea54
In case the key is not present or the set is "type" less default to t…
DiegoPino Nov 15, 2021
7edc6f8
Fix remote CSV load
DiegoPino Nov 16, 2021
88ba765
Allows CSV to work from S3 too
DiegoPino Nov 16, 2021
2166ce4
Another one. ZIP loading from S3 still needed
DiegoPino Nov 16, 2021
d800b3e
C'mon ZipArchive WHY! You can not stream from remote
DiegoPino Nov 17, 2021
2b92b72
Webform based Search and Replace is working!
DiegoPino Nov 18, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions ami.install
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ function ami_update_8902() {
->setDescription(new TranslatableMarkup('A Zip file containing accompanying Files for the Source Data'))
->setSetting('file_extensions', 'zip')
->setSetting('upload_validators', $validators)
->setRequired(TRUE)
->setSetting('uri_scheme', 'private')
->setSetting('file_directory', '/ami/zip')
->setRequired(FALSE)
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'file',
Expand Down Expand Up @@ -100,4 +102,17 @@ function ami_update_8903() {
"plugin_configuration"
],
]));
}
}

/**
* Update 8903 - Make Private default upload location for ami Set ZIP files.
*/
function ami_update_8904() {
$field_storage_definition = \Drupal::entityDefinitionUpdateManager()->getFieldStorageDefinition('zip_file', 'ami_set_entity');
$field_storage_definition->setSetting('uri_scheme', 'private');
$field_storage_definition->setSetting('file_directory', '/ami/zip');
\Drupal::entityDefinitionUpdateManager()->updateFieldStorageDefinition($field_storage_definition);
}



12 changes: 12 additions & 0 deletions ami.links.task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,15 @@ ami_set_entity.delete_process_form:
base_route: entity.ami_set_entity.canonical
title: Delete Processed ADOs
weight: 12

ami_set_entity.reconcile_form:
route_name: entity.ami_set_entity.reconcile_form
base_route: entity.ami_set_entity.canonical
title: Reconcile LoD
weight: 13

entity.ami_set_entity.reconcileedit_form:
route_name: entity.ami_set_entity.reconcileedit_form
base_route: entity.ami_set_entity.canonical
title: Edit Reconciled LoD
weight: 14
106 changes: 106 additions & 0 deletions ami.module
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
* @file
* Contains ami.module.
*/

use Drupal\Core\Language\Language;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\format_strawberryfield\Event\FormatStrawberryfieldFormAlterEvent;
use Drupal\format_strawberryfield\FormatStrawberryfieldEventType;

/**
* Implements hook_help().
*/
Expand All @@ -24,3 +31,102 @@ function ami_help($route_name, RouteMatchInterface $route_match) {
}
}
}

function ami_form_metadatadisplay_entity_edit_form_alter(&$form,FormStateInterface $form_state, $form_id) {

// Add our AMI options here
$form['preview']['entity_type'] = [
'#type' => 'radios',
'#weight' => -10,
'#title' => t('Entity type'),
'#description' => t('The Entity Type you want to preview.'),
'#options' => [
'ado' => t('Archipelago Digital Objects'),
'ami' => t('AMI Sets'),
],
'#default_value' => $form_state->getValue('entity_type', NULL) ?? 'ado'
];


$form['preview']['ado_context_preview']['#states'] = [
'visible' => [
':input[name="entity_type"]' => ['value' => 'ado'],
],
];

$form['preview']['ado_amiset_preview'] = [
'#type' => 'entity_autocomplete',
'#weight' => -9,
'#title' => t('Ami Set to preview'),
'#description' => t('The AMI Set to be used to preview the data.'),
'#target_type' => 'ami_set_entity',
'#maxlength' => 1024,
'#ajax' => [
'callback' => '\Drupal\ami\Controller\AmiRowAutocompleteHandler::rowAjaxCallback',
'event' => 'autocompleteclose change',
],
'#states' => [
'visible' => [':input[name="entity_type"]' => ['value' => 'ami']],
],
];

$form['preview']['ado_amiset_row_context_preview'] = [
'#type' => 'textfield',
'#weight' => -8,
'#title' => t('Row to preview'),
'#states' => [
'visible' => [
'input[name="entity_type"]' => ['value' => 'ami'],
'input[name="ado_amiset_preview"' => ['filled' => true],
],
],
];
$ami_set = $form_state->getValue('ado_amiset_preview', NULL);
if (is_scalar($ami_set)) {
$form['preview']['ado_amiset_row_context_preview']['#autocomplete_route_name'] = 'ami.rowsbylabel.autocomplete';
$form['preview']['ado_amiset_row_context_preview']['#autocomplete_route_parameters'] = [
'ami_set_entity' => $ami_set
];
}

$form['preview']['button_preview'][
'#states'] = [
'visible' => [
'input[name="ado_context_preview"' => ['filled' => true],
'input[name="entity_type"]' => ['value' => 'ado'],
],
];

$form['preview']['button_preview_amiset'] = [
'#type' => 'button',
'#op' => 'preview',
'#weight' => -7,
'#value' => t('Show preview for AMI Set'),
'#ajax' => [
'callback' => '\Drupal\ami\Controller\AmiRowAutocompleteHandler::ajaxPreviewAmiSet',
],
'#states' => [
'visible' => [
'input[name="ado_amiset_preview"' => ['filled' => true],
'input[name="entity_type"]' => ['value' => 'ami']
],
],
];

$form['preview']['render_native'] = [
'#type' => 'checkbox',
'#weight' => 10,
'#defaut_value' => FALSE,
'#title' => 'Show Preview using native Output Format (e.g HTML)',
'#states' => [
'visible' => [
['input[name="ado_context_preview"' => ['filled' => true]],
'or',
['input[name="ado_amiset_preview"' => ['filled' => true],
'input[name="ado_amiset_row_context_preview"' => ['filled' => true]]
],
],
];

return $form;
}
3 changes: 3 additions & 0 deletions ami.permissions.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Bulk Patch Strawberryfield:
title: 'JSON Patch Archipelago Digital Objects in Bulk using Views Batch Operations'
description: 'Allows JSON Patch actions to be executed against a "Strawberryfield" bearing Entity. Still on Patch time, individual permissions may apply and/or override this permission'
CSV Export Archipelago Digital Objects:
title: 'Export Archipelago Digital Objects in Bulk using Views Batch Operations to CSV'
description: 'CSV Export actions to be executed against a "Strawberryfield" bearing Entity. Still on export time, individual permissions may apply and/or override this permission'
Multi Import Digital Objects:
title: 'Import or Update assets from remote sources or files using Archipelago Multi Importer'
description: 'Allows AMI to be used to import or update Digital Objects and assets. Still on import(create) and update time, individual permissions may apply and/or override this permission'
Expand Down
29 changes: 29 additions & 0 deletions ami.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,32 @@ entity.ami_set_entity.delete_process_form:
_title: 'Process Ami Set'
requirements:
_entity_access: 'ami_set_entity.deleteados'

entity.ami_set_entity.reconcile_form:
path: '/amiset/{ami_set_entity}/reconcile'
defaults:
_entity_form: ami_set_entity.reconcile
_title: 'Reconcile LoD'
requirements:
_entity_access: 'ami_set_entity.process'
entity.ami_set_entity.reconcileedit_form:
path: '/amiset/{ami_set_entity}/editreconcile'
defaults:
_entity_form: ami_set_entity.editreconcile
_title: 'Clean Reconciled LoD'
requirements:
_entity_access: 'ami_set_entity.process'

ami.rowsbylabel.autocomplete:
path: '/admin/amiset/autocomplete/{ami_set_entity}/rowsbylabel'
options:
parameters:
ami_set_entity:
type: 'entity:ami_set_entity'
defaults:
_controller: '\Drupal\ami\Controller\AmiRowAutocompleteHandler::handleAutocomplete'
_format: json
requirements:
_entity_access: 'ami_set_entity.view'
_permission: 'access content'
_csrf_token: 'TRUE'
7 changes: 6 additions & 1 deletion ami.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ services:
arguments: ['@entity_type.manager']
ami.utility:
class: Drupal\ami\AmiUtilityService
arguments: [ '@file_system', '@file.usage', '@entity_type.manager', '@stream_wrapper_manager', '@plugin.manager.archiver', '@config.factory', '@current_user', '@language_manager', '@transliteration', '@module_handler', '@logger.factory', '@strawberryfield.utility', '@entity_field.manager', '@entity_type.bundle.info', '@http_client']
arguments: [ '@file_system', '@file.usage', '@entity_type.manager', '@stream_wrapper_manager', '@plugin.manager.archiver', '@config.factory', '@current_user', '@language_manager', '@transliteration', '@module_handler', '@logger.factory', '@strawberryfield.utility', '@entity_field.manager', '@entity_type.bundle.info', '@http_client', '@ami.lod', '@keyvalue', '@strawberryfield.file_metadata_extractor']
tags:
- { name: backend_overridable }
ami.lod:
class: Drupal\ami\AmiLoDService
arguments: [ '@file_system', '@file.usage', '@entity_type.manager', '@stream_wrapper_manager', '@plugin.manager.archiver', '@config.factory', '@current_user', '@language_manager', '@transliteration', '@module_handler', '@logger.factory', '@strawberryfield.utility', '@http_client', '@keyvalue']
tags:
- { name: backend_overridable }
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"swaggest/json-diff": "^3.7.5",
"phpoffice/phpspreadsheet": "^1.15.0",
"maennchen/zipstream-php": "^1.2 || ^2.1",
"drupal/google_api_client": "^3.0",
"drupal/google_api_client": "^3.0 || ^4.0",
"ramsey/uuid": "^4.1"
},
"minimum-stability": "dev",
Expand Down
26 changes: 20 additions & 6 deletions src/AmiBatchQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,15 @@ public static function takeOne(string $queue_name, string $set_id, array &$conte
try {
// Only process Items of this Set if $context['set_id'] is set.
if ($item = $queue->claimItem()) {
$ado_title = isset($item->data->info['row']['uuid']) ? 'ADO with UUID '.$item->data->info['row']['uuid'] : 'Unidentifed ADO without UUID';
// Let's figure out the type of queue running here, ADO or Attached file
if (!empty($item->data->info['filename']) && !empty($item->data->info['file_column']) && !empty($item->data->info['processed_row'])) {
$ado_title = 'File ' . $item->data->info['filename'];
$ado_title .= isset($item->data->info['uuid']) ? ' for ADO with UUID ' . $item->data->info['uuid'] : 'for Unidentifed ADO without UUID ';
}
else {
$ado_title = isset($item->data->info['row']['uuid']) ? 'ADO with UUID ' . $item->data->info['row']['uuid'] : 'Unidentifed ADO without UUID';
}

$title = t('For %name processing %adotitle, <b>%count</b> items remaining', [
'%name' => $context['results']['queue_label'],
'%adotitle' => $ado_title,
Expand Down Expand Up @@ -136,11 +144,17 @@ public static function finish($success, $results, $operations) {
)
);
}
// Cleanup and remove the queue. This is a live batch operation.
/** @var \Drupal\Core\Queue\QueueFactory $queue_factory */
$queue_name = $results['queue_name'];
$queue_factory = \Drupal::service('queue');
$queue_factory->get($queue_name)->deleteQueue();
// If the queue fails for whatever reason the $context may be lost
if (isset($results['queue_name'])) {
// Cleanup and remove the queue. This is a live batch operation.
/** @var \Drupal\Core\Queue\QueueFactory $queue_factory */
$queue_name = $results['queue_name'];
$queue_factory = \Drupal::service('queue');
$queue_factory->get($queue_name)->deleteQueue();
}
else {
\Drupal::messenger()->addError(\Drupal::translation('The Batch Operation failed. Please check your logs, available Filesystem space and try again'));
}
}

}
Expand Down
Loading