/**
  * @return Message
  */
 public function startMessage()
 {
     if (is_null($this->startMessage)) {
         $processingType = $this->payload['start_message']['processing_type'];
         $this->startMessage = Message::emulateProcessingWorkflowMessage(MessageType::fromString($this->payload['start_message']['message_type']), $processingType::prototype(), ProcessingMetadata::fromArray($this->payload['start_message']['metadata']));
     }
     return $this->startMessage;
 }
Beispiel #2
0
 /**
  * @return Message
  * @throws \RuntimeException
  */
 public function emulateWorkflowMessage()
 {
     if ($this->type()->isCollectData()) {
         $messageType = MessageType::collectData();
     } elseif ($this->type()->isProcessData()) {
         $messageType = MessageType::processData();
     } else {
         throw new \RuntimeException(sprintf("Can't create a message type for task type %s", $this->type()->toString()));
     }
     return Message::emulateProcessingWorkflowMessage($messageType, $this->processingType(), $this->metadata());
 }
 /**
  * @return Message
  */
 public function startMessage()
 {
     $startMessage = $this->payload['start_message'];
     if (isset($startMessage['metadata'])) {
         $metadata = ProcessingMetadata::fromArray($startMessage['metadata']);
     } else {
         $metadata = ProcessingMetadata::noData();
     }
     $processingType = $startMessage['processing_type'];
     return Message::emulateProcessingWorkflowMessage(MessageType::fromString($startMessage['message_type']), $processingType::prototype(), $metadata);
 }
 /**
  * @test
  */
 function it_is_equal_to_another_object_of_the_same_type()
 {
     $type1 = MessageType::collectData();
     $type2 = MessageType::collectData();
     $this->assertTrue($type1->equals($type2));
 }
 function provideStartScenarios()
 {
     return [[Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::collectData(), ArticleCollection::prototype(), ProcessingMetadata::noData()), $this->getArticleExporterMessageHandler(), ProcessingMetadata::noData(), Task\TaskType::TYPE_COLLECT_DATA, Workflow\ProcessType::TYPE_LINEAR_MESSAGING], [Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::dataProcessed(), ArticleCollection::prototype(), ProcessingMetadata::noData()), $this->getArticleImporterMessageHandler(), ProcessingMetadata::noData(), Task\TaskType::TYPE_PROCESS_DATA, Workflow\ProcessType::TYPE_LINEAR_MESSAGING], [Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::collectData(), ArticleCollection::prototype(), ProcessingMetadata::noData()), $this->getArticleExporterMessageHandler(true), ProcessingMetadata::noData(), Task\TaskType::TYPE_COLLECT_DATA, Workflow\ProcessType::TYPE_PARALLEL_FOREACH], [Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::dataProcessed(), ArticleCollection::prototype(), ProcessingMetadata::noData()), $this->getArticleImporterMessageHandler(true), ProcessingMetadata::noData(), Task\TaskType::TYPE_PROCESS_DATA, Workflow\ProcessType::TYPE_PARALLEL_FOREACH], [Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::collectData(), ArticleCollection::prototype(), ProcessingMetadata::fromArray([MessageMetadata::LIMIT => 100])), $this->getArticleExporterMessageHandler(), ProcessingMetadata::noData(), Task\TaskType::TYPE_COLLECT_DATA, Workflow\ProcessType::TYPE_PARALLEL_CHUNK], [Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::dataCollected(), ArticleCollection::prototype(), ProcessingMetadata::fromArray([MessageMetadata::LIMIT => 100])), $this->getArticleImporterMessageHandler(), ProcessingMetadata::noData(), Task\TaskType::TYPE_PROCESS_DATA, Workflow\ProcessType::TYPE_PARALLEL_CHUNK]];
 }
 /**
  * @return Message
  */
 public function toProcessDataMessage()
 {
     return self::emulateProcessingWorkflowMessage(MessageType::processData(), $this->processingType(), $this->processingMetadata());
 }
 /**
  * @param MessageType $messageType
  * @return bool
  */
 private function canHandleMessageType(MessageType $messageType)
 {
     if ($this->handlerType->isConnector()) {
         if ($messageType->isCollectDataMessage() && $this->dataDirection->isSource()) {
             return true;
         }
         if ($messageType->isProcessDataMessage() && $this->dataDirection->isTarget()) {
             return true;
         }
     } elseif ($this->handlerType->isScript()) {
         if ($messageType->isProcessDataMessage()) {
             return true;
         }
     } else {
         //HandlerType is callback, so handler can handle all message types
         return true;
     }
     //No matching until now, so handler is not able to handle the message type
     return false;
 }
 /**
  * @test
  */
 function it_is_equal_to_a_similar_message()
 {
     $message1 = Message::emulateProcessingWorkflowMessage(MessageType::collectData(), String::prototype(), ProcessingMetadata::fromArray(['meta' => 'data']));
     $message2 = Message::emulateProcessingWorkflowMessage(MessageType::collectData(), String::prototype(), ProcessingMetadata::fromArray(['meta' => 'data']));
     $this->assertTrue($message1->equals($message2));
 }
 function provideMessages()
 {
     return [[Message::emulateProcessingWorkflowMessage(MessageType::collectData(), ArticleCollection::prototype(), ProcessingMetadata::noData())], [Message::emulateProcessingWorkflowMessage(MessageType::dataCollected(), ArticleCollection::prototype(), ProcessingMetadata::noData())], [Message::emulateProcessingWorkflowMessage(MessageType::processData(), ArticleCollection::prototype(), ProcessingMetadata::noData())], [Message::emulateProcessingWorkflowMessage(MessageType::dataProcessed(), ArticleCollection::prototype(), ProcessingMetadata::noData())]];
 }
 /**
  * @param MessageType $other
  * @return bool
  */
 public function equals(MessageType $other)
 {
     return $this->toString() === $other->toString();
 }