Browse Source

Updates Reaction Rules for Media (#61)

* Adding iana

* Updated Rules for flushing binaries

* Checkstyle

* More checkstyle

* Logging instead of throwing exceptions
pull/756/head
dannylamb 7 years ago committed by Nick Ruest
parent
commit
d45c3e89ca
  1. 8
      config/install/rules.reaction.broadcast_media_create_event.yml
  2. 8
      config/install/rules.reaction.broadcast_media_delete_event.yml
  3. 8
      config/install/rules.reaction.broadcast_media_update_event.yml
  4. 1
      islandora.module
  5. 68
      src/EventGenerator/EventGenerator.php

8
config/install/rules.reaction.broadcast_media_create_event.yml

@ -2,12 +2,11 @@ uuid: c4447a0b-a2a8-4f32-947b-fbe1094632d5
langcode: en langcode: en
status: true status: true
dependencies: dependencies:
module:
- islandora
- rules
enforced: enforced:
module: module:
- islandora - islandora
_core:
default_config_hash: mRt_MC0dKA68qaoXI3WlnCg-ta5Wry0dLR2dpOqY4to
id: broadcast_media_create_event id: broadcast_media_create_event
label: 'Broadcast Media Create Event' label: 'Broadcast Media Create Event'
events: events:
@ -43,7 +42,8 @@ expression:
uuid: f7880d70-1411-4c60-a065-a7d187b604db uuid: f7880d70-1411-4c60-a065-a7d187b604db
context_values: context_values:
recipients: recipients:
- 'activemq:queue:islandora-indexing-triplestore' - "activemq:queue:islandora-indexing-triplestore\r"
- 'activemq:queue:islandora-indexing-fcrepo-binary-create'
context_mapping: context_mapping:
message: event_message message: event_message
context_processors: context_processors:

8
config/install/rules.reaction.broadcast_media_delete_event.yml

@ -2,12 +2,11 @@ uuid: 33b8afa6-1507-4f04-acc9-5a18ca2b0ccc
langcode: en langcode: en
status: true status: true
dependencies: dependencies:
module:
- islandora
- rules
enforced: enforced:
module: module:
- islandora - islandora
_core:
default_config_hash: Jejr-Hg2lX1o7mdUt_RBxW0xfzOKhoFbGGpepW_SoZg
id: broadcast_media_delete_event id: broadcast_media_delete_event
label: 'Broadcast Media Delete Event' label: 'Broadcast Media Delete Event'
events: events:
@ -43,7 +42,8 @@ expression:
uuid: 371b1104-1aa6-4b3d-82cf-e27168e664ae uuid: 371b1104-1aa6-4b3d-82cf-e27168e664ae
context_values: context_values:
recipients: recipients:
- 'activemq:queue:islandora-indexing-triplestore' - "activemq:queue:islandora-indexing-triplestore\r"
- 'activemq:queue:islandora-indexing-fcrepo-binary-delete'
context_mapping: context_mapping:
message: event_message message: event_message
context_processors: context_processors:

8
config/install/rules.reaction.broadcast_media_update_event.yml

@ -2,12 +2,11 @@ uuid: d58d3327-38d2-400b-91a0-3b00b3870121
langcode: en langcode: en
status: true status: true
dependencies: dependencies:
module:
- islandora
- rules
enforced: enforced:
module: module:
- islandora - islandora
_core:
default_config_hash: qAkxtz6jH0on_W4QXhpGqZMFfgyATahnUKdynX9bl1g
id: broadcast_media_update_event id: broadcast_media_update_event
label: 'Broadcast Media Update Event' label: 'Broadcast Media Update Event'
events: events:
@ -43,7 +42,8 @@ expression:
uuid: 6aa1f15c-3a39-4af5-b577-81fa7081de62 uuid: 6aa1f15c-3a39-4af5-b577-81fa7081de62
context_values: context_values:
recipients: recipients:
- 'activemq:queue:islandora-indexing-triplestore' - "activemq:queue:islandora-indexing-triplestore\r"
- 'activemq:queue:islandora-indexing-fcrepo-binary-update'
context_mapping: context_mapping:
message: event_message message: event_message
context_processors: context_processors:

1
islandora.module

@ -85,6 +85,7 @@ function islandora_rdf_namespaces() {
'islandora' => 'http://islandora.ca/CLAW/', 'islandora' => 'http://islandora.ca/CLAW/',
'pcdm' => 'http://pcdm.org/models#', 'pcdm' => 'http://pcdm.org/models#',
'use' => 'http://pcdm.org/use#', 'use' => 'http://pcdm.org/use#',
'iana' => 'http://www.iana.org/assignments/relation/',
]; ];
} }

