This repository has been archived by the owner on May 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Operations Status Search API Endpoint #12
Merged
magento-engcom-team
merged 10 commits into
magento:2.3-develop
from
comwrap:async-status-search
Jun 27, 2018
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c72fed2
Api endpoint for search operations by criteria
7d4ff3d
declare missing strict type
6104730
filter operations by bulk start_time field
1c4078f
OperationInterface extends ExtensibleDataInterface
5536151
OperationRepositoryInterface getList api-functional test
1aec471
add start_time extension attribute to webapi response
8306c69
add misisng new line to config file
3e7814a
add misisng strict declaration, fix tests data fixture, fix test
47c99cc
declare strict type for test data fixture
5d7b3ca
add description for new classed/interfaces, remove not duplicated int…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
app/code/Magento/AsynchronousOperations/Api/Data/OperationSearchResultsInterface.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,31 @@ | ||
<?php | ||
/** | ||
* | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\AsynchronousOperations\Api\Data; | ||
|
||
/** | ||
* @api | ||
*/ | ||
interface OperationSearchResultsInterface extends \Magento\Framework\Api\SearchResultsInterface | ||
{ | ||
/** | ||
* Get attributes list. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
* | ||
* @return \Magento\AsynchronousOperations\Api\Data\OperationInterface[] | ||
*/ | ||
public function getItems(); | ||
|
||
/** | ||
* Set attributes list. | ||
* | ||
* @param \Magento\AsynchronousOperations\Api\Data\OperationInterface[] $items | ||
* @return $this | ||
*/ | ||
public function setItems(array $items); | ||
} |
23 changes: 23 additions & 0 deletions
23
app/code/Magento/AsynchronousOperations/Api/OperationRepositoryInterface.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,23 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\AsynchronousOperations\Api; | ||
|
||
/** | ||
* @api | ||
*/ | ||
interface OperationRepositoryInterface | ||
{ | ||
/** | ||
* Find operation entities by criteria | ||
* | ||
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria | ||
* @return \Magento\AsynchronousOperations\Api\Data\OperationSearchResultsInterface | ||
*/ | ||
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria); | ||
} |
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
121 changes: 121 additions & 0 deletions
121
app/code/Magento/AsynchronousOperations/Model/OperationRepository.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,121 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\AsynchronousOperations\Model; | ||
|
||
use Magento\Framework\App\ObjectManager; | ||
use Magento\AsynchronousOperations\Api\Data\DetailedOperationStatusInterfaceFactory; | ||
use Magento\Framework\EntityManager\EntityManager; | ||
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface; | ||
use Magento\AsynchronousOperations\Api\Data\OperationSearchResultsInterfaceFactory as SearchResultFactory; | ||
use Magento\AsynchronousOperations\Api\Data\OperationExtensionInterfaceFactory; | ||
use Magento\AsynchronousOperations\Model\ResourceModel\Operation\CollectionFactory; | ||
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface; | ||
use Magento\Framework\Exception\InputException; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
|
||
/** | ||
* Class OperationManagement | ||
*/ | ||
class OperationRepository implements \Magento\AsynchronousOperations\Api\OperationRepositoryInterface | ||
{ | ||
/** | ||
* @var EntityManager | ||
*/ | ||
private $entityManager; | ||
|
||
/** | ||
* @var CollectionFactory | ||
*/ | ||
private $collectionFactory; | ||
|
||
/** | ||
* @var SearchResultFactory | ||
*/ | ||
private $searchResultFactory; | ||
|
||
/** | ||
* @var JoinProcessorInterface | ||
*/ | ||
private $joinProcessor; | ||
|
||
/** | ||
* @var \Magento\AsynchronousOperations\Api\Data\OperationExtensionInterfaceFactory | ||
*/ | ||
private $operationExtensionFactory; | ||
|
||
/** | ||
* @var CollectionProcessorInterface | ||
*/ | ||
private $collectionProcessor; | ||
|
||
/** | ||
* @var \Psr\Log\LoggerInterface | ||
*/ | ||
private $logger; | ||
|
||
/** | ||
* Initialize dependencies. | ||
* | ||
* @param \Magento\Framework\EntityManager\EntityManager $entityManager | ||
* @param \Magento\AsynchronousOperations\Model\ResourceModel\Operation\CollectionFactory $collectionFactory | ||
* @param \Magento\AsynchronousOperations\Api\Data\OperationSearchResultsInterfaceFactory $searchResultFactory | ||
* @param \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $joinProcessor | ||
* @param \Magento\AsynchronousOperations\Api\Data\OperationExtensionInterfaceFactory $operationExtensionFactory | ||
* @param \Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface|null $collectionProcessor | ||
* @param \Psr\Log\LoggerInterface $logger | ||
*/ | ||
public function __construct( | ||
EntityManager $entityManager, | ||
CollectionFactory $collectionFactory, | ||
SearchResultFactory $searchResultFactory, | ||
JoinProcessorInterface $joinProcessor, | ||
OperationExtensionInterfaceFactory $operationExtension, | ||
CollectionProcessorInterface $collectionProcessor = null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This argument should not be optional. |
||
\Psr\Log\LoggerInterface $logger | ||
) { | ||
$this->entityManager = $entityManager; | ||
$this->collectionFactory = $collectionFactory; | ||
$this->searchResultFactory = $searchResultFactory; | ||
$this->joinProcessor = $joinProcessor; | ||
$this->operationExtensionFactory = $operationExtension; | ||
$this->collectionProcessor = $collectionProcessor ? : ObjectManager::getInstance() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a new class, what is the reason to use object manager (it is normally used for backward compatibility)? |
||
->get(\Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface::class); | ||
$this->logger = $logger; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) | ||
{ | ||
/** @var \Magento\AsynchronousOperations\Api\Data\OperationSearchResultsInterface $searchResult */ | ||
$searchResult = $this->searchResultFactory->create(); | ||
|
||
/** @var \Magento\AsynchronousOperations\Model\ResourceModel\Operation\Collection $collection */ | ||
$collection = $this->collectionFactory->create(); | ||
$this->joinProcessor->process($collection, \Magento\AsynchronousOperations\Api\Data\OperationInterface::class); | ||
$this->collectionProcessor->process($searchCriteria, $collection); | ||
$searchResult->setSearchCriteria($searchCriteria); | ||
$searchResult->setTotalCount($collection->getSize()); | ||
|
||
$items = []; | ||
foreach ($collection->getItems() as $item) { | ||
$extensionAttributes = $item->getExtensionAttributes(); | ||
if ($extensionAttributes == null) { | ||
$extensionAttributes = $this->operationExtensionFactory->create(); | ||
} | ||
$extensionAttributes->setStartTime('dsadsa'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does 'dsadsa' mean? |
||
$item->setExtensionAttributes($extensionAttributes); | ||
$items[] = $item; | ||
} | ||
$searchResult->setItems($items); | ||
|
||
return $searchResult; | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
app/code/Magento/AsynchronousOperations/etc/extension_attributes.xml
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,19 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd"> | ||
<extension_attributes for="Magento\AsynchronousOperations\Api\Data\OperationInterface"> | ||
<attribute code="start_time" type="string"> | ||
<resources> | ||
<resource ref="Magento_Logging::system_magento_logging_bulk_operations"/> | ||
</resources> | ||
<join reference_table="magento_bulk" join_on_field="bulk_uuid" reference_field="uuid"> | ||
<field column="start_time">start_time</field> | ||
</join> | ||
</attribute> | ||
</extension_attributes> | ||
</config> |
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
124 changes: 124 additions & 0 deletions
124
...ctional/testsuite/Magento/AsynchronousOperations/Api/OperationRepositoryInterfaceTest.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,124 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\AsynchronousOperations\Api; | ||
|
||
use Magento\Framework\Webapi\Rest\Request; | ||
use Magento\TestFramework\TestCase\WebapiAbstract; | ||
use Magento\Framework\Bulk\OperationInterface; | ||
|
||
class OperationRepositoryInterfaceTest extends WebapiAbstract | ||
{ | ||
const RESOURCE_PATH = '/V1/bulk'; | ||
const SERVICE_NAME = 'asynchronousOperationsOperationRepositoryV1'; | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/AsynchronousOperations/_files/operation_searchable.php | ||
*/ | ||
public function testGetListByBulkStartTime() | ||
{ | ||
$searchCriteria = [ | ||
'searchCriteria' => [ | ||
'filter_groups' => [ | ||
[ | ||
'filters' => [ | ||
[ | ||
'field' => 'start_time', | ||
'value' => '2010-10-10 00:00:00', | ||
'condition_type' => 'lteq', | ||
], | ||
], | ||
], | ||
], | ||
'current_page' => 1, | ||
], | ||
]; | ||
|
||
$serviceInfo = [ | ||
'rest' => [ | ||
'resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($searchCriteria), | ||
'httpMethod' => Request::HTTP_METHOD_GET, | ||
], | ||
'soap' => [ | ||
'service' => self::SERVICE_NAME, | ||
'operation' => self::SERVICE_NAME . 'GetList', | ||
], | ||
]; | ||
|
||
$response = $this->_webApiCall($serviceInfo, $searchCriteria); | ||
|
||
$this->assertArrayHasKey('search_criteria', $response); | ||
$this->assertArrayHasKey('total_count', $response); | ||
$this->assertArrayHasKey('items', $response); | ||
|
||
$this->assertEquals($searchCriteria['searchCriteria'], $response['search_criteria']); | ||
$this->assertEquals(3, $response['total_count']); | ||
$this->assertEquals(3, count($response['items'])); | ||
|
||
foreach ($response['items'] as $item) { | ||
$this->assertEquals('bulk-uuid-searchable-6', $item['bulk_uuid']); | ||
} | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/AsynchronousOperations/_files/operation_searchable.php | ||
*/ | ||
public function testGetList() | ||
{ | ||
$searchCriteria = [ | ||
'searchCriteria' => [ | ||
'filter_groups' => [ | ||
[ | ||
'filters' => [ | ||
[ | ||
'field' => 'bulk_uuid', | ||
'value' => 'bulk-uuid-searchable-6', | ||
'condition_type' => 'eq', | ||
], | ||
], | ||
], | ||
[ | ||
'filters' => [ | ||
[ | ||
'field' => 'status', | ||
'value' => OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED, | ||
'condition_type' => 'eq', | ||
], | ||
], | ||
], | ||
], | ||
'current_page' => 1, | ||
], | ||
]; | ||
|
||
$serviceInfo = [ | ||
'rest' => [ | ||
'resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($searchCriteria), | ||
'httpMethod' => Request::HTTP_METHOD_GET, | ||
], | ||
'soap' => [ | ||
'service' => self::SERVICE_NAME, | ||
'operation' => self::SERVICE_NAME . 'GetList', | ||
], | ||
]; | ||
|
||
$response = $this->_webApiCall($serviceInfo, $searchCriteria); | ||
|
||
$this->assertArrayHasKey('search_criteria', $response); | ||
$this->assertArrayHasKey('total_count', $response); | ||
$this->assertArrayHasKey('items', $response); | ||
|
||
$this->assertEquals($searchCriteria['searchCriteria'], $response['search_criteria']); | ||
$this->assertEquals(1, $response['total_count']); | ||
$this->assertEquals(1, count($response['items'])); | ||
|
||
foreach ($response['items'] as $item) { | ||
$this->assertEquals('bulk-uuid-searchable-6', $item['bulk_uuid']); | ||
} | ||
} | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add description to all new classes/interfaces