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;
 }
 /**
  * Loads available DataTypes from system config and converts some to cient format
  *
  * If optional data type array is passed as argument, this is used instead of all available types
  *
  * @param array|null $processingTypes
  * @return array
  */
 protected function getProcessingTypesForClient(array $processingTypes = null)
 {
     if (is_null($processingTypes)) {
         $processingTypes = $this->systemConfig->getAllAvailableProcessingTypes();
     }
     return array_map(function ($processingTypeClass) {
         return $this->prepareProcessingType($processingTypeClass);
     }, $processingTypes);
 }
Ejemplo n.º 3
0
 /**
  * @param mixed $id
  * @return array|mixed
  */
 public function get($id)
 {
     $processLog = $this->processLogFinder->getLoggedProcess($id);
     if ($processLog === null) {
         return $this->notFoundAction();
     }
     $processLog['events'] = $this->convertToClientProcessEvents($this->processStreamReader->getStreamOfProcess($id));
     $processDefinitions = $this->systemConfig->getProcessDefinitions();
     if (!isset($processDefinitions[$processLog['start_message']])) {
         //@TODO: Provide better error, so that the client can show the user a message that config is missing
         return $this->notFoundAction();
     }
     $processDefinition = $processDefinitions[$processLog['start_message']];
     $processDefinition = ProcessToClientTranslator::translate($processLog['start_message'], $processDefinition, $this->systemConfig->getAllAvailableProcessingTypes(), $this->scriptLocation);
     $processLog['tasks'] = $processDefinition['tasks'];
     $this->populateTaskEvents($processLog);
     return ['log' => $processLog];
 }
 /**
  * @param Workflow $workflow
  * @throws \RuntimeException
  * @return void
  */
 public function writeToProcessingConfig(Workflow $workflow)
 {
     $processNum = count($workflow->processList());
     if ($processNum == 0) {
         $this->commandBus->dispatch(RemoveProcessConfig::ofProcessTriggeredByMessage($workflow->startMessage()->messageName(), $this->processingConfigLocation));
         return;
     }
     $processDefinitions = $this->processingConfig->getProcessDefinitions();
     if ($processNum == 1) {
         $processConfig = $this->translateToProcessingProcess($workflow->processList()[0]);
         $processConfig['name'] = $workflow->name();
         if (isset($processDefinitions[$workflow->startMessage()->messageName()])) {
             $this->commandBus->dispatch(ChangeProcessConfig::ofProcessTriggeredByMessage($workflow->startMessage()->messageName(), $processConfig, $this->processingConfigLocation));
         } else {
             $this->commandBus->dispatch(AddNewProcessToConfig::fromDefinition($processConfig['name'], $processConfig['process_type'], $workflow->startMessage()->messageName(), $processConfig['tasks'], $this->processingConfigLocation));
         }
     } else {
         throw new \RuntimeException("Handling of more than process per workflow is not supported yet!");
     }
 }
 /**
  * @param string $id
  * @param array $connector
  * @throws \InvalidArgumentException
  */
 public function addConnector($id, array $connector)
 {
     $this->assertConnector($connector);
     if (!$this->dbalConnections->containsKey($connector['dbal_connection'])) {
         throw new \InvalidArgumentException(sprintf("Dbal connection %s for connector %s does not exists", $connector['dbal_connection'], $connector['name']));
     }
     $connection = $this->dbalConnections->get($connector['dbal_connection']);
     $generatedTypes = $this->generateProcessingTypesIfNotExist($connection->config()['dbname'], $connector['table'], $connection->connection());
     $connectorName = $connector['name'];
     unset($connector['name']);
     $connector['icon'] = self::ICON;
     $connector['icon_type'] = self::ICON_TYPE;
     $connector['ui_metadata_riot_tag'] = self::METADATA_UI_KEY;
     $connector['node_name'] = $this->processingConfig->getNodeName();
     $addConnector = AddConnectorToConfig::fromDefinition($id, $connectorName, [MessageNameUtils::COLLECT_DATA, MessageNameUtils::PROCESS_DATA], $generatedTypes, $this->configLocation, $connector);
     $this->commandBus->dispatch($addConnector);
 }
 /**
  * @param array $processLog
  * @param ProcessingConfig $config
  * @param TranslatorInterface $translator
  */
 public static function formatProcessLog(array &$processLog, ProcessingConfig $config, TranslatorInterface $translator)
 {
     $processDefinitions = $config->getProcessDefinitions();
     self::addPrcessName($processLog, $processDefinitions, $translator);
 }
