|
|
|
@ -11,7 +11,7 @@ use Drupal\Core\Form\FormStateInterface;
|
|
|
|
|
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; |
|
|
|
|
use Drupal\Core\Session\AccountInterface; |
|
|
|
|
use Drupal\Core\StringTranslation\StringTranslationTrait; |
|
|
|
|
use Drupal\jwt\Authentication\Provider\JwtAuth; |
|
|
|
|
use Drupal\islandora\Event\StompHeaderEventException; |
|
|
|
|
use Stomp\Exception\StompException; |
|
|
|
|
use Stomp\StatefulStomp; |
|
|
|
|
use Stomp\Transport\Message; |
|
|
|
@ -52,11 +52,11 @@ abstract class EmitEvent extends ConfigurableActionBase implements ContainerFact
|
|
|
|
|
protected $stomp; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* The JWT Auth Service. |
|
|
|
|
* Event dispatcher service.. |
|
|
|
|
* |
|
|
|
|
* @var \Drupal\jwt\Authentication\Provider\JwtAuth |
|
|
|
|
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface |
|
|
|
|
*/ |
|
|
|
|
protected $auth; |
|
|
|
|
protected $eventDispatcher; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* The messenger. |
|
|
|
@ -95,16 +95,16 @@ abstract class EmitEvent extends ConfigurableActionBase implements ContainerFact
|
|
|
|
|
EntityTypeManagerInterface $entity_type_manager, |
|
|
|
|
EventGeneratorInterface $event_generator, |
|
|
|
|
StatefulStomp $stomp, |
|
|
|
|
JwtAuth $auth, |
|
|
|
|
MessengerInterface $messenger |
|
|
|
|
MessengerInterface $messenger, |
|
|
|
|
EventDispatcherInterface $event_dispatcher |
|
|
|
|
) { |
|
|
|
|
parent::__construct($configuration, $plugin_id, $plugin_definition); |
|
|
|
|
$this->account = $account; |
|
|
|
|
$this->entityTypeManager = $entity_type_manager; |
|
|
|
|
$this->eventGenerator = $event_generator; |
|
|
|
|
$this->stomp = $stomp; |
|
|
|
|
$this->auth = $auth; |
|
|
|
|
$this->messenger = $messenger; |
|
|
|
|
$this->eventDispatcher = $event_dispatcher; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -119,8 +119,8 @@ abstract class EmitEvent extends ConfigurableActionBase implements ContainerFact
|
|
|
|
|
$container->get('entity_type.manager'), |
|
|
|
|
$container->get('islandora.eventgenerator'), |
|
|
|
|
$container->get('islandora.stomp'), |
|
|
|
|
$container->get('jwt.authentication.jwt'), |
|
|
|
|
$container->get('messenger') |
|
|
|
|
$container->get('messenger'), |
|
|
|
|
$container->get('event_dispatcher') |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -128,29 +128,26 @@ abstract class EmitEvent extends ConfigurableActionBase implements ContainerFact
|
|
|
|
|
* {@inheritdoc} |
|
|
|
|
*/ |
|
|
|
|
public function execute($entity = NULL) { |
|
|
|
|
|
|
|
|
|
// Include a token for later authentication in the message. |
|
|
|
|
$token = $this->auth->generateToken(); |
|
|
|
|
if (empty($token)) { |
|
|
|
|
// JWT isn't properly configured. Log and notify user. |
|
|
|
|
\Drupal::logger('islandora')->error( |
|
|
|
|
$this->t('Error getting JWT token for message. Check JWT Configuration.') |
|
|
|
|
); |
|
|
|
|
$this->messenger->addMessage( |
|
|
|
|
$this->t('Error getting JWT token for message. Check JWT Configuration.'), 'error' |
|
|
|
|
); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Generate event as stomp message. |
|
|
|
|
try { |
|
|
|
|
$user = $this->entityTypeManager->getStorage('user')->load($this->account->id()); |
|
|
|
|
$data = $this->generateData($entity); |
|
|
|
|
|
|
|
|
|
$event = $this->eventDispatcher->dispatch( |
|
|
|
|
StompHeaderEvent::EVENT_NAME, |
|
|
|
|
new StompHeaderEvent($entity, $user) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$message = new Message( |
|
|
|
|
$this->eventGenerator->generateEvent($entity, $user, $data), |
|
|
|
|
['Authorization' => "Bearer $token"] |
|
|
|
|
$event->getHeaders()->all() |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
catch (StompHeaderEventException $e) { |
|
|
|
|
\Drupal::logger('islandora')->error($e->getMessage()); |
|
|
|
|
$this->messenger->addMessage($e->getMessage(), 'error'); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
catch (\RuntimeException $e) { |
|
|
|
|
// Notify the user the event couldn't be generated and abort. |
|
|
|
|
\Drupal::logger('islandora')->error( |
|
|
|
|