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

Make rdf namespaces configurable (Issue 1520) #831

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 52 additions & 0 deletions config/install/islandora.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/'
12 changes: 12 additions & 0 deletions config/schema/islandora.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
66 changes: 66 additions & 0 deletions islandora.install
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
29 changes: 10 additions & 19 deletions islandora.module
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
43 changes: 43 additions & 0 deletions src/Form/IslandoraSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class IslandoraSettingsForm extends ConfigFormBase {
'month',
'year',
];
const RDF_NAMESPACES = 'rdf_namespaces';

/**
* To list the available bundle types.
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)]
)
);
}
}
}

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