-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2350 from magento-engcom/async-bulk-webapi
[Engcom] Async bulk webapi
- Loading branch information
Showing
13 changed files
with
848 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\Webapi\Model; | ||
|
||
/** | ||
* This class gives access to consolidated web API configuration from <Module_Name>/etc/webapi.xml files. | ||
* | ||
* @api | ||
*/ | ||
interface ConfigInterface | ||
{ | ||
/** | ||
* Return services loaded from cache if enabled or from files merged previously | ||
* | ||
* @return array | ||
*/ | ||
public function getServices(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
app/code/Magento/WebapiAsync/Controller/Rest/Asynchronous/InputParamsResolver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\WebapiAsync\Controller\Rest\Asynchronous; | ||
|
||
use Magento\Framework\Webapi\ServiceInputProcessor; | ||
use Magento\Framework\Webapi\Rest\Request as RestRequest; | ||
use Magento\Webapi\Controller\Rest\Router; | ||
use Magento\Webapi\Controller\Rest\ParamsOverrider; | ||
use Magento\Webapi\Controller\Rest\RequestValidator; | ||
use Magento\Webapi\Controller\Rest\InputParamsResolver as WebapiInputParamsResolver; | ||
|
||
/** | ||
* This class is responsible for retrieving resolved input data | ||
*/ | ||
class InputParamsResolver | ||
{ | ||
/** | ||
* @var RestRequest | ||
*/ | ||
private $request; | ||
/** | ||
* @var ParamsOverrider | ||
*/ | ||
private $paramsOverrider; | ||
/** | ||
* @var ServiceInputProcessor | ||
*/ | ||
private $serviceInputProcessor; | ||
/** | ||
* @var Router | ||
*/ | ||
private $router; | ||
/** | ||
* @var RequestValidator | ||
*/ | ||
private $requestValidator; | ||
/** | ||
* @var \Magento\Webapi\Controller\Rest\InputParamsResolver | ||
*/ | ||
private $inputParamsResolver; | ||
/** | ||
* @var bool | ||
*/ | ||
private $isBulk; | ||
|
||
/** | ||
* Initialize dependencies. | ||
* | ||
* @param \Magento\Framework\Webapi\Rest\Request $request | ||
* @param \Magento\Webapi\Controller\Rest\ParamsOverrider $paramsOverrider | ||
* @param \Magento\Framework\Webapi\ServiceInputProcessor $inputProcessor | ||
* @param \Magento\Webapi\Controller\Rest\Router $router | ||
* @param \Magento\Webapi\Controller\Rest\RequestValidator $requestValidator | ||
* @param \Magento\Webapi\Controller\Rest\InputParamsResolver $inputParamsResolver | ||
* @param bool $isBulk | ||
*/ | ||
public function __construct( | ||
RestRequest $request, | ||
ParamsOverrider $paramsOverrider, | ||
ServiceInputProcessor $inputProcessor, | ||
Router $router, | ||
RequestValidator $requestValidator, | ||
WebapiInputParamsResolver $inputParamsResolver, | ||
$isBulk = false | ||
) { | ||
$this->request = $request; | ||
$this->paramsOverrider = $paramsOverrider; | ||
$this->serviceInputProcessor = $inputProcessor; | ||
$this->router = $router; | ||
$this->requestValidator = $requestValidator; | ||
$this->inputParamsResolver = $inputParamsResolver; | ||
$this->isBulk = $isBulk; | ||
} | ||
|
||
/** | ||
* Process and resolve input parameters | ||
* Return array with validated input params | ||
* or throw \Exception if at least one request entity params is not valid | ||
* | ||
* @return array | ||
* @throws \Magento\Framework\Exception\InputException if no value is provided for required parameters | ||
* @throws \Magento\Framework\Webapi\Exception | ||
*/ | ||
public function resolve() | ||
{ | ||
if ($this->isBulk === false) { | ||
return [$this->inputParamsResolver->resolve()]; | ||
} | ||
$this->requestValidator->validate(); | ||
$webapiResolvedParams = []; | ||
$inputData = $this->request->getRequestData(); | ||
foreach ($inputData as $key => $singleEntityParams) { | ||
$webapiResolvedParams[$key] = $this->resolveBulkItemParams($singleEntityParams); | ||
} | ||
|
||
return $webapiResolvedParams; | ||
} | ||
|
||
/** | ||
* @return \Magento\Webapi\Controller\Rest\Router\Route | ||
*/ | ||
public function getRoute() | ||
{ | ||
return $this->inputParamsResolver->getRoute(); | ||
} | ||
|
||
/** | ||
* Convert the input array from key-value format to a list of parameters | ||
* suitable for the specified class / method. | ||
* | ||
* Instead of \Magento\Webapi\Controller\Rest\InputParamsResolver | ||
* we don't need to merge body params with url params and use only body params | ||
* | ||
* @param array $inputData data to send to method in key-value format | ||
* @return array list of parameters that can be used to call the service method | ||
* @throws \Magento\Framework\Exception\InputException if no value is provided for required parameters | ||
* @throws \Magento\Framework\Webapi\Exception | ||
*/ | ||
private function resolveBulkItemParams($inputData) | ||
{ | ||
$route = $this->getRoute(); | ||
$serviceMethodName = $route->getServiceMethod(); | ||
$serviceClassName = $route->getServiceClass(); | ||
$inputParams = $this->serviceInputProcessor->process($serviceClassName, $serviceMethodName, $inputData); | ||
|
||
return $inputParams; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.