public function create($data)
 {
     if (!array_key_exists("collect_data_trigger", $data)) {
         return new ApiProblemResponse(new ApiProblem(422, 'Root key collect_data_trigger missing in request data'));
     }
     $data = $data["collect_data_trigger"];
     if (!array_key_exists('processing_type', $data)) {
         return new ApiProblemResponse(new ApiProblem(422, 'Key processing_type is missing'));
     }
     $processingType = $data['processing_type'];
     if (!class_exists($processingType)) {
         return new ApiProblemResponse(new ApiProblem(422, 'Provided processing type is unknown'));
     }
     try {
         Assertion::implementsInterface($processingType, 'Prooph\\Processing\\Type\\Type');
     } catch (\InvalidArgumentException $ex) {
         return new ApiProblemResponse(new ApiProblem(422, 'Provided processing type is not valid'));
     }
     $wfMessage = WorkflowMessage::collectDataOf($processingType::prototype(), __CLASS__, $this->ProcessingConfig->getNodeName());
     $this->messageLogger->logIncomingMessage($wfMessage);
     $this->workflowEngine->dispatch($wfMessage);
     /** @var $response Response */
     $response = $this->getResponse();
     $response->getHeaders()->addHeaderLine('Location', $this->url()->fromRoute('prooph.link/processor_proxy/api/messages', ['id' => $wfMessage->uuid()->toString()]));
     $response->setStatusCode(201);
     return $response;
 }
 /**
  * @param WorkflowMessage $workflowMessage
  * @return void
  */
 public function handleWorkflowMessage(WorkflowMessage $workflowMessage)
 {
     if (!MessageNameUtils::isProcessingCommand($workflowMessage->messageName())) {
         $this->workflowEngine->dispatch(LogMessage::logUnsupportedMessageReceived($workflowMessage));
     }
     try {
         if ($workflowMessage->messageType() === MessageNameUtils::COLLECT_DATA) {
             $processingMessage = $this->handleCollectData($workflowMessage);
             if (!$processingMessage instanceof ProcessingMessage) {
                 throw new \RuntimeException(sprintf("%s::handleCollectData method returned %s instead of a ProcessingMessage", get_called_class(), is_object($processingMessage) ? get_class($processingMessage) : gettype($processingMessage)));
             }
         } else {
             if ($workflowMessage->messageType() === MessageNameUtils::PROCESS_DATA) {
                 $processingMessage = $this->handleProcessData($workflowMessage);
                 if (!$processingMessage instanceof ProcessingMessage) {
                     throw new \RuntimeException(sprintf("%s::handleProcessData method returned %s instead of a ProcessingMessage", get_called_class(), is_object($processingMessage) ? get_class($processingMessage) : gettype($processingMessage)));
                 }
             } else {
                 $this->workflowEngine->dispatch(LogMessage::logUnsupportedMessageReceived($workflowMessage));
                 return;
             }
         }
         $this->workflowEngine->dispatch($processingMessage);
         return;
     } catch (\Exception $ex) {
         $this->workflowEngine->dispatch(LogMessage::logException($ex, $workflowMessage));
         return;
     }
 }
 /**
  * @param array $data
  * @return mixed|void
  */
 public function create($data)
 {
     $message = StandardMessage::fromArray($data);
     $this->workflowEngine->dispatch($message);
     //@TODO: improve response, provide get service which returns status of the message including related actions
     //@TODO: like started process etc.
     return $message->toArray();
 }
 /**
  * @param WorkflowMessage $aWorkflowMessage
  * @return void
  */
 public function handleWorkflowMessage(WorkflowMessage $aWorkflowMessage)
 {
     $this->lastWorkflowMessage = $aWorkflowMessage;
     if ($this->nextAnswer && $this->workflowEngine) {
         if (is_null($this->nextAnswer->processTaskListPosition())) {
             $this->nextAnswer->connectToProcessTask($aWorkflowMessage->processTaskListPosition());
         }
         $this->workflowEngine->dispatch($this->nextAnswer);
         $this->nextAnswer = null;
     }
 }
 protected function setUp()
 {
     UsersFixture::createTableAndInsertUsers($this->getDbalConnection());
     $this->messageReceiver = new StupidWorkflowProcessorMock();
     $this->commandBus = new CommandBus();
     $this->commandBus->utilize(new SingleTargetMessageRouter($this->messageReceiver));
     $this->commandBus->utilize(new WorkflowProcessorInvokeStrategy());
     $this->eventBus = new EventBus();
     $this->eventBus->utilize(new SingleTargetMessageRouter($this->messageReceiver));
     $this->eventBus->utilize(new WorkflowProcessorInvokeStrategy());
     $this->tableGateway = new DoctrineTableGateway($this->getDbalConnection(), self::TEST_TABLE);
     $this->workflowEngine = new RegistryWorkflowEngine();
     $this->workflowEngine->registerCommandBus($this->commandBus, [NodeName::defaultName()->toString(), 'test-case']);
     $this->workflowEngine->registerEventBus($this->eventBus, [NodeName::defaultName()->toString(), 'test-case']);
     $this->tableGateway->useWorkflowEngine($this->workflowEngine);
 }
 /**
  * @param BernardMessage $message
  */
 public function routeMessage(BernardMessage $message)
 {
     $this->workflowEngine->dispatch($message->getRemoteMessage(), 'prooph.link.message_queue.consumer');
 }
 private function informParentProcessAboutSubProcess(Process $subProcess, $succeed, $lastAnswerReceivedForSubProcess)
 {
     $event = SubProcessFinished::record($this->nodeName, $subProcess->processId(), $succeed, $lastAnswerReceivedForSubProcess, $subProcess->parentTaskListPosition());
     $this->workflowEngine->dispatch($event);
 }
Beispiel #8
0
 /**
  * @param RunSubProcess $task
  * @param TaskListPosition $taskListPosition
  * @param WorkflowEngine $workflowEngine
  * @param WorkflowMessage $previousMessage
  */
 protected function performRunSubProcess(RunSubProcess $task, TaskListPosition $taskListPosition, WorkflowEngine $workflowEngine, WorkflowMessage $previousMessage = null)
 {
     try {
         $startSubProcessCommand = $task->generateStartCommandForSubProcess($taskListPosition, $previousMessage);
         $workflowEngine->dispatch($startSubProcessCommand);
     } catch (CommandDispatchException $ex) {
         $this->receiveMessage(LogMessage::logException($ex->getPrevious(), $taskListPosition), $workflowEngine);
     } catch (\Exception $ex) {
         $this->receiveMessage(LogMessage::logException($ex, $taskListPosition), $workflowEngine);
     }
 }