From 4a1696ea00904505f3e44e7820f8872dbf3a9887 Mon Sep 17 00:00:00 2001 From: Seth Shaw Date: Tue, 20 Apr 2021 15:47:31 -0700 Subject: [PATCH 1/3] make rdf namespaces configurable --- config/install/islandora.settings.yml | 52 +++++++++++++++++++++++++++ config/schema/islandora.schema.yml | 12 +++++++ islandora.module | 29 ++++++--------- src/Form/IslandoraSettingsForm.php | 43 ++++++++++++++++++++++ 4 files changed, 117 insertions(+), 19 deletions(-) diff --git a/config/install/islandora.settings.yml b/config/install/islandora.settings.yml index 8fb25fb8c..7b4646339 100644 --- a/config/install/islandora.settings.yml +++ b/config/install/islandora.settings.yml @@ -2,3 +2,55 @@ broker_url: 'tcp://localhost:61613' jwt_expiry: '+2 hour' gemini_url: '' gemini_pseudo_bundles: [] +rdf_namespaces: + - + prefix: 'ldp' + namespace: 'http://www.w3.org/ns/ldp#', + - + prefix: 'dc11' + namespace: 'http://purl.org/dc/elements/1.1/', + - + prefix: 'dcterms' + namespace: 'http://purl.org/dc/terms/', + - + prefix: 'nfo' + namespace: 'http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/v1.1/', + - + prefix: 'ebucore' + namespace: 'http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#', + - + prefix: 'fedora' + namespace: 'http://fedora.info/definitions/v4/repository#', + - + prefix: 'owl' + namespace: 'http://www.w3.org/2002/07/owl#', + - + prefix: 'ore' + namespace: 'http://www.openarchives.org/ore/terms/', + - + prefix: 'rdf' + namespace: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', + - + prefix: 'rdau' + namespace: 'http://rdaregistry.info/Elements/u/' + - + prefix: 'islandora' + namespace: 'http://islandora.ca/', + - + prefix: 'pcdm' + namespace: 'http://pcdm.org/models#', + - + prefix: 'use' + namespace: 'http://pcdm.org/use#', + - + prefix: 'iana' + namespace: 'http://www.iana.org/assignments/relation/', + - + prefix: 'premis' + namespace: 'http://www.loc.gov/premis/rdf/v1#', + - + prefix: 'premis3' + namespace: 'http://www.loc.gov/premis/rdf/v3/', + - + prefix: 'co' + namespace: 'http://purl.org/co/', \ No newline at end of file diff --git a/config/schema/islandora.schema.yml b/config/schema/islandora.schema.yml index f63e43415..538077dcc 100644 --- a/config/schema/islandora.schema.yml +++ b/config/schema/islandora.schema.yml @@ -22,6 +22,18 @@ islandora.settings: label: 'List of node, media and taxonomy terms that should include the linked Fedora URI' sequence: type: string + rdf_namespaces: + type: sequence + label: 'RDF Namespaces' + sequence: + type: mapping + mapping: + prefix: + type: string + label: 'RDF Prefix' + namespace: + type: string + label: 'Fully Qualified RDF Namespace' action.configuration.emit_node_event: diff --git a/islandora.module b/islandora.module index 0a86a6ac2..46ee0806a 100644 --- a/islandora.module +++ b/islandora.module @@ -47,25 +47,16 @@ function islandora_help($route_name, RouteMatchInterface $route_match) { * Implements hook_rdf_namespaces(). */ function islandora_rdf_namespaces() { - // Yes, it's amazing, rdf is not registered by default! - return [ - 'ldp' => 'http://www.w3.org/ns/ldp#', - 'dc11' => 'http://purl.org/dc/elements/1.1/', - 'dcterms' => 'http://purl.org/dc/terms/', - 'nfo' => 'http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/v1.1/', - 'ebucore' => 'http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#', - 'fedora' => 'http://fedora.info/definitions/v4/repository#', - 'owl' => 'http://www.w3.org/2002/07/owl#', - 'ore' => 'http://www.openarchives.org/ore/terms/', - 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', - 'islandora' => 'http://islandora.ca/', - 'pcdm' => 'http://pcdm.org/models#', - 'use' => 'http://pcdm.org/use#', - 'iana' => 'http://www.iana.org/assignments/relation/', - 'premis' => 'http://www.loc.gov/premis/rdf/v1#', - 'premis3' => 'http://www.loc.gov/premis/rdf/v3/', - 'co' => 'http://purl.org/co/', - ]; + $config = \Drupal::config('islandora.settings'); + $namespace_config = $config->get('rdf_namespaces'); + if (!is_array($namespace_config)) { + \Drupal::logger('islandora')->warning("RDF Map config is not an array. Please check your RDF namespaces configuration in islandora core settings."); + } + $namespaces = []; + foreach ($namespace_config as $namespace) { + $namespaces[$namespace['prefix']] = $namespace['namespace']; + } + return $namespaces; } /** diff --git a/src/Form/IslandoraSettingsForm.php b/src/Form/IslandoraSettingsForm.php index cdaa358d8..36f2ad2e6 100644 --- a/src/Form/IslandoraSettingsForm.php +++ b/src/Form/IslandoraSettingsForm.php @@ -34,6 +34,7 @@ class IslandoraSettingsForm extends ConfigFormBase { 'month', 'year', ]; + const RDF_NAMESPACES = 'rdf_namespaces'; /** * To list the available bundle types. @@ -184,6 +185,17 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#default_value' => $selected_bundles, ], ]; + + $rdf_namespaces = ''; + foreach ($config->get('rdf_namespaces') as $namespace) { + $rdf_namespaces .= $namespace['prefix'] . '|' . $namespace['namespace'] . "\n"; + } + $form[self::RDF_NAMESPACES] = [ + '#type' => 'textarea', + '#title' => $this->t('RDF Namespaces'), + '#default_value' => $rdf_namespaces, + ]; + return parent::buildForm($form, $form_state); } @@ -259,6 +271,22 @@ public function validateForm(array &$form, FormStateInterface $form_state) { ); } } + + // Validate RDF Namespaces. + foreach (preg_split("/[\r\n]+/", $form_state->getValue(self::RDF_NAMESPACES)) as $line) { + if (empty($line)) { + continue; + } + $namespace = explode("|", trim($line)); + if (empty($namespace[0]) || empty($namespace[1])) { + $form_state->setErrorByName( + self::RDF_NAMESPACES, + $this->t("RDF Namespace form is malformed on line '@line'", + ['@line' => trim($line)] + ) + ); + } + } } /** @@ -285,10 +313,25 @@ public function submitForm(array &$form, FormStateInterface $form_state) { } } + $namespaces_array = []; + foreach (preg_split("/[\r\n]+/", $form_state->getValue(self::RDF_NAMESPACES)) as $line) { + if (empty($line)) { + continue; + } + $namespace = explode("|", trim($line)); + if (!empty($namespace[0]) && !empty($namespace[1])) { + $namespaces_array[] = [ + 'prefix' => trim($namespace[0]), + 'namespace' => trim($namespace[1]), + ]; + } + } + $config ->set(self::BROKER_URL, $form_state->getValue(self::BROKER_URL)) ->set(self::JWT_EXPIRY, $form_state->getValue(self::JWT_EXPIRY)) ->set(self::GEMINI_PSEUDO, $pseudo_types) + ->set(self::RDF_NAMESPACES, $namespaces_array) ->save(); parent::submitForm($form, $form_state); From e8764288028616fd8d6be5d47b71af35c22e6134 Mon Sep 17 00:00:00 2001 From: Seth Shaw Date: Tue, 20 Apr 2021 16:04:19 -0700 Subject: [PATCH 2/3] namespaces config update hook --- islandora.install | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/islandora.install b/islandora.install index e4d94f9e7..417143b70 100644 --- a/islandora.install +++ b/islandora.install @@ -90,3 +90,69 @@ function islandora_update_8005() { } } } + +/** + * Adds initial namespace configurations. + */ +function islandora_update_8006() { + $namespaces = [ + [ + 'prefix' => 'ldp', + 'namespace' => 'http://www.w3.org/ns/ldp#', + ], [ + 'prefix' => 'dc11', + 'namespace' => 'http://purl.org/dc/elements/1.1/', + ], [ + 'prefix' => 'dcterms', + 'namespace' => 'http://purl.org/dc/terms/', + ], [ + 'prefix' => 'nfo', + 'namespace' => 'http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/v1.1/', + ], [ + 'prefix' => 'ebucore', + 'namespace' => 'http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#', + ], [ + 'prefix' => 'fedora', + 'namespace' => 'http://fedora.info/definitions/v4/repository#', + ], [ + 'prefix' => 'owl', + 'namespace' => 'http://www.w3.org/2002/07/owl#', + ], [ + 'prefix' => 'ore', + 'namespace' => 'http://www.openarchives.org/ore/terms/', + ], [ + 'prefix' => 'rdf', + 'namespace' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', + ], [ + 'prefix' => 'rdau', + 'namespace' => 'http://rdaregistry.info/Elements/u/', + ], [ + 'prefix' => 'islandora', + 'namespace' => 'http://islandora.ca/', + ], [ + 'prefix' => 'pcdm', + 'namespace' => 'http://pcdm.org/models#', + ], [ + 'prefix' => 'use', + 'namespace' => 'http://pcdm.org/use#', + ], [ + 'prefix' => 'iana', + 'namespace' => 'http://www.iana.org/assignments/relation/', + ], [ + 'prefix' => 'premis', + 'namespace' => 'http://www.loc.gov/premis/rdf/v1#', + ], [ + 'prefix' => 'premis3', + 'namespace' => 'http://www.loc.gov/premis/rdf/v3/', + ], [ + 'prefix' => 'co', + 'namespace' => 'http://purl.org/co/', + ], + ]; + + $config = \Drupal::configFactory()->getEditable('islandora.settings'); + if ($config && !is_array($config->get('rdf_namespaces'))) { + $config->set('rdf_namespaces', $namespaces); + $config->save(TRUE); + } +} From 908b534b8a16e69a9f9c9e451320a1e10b6f4eb5 Mon Sep 17 00:00:00 2001 From: Seth Shaw Date: Tue, 20 Apr 2021 22:09:40 -0700 Subject: [PATCH 3/3] fix broken islandora.settings.yml --- config/install/islandora.settings.yml | 32 +++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/config/install/islandora.settings.yml b/config/install/islandora.settings.yml index 7b4646339..61d7d60bb 100644 --- a/config/install/islandora.settings.yml +++ b/config/install/islandora.settings.yml @@ -5,52 +5,52 @@ gemini_pseudo_bundles: [] rdf_namespaces: - prefix: 'ldp' - namespace: 'http://www.w3.org/ns/ldp#', + namespace: 'http://www.w3.org/ns/ldp#' - prefix: 'dc11' - namespace: 'http://purl.org/dc/elements/1.1/', + namespace: 'http://purl.org/dc/elements/1.1/' - prefix: 'dcterms' - namespace: 'http://purl.org/dc/terms/', + namespace: 'http://purl.org/dc/terms/' - prefix: 'nfo' - namespace: 'http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/v1.1/', + namespace: 'http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/v1.1/' - prefix: 'ebucore' - namespace: 'http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#', + namespace: 'http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#' - prefix: 'fedora' - namespace: 'http://fedora.info/definitions/v4/repository#', + namespace: 'http://fedora.info/definitions/v4/repository#' - prefix: 'owl' - namespace: 'http://www.w3.org/2002/07/owl#', + namespace: 'http://www.w3.org/2002/07/owl#' - prefix: 'ore' - namespace: 'http://www.openarchives.org/ore/terms/', + namespace: 'http://www.openarchives.org/ore/terms/' - prefix: 'rdf' - namespace: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', + namespace: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' - prefix: 'rdau' namespace: 'http://rdaregistry.info/Elements/u/' - prefix: 'islandora' - namespace: 'http://islandora.ca/', + namespace: 'http://islandora.ca/' - prefix: 'pcdm' - namespace: 'http://pcdm.org/models#', + namespace: 'http://pcdm.org/models#' - prefix: 'use' - namespace: 'http://pcdm.org/use#', + namespace: 'http://pcdm.org/use#' - prefix: 'iana' - namespace: 'http://www.iana.org/assignments/relation/', + namespace: 'http://www.iana.org/assignments/relation/' - prefix: 'premis' - namespace: 'http://www.loc.gov/premis/rdf/v1#', + namespace: 'http://www.loc.gov/premis/rdf/v1#' - prefix: 'premis3' - namespace: 'http://www.loc.gov/premis/rdf/v3/', + namespace: 'http://www.loc.gov/premis/rdf/v3/' - prefix: 'co' - namespace: 'http://purl.org/co/', \ No newline at end of file + namespace: 'http://purl.org/co/'