Results

24.06.2020
dcat 8.x-1.x-dev :: dcat_export/tests/src/Unit/DcatExportServiceTest.php
   * Easy Rdf graph object.
   *
   * @var \EasyRdf_Graph
   */
  protected $graph;

  /**
   * {@inheritdoc}
   */
    $this->dcatExportService = $this->getDcatExportService();
    $this->graph = new \EasyRdf_Graph();
  }

  /**
   * {@inheritdoc}
   */
  protected function tearDown() {
24.06.2020
dcat 8.x-1.x-dev :: dcat_export/src/Controller/DcatExportController.php
   * @return \Symfony\Component\HttpFoundation\Response
   *
   * @throws \EasyRdf_Exception
   *   Thrown if EasyRdf fails in exporting data.
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   *   Thrown if the entity type doesn't exist.
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   *   Thrown if the storage handler couldn't be loaded.
   * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
   *   Thrown when the output format is not found.
24.06.2020
dcat 8.x-1.x-dev :: dcat_export/src/Event/AddResourceEvent.php
use Drupal\Core\Entity\ContentEntityInterface;
use Symfony\Component\EventDispatcher\Event;
use EasyRdf_Resource;

/**
 * Provides an add-resource event for event listeners.
 */
class AddResourceEvent extends Event {
  /**
   * EasyRdf resource object.
   *
   * @var \EasyRdf_Resource
   */
  protected $resource;

  /**
   * Entity object.
   *
   * Constructs an add-resource event object.
   *
   * @param \EasyRdf_Resource $resource
   *   The EasyRdf resource, based on the given entity.
   * @param \Drupal\Core\Entity\ContentEntityInterface $entity
   *   The entity that is processed into the resource.
   */
  public function __construct(EasyRdf_Resource $resource, ContentEntityInterface $entity) {
    $this->resource = $resource;
    $this->entity = $entity;
  }

  /**
   * Gets the resource object.
   * object is a reference. There is no need to set the object after altering.
   *
   * @return \EasyRdf_Resource
   *   The EasyRdf resource, based on the entity in this event object.
   */
  public function getResource() {
    return $this->resource;
  }

  /**
   *
   * @return \Drupal\Core\Entity\ContentEntityInterface
   *   The EasyRdf resource, based on the entity in this event object.
   */
  public function getEntity() {
    return $this->entity;
  }

}
24.06.2020
dcat 8.x-1.x-dev :: dcat_export/src/Event/SerializeGraphEvent.php
use Symfony\Component\EventDispatcher\Event;
use EasyRdf_Graph;

/**
 * Provides an serialize-graph event for event listeners.
 */
class SerializeGraphEvent extends Event {
  /**
   * EasyRdf graph object.
   *
   * @var \EasyRdf_Graph
   */
  protected $graph;

  /**
   * Constructs a configuration event object.
   *
   * Constructs a configuration event object.
   *
   * @param \EasyRdf_Graph $graph
   *   The EasyRdf resource, based on the given entity.
   */
  public function __construct(EasyRdf_Graph $graph) {
    $this->graph = $graph;
  }

  /**
   * Gets the graph object.
   *
   * after altering.
   *
   * @return \EasyRdf_Graph
   *   The EasyRdf graph.
   */
  public function getGraph() {
    return $this->graph;
  }

}
24.06.2020
dcat 8.x-1.x-dev :: dcat_export/src/DcatExportService.php
use Drupal\dcat_export\Event\SerializeGraphEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use EasyRdf_Graph;
use EasyRdf_Resource;
use EasyRdf_Format;
use InvalidArgumentException;

/**
 * Class DcatExportService.
 *
 * @package Drupal\dcat_export
  /**
   * EasyRdf graph object.
   *
   * @var \EasyRdf_Graph
   */
  protected $graph;

  /**
   * DcatExportService constructor.
   *
    $this->entityTypeManager = $entity_type_manager;
    $this->eventDispatcher = $event_dispatcher;
    $this->graph = new EasyRdf_Graph();

    $this->checkConfiguration();

    // Set namespaces according to the DCAT-AP standard.
    \EasyRdf_Namespace::set('adms', 'http://www.w3.org/ns/adms#');
    \EasyRdf_Namespace::set('dct', 'http://purl.org/dc/terms/');
    \EasyRdf_Namespace::delete('dcterms');
    \EasyRdf_Namespace::delete('dc');
  }

  /**
   * Export DCAT entities as serialised data.
   *
   * @param string $format
   *   The exported dcat string.
   *
   * @throws \EasyRdf_Exception
   *   Thrown if EasyRdf fails in exporting data.
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   *   Thrown if the entity type doesn't exist.
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   *   Thrown if the storage handler couldn't be loaded.
   */
  public function export($format) {
    $format = $this->sanitizeFormat($format);
    $rdf_format = EasyRdf_Format::getFormat($format);

    // Allow other modules to alter the resource being added to the graph.
    $event = new SerializeGraphEvent($this->graph);
    $this->eventDispatcher->dispatch('dcat_export.graph.serialize', $event);

    return $this->graph->serialise($rdf_format);
   * Add a value to a resource, only when the value is not empty.
   *
   * @param \EasyRdf_Resource $resource
   *   The resource to add the value to.
   * @param string $property
   *   The property name.
   * @param mixed $values
   *   Value as string or array.
   * @param string $lang
   *   The number of values added.
   */
  public function addLiteral(EasyRdf_Resource $resource, $property, $values, $lang = NULL) {
    if ($values) {
      return $resource->addLiteral($property, $values, $lang);
    }

    return 0;
  }
   * Add a resource to another resource without throwing errors when empty.
   *
   * @param \EasyRdf_Resource $resource1
   *   The resource to add another resource to.
   * @param string $property
   *   The property name.
   * @param string|\EasyRdf_Resource $resource2
   *   The resource to be the value of the property.
   *
   * @return int
   *   The number of values added (1 or 0).
   */
  public function addResourceSilently(EasyRdf_Resource $resource1, $property, $resource2) {
    if ($resource2) {
      return $resource1->addResource($property, $resource2);
    }

    return 0;
  }
   * Add resources to the graph and return them as objects.
   *
   * @param \EasyRdf_Graph $graph
   *   The RDF graph.
   * @param \Drupal\Core\Entity\ContentEntityInterface[] $entities
   *   The entities of the same type to transform to RDF resources.
   * @param string|null $type
   *   Set type of resource. If not set, the type will be based on entity type.
   *
   *   Set type of resource. If not set, the type will be based on entity type.
   *
   * @return \EasyRdf_Resource[]
   *
   * @throws \InvalidArgumentException
   *   When a resource type has not supporting method.
   */
  protected function addResources(EasyRdf_Graph $graph, array $entities, $type = NULL) {
    $resources = [];

    if (!$entities) {
      return $resources;
    }
   * Add catalog information to the RDF graph.
   *
   * @param \EasyRdf_Graph $graph
   *   The graph object.
   *
   * @return \EasyRdf_Resource
   *
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   *   Thrown if the entity type doesn't exist.
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   *   Thrown if the storage handler couldn't be loaded.
   */
   *   Thrown if the storage handler couldn't be loaded.
   */
  protected function addCatalogResource(EasyRdf_Graph $graph) {
    /** @var \EasyRdf_Resource $resource */
    $resource = $graph->resource($this->config->get('catalog_uri'), ['dcat:Catalog']);
    $this->addLiteral($resource, 'dct:title', $this->config->get('catalog_title'));
    $this->addLiteral($resource, 'dct:description', $this->config->get('catalog_description'));
    $this->addLiteral($resource, 'dct:issued', new \DateTime((string) $this->config->get('catalog_issued')));
    $this->addLiteral($resource, 'dct:modified', new \DateTime($this->lastModified()));
    $this->addResourceSilently($resource, 'foaf:homepage', $this->createCustomResource(
   * Add dataset information to the RDF graph.
   *
   * @param \EasyRdf_Graph $graph
   *   The graph object.
   * @param \Drupal\Core\Entity\ContentEntityInterface $dataset
   *   The dataset entity.
   *
   * @return \EasyRdf_Resource
   *   The created RDF resource.
   *
   * @throws \InvalidArgumentException
   *   When a resource type is not supported.
   */
  protected function addDatasetResource(EasyRdf_Graph $graph, ContentEntityInterface $dataset) {
    /** @var \EasyRdf_Resource $resource */
    $resource = $graph->resource($this->getDatasetUrl($dataset), ['dcat:Dataset']);
    $this->addLiteral($resource, 'dct:title', $dataset->label());
    $this->addLiteral($resource, 'dct:description', $dataset->get('description')->getString());
    $this->addLiteral($resource, 'dct:identifier', $dataset->uuid());
    $this->addResourceSilently($resource,'dct:accrualPeriodicity', $dataset->get('accrual_periodicity')->getString());
    $this->addLiteral($resource, 'dct:issued', new \DateTime($dataset->get('issued')->getString()));
   * Add vcard information to the RDF graph.
   *
   * @param \EasyRdf_Graph $graph
   *   The graph object.
   * @param \Drupal\Core\Entity\ContentEntityInterface $vcard
   *   The vcard entity.
   *
   * @return \EasyRdf_Resource
   */
  protected function addVcardResource(EasyRdf_Graph $graph, ContentEntityInterface $vcard) {
    /** @var \EasyRdf_Resource $resource */
    $resource = $graph->resource($vcard->get('external_id')->getString(), ['vcard:Kind']);
    $this->addLiteral($resource, 'vcard:hasFN', $vcard->label());

    switch ($vcard->bundle()) {
      case 'individual':
        $this->addLiteral($resource, 'vcard:hasNickname', $vcard->get('nickname')->getString());
   * Add agent information to the RDF graph.
   *
   * @param \EasyRdf_Graph $graph
   *   The graph object.
   * @param \Drupal\Core\Entity\ContentEntityInterface $agent
   *   The agent entity.
   *
   * @return \EasyRdf_Resource
   */
  protected function addAgentResource(EasyRdf_Graph $graph, ContentEntityInterface $agent) {
    /** @var \EasyRdf_Resource $resource */
    $resource = $graph->resource($agent->get('external_id')->getString(), ['foaf:Agent']);
    $this->addLiteral($resource, 'foaf:name', $agent->label());

    return $resource;
  }
   * Add distribution information to the RDF graph.
   *
   * @param \EasyRdf_Graph $graph
   *   The graph object.
   * @param \Drupal\Core\Entity\ContentEntityInterface $distribution
   *   The distribution entity.
   *
   * @return \EasyRdf_Resource
   */
  protected function addDistributionResource(EasyRdf_Graph $graph, ContentEntityInterface $distribution) {
    /** @var \EasyRdf_Resource $resource */
    $resource = $graph->resource($distribution->get('external_id')->getString(), ['dcat:Distribution']);
    $this->addResourceSilently($resource, 'dcat:accessURL', $distribution->get('access_url')->getString());
    $this->addResourceSilently($resource, 'dcat:downloadURL', $distribution->get('download_url')->getString());
    $this->addLiteral($resource,'dct:title', $distribution->label());
    $this->addLiteral($resource, 'dct:description', $distribution->get('description')->getString());
    $this->addLiteral($resource, 'dcat:mediaType', $distribution->get('media_type')->getString());
   * Add theme information to the RDF graph.
   *
   * @param \EasyRdf_Graph $graph
   *   The graph object.
   * @param \Drupal\Core\Entity\ContentEntityInterface $theme
   *   The theme entity.
   *
   * @return \EasyRdf_Resource
   */
  protected function addThemeResource(EasyRdf_Graph $graph, ContentEntityInterface $theme) {
    /** @var \EasyRdf_Resource $resource */
    $resource = $graph->resource($theme->get('external_id')->getString(), ['dcat:Theme']);
    $this->addLiteral($resource, 'dct:label', $theme->label());

    return $resource;
  }
   * Add a custom resource to the RDF graph.
   *
   * @param \EasyRdf_Graph $graph
   *   The graph object.
   * @param string $type
   *   The type of the resource.
   * @param string $uri
   *   The URI of the resource.
   * @param array $properties
   *   ]
   *
   * @return \EasyRdf_Resource|false
   *   The RDF resource object or false if not able to create it.
   */
  protected function createCustomResource(EasyRdf_Graph $graph, $type, $uri, array $properties = []) {
    try {
      /** @var \EasyRdf_Resource $resource */
      $resource = $graph->resource($uri, [$type]);

      // Merge in defaults.
      $properties += [
        'literals' => [],
        'resources' => [],
  /**
   * Set the format in right form suited for the EasyRdf library.
   *
   * @param string $format
   *   The output format.
   *
   * @return string
   *   The sanitized format.
24.06.2020
dcat 8.x-1.x-dev :: dcat_import/tests/src/Unit/Plugin/migrate/source/DcatFeedSourceTest.php
use Drupal\Tests\UnitTestCase;
use Drupal\dcat_import\Plugin\migrate\source\DcatFeedSource;
use EasyRdf_Resource;
use EasyRdf_Literal;
use EasyRdf_Literal_Integer;
use EasyRdf_Literal_DateTime;
use DateTime;

/**
 * @coversDefaultClass \Drupal\dcat_import\Plugin\migrate\source\DcatFeedSource
 * @group dcat_import
 */
   */
  public function providerGetSingleValue() {
    $resource = new EasyRdf_Resource('http://example.com');
    $literal = new EasyRdf_Literal('abcde');
    $literal_integer = new EasyRdf_Literal_Integer(9);
    $date = new DateTime();
    $literal_date = new EasyRdf_Literal_DateTime($date);

    return [
      ['http://example.com', $resource],
      ['abcde', $literal],
      [9, $literal_integer],
      [$date->format('c'), $literal_date],
24.06.2020
dcat 8.x-1.x-dev :: dcat_import/tests/src/Unit/Plugin/DcatGraphTest.php
use Drupal\Tests\UnitTestCase;
use Drupal\dcat_import\Plugin\DcatGraph;
use EasyRdf_Resource;
use EasyRdf_Http_Exception;

/**
 * @coversDefaultClass \Drupal\dcat_import\Plugin\DcatGraph
 * @group dcat_import
 */
class DcatGraphTest extends UnitTestCase {
   */
  public function providerCompareResults() {
    $rescource_a = new EasyRdf_Resource('http://example.com/A');
    $rescource_b = new EasyRdf_Resource('http://example.com/B');

    return [
      [TRUE, [$rescource_a], [$rescource_a]],
      [FALSE, [$rescource_a], [$rescource_b]],
      [
        FALSE, [
        $count++;
        if ($count == 3) {
          throw new EasyRdf_Http_Exception('404 Test', 404);
        }
      }));
    $this->assertSame(4, $graph->load());
  }

  /**
  /**
   * Test load() exceptions other than EasyRdf_Http_Exception are still thrown.
   *
   * @expectedException \Exception
   */
  public function testLoadException() {
    $graph = $this->mockedGraph('load');
  /**
   * Test load() EasyRdf_Http_Exception 404 should throw when there is no data.
   *
   * @expectedException EasyRdf_Http_Exception
   */
  public function testLoadException404() {
    $graph = $this->mockedGraph('load');

    $graph->expects($this->once())
      ->method('loadSingle')
      ->method('loadSingle')
      ->will($this->returnCallback(function() {
        throw new EasyRdf_Http_Exception('404 Test', 404);
      }));
    $graph->load();
  }

  /**
   * Test load() only EasyRdf_Http_Exception 404 should be catched.
   *
   * @expectedException EasyRdf_Http_Exception
   */
  public function testLoadException500() {
    $graph = $this->mockedGraph('load');

    $graph->expects($this->once())
      ->method('loadSingle')
      ->method('loadSingle')
      ->will($this->returnCallback(function() {
        throw new EasyRdf_Http_Exception('500 Test', 500);
      }));
    $graph->load();
  }

}
24.06.2020
dcat 8.x-1.x-dev :: dcat_import/src/Plugin/migrate/source/AgentDcatFeedSource.php
namespace Drupal\dcat_import\Plugin\migrate\source;

use EasyRdf_Resource;
use EasyRdf_Graph;

/**
 * Agent feed source.
 *
 * @MigrateSource(
 *   id = "dcat.agent"
   * {@inheritdoc}
   */
  public function getDcatData(EasyRdf_Graph $graph) {
    $publishers = array();
    $datasets = $graph->allOfType('dcat:Dataset');

    /** @var EasyRdf_Resource $dataset */
    foreach ($datasets as $dataset) {
      $publishers = array_merge($publishers, $dataset->allResources('dc:publisher'));
    }

    // Remove duplicates.
    $uris = array();
    // Remove duplicates.
    $uris = array();
    /** @var EasyRdf_Resource $publisher */
    foreach ($publishers as $key => $publisher) {
      $uri = $publisher->getUri();
      if (isset($uris[$uri])) {
        unset($publishers[$key]);
      }
      else {
    $data = array();

    /** @var EasyRdf_Resource $agent */
    foreach ($this->getSourceData() as $agent) {
      $data[] = array(
        'uri' => $agent->getUri(),
        'name' => $this->getValue($agent, 'foaf:name'),
        'agent_type' => $this->getValue($agent, 'dc:type'),
      );
24.06.2020
dcat 8.x-1.x-dev :: dcat_import/src/Plugin/migrate/source/ThemeGlobalDcatFeedSource.php
namespace Drupal\dcat_import\Plugin\migrate\source;

use EasyRdf_Resource;
use EasyRdf_Graph;

/**
 * External theme feed source.
 *
 * @MigrateSource(
 *   id = "dcat.global_theme"
    $data = array();

    /** @var EasyRdf_Resource $theme */
    foreach ($this->getSourceData() as $theme) {

      $data[] = array(
        'uri' => $theme->getUri(),
        'name' => $this->getValue($theme, 'skos:prefLabel'),
        'description' => $this->getValue($theme, 'rdfs:comment'),
   * Returns the mapping field values for the given $theme.
   *
   * @param EasyRdf_Resource $theme
   *   The resource to get the mapping values from.
   *
   * @return array|null|string
   *   The mapping values.
   */
  public function getMappingValues(EasyRdf_Resource $theme) {
    $mapping = [];
    foreach (self::mappingTags() as $tag) {
      $mapping = array_merge($mapping, $this->getValueArray($theme, $tag));
    }

    return $mapping;
24.06.2020
dcat 8.x-1.x-dev :: dcat_import/src/Plugin/migrate/source/DatasetDcatFeedSource.php
use Drupal\Component\Utility\Unicode;
use Drupal\taxonomy\Plugin\views\wizard\TaxonomyTerm;
use EasyRdf_Resource;
use Drupal\migrate\Row;

/**
 * DCAT Dataset feed source.
 *
 * @MigrateSource(
   * {@inheritdoc}
   */
  public function convertResource(EasyRdf_Resource $resource) {
    return parent::convertResource($resource) + [
      'title' => $this->getValue($resource, 'dc:title'),
      'description' => $this->getValue($resource, 'dc:description'),
      'issued' => $this->getDateValue($resource, 'dc:issued'),
      'modified' => $this->getDateValue($resource, 'dc:modified'),
      'landing_page' => $this->getValue($resource, 'dcat:landingPage'),
24.06.2020
dcat 8.x-1.x-dev :: dcat_import/src/Plugin/migrate/source/DistributionDcatFeedSource.php
namespace Drupal\dcat_import\Plugin\migrate\source;

use EasyRdf_Resource;

/**
 * DCAT Dataset feed source.
 *
 * @MigrateSource(
 *   id = "dcat.distribution"
   * {@inheritdoc}
   */
  public function convertResource(EasyRdf_Resource $resource) {
    return parent::convertResource($resource) + [
      'title' => $this->getValue($resource, 'dc:title'),
      'description' => $this->getValue($resource, 'dc:description'),
      'issued' => $this->getDateValue($resource, 'dc:issued'),
      'modified' => $this->getDateValue($resource, 'dc:modified'),
      'access_url' => $this->getValue($resource, 'dcat:accessURL'),
24.06.2020
dcat 8.x-1.x-dev :: dcat_import/src/Plugin/migrate/source/TermDcatFeedSource.php
use Drupal\Component\Utility\Unicode;
use EasyRdf_Resource;
use EasyRdf_Graph;
use Drupal\migrate\Row;

/**
 * DCAT Term feed source.
 */
abstract class TermDcatFeedSource extends DcatFeedSource {
   * {@inheritdoc}
   */
  public function getDcatData(EasyRdf_Graph $graph) {
    $data = array();
    $datasets = $graph->allOfType('dcat:Dataset');

    /** @var EasyRdf_Resource $dataset */
    foreach ($datasets as $dataset) {
      $keywords = $this->getValue($dataset, $this->getTermField());
      if ($keywords) {
        $keywords = is_array($keywords) ? $keywords : array($keywords);
        $data += array_combine($keywords, $keywords);
      }
24.06.2020
dcat 8.x-1.x-dev :: dcat_import/src/Plugin/migrate/source/DcatFeedSource.php
use Drupal\migrate\Plugin\migrate\source\SourcePluginBase;
use Drupal\dcat_import\Plugin\DcatGraph;
use EasyRdf_Graph;
use EasyRdf_Resource;

/**
 * DCAT feed source.
 */
abstract class DcatFeedSource extends SourcePluginBase {
  /**
   * Extract data from the given EasyRdf Graph.
   *
   * @param EasyRdf_Graph $graph
   *   The EasyRdf Graph to extract the data from.
   *
   * @return array
   *   The extracted data.
   */
  public function getDcatData(EasyRdf_Graph $graph) {
    $data = $graph->allOfType($this->getDcatType());
    return $graph->getNoneBlankResources($data);
  }

  /**
   * Data getter.
   *
   * @return array
   *   An array of EasyRdf resources that are deleted in the current graph.
   */
  private function deletedResources(array $data, DcatGraph $graph) {
    $deleted = [];
    /** @var Sql $map */
    $map = $this->migration->getIdMap();
        return [];
      }
      /** @var EasyRdf_Resource $uri */
      $uri = $resource->getUri();
      unset($imported[(string) $uri]);
    }

    foreach ($imported as $uri => $uuid) {
      $resource = $graph->resource($uri);
  /**
   * Convert an EasyRdf resource to an array.
   *
   * @param \EasyRdf_Resource $resource
   *   The resource to covert.
   *
   * @return array
   *   Array of values to import.
   */
  public function convertResource(EasyRdf_Resource $resource) {
    return [
      'uri' => $resource->getUri(),
      'status' => !$this->getValue($resource, 'deleted'),
    ];
  }
  /**
   * Return all values for a property from an EasyRdf resource.
   *
   * @param \EasyRdf_Resource $resource
   *   The EasyRdf resource to get the property from.
   * @param string $property
   *   The name of the property to get.
   *
   * @return array
   *   The values as an array of strings.
   */
   *   The values as an array of strings.
   */
  public function getValueArray(EasyRdf_Resource $resource, $property) {
    $values = array();

    foreach ($resource->all($property) as $value) {
      if (!empty($value)) {
        $values[] = $this->getSingleValue($value);
      }
  /**
   * Convert an EasyRdf Resource or Literal to a single value.
   *
   * @param mixed $value
   *   EasyRdf_Resource or EasyRdf_Literal object.
   *
   * @return string|null
   *   A single value representing the object or Null if it is a blank resource.
   */
  public function getSingleValue($value) {
    $class = get_class($value);
    $class = get_class($value);
    switch ($class) {
      case 'EasyRdf_Resource':
        if ($value->isBNode()) {
          return NULL;
        }
        return $value->getUri();

      case 'EasyRdf_Literal_DateTime':
        return $value->getValue()->format('c');

      default:
        return $value->getValue();
    }
  }
  /**
   * Get the value for a property from an EasyRdf resource.
   *
   * @param \EasyRdf_Resource $resource
   *   The EasyRdf resource to get the property from.
   * @param string $property
   *   The name of the property to get.
   *
   * @return null|string|array
   *   Null if empty, string if single value, array if multi value.
   */
   *   Null if empty, string if single value, array if multi value.
   */
  public function getValue(EasyRdf_Resource $resource, $property) {
    $values = $this->getValueArray($resource, $property);
    return $this->unifyReturnValue($values);
  }

  /**
   * Get a certain property from an EasyRdf resource as datetime storage string.
   *
   * @param \EasyRdf_Resource $resource
   *   The EasyRdf resource to get the property from.
   * @param string $property
   *   The name of the property to get.
   *
   * @return null|string|array
   *   Null if empty, string if single value, array if multi value.
   */
   *   Null if empty, string if single value, array if multi value.
   */
  public function getDateValue(EasyRdf_Resource $resource, $property) {
    $values = $this->getValueArray($resource, $property);

    $dates = array();
    foreach ($values as $value) {
      $date = $value instanceof \DateTime ? DrupalDateTime::createFromDateTime($value) : new DrupalDateTime($value);
      $dates[] = $date->format(DATETIME_DATETIME_STORAGE_FORMAT);
  /**
   * Get a certain property from an EasyRdf resource as an email string.
   *
   * Basically removes mailto: part.
   *
   * @param \EasyRdf_Resource $resource
   *   The EasyRdf resource to get the property from.
   * @param string $property
   *   The name of the property to get.
   *
   * @return null|string|array
   *   Null if empty, string if single value, array if multi value.
   */
   *   Null if empty, string if single value, array if multi value.
   */
  public function getEmailValue(EasyRdf_Resource $resource, $property) {
    $values = $this->getValueArray($resource, $property);

    $emails = [];
    foreach ($values as $value) {
      $emails[] = $this->stripMailto($value);
    }
24.06.2020
dcat 8.x-1.x-dev :: dcat_import/src/Plugin/migrate/source/VcardDcatFeedSource.php
namespace Drupal\dcat_import\Plugin\migrate\source;

use EasyRdf_Resource;
use EasyRdf_Graph;

/**
 * Agent feed source.
 *
 * @MigrateSource(
 *   id = "dcat.vcard"
   * {@inheritdoc}
   */
  public function getDcatData(EasyRdf_Graph $graph) {
    $vcards = array();
    $datasets = $graph->allOfType('dcat:Dataset');

    /** @var EasyRdf_Resource $dataset */
    foreach ($datasets as $dataset) {
      $vcards = array_merge($vcards, $dataset->allResources('dcat:contactPoint'));
    }

    // Remove duplicates.
    $uris = array();
    // Remove duplicates.
    $uris = array();
    /** @var EasyRdf_Resource $vcard */
    foreach ($vcards as $key => $vcard) {
      $uri = $vcard->getUri();
      if (isset($uris[$uri])) {
        unset($vcards[$key]);
      }
      else {
   * {@inheritdoc}
   */
  public function convertResource(EasyRdf_Resource $resource) {
    if (isset(self::bundleMapping()[$resource->type()])) {
      $bundle = self::bundleMapping()[$resource->type()];
    }
    else {
      // Default to organization;
      $bundle = 'organization';
24.06.2020
dcat 8.x-1.x-dev :: dcat_import/src/Plugin/migrate/source/ThemeDcatFeedSource.php
namespace Drupal\dcat_import\Plugin\migrate\source;

use EasyRdf_Resource;
use EasyRdf_Graph;

/**
 * Theme feed source.
 *
 * @MigrateSource(
 *   id = "dcat.theme"
   * {@inheritdoc}
   */
  public function getDcatData(EasyRdf_Graph $graph) {
    $data = array();
    $datasets = $graph->allOfType('dcat:Dataset');

    /** @var EasyRdf_Resource $dataset */
    foreach ($datasets as $dataset) {
      $themes = $this->getValue($dataset, 'dcat:theme');
      if ($themes) {
        $themes = is_array($themes) ? $themes : array($themes);
        $data += array_combine($themes, $themes);
      }
    $data = array();

    /** @var EasyRdf_Resource $theme */
    foreach ($this->getSourceData() as $theme) {
      // Until we have a better solution, we'll use the URI as name.
      $data[] = array(
        'uri' => $theme,
        'name' => $theme,
      );
24.06.2020
dcat 8.x-1.x-dev :: dcat_import/src/Plugin/DcatGraph.php
namespace Drupal\dcat_import\Plugin;

use EasyRdf_Graph;
use EasyRdf_Resource;
use EasyRdf_Http_Exception;

/**
 * Class DcatGraph.
 *
 * @package Drupal\dcat_import\Plugin
 */
 * @package Drupal\dcat_import\Plugin
 */
class DcatGraph extends EasyRdf_Graph {

  /**
   * Pager argument.
   *
   * @var string.
   */
    parent::__construct($uri, $data, $format);

    \EasyRdf_Namespace::set('adms', 'http://www.w3.org/ns/adms#');
  }

  /**
   * {@inheritdoc}
   */
  public static function newAndLoad($uri, $format = NULL, $pager_argument = NULL) {
   *
   * @param array $previous
   *   An array of EasyRdf_Resource objects.
   * @param array $current
   *   An array of EasyRdf_Resource objects to compare to.
   *
   * @return bool
   *   True if results are the same.
   */
  public function compareResults(array $previous, array $current) {
    // To limit complexity and execution time, only compare the last result.
  public function compareResults(array $previous, array $current) {
    // To limit complexity and execution time, only compare the last result.
    /** @var EasyRdf_Resource $previous_last */
    $previous_last = end($previous);
    /** @var EasyRdf_Resource $current_last */
    $current_last = end($current);

    return $previous_last->getUri() == $current_last->getUri();
  }

  /**
    $resources = empty($resources) ? $this->resources() : $resources;

    /** @var EasyRdf_Resource $resource */
    foreach ($resources as $key => $resource) {
      if ($resource->isBNode() || empty($resource->type())) {
        unset($resources[$key]);
      }
    }
      catch (EasyRdf_Http_Exception $e) {
        if ($e->getCode() == 404 && !empty($current_data)) {
          // When we receive a 404 after we have already received data, it is
          // most likely that we just encountered the end of the DCAT feed.
          break;
        }
        throw $e;
05.10.2020
powertagging 8.x-1.2 :: src/Plugin/Block/PowerTaggingTagGlossaryBlock.php
use Drupal\Core\Block\BlockBase;
use Drupal\taxonomy\Entity\Term;
use EasyRdf_Sparql_Client;

/**
 * Provides a 'PowerTaggingBlock' block plugin.
 *
 * @Block(
 *   id = "powertagging_tag_glossary_block",
          // Get missing definitions from DBpedia if possible.
          if ($global_config->get('tag_glossary_use_dbpedia_definition') && !empty($dbpedia_check_terms)) {
            $dbpedia_store = new EasyRdf_Sparql_Client('http://dbpedia.org/sparql');

            // Define the SPARQL query.
            $query = "
    PREFIX onto:<http://dbpedia.org/ontology/>

    SELECT ?uri, ?definition
28.09.2020
rdfui 8.x-1.0-beta4 :: rdf_builder/src/Form/ContentBuilderForm.php
   * Easy_RDF Converter from rdfui.
   *
   * @var /Drupal/rdfui/EasyRdfConverter
   */
  protected $converter;

  /**
   * The field type manager.
   *
28.09.2020
rdfui 8.x-1.0-beta4 :: src/Form/FieldMappings.php
  /**
   * The EasyRdfConverter.
   *
   * @var \Drupal\rdfui\EasyRdfConverter
   */
  protected $rdfConverter;

  protected $displayContext = 'form';

  protected $entityTypeId;
28.09.2020
rdfui 8.x-1.0-beta4 :: src/Tests/EasyRdfConverterTest.php
 * @group RDF UI
 */
class EasyRdfConverterTest extends KernelTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */

Pages

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc