Browse Source

Merging from upstream

pull/756/head
Danny Lamb 8 years ago
parent
commit
2b8146b5a8
  1. 23
      .scripts/travis_setup.sh
  2. 4
      .travis.yml
  3. 13
      islandora/config/install/rdf.mapping.fedora_resource_type.rdf_source.yml
  4. 1
      islandora/islandora.module
  5. 2
      islandora/islandora.services.yml
  6. 26
      islandora/src/Entity/FedoraResource.php
  7. 60
      islandora/src/EventGenerator/EventGenerator.php
  8. 52
      islandora/src/EventGenerator/EventGeneratorInterface.php
  9. 8
      islandora/src/FedoraResourceInterface.php
  10. 124
      islandora/tests/src/Kernel/EventGeneratorTest.php
  11. 48
      islandora/tests/src/Kernel/IslandoraKernelTestBase.php
  12. 54
      islandora/tests/src/Kernel/VectorClockTest.php
  13. 8
      islandora_collection/config/install/field.field.fedora_resource.collection.field_description.yml
  14. 8
      islandora_collection/config/install/field.storage.fedora_resource.field_description.yml
  15. 6
      islandora_collection/config/install/rdf.mapping.fedora_resource_type.collection.yml

23
.scripts/travis_setup.sh

@ -3,16 +3,16 @@ mysql -u root -e 'create database drupal;'
mysql -u root -e "GRANT ALL PRIVILEGES ON drupal.* To 'drupal'@'localhost' IDENTIFIED BY 'drupal';"
# Java (Oracle)
sudo apt-get install -y software-properties-common
sudo apt-get install -y python-software-properties
sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
sudo apt-get install -y oracle-java8-installer
sudo update-java-alternatives -s java-8-oracle
sudo apt-get install -y oracle-java8-set-default
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
#sudo apt-get install -y software-properties-common
#sudo apt-get install -y python-software-properties
#sudo add-apt-repository -y ppa:webupd8team/java
#sudo apt-get update
#echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
#echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
#sudo apt-get install -y oracle-java8-installer
#sudo update-java-alternatives -s java-8-oracle
#sudo apt-get install -y oracle-java8-set-default
#export JAVA_HOME=/usr/lib/jvm/java-8-oracle
# phpcpd
#sudo apt-get install -y phpcpd
@ -46,6 +46,7 @@ drush en -y syslog
drush en -y serialization
drush en -y basic_auth
drush en -y rest
drush en -y simpletest
drush dl rdfui --dev
drush en -y rdfui
@ -71,6 +72,8 @@ cd $HOME/drupal/modules
git clone https://github.com/DiegoPino/claw-jsonld.git
drush en -y jsonld
drush en -y islandora
drush -y dl bootstrap
drush -y en bootstrap
drush -y config-set system.theme default bootstrap

4
.travis.yml

@ -20,15 +20,17 @@ before_install:
- export ISLANDORA_DIR=$TRAVIS_BUILD_DIR
install:
# - $TRAVIS_BUILD_DIR/tests/scripts/travis_setup.sh
- $TRAVIS_BUILD_DIR/.scripts/travis_setup.sh
- composer install
- php vendor/bin/phpcs --config-set installed_paths vendor/drupal/coder/coder_sniffer
script:
- $ISLANDORA_DIR/.scripts/line_endings.sh .
- cd $HOME/drupal/modules/islandora
- php vendor/bin/phpcs --standard=Drupal **/*.module **/*.php --ignore=tests,vendor .
- php vendor/bin/phpcpd --names *.module,*.inc,*.test,*.php --exclude=vendor .
- cd $HOME/drupal; php core/scripts/run-tests.sh --php `which php` islandora
notifications:
irc:

13
islandora/config/install/rdf.mapping.fedora_resource_type.rdf_source.yml

@ -6,7 +6,7 @@ dependencies:
module:
- islandora
id: fedora_resource_type.rdf_source
targetEntityType: fedora_resource_type
targetEntityType: fedora_resource
bundle: rdf_source
types:
- 'schema:Thing'
@ -30,7 +30,18 @@ fieldMappings:
rdf_type:
properties:
- 'rdf:type'
vclock:
properties:
- 'islandora:vclock'
uid:
properties:
- 'schema:author'
mapping_type: rel
fedora_has_parent:
properties:
- 'fedora:hasParent'
mapping_type: rel
ldp_contains:
properties:
- 'ldp:contains'
mapping_type: rel