Ejemplo n.º 7
0
 /**
  * @param $connectorId
  * @return bool
  */
 private function existsConnector($connectorId)
 {
     return isset($this->systemConfig->getConnectors()[$connectorId]);
 }
Ejemplo n.º 8
0
 /**
  * @param string $connectorId
  * @param array $connectorConfig
  * @param \Prooph\Link\Application\Projection\ProcessingConfig $config
  * @param bool $isNewConnector
  * @throws \InvalidArgumentException
  */
 private function assertConnectorConfig($connectorId, array $connectorConfig, \Prooph\Link\Application\Projection\ProcessingConfig $config, $isNewConnector = false)
 {
     if (!is_string($connectorId) || empty($connectorId)) {
         throw new \InvalidArgumentException("Connector id must a non empty string");
     }
     if (!array_key_exists('name', $connectorConfig)) {
         throw new \InvalidArgumentException('Missing name in connector config ' . $connectorId);
     }
     if (!is_string($connectorConfig['name']) || empty($connectorConfig['name'])) {
         throw new \InvalidArgumentException('Name must be a non empty string in connector config ' . $connectorId);
     }
     if (!array_key_exists('allowed_messages', $connectorConfig)) {
         throw new \InvalidArgumentException('Missing allowed messages in connector config ' . $connectorId);
     }
     if (!is_array($connectorConfig['allowed_messages'])) {
         throw new \InvalidArgumentException('Allowed messages must be an array in connector config ' . $connectorId);
     }
     if (!array_key_exists('icon', $connectorConfig)) {
         throw new \InvalidArgumentException('Missing icon in connector config ' . $connectorId);
     }
     if (!array_key_exists('icon_type', $connectorConfig)) {
         throw new \InvalidArgumentException('Missing icon_type in connector config ' . $connectorId);
     }
     if (!array_key_exists('node_name', $connectorConfig)) {
         throw new \InvalidArgumentException('Missing node_name in connector config ' . $connectorId);
     }
     array_walk($connectorConfig['allowed_messages'], function ($allowedMessage) use($connectorId) {
         if (!in_array($allowedMessage, $this->getAvailableMessageTypes())) {
             throw new \InvalidArgumentException(sprintf('Allowed message %s is not a valid workflow message suffix in connector config %s', $allowedMessage, $connectorId));
         }
     });
     if (!array_key_exists('allowed_types', $connectorConfig)) {
         throw new \InvalidArgumentException('Missing allowed types in connector config ' . $connectorId);
     }
     if (!is_array($connectorConfig['allowed_types'])) {
         throw new \InvalidArgumentException('Allowed types must be an array in connector config ' . $connectorId);
     }
     if (!$isNewConnector) {
         array_walk($connectorConfig['allowed_types'], function ($allowedType) use($connectorId, $config) {
             if (!in_array($allowedType, $config->getAllAvailableProcessingTypes())) {
                 throw new \InvalidArgumentException(sprintf('Allowed data type %s is not known by the system in connector config %s', $allowedType, $connectorId));
             }
         });
     }
     if (isset($connectorConfig['metadata'])) {
         if (!is_array($connectorConfig['metadata'])) {
             throw new \InvalidArgumentException('Metadata must be an array in connector config ' . $connectorId);
         }
     }
     if (!$isNewConnector) {
         if (isset($connectorConfig['preferred_type'])) {
             if (!in_array($connectorConfig['preferred_type'], $config->getAllAvailableProcessingTypes())) {
                 throw new \InvalidArgumentException(sprintf('Preferred data type %s is not known by the system in connector config %s', $connectorConfig['preferred_type'], $connectorId));
             }
         }
     }
 }