From 1e95930a2a0319d2dde38913e44bff0ffbe82423 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Mon, 28 May 2018 17:29:01 +0300 Subject: [PATCH 1/6] Add an empty dcat_demo module. --- modules/dcat_demo/dcat_demo.info.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 modules/dcat_demo/dcat_demo.info.yml diff --git a/modules/dcat_demo/dcat_demo.info.yml b/modules/dcat_demo/dcat_demo.info.yml new file mode 100644 index 00000000..1cf71b98 --- /dev/null +++ b/modules/dcat_demo/dcat_demo.info.yml @@ -0,0 +1,7 @@ +name: 'DCAT Demo' +type: module +description: 'DCAT Demo' +core: 8.x +package: Custom +dependencies: + - rdf_entity From eb902917b0adbdf309d0b20381891389d1ee9139 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Mon, 28 May 2018 17:30:25 +0300 Subject: [PATCH 2/6] Allow to pass a custom SPARQL endpoint path to the connection. Default to 'sparql'. --- src/Database/Driver/sparql/Connection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Database/Driver/sparql/Connection.php b/src/Database/Driver/sparql/Connection.php index c0090de8..08e926c3 100644 --- a/src/Database/Driver/sparql/Connection.php +++ b/src/Database/Driver/sparql/Connection.php @@ -184,8 +184,8 @@ public function getLogger() { * The EasyRdf connection. */ public static function open(array &$connection_options = []) { - // @todo Get endpoint string from settings file. - $connect_string = 'http://' . $connection_options['host'] . ':' . $connection_options['port'] . '/sparql'; + $enpoint_path = $connection_options['database'] ?? 'sparql'; + $connect_string = "http://{$connection_options['host']}:{$connection_options['port']}/{$enpoint_path}"; return new Client($connect_string); } From c3c27e4688d2c16a6bc7eb253b0fe4a761d2b38f Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Mon, 28 May 2018 17:32:41 +0300 Subject: [PATCH 3/6] Externalize the build SPARQL connection info array in RdfDatabaseConnectionTrait, so that a test can override it. --- .../src/Traits/RdfDatabaseConnectionTrait.php | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/tests/src/Traits/RdfDatabaseConnectionTrait.php b/tests/src/Traits/RdfDatabaseConnectionTrait.php index a0faf637..915d3825 100644 --- a/tests/src/Traits/RdfDatabaseConnectionTrait.php +++ b/tests/src/Traits/RdfDatabaseConnectionTrait.php @@ -33,7 +33,7 @@ trait RdfDatabaseConnectionTrait { protected function detectVirtuoso6() { $client = Http::getDefaultHttpClient(); $client->resetParameters(TRUE); - $client->setUri("http://{$this->sparqlConnectionInfo['host']}:{$this->sparqlConnectionInfo['port']}/"); + $client->setUri("http://{$this->getSparqlConnectionInfo()['host']}:{$this->getSparqlConnectionInfo()['port']}/"); $client->setMethod('GET'); $response = $client->request(); $server_header = $response->getHeader('Server'); @@ -49,21 +49,8 @@ protected function detectVirtuoso6() { * When SIMPLETEST_SPARQL_DB is not set. */ protected function setUpSparql() { - // If the test is run with argument db url then use it. - // export SIMPLETEST_SPARQL_DB='sparql://127.0.0.1:8890/'. - $db_url = getenv('SIMPLETEST_SPARQL_DB'); - if (empty($db_url)) { - throw new \LogicException('No Sparql connection was defined. Set the SIMPLETEST_SPARQL_DB environment variable.'); - } - - $this->sparqlConnectionInfo = Database::convertDbUrlToConnectionInfo($db_url, dirname(dirname(__FILE__))); - $this->sparqlConnectionInfo['namespace'] = 'Drupal\\rdf_entity\\Database\\Driver\\sparql'; - - // Do not allow Virtuoso 6. $this->detectVirtuoso6(); - - Database::addConnectionInfo('sparql_default', 'default', $this->sparqlConnectionInfo); - + Database::addConnectionInfo('sparql_default', 'default', $this->getSparqlConnectionInfo()); $this->sparql = Database::getConnection('default', 'sparql_default'); } @@ -85,4 +72,21 @@ protected function writeSettings(array $settings) { parent::writeSettings($settings); } + /** + * Returns the SPARQL connection info. + * + * @return array + * The connection infp array. + */ + protected function getSparqlConnectionInfo(): array { + if (!isset($this->sparqlConnectionInfo)) { + if (empty($db_url = getenv('SIMPLETEST_SPARQL_DB'))) { + throw new \LogicException('No SPARQL connection was defined. Set the SIMPLETEST_SPARQL_DB environment variable.'); + } + $this->sparqlConnectionInfo = Database::convertDbUrlToConnectionInfo($db_url, dirname(dirname(__FILE__))); + $this->sparqlConnectionInfo['namespace'] = 'Drupal\\rdf_entity\\Database\\Driver\\sparql'; + } + return $this->sparqlConnectionInfo; + } + } From 088022f23ff9c23c6ff97341fac22c2f377f1b6f Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Mon, 28 May 2018 17:34:03 +0300 Subject: [PATCH 4/6] Give it a first try to get data from European data Portal endpoint. --- .../tests/src/Functional/DcatDemoTest.php | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 modules/dcat_demo/tests/src/Functional/DcatDemoTest.php diff --git a/modules/dcat_demo/tests/src/Functional/DcatDemoTest.php b/modules/dcat_demo/tests/src/Functional/DcatDemoTest.php new file mode 100644 index 00000000..525cb4c5 --- /dev/null +++ b/modules/dcat_demo/tests/src/Functional/DcatDemoTest.php @@ -0,0 +1,60 @@ +setUpSparql(); + parent::setUp(); + } + + /** + * {@inheritdoc} + */ + public function test() { + $query = <<sparql->query($query); + $this->assertNotEmpty($response); + } + + /** + * {@inheritdoc} + */ + protected function getSparqlConnectionInfo(): array { + if (!isset($this->sparqlConnectionInfo)) { + $this->getSparqlConnectionInfoTrait(); + $this->sparqlConnectionInfo['host'] = 'data.europa.eu'; + $this->sparqlConnectionInfo['port'] = 80; + $this->sparqlConnectionInfo['database'] = 'euodp/sparqlep'; + } + return $this->sparqlConnectionInfo; + } + +} From 75c9b8542f171c0eac519df49dd45c05dc88583f Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Mon, 28 May 2018 17:40:05 +0300 Subject: [PATCH 5/6] Document that the SPARQL endpoint path can be configured. --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 60364535..baa99179 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Grant 'update' rights to the SPARQL user: System admin -> Users -> SPARQL (edit) Account roles -> Put SPARQL_UPDATE in 'Selected' -## Connecting Drupal to the Sparql endpoint +## Connecting Drupal to the SPARQL endpoint The following example demonstrates the use with a local Virtuoso installation. To connect Drupal to the endpoint, the db connection should be added to the settings.php file. @@ -54,6 +54,9 @@ settings.php file. 'prefix' => '', 'host' => '127.0.0.1', 'port' => '8890', + // Optional. This is actually the endpoint path. If omitted, 'sparql' will + // be used. + 'database' => 'data/endpoint', 'namespace' => 'Drupal\\rdf_entity\\Database\\Driver\\sparql', 'driver' => 'sparql', ]; From a3e89d024b64d67aa2101b180d420de61ded726a Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Tue, 29 May 2018 13:46:33 +0300 Subject: [PATCH 6/6] TMP --- config/schema/rdf_entity.schema.yml | 2 +- .../rdf_entity.mapping.rdf_entity.catalog.yml | 72 +++++++++++++++++++ .../install/rdf_entity.rdfentity.catalog.yml | 7 ++ .../install/rdf_entity.rdfentity.dataset.yml | 7 ++ src/Entity/RdfEntityType.php | 9 ++- src/RdfEntityTypeInterface.php | 3 +- .../install/rdf_entity.rdfentity.dummy.yml | 4 ++ .../rdf_entity.rdfentity.multifield.yml | 4 ++ .../rdf_entity.rdfentity.with_owner.yml | 4 ++ 9 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 modules/dcat_demo/config/install/rdf_entity.mapping.rdf_entity.catalog.yml create mode 100644 modules/dcat_demo/config/install/rdf_entity.rdfentity.catalog.yml create mode 100644 modules/dcat_demo/config/install/rdf_entity.rdfentity.dataset.yml diff --git a/config/schema/rdf_entity.schema.yml b/config/schema/rdf_entity.schema.yml index 8516a3fe..00244fca 100644 --- a/config/schema/rdf_entity.schema.yml +++ b/config/schema/rdf_entity.schema.yml @@ -1,7 +1,7 @@ # Schema for the configuration files of the rdf_entity module. rdf_entity.rdfentity.*: - type: config_entity + type: bundle_entity_with_plural_labels label: 'Rdf type' mapping: name: diff --git a/modules/dcat_demo/config/install/rdf_entity.mapping.rdf_entity.catalog.yml b/modules/dcat_demo/config/install/rdf_entity.mapping.rdf_entity.catalog.yml new file mode 100644 index 00000000..1fc1d65d --- /dev/null +++ b/modules/dcat_demo/config/install/rdf_entity.mapping.rdf_entity.catalog.yml @@ -0,0 +1,72 @@ +langcode: en +status: true +dependencies: + config: + - rdf_entity.graph.default + - rdf_entity.rdfentity.catalog +third_party_settings: { } +id: rdf_entity.catalog +entity_type_id: rdf_entity +bundle: catalog +rdf_type: 'http://www.w3.org/ns/dcat#Catalog' +base_fields_mapping: + rid: + target_id: + predicate: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' + format: resource + label: + value: + predicate: 'http://purl.org/dc/terms/title' + format: t_literal + created: + value: + predicate: 'http://purl.org/dc/terms/issued' + format: 'xsd:dateTime' + changed: + value: + predicate: 'http://purl.org/dc/terms/modified' + format: 'xsd:dateTime' + uuid: + value: + predicate: '' + format: '' + langcode: + value: + predicate: 'http://joinup.eu/language' + format: t_literal + default_langcode: + value: + predicate: 'http://joinup.eu/language/default' + format: literal + content_translation_source: + value: + predicate: 'http://joinup.eu/language/translation_source' + format: t_literal + content_translation_outdated: + value: + predicate: 'http://joinup.eu/language/translation_outdated' + format: t_literal + content_translation_uid: + target_id: + predicate: 'http://joinup.eu/language/translation_author' + format: t_literal + content_translation_status: + value: + predicate: 'http://joinup.eu/language/translation_status' + format: t_literal + content_translation_created: + value: + predicate: 'http://joinup.eu/language/translation_created_time' + format: t_literal + content_translation_changed: + value: + predicate: 'http://joinup.eu/language/translation_changed_time' + format: t_literal + graph: + value: + predicate: '' + format: '' +graph: + default: 'http://joinup.eu/catalog/published' + draft: 'http://joinup.eu/catalog/draft' +entity_id_plugin: joinup_po_namespace diff --git a/modules/dcat_demo/config/install/rdf_entity.rdfentity.catalog.yml b/modules/dcat_demo/config/install/rdf_entity.rdfentity.catalog.yml new file mode 100644 index 00000000..f77d46a1 --- /dev/null +++ b/modules/dcat_demo/config/install/rdf_entity.rdfentity.catalog.yml @@ -0,0 +1,7 @@ +langcode: en +status: true +dependencies: { } +third_party_settings: { } +name: Dataset +rid: dataset +description: 'Represents a set of data.' diff --git a/modules/dcat_demo/config/install/rdf_entity.rdfentity.dataset.yml b/modules/dcat_demo/config/install/rdf_entity.rdfentity.dataset.yml new file mode 100644 index 00000000..187873c7 --- /dev/null +++ b/modules/dcat_demo/config/install/rdf_entity.rdfentity.dataset.yml @@ -0,0 +1,7 @@ +langcode: en +status: true +dependencies: { } +third_party_settings: { } +name: Catalog +rid: catalog +description: 'A catalog of data-sets.' diff --git a/src/Entity/RdfEntityType.php b/src/Entity/RdfEntityType.php index 98788e7c..dcfd2781 100644 --- a/src/Entity/RdfEntityType.php +++ b/src/Entity/RdfEntityType.php @@ -3,6 +3,7 @@ namespace Drupal\rdf_entity\Entity; use Drupal\Core\Config\Entity\ConfigEntityBundleBase; +use Drupal\Core\Config\Entity\EntityBundleWithPluralLabelsTrait; use Drupal\rdf_entity\RdfEntityTypeInterface; /** @@ -36,11 +37,17 @@ * config_export = { * "name", * "rid", - * "description" + * "description", + * "label_singular", + * "label_plural", + * "label_count", * } * ) */ class RdfEntityType extends ConfigEntityBundleBase implements RdfEntityTypeInterface { + + use EntityBundleWithPluralLabelsTrait; + /** * The bundle type of RDF entity. * diff --git a/src/RdfEntityTypeInterface.php b/src/RdfEntityTypeInterface.php index 11ca4a5c..1a9b40c0 100644 --- a/src/RdfEntityTypeInterface.php +++ b/src/RdfEntityTypeInterface.php @@ -3,6 +3,7 @@ namespace Drupal\rdf_entity; use Drupal\Core\Config\Entity\ConfigEntityInterface; +use Drupal\Core\Config\Entity\EntityBundleWithPluralLabelsInterface; /** * Provides an interface defining a Rdf entity. @@ -11,6 +12,6 @@ * * @ingroup rdf_entity */ -interface RdfEntityTypeInterface extends ConfigEntityInterface { +interface RdfEntityTypeInterface extends ConfigEntityInterface, EntityBundleWithPluralLabelsInterface { } diff --git a/tests/modules/rdf_entity_test/config/install/rdf_entity.rdfentity.dummy.yml b/tests/modules/rdf_entity_test/config/install/rdf_entity.rdfentity.dummy.yml index d778812a..77e6b887 100644 --- a/tests/modules/rdf_entity_test/config/install/rdf_entity.rdfentity.dummy.yml +++ b/tests/modules/rdf_entity_test/config/install/rdf_entity.rdfentity.dummy.yml @@ -5,3 +5,7 @@ third_party_settings: { } name: Dummy rid: dummy description: '' +label_singular: 'dummy item' +label_plural: 'dummy items' +label_count: + - "1 dummy item\x03@count dummy items" diff --git a/tests/modules/rdf_entity_test/config/install/rdf_entity.rdfentity.multifield.yml b/tests/modules/rdf_entity_test/config/install/rdf_entity.rdfentity.multifield.yml index b8769963..313b0021 100644 --- a/tests/modules/rdf_entity_test/config/install/rdf_entity.rdfentity.multifield.yml +++ b/tests/modules/rdf_entity_test/config/install/rdf_entity.rdfentity.multifield.yml @@ -5,3 +5,7 @@ third_party_settings: { } name: Multifield rid: multifield description: '' +label_singular: 'multifield item' +label_plural: 'multifield items' +label_count: + - "1 multifield item\x03@count multifield items" diff --git a/tests/modules/rdf_entity_test/config/install/rdf_entity.rdfentity.with_owner.yml b/tests/modules/rdf_entity_test/config/install/rdf_entity.rdfentity.with_owner.yml index 76839382..6fd7badb 100644 --- a/tests/modules/rdf_entity_test/config/install/rdf_entity.rdfentity.with_owner.yml +++ b/tests/modules/rdf_entity_test/config/install/rdf_entity.rdfentity.with_owner.yml @@ -5,3 +5,7 @@ third_party_settings: { } name: 'With Owner' rid: with_owner description: '' +label_singular: "'with owner' item" +label_plural: "'with owner' items" +label_count: + - "1 'with owner' item\x03@count 'with owner' items"