1
islandora/islandora.module

@ -80,5 +80,6 @@ function islandora_rdf_namespaces() {
'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/CLAW/',
);
}

2
islandora/islandora.services.yml

@ -6,3 +6,5 @@ services:
tags:
- { name: paramconverter }
arguments: ['@entity.manager']
islandora.eventgenerator:
class: Drupal\islandora\EventGenerator\EventGenerator

26
islandora/src/Entity/FedoraResource.php

@ -121,6 +121,18 @@ class FedoraResource extends ContentEntityBase implements FedoraResourceInterfac
);
}
/**
* {@inheritdoc}
*/
public function preSave(EntityStorageInterface $storage) {
parent::preSave($storage);
// Increment the vclock.
if (!$this->isNew()) {
$this->set("vclock", $this->get("vclock")->value + 1);
}
}
/**
* {@inheritdoc}
*/
@ -261,6 +273,13 @@ class FedoraResource extends ContentEntityBase implements FedoraResourceInterfac
return array('root');
}
/**
* {@inheritdoc}
*/
public function getVclock() {
return $this->get('vclock')->value;
}
/**
* {@inheritdoc}
*/
@ -283,6 +302,11 @@ class FedoraResource extends ContentEntityBase implements FedoraResourceInterfac
->setLabel(t('UUID'))
->setDescription(t('The UUID of the Fedora resource entity.'))
->setReadOnly(TRUE);
$fields['vclock'] = BaseFieldDefinition::create('integer')
->setLabel(t('Vector Clock'))
->setDescription(t('Simple accumulator used for causality tracking'))
->setDefaultValue(0)
->setSetting('unsigned', TRUE);
$fields['user_id'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Authored by'))
@ -340,7 +364,7 @@ class FedoraResource extends ContentEntityBase implements FedoraResourceInterfac
->setLabel(t('LDP Contains'))
->setDescription(t('Contains Fedora Resource.'))
->setRevisionable(TRUE)
->setSetting('target_type', 'fedora_resource_type')
->setSetting('target_type', 'fedora_resource')
->setSetting('handler', 'default')
->setTranslatable(TRUE)
->setDisplayOptions('view', array(

60
islandora/src/EventGenerator/EventGenerator.php

@ -0,0 +1,60 @@
<?php
namespace Drupal\islandora\EventGenerator;
use Drupal\Core\Entity\EntityInterface;
use Drupal\user\UserInterface;
/**
* The default EventGenerator implementation.
*
* Provides Activity Stream 2.0 serialized events.
*/
class EventGenerator implements EventGeneratorInterface {
/**
* {@inheritdoc}
*/
public function generateCreateEvent(EntityInterface $entity, UserInterface $user) {
return json_encode([
"@context" => "https://www.w3.org/ns/activitystreams",
"type" => "Create",
"actor" => [
"type" => "Person",
"id" => $user->toUrl()->setAbsolute()->toString(),
],
"object" => $entity->toUrl()->setAbsolute()->toString(),
]);
}
/**
* {@inheritdoc}
*/
public function generateUpdateEvent(EntityInterface $entity, UserInterface $user) {
return json_encode([
"@context" => "https://www.w3.org/ns/activitystreams",
"type" => "Update",
"actor" => [
"type" => "Person",
"id" => $user->toUrl()->setAbsolute()->toString(),
],
"object" => $entity->toUrl()->setAbsolute()->toString(),
]);
}
/**
* {@inheritdoc}
*/
public function generateDeleteEvent(EntityInterface $entity, UserInterface $user) {
return json_encode([
"@context" => "https://www.w3.org/ns/activitystreams",
"type" => "Delete",
"actor" => [
"type" => "Person",
"id" => $user->toUrl()->setAbsolute()->toString(),
],
"object" => $entity->toUrl()->setAbsolute()->toString(),
]);
}
}

52
islandora/src/EventGenerator/EventGeneratorInterface.php

@ -0,0 +1,52 @@
<?php
namespace Drupal\islandora\EventGenerator;
use Drupal\Core\Entity\EntityInterface;
use Drupal\user\UserInterface;
/**
* Inteface for a service that provides serialized event messages.
*/
interface EventGeneratorInterface {
/**
* Generates a serialized 'Create' event.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity that was created.
* @param \Drupal\user\UserInterface $user
* The user who created the entity.
*
* @return string
* Serialized event message
*/
public function generateCreateEvent(EntityInterface $entity, UserInterface $user);
/**
* Generates a serialized 'Create' event.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity that was updated.
* @param \Drupal\user\UserInterface $user
* The user who updated the entity.
*
* @return string
* Serialized event message
*/
public function generateUpdateEvent(EntityInterface $entity, UserInterface $user);
/**
* Generates a serialized 'Create' event.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity that was deleted.
* @param \Drupal\user\UserInterface $user
* The user who deleted the entity.
*
* @return string
* Serialized event message
*/
public function generateDeleteEvent(EntityInterface $entity, UserInterface $user);
}

8
islandora/src/FedoraResourceInterface.php

@ -117,4 +117,12 @@ interface FedoraResourceInterface extends ContentEntityInterface, EntityChangedI
*/
public function setParent(EntityTypeInterface $entity);
/**
* Gets the vector clock of this entity.
*
* @return int
* The vector clock, used for determining causality.
*/
public function getVclock();
}

124
islandora/tests/src/Kernel/EventGeneratorTest.php

@ -0,0 +1,124 @@
<?php
namespace Drupal\Tests\islandora\Kernel;
use Drupal\islandora\Entity\FedoraResource;
use Drupal\islandora\EventGenerator\EventGenerator;
use Drupal\simpletest\UserCreationTrait;
/**
* Tests the EventGenerator default implementation.
*
* @group islandora
*/
class EventGeneratorTest extends IslandoraKernelTestBase {
use UserCreationTrait {
createUser as drupalCreateUser;
}
/**
* User entity.
*
* @var \Drupal\user\UserInterface
*/
protected $user;
/**
* Fedora resource entity.
*
* @var \Drupal\islandora\FedoraResourceInterface
*/
protected $entity;
/**
* The EventGenerator to test.
*
* @var \Drupal\islandora\EventGenerator\EventGeneratorInterface
*/
protected $eventGenerator;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
// Create a test user.
$this->user = $this->drupalCreateUser();
// Create a test entity.
$this->entity = FedoraResource::create([
"type" => "rdf_source",
"uid" => 1,
"name" => "Test Fixture",
"langcode" => "und",
"status" => 1,
]);
$this->entity->save();
// Create the event generator so we can test it.
$this->eventGenerator = new EventGenerator();
}
/**
* Tests the generateCreateEvent() method.
*/
public function testGenerateCreateEvent() {
$json = $this->eventGenerator->generateCreateEvent($this->entity, $this->user);
$msg = json_decode($json, TRUE);
$this->assertBasicStructure($msg);
$this->assertTrue($msg["type"] == "Create", "Event type is 'Create'.");
}
/**
* Tests the generateUpdateEvent() method.
*/
public function testGenerateUpdateEvent() {
$json = $this->eventGenerator->generateUpdateEvent($this->entity, $this->user);
$msg = json_decode($json, TRUE);
$this->assertBasicStructure($msg);
$this->assertTrue($msg["type"] == "Update", "Event type is 'Update'.");
}
/**
* Tests the generateDeleteEvent() method.
*/
public function testGenerateDeleteEvent() {
$json = $this->eventGenerator->generateDeleteEvent($this->entity, $this->user);
$msg = json_decode($json, TRUE);
$this->assertBasicStructure($msg);
$this->assertTrue($msg["type"] == "Delete", "Event type is 'Delete'.");
}
/**
* Util function for repeated checks.
*
* @param array $msg
* The message parsed as an array.
*/
protected function assertBasicStructure(array $msg) {
// Looking for @context.
$this->assertTrue(array_key_exists('@context', $msg), "Context key exists");
$this->assertTrue($msg["@context"] == "https://www.w3.org/ns/activitystreams", "Context is activity stream.");
// Make sure it has a type.
$this->assertTrue(array_key_exists('type', $msg), "Type key exists");
// Make sure the actor exists, is a person, and has a uri.
$this->assertTrue(array_key_exists('actor', $msg), "Actor key exists");
$this->assertTrue(array_key_exists("type", $msg["actor"]), "Type key exists for actor.");
$this->assertTrue($msg["actor"]["type"] == "Person", "Actor is a person.");
$this->assertTrue(array_key_exists("id", $msg["actor"]), "Id key exists for actor.");
$this->assertTrue($msg["actor"]["id"] == $this->user->toUrl()->setAbsolute()->toString(), "Id is user's uri");
// Make sure the object exists and is a uri.
$this->assertTrue(array_key_exists('object', $msg), "Object key exists");
$this->assertTrue($msg["object"] == $this->entity->toUrl()->setAbsolute()->toString(), "Object is entity uri.");
}
}

48
islandora/tests/src/Kernel/IslandoraKernelTestBase.php

@ -0,0 +1,48 @@
<?php
namespace Drupal\Tests\islandora\Kernel;
use Drupal\KernelTests\KernelTestBase;
/**
* Abstract base class for Islandora kernel tests.
*
*/
abstract class IslandoraKernelTestBase extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'system',
'user',
'field',
'filter',
'block',
'node',
'path',
'text',
'options',
'inline_entity_form',
'serialization',
'rest',
'rdf',
'jsonld',
'islandora'
];
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
// Bootstrap minimal Drupal environment to run the tests.
$this->installSchema('system', 'sequences');
$this->installEntitySchema('user');
$this->installConfig('filter');
$this->installEntitySchema('fedora_resource');
}
}

