response = $response; $this->inputParamsResolver = $inputParamsResolver; $this->asyncBulkPublisher = $asyncBulkPublisher; $this->webapiAsyncConfig = $webapiAsyncConfig; $this->dataObjectProcessor = $dataObjectProcessor; $this->asyncResponseFactory = $asyncResponse; $this->processorPath = $processorPath; } /** * {@inheritdoc} */ public function process(\Magento\Framework\Webapi\Rest\Request $request) { $path = $request->getPathInfo(); $path = preg_replace($this->processorPath, "$1", $path); $request->setPathInfo( $path ); $entitiesParamsArray = $this->inputParamsResolver->resolve(); $topicName = $this->getTopicName($request); try { $asyncResponse = $this->asyncBulkPublisher->publishMass( $topicName, $entitiesParamsArray ); } catch (BulkException $bulkException) { $asyncResponse = $bulkException->getData(); } $responseData = $this->dataObjectProcessor->buildOutputDataArray( $asyncResponse, AsyncResponseInterface::class ); $this->response->setStatusCode(RestResponse::STATUS_CODE_202) ->prepareResponse($responseData); } /** * @param \Magento\Framework\Webapi\Rest\Request $request * @return string */ private function getTopicName($request) { $route = $this->inputParamsResolver->getRoute(); return $this->webapiAsyncConfig->getTopicName( $route->getRoutePath(), $request->getHttpMethod() ); } /** * {@inheritdoc} */ public function canProcess(\Magento\Framework\Webapi\Rest\Request $request) { if ($request->getHttpMethod() === \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET) { return false; } if (preg_match($this->processorPath, $request->getPathInfo()) === 1) { return true; } return false; } /** * @param \Magento\Framework\Webapi\Rest\Request $request * @return bool */ public function isBulk(\Magento\Framework\Webapi\Rest\Request $request) { if (preg_match(self::BULK_PROCESSOR_PATH, $request->getPathInfo()) === 1) { return true; } return false; } }