public function create($connection)
 {
     if (!array_key_exists('type', $connection)) {
         return $this->apiProblem(422, "No type given for the connection");
     }
     if (!array_key_exists('message_handler', $connection)) {
         return $this->apiProblem(422, "No message_handler given for the connection");
     }
     if (!array_key_exists('workflow_id', $connection)) {
         return $this->apiProblem(422, "No workflow_id given for the connection");
     }
     if ($connection['type'] == "start_connection") {
         if (!array_key_exists('start_message', $connection)) {
             return $this->apiProblem(422, "No start_message given for the connection");
         }
         $this->commandBus->dispatch(ScheduleFirstTasksForWorkflow::withData($connection['workflow_id'], $connection['start_message'], $connection['message_handler']));
         return $this->accepted();
     } elseif ($connection['type'] == "source_target_connection") {
         if (!array_key_exists('previous_task', $connection)) {
             return $this->apiProblem(422, "No previous_task given for the connection");
         }
         $this->commandBus->dispatch(ScheduleNextTasksForWorkflow::withData($connection['workflow_id'], $connection['previous_task'], $connection['message_handler']));
         return $this->accepted();
     } else {
         return $this->apiProblem(422, "Unknown connection type");
     }
 }
 /**
  * @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);
     }
 }