54
islandora/tests/src/Kernel/VectorClockTest.php

@ -0,0 +1,54 @@
<?php
namespace Drupal\Tests\islandora\Kernel;
use Drupal\islandora\Entity\FedoraResource;
use Drupal\simpletest\UserCreationTrait;
/**
* Tests the basic behavior of a vector clock.
*
* @group islandora
*/
class VectorClockTest extends IslandoraKernelTestBase {
/**
* Fedora resource entity.
*
* @var \Drupal\islandora\FedoraResourceInterface
*/
protected $entity;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
// Create a test entity.
$this->entity = FedoraResource::create([
"type" => "rdf_source",
"uid" => 1,
"name" => "Test Fixture",
"langcode" => "und",
"status" => 1,
]);
$this->entity->save();
}
/**
* Tests the basic behavior of the vector clock.
*/
public function testVectorClock() {
// Check the vclock is set to 0 when a new entity is created.
$this->assertTrue($this->entity->getVclock() == 0, "Vector clock initialized to zero.");
// Edit the entity.
$this->entity->setName("Edited Test Fixture")->save();
// Check the vclock is incremented when the entity is updated.
$this->assertTrue($this->entity->getVclock() == 1, "Vector clock incremented on update.");
}
}

8
islandora_collection/config/install/field.field.fedora_resource.collection.field_description.yml

