From 4bd401a60069de0591e1f2e4914dfb3c3bb16f7b Mon Sep 17 00:00:00 2001 From: Jared Whiklo Date: Sun, 4 Dec 2016 12:32:15 -0600 Subject: [PATCH 01/12] Fix ldp:contains reference target and add default rdf map for fedora:hasParent,ldp:contains (#16) --- .../rdf.mapping.fedora_resource_type.rdf_source.yml | 10 +++++++++- islandora/src/Entity/FedoraResource.php | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/islandora/config/install/rdf.mapping.fedora_resource_type.rdf_source.yml b/islandora/config/install/rdf.mapping.fedora_resource_type.rdf_source.yml index c26306a1..cc55ce2d 100644 --- a/islandora/config/install/rdf.mapping.fedora_resource_type.rdf_source.yml +++ b/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' @@ -34,3 +34,11 @@ fieldMappings: properties: - 'schema:author' mapping_type: rel + fedora_has_parent: + properties: + - 'fedora:hasParent' + mapping_type: rel + ldp_contains: + properties: + - 'ldp:contains' + mapping_type: rel diff --git a/islandora/src/Entity/FedoraResource.php b/islandora/src/Entity/FedoraResource.php index 7ae84542..a39ac73c 100644 --- a/islandora/src/Entity/FedoraResource.php +++ b/islandora/src/Entity/FedoraResource.php @@ -340,7 +340,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( From 3d3ebc432fbf3436ad0e6f716df20763faefb3a7 Mon Sep 17 00:00:00 2001 From: Natkeeran Date: Tue, 6 Dec 2016 08:41:23 -0500 Subject: [PATCH 02/12] change description field to plain text (#19) --- ...field.fedora_resource.collection.field_description.yml | 8 ++------ .../field.storage.fedora_resource.field_description.yml | 8 ++++---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/islandora_collection/config/install/field.field.fedora_resource.collection.field_description.yml b/islandora_collection/config/install/field.field.fedora_resource.collection.field_description.yml index 65faeb0b..4ddacfb7 100644 --- a/islandora_collection/config/install/field.field.fedora_resource.collection.field_description.yml +++ b/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 diff --git a/islandora_collection/config/install/field.storage.fedora_resource.field_description.yml b/islandora_collection/config/install/field.storage.fedora_resource.field_description.yml index e32f1bec..f3a05483 100644 --- a/islandora_collection/config/install/field.storage.fedora_resource.field_description.yml +++ b/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 From 644afe0b0ea6e31c4bdfe10d2d10c7d918321eb6 Mon Sep 17 00:00:00 2001 From: Danny Lamb Date: Tue, 6 Dec 2016 15:38:23 +0000 Subject: [PATCH 03/12] First pass at AS2 event generator --- islandora/islandora.services.yml | 2 + .../src/EventGenerator/EventGenerator.php | 60 +++++++ .../EventGeneratorInterface.php | 48 +++++ .../tests/src/Kernel/EventGeneratorTest.php | 164 ++++++++++++++++++ 4 files changed, 274 insertions(+) create mode 100644 islandora/src/EventGenerator/EventGenerator.php create mode 100644 islandora/src/EventGenerator/EventGeneratorInterface.php create mode 100644 islandora/tests/src/Kernel/EventGeneratorTest.php diff --git a/islandora/islandora.services.yml b/islandora/islandora.services.yml index 938de6ed..d1a94b40 100644 --- a/islandora/islandora.services.yml +++ b/islandora/islandora.services.yml @@ -6,3 +6,5 @@ services: tags: - { name: paramconverter } arguments: ['@entity.manager'] + islandora.eventgenerator: + class: Drupal\islandora\EventGenerator\EventGenerator diff --git a/islandora/src/EventGenerator/EventGenerator.php b/islandora/src/EventGenerator/EventGenerator.php new file mode 100644 index 00000000..6040bed6 --- /dev/null +++ b/islandora/src/EventGenerator/EventGenerator.php @@ -0,0 +1,60 @@ + "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(), + ]); + } + +} diff --git a/islandora/src/EventGenerator/EventGeneratorInterface.php b/islandora/src/EventGenerator/EventGeneratorInterface.php new file mode 100644 index 00000000..59578a8f --- /dev/null +++ b/islandora/src/EventGenerator/EventGeneratorInterface.php @@ -0,0 +1,48 @@ +installSchema('system', 'sequences'); + $this->installEntitySchema('user'); + $this->installConfig('filter'); + $this->installEntitySchema('fedora_resource'); + + // 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); + + // Assert basic message structure. + $this->assertTrue(array_key_exists('@context', $msg), "Context key exists"); + $this->assertTrue($msg["@context"] == "https://www.w3.org/ns/activitystreams", "Context is activity stream."); + + $this->assertTrue(array_key_exists('type', $msg), "Type key exists"); + $this->assertTrue($msg["type"] == "Create", "Event type is 'Create'."); + + $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"); + + $this->assertTrue(array_key_exists('object', $msg), "Object key exists"); + $this->assertTrue($msg["object"] == $this->entity->toUrl()->setAbsolute()->toString(), "Object is entity uri."); + } + + /** + * Tests the generateUpdateEvent() method. + */ + public function testGenerateUpdateEvent() { + $json = $this->eventGenerator->generateUpdateEvent($this->entity, $this->user); + $msg = json_decode($json, TRUE); + + // Assert basic message structure. + $this->assertTrue(array_key_exists('@context', $msg), "Context key exists"); + $this->assertTrue($msg["@context"] == "https://www.w3.org/ns/activitystreams", "Context is activity stream."); + + $this->assertTrue(array_key_exists('type', $msg), "Type key exists"); + $this->assertTrue($msg["type"] == "Update", "Event type is 'Update'."); + + $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"); + + $this->assertTrue(array_key_exists('object', $msg), "Object key exists"); + $this->assertTrue($msg["object"] == $this->entity->toUrl()->setAbsolute()->toString(), "Object is entity uri."); + } + + /** + * Tests the generateDeleteEvent() method. + */ + public function testGenerateDeleteEvent() { + $json = $this->eventGenerator->generateDeleteEvent($this->entity, $this->user); + $msg = json_decode($json, TRUE); + + // Assert basic message structure. + $this->assertTrue(array_key_exists('@context', $msg), "Context key exists"); + $this->assertTrue($msg["@context"] == "https://www.w3.org/ns/activitystreams", "Context is activity stream."); + + $this->assertTrue(array_key_exists('type', $msg), "Type key exists"); + $this->assertTrue($msg["type"] == "Delete", "Event type is 'Delete'."); + + $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"); + + $this->assertTrue(array_key_exists('object', $msg), "Object key exists"); + $this->assertTrue($msg["object"] == $this->entity->toUrl()->setAbsolute()->toString(), "Object is entity uri."); + } + +} From bbc0d1e0bacbb19464952342d2d7edb6216b1c0e Mon Sep 17 00:00:00 2001 From: Danny Lamb Date: Tue, 6 Dec 2016 15:46:50 +0000 Subject: [PATCH 04/12] Coding fix --- islandora/src/EventGenerator/EventGenerator.php | 2 +- islandora/src/EventGenerator/EventGeneratorInterface.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/islandora/src/EventGenerator/EventGenerator.php b/islandora/src/EventGenerator/EventGenerator.php index 6040bed6..e0463277 100644 --- a/islandora/src/EventGenerator/EventGenerator.php +++ b/islandora/src/EventGenerator/EventGenerator.php @@ -25,7 +25,7 @@ class EventGenerator implements EventGeneratorInterface { ], "object" => $entity->toUrl()->setAbsolute()->toString(), ]); - } + } /** * {@inheritdoc} diff --git a/islandora/src/EventGenerator/EventGeneratorInterface.php b/islandora/src/EventGenerator/EventGeneratorInterface.php index 59578a8f..766e1389 100644 --- a/islandora/src/EventGenerator/EventGeneratorInterface.php +++ b/islandora/src/EventGenerator/EventGeneratorInterface.php @@ -5,6 +5,9 @@ namespace Drupal\islandora\EventGenerator; use Drupal\Core\Entity\EntityInterface; use Drupal\user\UserInterface; +/** + * Inteface for a service that provides serialized event messages. + */ interface EventGeneratorInterface { /** @@ -45,4 +48,5 @@ interface EventGeneratorInterface { * Serialized event message */ public function generateDeleteEvent(EntityInterface $entity, UserInterface $user); + } From 39ef47b623df48a4e79112a2e0948e471dacb4a4 Mon Sep 17 00:00:00 2001 From: Danny Lamb Date: Tue, 6 Dec 2016 15:58:45 +0000 Subject: [PATCH 05/12] Take that phpcpd --- .../tests/src/Kernel/EventGeneratorTest.php | 48 +++++++------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/islandora/tests/src/Kernel/EventGeneratorTest.php b/islandora/tests/src/Kernel/EventGeneratorTest.php index d0fcceef..4e297c57 100644 --- a/islandora/tests/src/Kernel/EventGeneratorTest.php +++ b/islandora/tests/src/Kernel/EventGeneratorTest.php @@ -96,21 +96,8 @@ class EventGeneratorTest extends KernelTestBase { $json = $this->eventGenerator->generateCreateEvent($this->entity, $this->user); $msg = json_decode($json, TRUE); - // Assert basic message structure. - $this->assertTrue(array_key_exists('@context', $msg), "Context key exists"); - $this->assertTrue($msg["@context"] == "https://www.w3.org/ns/activitystreams", "Context is activity stream."); - - $this->assertTrue(array_key_exists('type', $msg), "Type key exists"); + $this->assertBasicStructure($msg); $this->assertTrue($msg["type"] == "Create", "Event type is 'Create'."); - - $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"); - - $this->assertTrue(array_key_exists('object', $msg), "Object key exists"); - $this->assertTrue($msg["object"] == $this->entity->toUrl()->setAbsolute()->toString(), "Object is entity uri."); } /** @@ -120,21 +107,8 @@ class EventGeneratorTest extends KernelTestBase { $json = $this->eventGenerator->generateUpdateEvent($this->entity, $this->user); $msg = json_decode($json, TRUE); - // Assert basic message structure. - $this->assertTrue(array_key_exists('@context', $msg), "Context key exists"); - $this->assertTrue($msg["@context"] == "https://www.w3.org/ns/activitystreams", "Context is activity stream."); - - $this->assertTrue(array_key_exists('type', $msg), "Type key exists"); + $this->assertBasicStructure($msg); $this->assertTrue($msg["type"] == "Update", "Event type is 'Update'."); - - $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"); - - $this->assertTrue(array_key_exists('object', $msg), "Object key exists"); - $this->assertTrue($msg["object"] == $this->entity->toUrl()->setAbsolute()->toString(), "Object is entity uri."); } /** @@ -144,19 +118,33 @@ class EventGeneratorTest extends KernelTestBase { $json = $this->eventGenerator->generateDeleteEvent($this->entity, $this->user); $msg = json_decode($json, TRUE); - // Assert basic message structure. + $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"); - $this->assertTrue($msg["type"] == "Delete", "Event type is 'Delete'."); + // 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."); } From 8e4e15b88e4ba4978dd77ac8caeaaba787288a01 Mon Sep 17 00:00:00 2001 From: Danny Lamb Date: Tue, 6 Dec 2016 18:00:25 +0000 Subject: [PATCH 06/12] Attempting to run tests --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index b3d2ddec..ebb1bc0d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,6 +29,7 @@ script: - $ISLANDORA_DIR/.scripts/line_endings.sh . - php vendor/bin/phpcs --standard=Drupal **/*.module **/*.php --ignore=tests,vendor . - php vendor/bin/phpcpd --names *.module,*.inc,*.test,*.php --exclude=vendor . + - php core/scripts/run-tests.sh islandora notifications: irc: From f8a63869f752f0b2def5cf70064d6f89eeaa376f Mon Sep 17 00:00:00 2001 From: Danny Lamb Date: Tue, 6 Dec 2016 18:09:08 +0000 Subject: [PATCH 07/12] This goes a bit deeper than I thought it did initially --- .scripts/travis_setup.sh | 20 ++++++++++---------- .travis.yml | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.scripts/travis_setup.sh b/.scripts/travis_setup.sh index 3123d11f..12c8c5a0 100755 --- a/.scripts/travis_setup.sh +++ b/.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 diff --git a/.travis.yml b/.travis.yml index ebb1bc0d..052abaa7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ before_install: - export ISLANDORA_DIR=$TRAVIS_BUILD_DIR install: -# - $TRAVIS_BUILD_DIR/tests/scripts/travis_setup.sh + - $TRAVIS_BUILD_DIR/tests/scripts/travis_setup.sh - composer install - php vendor/bin/phpcs --config-set installed_paths vendor/drupal/coder/coder_sniffer @@ -29,7 +29,7 @@ script: - $ISLANDORA_DIR/.scripts/line_endings.sh . - php vendor/bin/phpcs --standard=Drupal **/*.module **/*.php --ignore=tests,vendor . - php vendor/bin/phpcpd --names *.module,*.inc,*.test,*.php --exclude=vendor . - - php core/scripts/run-tests.sh islandora + - php /var/www/html/drupal/core/scripts/run-tests.sh islandora notifications: irc: From 71afcf9a58f4cf712dcc75e3f79b0097ee52ab05 Mon Sep 17 00:00:00 2001 From: Danny Lamb Date: Tue, 6 Dec 2016 18:12:12 +0000 Subject: [PATCH 08/12] Pointing to correct setup script. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 052abaa7..5edb784e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ 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 From cabbc9614797a8499094304cb6ac3fe256f96cae Mon Sep 17 00:00:00 2001 From: Danny Lamb Date: Tue, 6 Dec 2016 18:25:27 +0000 Subject: [PATCH 09/12] How about now? --- .scripts/travis_setup.sh | 2 ++ .travis.yml | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.scripts/travis_setup.sh b/.scripts/travis_setup.sh index 12c8c5a0..956c0fc6 100755 --- a/.scripts/travis_setup.sh +++ b/.scripts/travis_setup.sh @@ -71,6 +71,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 diff --git a/.travis.yml b/.travis.yml index 5edb784e..d92c7ae8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,9 +27,10 @@ install: script: - $ISLANDORA_DIR/.scripts/line_endings.sh . + - cd $ISLANDORA_DIR/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 . - - php /var/www/html/drupal/core/scripts/run-tests.sh islandora + - cd $ISLANDORA_DIR/drupal; php core/scripts/run-tests.sh islandora notifications: irc: From 703327c67fdab68ae3f55b5b3bf37e85eb760cc3 Mon Sep 17 00:00:00 2001 From: Danny Lamb Date: Tue, 6 Dec 2016 18:35:45 +0000 Subject: [PATCH 10/12] Fixing pathing on script in yml --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d92c7ae8..7b0d604a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,10 +27,10 @@ install: script: - $ISLANDORA_DIR/.scripts/line_endings.sh . - - cd $ISLANDORA_DIR/drupal/modules/islandora + - 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 $ISLANDORA_DIR/drupal; php core/scripts/run-tests.sh islandora + - cd $HOME/drupal; php core/scripts/run-tests.sh islandora notifications: irc: From d2302ac7ecc900c1f985a275ef513cbea6e0adbc Mon Sep 17 00:00:00 2001 From: Danny Lamb Date: Tue, 6 Dec 2016 18:48:14 +0000 Subject: [PATCH 11/12] Adding simpletest and pointing the script to the current php install --- .scripts/travis_setup.sh | 1 + .travis.yml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.scripts/travis_setup.sh b/.scripts/travis_setup.sh index 956c0fc6..61a75be1 100755 --- a/.scripts/travis_setup.sh +++ b/.scripts/travis_setup.sh @@ -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 diff --git a/.travis.yml b/.travis.yml index 7b0d604a..5948f67c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,7 @@ script: - 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 islandora + - cd $HOME/drupal; php core/scripts/run-tests.sh --php `which php` islandora notifications: irc: From a7801811e0a46c95824990c99178870dd7f5c1d5 Mon Sep 17 00:00:00 2001 From: dannylamb Date: Thu, 8 Dec 2016 10:08:29 -0400 Subject: [PATCH 12/12] Issue 429 (#21) * Naive vector clock implementation * RDF mapping and dummy/namespace predicate. * Derpin it up * Removing the derp to make branch appear on github * Tests * in => int --- ...apping.fedora_resource_type.rdf_source.yml | 3 ++ islandora/islandora.module | 1 + islandora/src/Entity/FedoraResource.php | 24 +++++++++ islandora/src/FedoraResourceInterface.php | 8 +++ .../tests/src/Kernel/EventGeneratorTest.php | 30 +---------- .../src/Kernel/IslandoraKernelTestBase.php | 48 +++++++++++++++++ .../tests/src/Kernel/VectorClockTest.php | 54 +++++++++++++++++++ ...apping.fedora_resource_type.collection.yml | 3 ++ 8 files changed, 142 insertions(+), 29 deletions(-) create mode 100644 islandora/tests/src/Kernel/IslandoraKernelTestBase.php create mode 100644 islandora/tests/src/Kernel/VectorClockTest.php diff --git a/islandora/config/install/rdf.mapping.fedora_resource_type.rdf_source.yml b/islandora/config/install/rdf.mapping.fedora_resource_type.rdf_source.yml index cc55ce2d..6697ebc7 100644 --- a/islandora/config/install/rdf.mapping.fedora_resource_type.rdf_source.yml +++ b/islandora/config/install/rdf.mapping.fedora_resource_type.rdf_source.yml @@ -30,6 +30,9 @@ fieldMappings: rdf_type: properties: - 'rdf:type' + vclock: + properties: + - 'islandora:vclock' uid: properties: - 'schema:author' diff --git a/islandora/islandora.module b/islandora/islandora.module index ac28cddc..7250ef53 100644 --- a/islandora/islandora.module +++ b/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/', ); } diff --git a/islandora/src/Entity/FedoraResource.php b/islandora/src/Entity/FedoraResource.php index a39ac73c..ac59060a 100644 --- a/islandora/src/Entity/FedoraResource.php +++ b/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')) diff --git a/islandora/src/FedoraResourceInterface.php b/islandora/src/FedoraResourceInterface.php index baefb5a8..806504d7 100644 --- a/islandora/src/FedoraResourceInterface.php +++ b/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(); + } diff --git a/islandora/tests/src/Kernel/EventGeneratorTest.php b/islandora/tests/src/Kernel/EventGeneratorTest.php index 4e297c57..e1b63559 100644 --- a/islandora/tests/src/Kernel/EventGeneratorTest.php +++ b/islandora/tests/src/Kernel/EventGeneratorTest.php @@ -4,7 +4,6 @@ namespace Drupal\Tests\islandora\Kernel; use Drupal\islandora\Entity\FedoraResource; use Drupal\islandora\EventGenerator\EventGenerator; -use Drupal\KernelTests\KernelTestBase; use Drupal\simpletest\UserCreationTrait; /** @@ -12,7 +11,7 @@ use Drupal\simpletest\UserCreationTrait; * * @group islandora */ -class EventGeneratorTest extends KernelTestBase { +class EventGeneratorTest extends IslandoraKernelTestBase { use UserCreationTrait { createUser as drupalCreateUser; @@ -39,39 +38,12 @@ class EventGeneratorTest extends KernelTestBase { */ protected $eventGenerator; - /** - * {@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'); - // Create a test user. $this->user = $this->drupalCreateUser(); diff --git a/islandora/tests/src/Kernel/IslandoraKernelTestBase.php b/islandora/tests/src/Kernel/IslandoraKernelTestBase.php new file mode 100644 index 00000000..fb5932ab --- /dev/null +++ b/islandora/tests/src/Kernel/IslandoraKernelTestBase.php @@ -0,0 +1,48 @@ +installSchema('system', 'sequences'); + $this->installEntitySchema('user'); + $this->installConfig('filter'); + $this->installEntitySchema('fedora_resource'); + } + +} + diff --git a/islandora/tests/src/Kernel/VectorClockTest.php b/islandora/tests/src/Kernel/VectorClockTest.php new file mode 100644 index 00000000..c73df8ee --- /dev/null +++ b/islandora/tests/src/Kernel/VectorClockTest.php @@ -0,0 +1,54 @@ +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."); + } + +} diff --git a/islandora_collection/config/install/rdf.mapping.fedora_resource_type.collection.yml b/islandora_collection/config/install/rdf.mapping.fedora_resource_type.collection.yml index 25d05a00..0ccef80c 100644 --- a/islandora_collection/config/install/rdf.mapping.fedora_resource_type.collection.yml +++ b/islandora_collection/config/install/rdf.mapping.fedora_resource_type.collection.yml @@ -40,6 +40,9 @@ fieldMappings: rdf_type: properties: - 'rdf:type' + vclock: + properties: + - 'islandora:vclock' uid: properties: - 'schema:author'