/**
  * @param ScheduleFirstTasksForWorkflow $command
  * @throws Exception\WorkflowNotFound
  * @throws \Prooph\Link\ProcessManager\Model\MessageHandler\Exception\MessageHandlerNotFound
  */
 public function handle(ScheduleFirstTasksForWorkflow $command)
 {
     $workflow = $this->workflowCollection->get($command->workflowId());
     if (is_null($workflow)) {
         throw WorkflowNotFound::withId($command->workflowId());
     }
     $messageHandler = $this->messageHandlerCollection->get($command->firstMessageHandlerId());
     if (is_null($messageHandler)) {
         throw MessageHandlerNotFound::withId($command->firstMessageHandlerId());
     }
     $tasks = $workflow->determineFirstTasks($command->startMessage(), $messageHandler);
     foreach ($tasks as $task) {
         $this->taskCollection->add($task);
     }
 }
 public function handle(ScheduleNextTasksForWorkflow $command)
 {
     $workflow = $this->workflowCollection->get($command->workflowId());
     if (is_null($workflow)) {
         throw WorkflowNotFound::withId($command->workflowId());
     }
     $previousTask = $this->taskCollection->get($command->previousTaskId());
     if (is_null($previousTask)) {
         throw TaskNotFound::withId($command->previousTaskId());
     }
     $previousMessageHandler = $this->messageHandlerCollection->get($previousTask->messageHandlerId());
     if (is_null($previousMessageHandler)) {
         throw MessageHandlerNotFound::withId($previousTask->messageHandlerId());
     }
     $nextMessageHandler = $this->messageHandlerCollection->get($command->nextMessageHandlerId());
     if (is_null($nextMessageHandler)) {
         throw MessageHandlerNotFound::withId($command->nextMessageHandlerId());
     }
     $nextTasks = $workflow->determineNextTasks($previousTask, $previousMessageHandler, $nextMessageHandler);
     foreach ($nextTasks as $nextTask) {
         $this->taskCollection->add($nextTask);
     }
 }
 /**
  * @param TaskId $taskId
  * @return array
  * @throws MessageHandlerNotFound
  * @throws \RuntimeException
  * @throws TaskNotFound
  */
 private function translateToProcessingTask(TaskId $taskId)
 {
     $task = $this->taskCollection->get($taskId);
     if (is_null($task)) {
         throw TaskNotFound::withId($taskId);
     }
     $messageHandler = $this->messageHandlerCollection->get($task->messageHandlerId());
     if (is_null($messageHandler)) {
         throw MessageHandlerNotFound::withId($task->messageHandlerId());
     }
     $this->syncMessageHandler($messageHandler);
     $taskData = ['task_type' => $task->type()->toString(), 'metadata' => $task->metadata()->toArray()];
     if ($task->type()->isCollectData()) {
         $taskData['source'] = $messageHandler->processingId()->toString();
         $taskData['processing_type'] = $task->processingType()->of();
     } elseif ($task->type()->isProcessData()) {
         $taskData['target'] = $messageHandler->processingId()->toString();
         $taskData['allowed_types'] = [$task->processingType()->of()];
         $taskData['preferred_type'] = $task->processingType()->of();
     } else {
         throw new \RuntimeException("TaskType {$task->type()->toString()} is not supported yet");
     }
     return $taskData;
 }
 /**
  * @param InstallMessageHandler $command
  */
 public function handle(InstallMessageHandler $command)
 {
     $node = $this->processingNodeList->getNode($command->nodeName());
     $handler = $node->installMessageHandler($command->messageHandlerId(), $command->messageHandlerName(), $command->handlerType(), $command->dataDirection(), $command->supportedProcessingTypes(), $command->processingMetadata(), $command->metadataRiotTag(), $command->icon(), $command->iconType(), $command->preferredProcessingType(), $command->handlerProcessingId(), $command->additionalData());
     $this->messageHandlerCollection->add($handler);
 }