@ -7,8 +7,6 @@ dependencies:
enforced:
module:
- islandora_collection
module:
- text
id: fedora_resource.collection.field_description
field_name: field_description
entity_type: fedora_resource
@ -19,7 +17,5 @@ required: false
translatable: false
default_value: { }
default_value_callback: ''
settings:
display_summary: false
field_type: text_with_summary
settings: { }
field_type: string_long

8
islandora_collection/config/install/field.storage.fedora_resource.field_description.yml

@ -3,16 +3,16 @@ status: true
dependencies:
module:
- islandora
- text
enforced:
module:
- islandora_collection
id: fedora_resource.field_description
field_name: field_description
entity_type: fedora_resource
type: text_with_summary
settings: { }
module: text
type: string_long
settings:
case_sensitive: false
module: core
locked: false
cardinality: 1
translatable: true

6
islandora_collection/config/install/rdf.mapping.fedora_resource_type.collection.yml

@ -34,6 +34,12 @@ fieldMappings:
- 'schema:dateModified'
datatype_callback:
callable: 'Drupal\rdf\CommonDataConverter::dateIso8601Value'
rdf_type:
properties:
- 'rdf:type'
vclock:
properties:
- 'islandora:vclock'
uid:
properties:
- 'schema:author'

Loading…
Cancel
Save