Skip to content

Commit 7a6c902

Browse files
committed
Merge remote-tracking branch 'comwrap/async-status-search' into bulk-status-search
2 parents 6c69054 + 47c99cc commit 7a6c902

File tree

11 files changed

+399
-4
lines changed

11 files changed

+399
-4
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Magento\AsynchronousOperations\Api\Data;
11+
12+
/**
13+
* @api
14+
*/
15+
interface OperationSearchResultsInterface extends \Magento\Framework\Api\SearchResultsInterface
16+
{
17+
/**
18+
* Get attributes list.
19+
*
20+
* @return \Magento\AsynchronousOperations\Api\Data\OperationInterface[]
21+
*/
22+
public function getItems();
23+
24+
/**
25+
* Set attributes list.
26+
*
27+
* @param \Magento\AsynchronousOperations\Api\Data\OperationInterface[] $items
28+
* @return $this
29+
*/
30+
public function setItems(array $items);
31+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\AsynchronousOperations\Api;
10+
11+
/**
12+
* @api
13+
*/
14+
interface OperationRepositoryInterface
15+
{
16+
/**
17+
* Find operation entities by criteria
18+
*
19+
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
20+
* @return \Magento\AsynchronousOperations\Api\Data\OperationSearchResultsInterface
21+
*/
22+
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria);
23+
}

