Skip to content
This repository has been archived by the owner on Aug 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #84 from ec-europa/serializer
Browse files Browse the repository at this point in the history
Move the serializer to the rdf_entity module and expand for all related entities.
  • Loading branch information
idimopoulos authored Mar 1, 2019
2 parents 11961c6 + 22b485e commit fa2cbd3
Show file tree
Hide file tree
Showing 28 changed files with 332 additions and 279 deletions.
35 changes: 0 additions & 35 deletions modules/rdf_export/rdf_export.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,3 @@ services:
arguments: ['@entity_type.manager']
tags:
- { name: event_subscriber }
rdf_export.serializer:
class: Drupal\rdf_export\RdfSerializer
arguments: ['@sparql_endpoint']
rdf_export.encoder_base:
abstract: true
class: Drupal\rdf_export\Encoder\RdfEncoder
rdf_export.encoder.jsonld:
parent: rdf_export.encoder_base
tags:
- { name: encoder, format: jsonld }
rdf_export.encoder.rdfxml:
parent: rdf_export.encoder_base
tags:
- { name: encoder, format: rdfxml }
rdf_export.encoder.ntriples:
parent: rdf_export.encoder_base
tags:
- { name: encoder, format: ntriples }
rdf_export.encoder.turtle:
parent: rdf_export.encoder_base
tags:
- { name: encoder, format: turtle }
rdf_export.encoder.n3:
parent: rdf_export.encoder_base
tags:
- { name: encoder, format: n3 }
rdf_export.rdfsubscriber:
class: Drupal\rdf_export\EventSubscriber\RdfSubscriber
tags:
- { name: event_subscriber }
serializer.normalizer.entity.rdf:
class: Drupal\rdf_export\Normalizer\RdfEntityNormalizer
arguments: ['@rdf_export.serializer']
tags:
- { name: normalizer, priority: 10 }
20 changes: 10 additions & 10 deletions modules/rdf_export/src/Controller/RdfExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\rdf_export\RdfSerializerInterface;
use Drupal\rdf_entity\SparqlSerializerInterface;
use EasyRdf\Format;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -19,28 +19,28 @@
class RdfExportController extends ControllerBase {

/**
* The RDF serializer service.
* The SPARQL serializer service.
*
* @var \Drupal\rdf_export\RdfSerializerInterface
* @var \Drupal\rdf_entity\SparqlSerializerInterface
*/
protected $rdfSerializer;
protected $sparqlSerializer;

/**
* Instantiates a new RdfExportController object.
*
* @param \Drupal\rdf_export\RdfSerializerInterface $rdf_serializer
* The RDF serializer interface.
* @param \Drupal\rdf_entity\SparqlSerializerInterface $sparql_serializer
* The SPARQL serializer interface.
*/
public function __construct(RdfSerializerInterface $rdf_serializer) {
$this->rdfSerializer = $rdf_serializer;
public function __construct(SparqlSerializerInterface $sparql_serializer) {
$this->sparqlSerializer = $sparql_serializer;
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('rdf_export.serializer')
$container->get('rdf_entity.serializer')
);
}

Expand Down Expand Up @@ -97,7 +97,7 @@ public function download(RouteMatchInterface $route_match, $export_format) {
if (!$entity || !$entity instanceof EntityInterface) {
throw new AccessDeniedHttpException();
}
$output = $this->rdfSerializer->serializeEntity($entity, $export_format);
$output = $this->sparqlSerializer->serializeEntity($entity, $export_format);

$response = new Response();
$response->setContent($output);
Expand Down
40 changes: 0 additions & 40 deletions modules/rdf_export/src/Normalizer/RdfEntityNormalizer.php

This file was deleted.

98 changes: 0 additions & 98 deletions modules/rdf_export/src/RdfSerializer.php

This file was deleted.

27 changes: 0 additions & 27 deletions modules/rdf_export/src/RdfSerializerInterface.php

This file was deleted.

This file was deleted.

This file was deleted.

33 changes: 6 additions & 27 deletions modules/rdf_export/tests/src/Functional/RdfExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ class RdfExportTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['rdf_export_test'];
protected static $modules = [
'sparql_entity_serializer_test',
'rdf_export',
];

/**
* Testing entity.
Expand Down Expand Up @@ -53,42 +56,18 @@ public function testRdfExport() {
$page->clickLink('Turtle Terse RDF Triple Language');
$this->assertSession()->statusCodeEquals(200);
$actual_content = $page->getContent();
$expected_content = trim(file_get_contents(__DIR__ . "/../../fixtures/content-negotiation/turtle"));
$expected_content = trim(file_get_contents(__DIR__ . "/../../../../../tests/fixtures/content-negotiation/turtle"));
$this->assertEquals($expected_content, $actual_content);

$this->drupalGet($this->entity->toUrl('rdf-export'));
$page = $this->getSession()->getPage();
$page->clickLink('RDF/XML');
$this->assertSession()->statusCodeEquals(200);
$actual_content = $page->getContent();
$expected_content = trim(file_get_contents(__DIR__ . "/../../fixtures/content-negotiation/rdfxml"));
$expected_content = trim(file_get_contents(__DIR__ . "/../../../../../tests/fixtures/content-negotiation/rdfxml"));
$this->assertEquals($expected_content, $actual_content);
}

/**
* Tests content negotiation.
*/
public function testContentNegotiation() {
$serializers = [
'jsonld' => 'application/ld+json',
'n3' => 'text/n3; charset=UTF-8',
'ntriples' => 'application/n-triples',
'rdfxml' => 'application/rdf+xml',
'turtle' => 'text/turtle; charset=UTF-8',
];

$this->drupalLogin($this->drupalCreateUser(['view rdf entity']));

foreach ($serializers as $format => $content_type) {
$url = $this->entity->toUrl('canonical', ['query' => ['_format' => $format]]);
$this->drupalGet($url);
$content = $this->getSession()->getPage()->getContent();
$expected_content = trim(file_get_contents(__DIR__ . "/../../fixtures/content-negotiation/$format"));
$this->assertEquals($expected_content, $content);
$this->assertSession()->responseHeaderEquals('Content-Type', $content_type);
}
}

/**
* {@inheritdoc}
*/
Expand Down
35 changes: 35 additions & 0 deletions rdf_entity.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,38 @@ services:
arguments: ['@typed_data_manager']
tags:
- { name: event_subscriber }
rdf_entity.serializer:
class: Drupal\rdf_entity\SparqlSerializer
arguments: ['@sparql_endpoint', '@sparql.graph_handler']
rdf_entity.encoder_base:
abstract: true
class: Drupal\rdf_entity\Encoder\SparqlEncoder
rdf_entity.encoder.jsonld:
parent: rdf_entity.encoder_base
tags:
- { name: encoder, format: jsonld }
rdf_entity.encoder.rdfxml:
parent: rdf_entity.encoder_base
tags:
- { name: encoder, format: rdfxml }
rdf_entity.encoder.ntriples:
parent: rdf_entity.encoder_base
tags:
- { name: encoder, format: ntriples }
rdf_entity.encoder.turtle:
parent: rdf_entity.encoder_base
tags:
- { name: encoder, format: turtle }
rdf_entity.encoder.n3:
parent: rdf_entity.encoder_base
tags:
- { name: encoder, format: n3 }
rdf_entity.sparql_entity_normalizer:
class: Drupal\rdf_entity\Normalizer\SparqlEntityNormalizer
arguments: ['@rdf_entity.serializer', '@entity_type.manager']
tags:
- { name: normalizer, priority: 10 }
rdf_entity.rdf_content_type.subscriber:
class: Drupal\rdf_entity\EventSubscriber\RdfContentTypesSubscriber
tags:
- { name: event_subscriber }
Loading

0 comments on commit fa2cbd3

Please sign in to comment.