68
src/EventGenerator/EventGenerator.php

@ -3,6 +3,7 @@
namespace Drupal\islandora\EventGenerator; namespace Drupal\islandora\EventGenerator;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\media_entity\Entity\Media;
use Drupal\user\UserInterface; use Drupal\user\UserInterface;
/** /**
@ -16,7 +17,7 @@ class EventGenerator implements EventGeneratorInterface {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function generateCreateEvent(EntityInterface $entity, UserInterface $user) { public function generateCreateEvent(EntityInterface $entity, UserInterface $user) {
return json_encode([ $event = [
"@context" => "https://www.w3.org/ns/activitystreams", "@context" => "https://www.w3.org/ns/activitystreams",
"type" => "Create", "type" => "Create",
"actor" => [ "actor" => [
@ -24,14 +25,20 @@ class EventGenerator implements EventGeneratorInterface {
"id" => $user->toUrl()->setAbsolute()->toString(), "id" => $user->toUrl()->setAbsolute()->toString(),
], ],
"object" => $entity->toUrl()->setAbsolute()->toString(), "object" => $entity->toUrl()->setAbsolute()->toString(),
]); ];
if ($entity instanceof Media) {
$this->addAttachment($entity, $event);
}
return json_encode($event);
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function generateUpdateEvent(EntityInterface $entity, UserInterface $user) { public function generateUpdateEvent(EntityInterface $entity, UserInterface $user) {
return json_encode([ $event = [
"@context" => "https://www.w3.org/ns/activitystreams", "@context" => "https://www.w3.org/ns/activitystreams",
"type" => "Update", "type" => "Update",
"actor" => [ "actor" => [
@ -39,14 +46,20 @@ class EventGenerator implements EventGeneratorInterface {
"id" => $user->toUrl()->setAbsolute()->toString(), "id" => $user->toUrl()->setAbsolute()->toString(),
], ],
"object" => $entity->toUrl()->setAbsolute()->toString(), "object" => $entity->toUrl()->setAbsolute()->toString(),
]); ];
if ($entity instanceof Media) {
$this->addAttachment($entity, $event);
}
return json_encode($event);
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function generateDeleteEvent(EntityInterface $entity, UserInterface $user) { public function generateDeleteEvent(EntityInterface $entity, UserInterface $user) {
return json_encode([ $event = [
"@context" => "https://www.w3.org/ns/activitystreams", "@context" => "https://www.w3.org/ns/activitystreams",
"type" => "Delete", "type" => "Delete",
"actor" => [ "actor" => [
@ -54,7 +67,50 @@ class EventGenerator implements EventGeneratorInterface {
"id" => $user->toUrl()->setAbsolute()->toString(), "id" => $user->toUrl()->setAbsolute()->toString(),
], ],
"object" => $entity->toUrl()->setAbsolute()->toString(), "object" => $entity->toUrl()->setAbsolute()->toString(),
]); ];
if ($entity instanceof Media) {
$this->addAttachment($entity, $event);
}
return json_encode($event);
}
/**
* Adds the 'attachment' info to the event array.
*
* @param \Drupal\media_entity\Entity\Media $entity
* The entity that was updated.
* @param array $event
* Array of info to be serialized to jsonld.
*/
protected function addAttachment(Media $entity, array &$event) {
if ($entity->hasField("field_image")) {
$file = $entity->field_image->entity;
}
elseif ($entity->hasField("field_file")) {
$file = $entity->field_file->entity;
}
else {
\Drupal::logger('islandora')->warning(
"Cannot parse 'field_image' or 'field_file' from Media entity {$entity->id()}"
);
return;
}
if ($file === null) {
\Drupal::logger('islandora')->debug(
"'field_image' or 'field_file' is null in Media entity {$entity->id()}"
);
return;
}
$url = file_create_url($file->getFileUri());
$mime = $file->getMimeType();
$event['attachment'] = [
'url' => $url,
'mediaType' => $mime,
];
} }
} }

Loading…
Cancel
Save