app/code/Magento/AsynchronousOperations/Model/Operation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/**
1313
* Class Operation
1414
*/
15-
class Operation extends DataObject implements DetailedOperationStatusInterface, ExtensibleDataInterface
15+
class Operation extends DataObject implements DetailedOperationStatusInterface
1616
{
1717
/**
1818
* @inheritDoc
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\AsynchronousOperations\Model;
10+
11+
use Magento\Framework\App\ObjectManager;
12+
use Magento\AsynchronousOperations\Api\Data\DetailedOperationStatusInterfaceFactory;
13+
use Magento\Framework\EntityManager\EntityManager;
14+
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
15+
use Magento\AsynchronousOperations\Api\Data\OperationSearchResultsInterfaceFactory as SearchResultFactory;
16+
use Magento\AsynchronousOperations\Api\Data\OperationExtensionInterfaceFactory;
17+
use Magento\AsynchronousOperations\Model\ResourceModel\Operation\CollectionFactory;
18+
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
19+
use Magento\Framework\Exception\InputException;
20+
use Magento\Framework\Exception\NoSuchEntityException;
21+
22+
/**
23+
* Class OperationManagement
24+
*/
25+
class OperationRepository implements \Magento\AsynchronousOperations\Api\OperationRepositoryInterface
26+
{
27+
/**
28+
* @var EntityManager
29+
*/
30+
private $entityManager;
31+
32+
/**
33+
* @var CollectionFactory
34+
*/
35+
private $collectionFactory;
36+
37+
/**
38+
* @var SearchResultFactory
39+
*/
40+
private $searchResultFactory;
41+
42+
/**
43+
* @var JoinProcessorInterface
44+
*/
45+
private $joinProcessor;
46+
47+
/**
48+
* @var \Magento\AsynchronousOperations\Api\Data\OperationExtensionInterfaceFactory
49+
*/
50+
private $operationExtensionFactory;
51+
52+
/**
53+
* @var CollectionProcessorInterface
54+
*/
55+
private $collectionProcessor;
56+
57+
/**
58+
* @var \Psr\Log\LoggerInterface
59+
*/
60+
private $logger;
61+
62+
/**
63+
* Initialize dependencies.
64+
*
65+
* @param \Magento\Framework\EntityManager\EntityManager $entityManager
66+
* @param \Magento\AsynchronousOperations\Model\ResourceModel\Operation\CollectionFactory $collectionFactory
67+
* @param \Magento\AsynchronousOperations\Api\Data\OperationSearchResultsInterfaceFactory $searchResultFactory
68+
* @param \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $joinProcessor
69+
* @param \Magento\AsynchronousOperations\Api\Data\OperationExtensionInterfaceFactory $operationExtensionFactory
70+
* @param \Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface|null $collectionProcessor
71+
* @param \Psr\Log\LoggerInterface $logger
72+
*/
73+
public function __construct(
74+
EntityManager $entityManager,
75+
CollectionFactory $collectionFactory,
76+
SearchResultFactory $searchResultFactory,
77+
JoinProcessorInterface $joinProcessor,
78+
OperationExtensionInterfaceFactory $operationExtension,
79+
CollectionProcessorInterface $collectionProcessor = null,
80+
\Psr\Log\LoggerInterface $logger
81+
) {
82+
$this->entityManager = $entityManager;
83+
$this->collectionFactory = $collectionFactory;
84+
$this->searchResultFactory = $searchResultFactory;
85+
$this->joinProcessor = $joinProcessor;
86+
$this->operationExtensionFactory = $operationExtension;
87+
$this->collectionProcessor = $collectionProcessor ? : ObjectManager::getInstance()
88+
->get(\Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface::class);
89+
$this->logger = $logger;
90+
}
91+
92+
/**
93+
* @inheritDoc
94+
*/
95+
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
96+
{
97+
/** @var \Magento\AsynchronousOperations\Api\Data\OperationSearchResultsInterface $searchResult */
98+
$searchResult = $this->searchResultFactory->create();
99+
100+
/** @var \Magento\AsynchronousOperations\Model\ResourceModel\Operation\Collection $collection */
101+
$collection = $this->collectionFactory->create();
102+
$this->joinProcessor->process($collection, \Magento\AsynchronousOperations\Api\Data\OperationInterface::class);
103+
$this->collectionProcessor->process($searchCriteria, $collection);
104+
$searchResult->setSearchCriteria($searchCriteria);
105+
$searchResult->setTotalCount($collection->getSize());
106+
107+
$items = [];
108+
foreach ($collection->getItems() as $item) {
109+
$extensionAttributes = $item->getExtensionAttributes();
110+
if ($extensionAttributes == null) {
111+
$extensionAttributes = $this->operationExtensionFactory->create();
112+
}
113+
$extensionAttributes->setStartTime('dsadsa');
114+
$item->setExtensionAttributes($extensionAttributes);
115+
$items[] = $item;
116+
}
117+
$searchResult->setItems($items);
118+
119+
return $searchResult;
120+
}
121+
}

app/code/Magento/AsynchronousOperations/etc/di.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
<preference for="Magento\AsynchronousOperations\Api\Data\SummaryOperationStatusInterface" type="Magento\AsynchronousOperations\Model\OperationStatus" />
1818
<preference for="Magento\AsynchronousOperations\Api\Data\DetailedBulkOperationsStatusInterface" type="Magento\AsynchronousOperations\Model\BulkStatus\Detailed" />
1919
<preference for="Magento\AsynchronousOperations\Api\Data\BulkOperationsStatusInterface" type="Magento\AsynchronousOperations\Model\BulkStatus\Short" />
20+
<preference for="Magento\AsynchronousOperations\Api\Data\OperationSearchResultsInterface" type="Magento\Framework\Api\SearchResults" />
21+
<preference for="Magento\AsynchronousOperations\Api\OperationRepositoryInterface" type="Magento\AsynchronousOperations\Model\OperationRepository" />
2022
<type name="Magento\Framework\EntityManager\MetadataPool">
2123
<arguments>
2224
<argument name="metadata" xsi:type="array">
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2016 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
9+
<extension_attributes for="Magento\AsynchronousOperations\Api\Data\OperationInterface">
10+
<attribute code="start_time" type="string">
11+
<resources>
12+
<resource ref="Magento_Logging::system_magento_logging_bulk_operations"/>
13+
</resources>
14+
<join reference_table="magento_bulk" join_on_field="bulk_uuid" reference_field="uuid">
15+
<field column="start_time">start_time</field>
16+
</join>
17+
</attribute>
18+
</extension_attributes>
19+
</config>

app/code/Magento/AsynchronousOperations/etc/webapi.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,11 @@
2929
</resources>
3030
</route>
3131

32+
<route url="/V1/bulk" method="GET">
33+
<service class="Magento\AsynchronousOperations\Api\OperationRepositoryInterface" method="getList"/>
34+
<resources>
35+
<resource ref="Magento_Logging::system_magento_logging_bulk_operations" />
36+
</resources>
37+
</route>
38+
3239
</routes>
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\AsynchronousOperations\Api;
10+
11+
use Magento\Framework\Webapi\Rest\Request;
12+
use Magento\TestFramework\TestCase\WebapiAbstract;
13+
use Magento\Framework\Bulk\OperationInterface;
14+
15+
class OperationRepositoryInterfaceTest extends WebapiAbstract
16+
{
17+
const RESOURCE_PATH = '/V1/bulk';
18+
const SERVICE_NAME = 'asynchronousOperationsOperationRepositoryV1';
19+
20+
/**
21+
* @magentoApiDataFixture Magento/AsynchronousOperations/_files/operation_searchable.php
22+
*/
23+
public function testGetListByBulkStartTime()
24+
{
25+
$searchCriteria = [
26+
'searchCriteria' => [
27+
'filter_groups' => [
28+
[
29+
'filters' => [
30+
[
31+
'field' => 'start_time',
32+
'value' => '2010-10-10 00:00:00',
33+
'condition_type' => 'lteq',
34+
],
35+
],
36+
],
37+
],
38+
'current_page' => 1,
39+
],
40+
];
41+
42+
$serviceInfo = [
43+
'rest' => [
44+
'resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($searchCriteria),
45+
'httpMethod' => Request::HTTP_METHOD_GET,
46+
],
47+
'soap' => [
48+
'service' => self::SERVICE_NAME,
49+
'operation' => self::SERVICE_NAME . 'GetList',
50+
],
51+
];
52+
53+
$response = $this->_webApiCall($serviceInfo, $searchCriteria);
54+
55+
$this->assertArrayHasKey('search_criteria', $response);
56+
$this->assertArrayHasKey('total_count', $response);
57+
$this->assertArrayHasKey('items', $response);
58+
59+
$this->assertEquals($searchCriteria['searchCriteria'], $response['search_criteria']);
60+
$this->assertEquals(3, $response['total_count']);
61+
$this->assertEquals(3, count($response['items']));
62+
63+
foreach ($response['items'] as $item) {
64+
$this->assertEquals('bulk-uuid-searchable-6', $item['bulk_uuid']);
65+
}
66+
}
67+
68+
/**
69+
* @magentoApiDataFixture Magento/AsynchronousOperations/_files/operation_searchable.php
70+
*/
71+
public function testGetList()
72+
{
73+
$searchCriteria = [
74+
'searchCriteria' => [
75+
'filter_groups' => [
76+
[
77+
'filters' => [
78+
[
79+
'field' => 'bulk_uuid',
80+
'value' => 'bulk-uuid-searchable-6',
81+
'condition_type' => 'eq',
82+
],
83+
],
84+
],
85+
[
86+
'filters' => [
87+
[
88+
'field' => 'status',
89+
'value' => OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED,
90+
'condition_type' => 'eq',
91+
],
92+
],
93+
],
94+
],
95+
'current_page' => 1,
96+
],
97+
];
98+
99+
$serviceInfo = [
100+
'rest' => [
101+
'resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($searchCriteria),
102+
'httpMethod' => Request::HTTP_METHOD_GET,
103+
],
104+
'soap' => [
105+
'service' => self::SERVICE_NAME,
106+
'operation' => self::SERVICE_NAME . 'GetList',
107+
],
108+
];
109+
110+
$response = $this->_webApiCall($serviceInfo, $searchCriteria);
111+
112+
$this->assertArrayHasKey('search_criteria', $response);
113+
$this->assertArrayHasKey('total_count', $response);
114+
$this->assertArrayHasKey('items', $response);
115+
116+
$this->assertEquals($searchCriteria['searchCriteria'], $response['search_criteria']);
117+
$this->assertEquals(1, $response['total_count']);
118+
$this->assertEquals(1, count($response['items']));
119+
120+
foreach ($response['items'] as $item) {
121+
$this->assertEquals('bulk-uuid-searchable-6', $item['bulk_uuid']);
122+
}
123+
}
124+
}

dev/tests/integration/testsuite/Magento/AsynchronousOperations/_files/bulk.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
'user_id' => 1,
4545
'description' => 'Bulk Description',
4646
'operation_count' => 2,
47-
]
47+
],
4848
];
4949
// Only processed operations are saved into database (i.e. operations that are not in 'open' state)
5050
$operations = [
@@ -88,7 +88,6 @@
8888
'error_code' => 2222,
8989
'result_message' => 'Entity with ID=4 does not exist',
9090
],
91-
9291
];
9392

9493
$bulkQuery = "INSERT INTO {$bulkTable} (`uuid`, `user_id`, `description`, `operation_count`)"

0 commit comments

Comments
 (0)