Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit ce48579

Browse files
authored
Merge pull request #2769 from magento-engcom/status-searchapi
Status Search API
2 parents 168ecf4 + 8d75e92 commit ce48579

File tree

18 files changed

+414
-50
lines changed

18 files changed

+414
-50
lines changed

app/code/Magento/AsynchronousOperations/Api/BulkStatusInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
namespace Magento\AsynchronousOperations\Api;
1010

1111
/**
12-
* Interface BulkStatusInterface
12+
* Interface BulkStatusInterface.
13+
*
1314
* Bulk summary data with list of operations items short data.
1415
*
1516
* @api

app/code/Magento/AsynchronousOperations/Api/Data/DetailedBulkOperationsStatusInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ interface DetailedBulkOperationsStatusInterface extends BulkSummaryInterface
2323
/**
2424
* Retrieve operations list.
2525
*
26-
* @return \Magento\AsynchronousOperations\Api\Data\DetailedOperationStatusInterface[]
26+
* @return \Magento\AsynchronousOperations\Api\Data\OperationInterface[]
2727
*/
2828
public function getOperationsList();
2929

3030
/**
3131
* Set operations list.
3232
*
33-
* @param \Magento\AsynchronousOperations\Api\Data\DetailedOperationStatusInterface[] $operationStatusList
33+
* @param \Magento\AsynchronousOperations\Api\Data\OperationInterface[] $operationStatusList
3434
* @return $this
3535
*/
3636
public function setOperationsList($operationStatusList);

app/code/Magento/AsynchronousOperations/Api/Data/DetailedOperationStatusInterface.php

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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\Data;
10+
11+
/**
12+
* Bulk operation search result interface.
13+
*
14+
* An bulk is a group of queue messages. An bulk operation item is a queue message.
15+
* @api
16+
*/
17+
interface OperationSearchResultsInterface extends \Magento\Framework\Api\SearchResultsInterface
18+
{
19+
/**
20+
* Get list of operations.
21+
*
22+
* @return \Magento\AsynchronousOperations\Api\Data\OperationInterface[]
23+
*/
24+
public function getItems();
25+
26+
/**
27+
* Set list of operations.
28+
*
29+
* @param \Magento\AsynchronousOperations\Api\Data\OperationInterface[] $items
30+
* @return $this
31+
*/
32+
public function setItems(array $items);
33+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
* Bulk operation item repository interface.
13+
*
14+
* An bulk is a group of queue messages. An bulk operation item is a queue message.
15+
* @api
16+
*/
17+
interface OperationRepositoryInterface
18+
{
19+
/**
20+
* Lists the bulk operation items that match specified search criteria.
21+
*
22+
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
23+
* @return \Magento\AsynchronousOperations\Api\Data\OperationSearchResultsInterface
24+
*/
25+
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria);
26+
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
*/
66
namespace Magento\AsynchronousOperations\Model;
77

8-
use Magento\AsynchronousOperations\Api\Data\DetailedOperationStatusInterface;
8+
use Magento\AsynchronousOperations\Api\Data\OperationInterface;
99
use Magento\Framework\DataObject;
10-
use Magento\Framework\Api\ExtensibleDataInterface;
1110

1211
/**
1312
* Class Operation
1413
*/
15-
class Operation extends DataObject implements DetailedOperationStatusInterface, ExtensibleDataInterface
14+
class Operation extends DataObject implements OperationInterface
1615
{
1716
/**
1817
* @inheritDoc

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Magento\AsynchronousOperations\Model;
88

9-
use Magento\AsynchronousOperations\Api\Data\DetailedOperationStatusInterfaceFactory;
9+
use Magento\AsynchronousOperations\Api\Data\OperationInterfaceFactory;
1010
use Magento\Framework\EntityManager\EntityManager;
1111

1212
/**
@@ -20,7 +20,7 @@ class OperationManagement implements \Magento\Framework\Bulk\OperationManagement
2020
private $entityManager;
2121

2222
/**
23-
* @var DetailedOperationStatusInterfaceFactory
23+
* @var OperationInterfaceFactory
2424
*/
2525
private $operationFactory;
2626

@@ -33,12 +33,12 @@ class OperationManagement implements \Magento\Framework\Bulk\OperationManagement
3333
* OperationManagement constructor.
3434
*
3535
* @param EntityManager $entityManager
36-
* @param DetailedOperationStatusInterfaceFactory $operationFactory
36+
* @param OperationInterfaceFactory $operationFactory
3737
* @param \Psr\Log\LoggerInterface $logger
3838
*/
3939
public function __construct(
4040
EntityManager $entityManager,
41-
DetailedOperationStatusInterfaceFactory $operationFactory,
41+
OperationInterfaceFactory $operationFactory,
4242
\Psr\Log\LoggerInterface $logger
4343
) {
4444
$this->entityManager = $entityManager;
@@ -65,7 +65,6 @@ public function changeOperationStatus(
6565
$operationEntity->setResultMessage($message);
6666
$operationEntity->setSerializedData($data);
6767
$operationEntity->setResultSerializedData($resultData);
68-
$operationEntity->setResultSerializedData($resultData);
6968
$this->entityManager->save($operationEntity);
7069
} catch (\Exception $exception) {
7170
$this->logger->critical($exception->getMessage());
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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\EntityManager\EntityManager;
12+
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
13+
use Magento\AsynchronousOperations\Api\Data\OperationSearchResultsInterfaceFactory as SearchResultFactory;
14+
use Magento\AsynchronousOperations\Api\Data\OperationExtensionInterfaceFactory;
15+
use Magento\AsynchronousOperations\Model\ResourceModel\Operation\CollectionFactory;
16+
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
17+
use Magento\Framework\Exception\InputException;
18+
use Magento\Framework\Exception\NoSuchEntityException;
19+
20+
/**
21+
* Repository class for @see \Magento\AsynchronousOperations\Api\OperationRepositoryInterface
22+
*/
23+
class OperationRepository implements \Magento\AsynchronousOperations\Api\OperationRepositoryInterface
24+
{
25+
/**
26+
* @var EntityManager
27+
*/
28+
private $entityManager;
29+
30+
/**
31+
* @var CollectionFactory
32+
*/
33+
private $collectionFactory;
34+
35+
/**
36+
* @var SearchResultFactory
37+
*/
38+
private $searchResultFactory;
39+
40+
/**
41+
* @var JoinProcessorInterface
42+
*/
43+
private $joinProcessor;
44+
45+
/**
46+
* @var \Magento\AsynchronousOperations\Api\Data\OperationExtensionInterfaceFactory
47+
*/
48+
private $operationExtensionFactory;
49+
50+
/**
51+
* @var CollectionProcessorInterface
52+
*/
53+
private $collectionProcessor;
54+
55+
/**
56+
* @var \Psr\Log\LoggerInterface
57+
*/
58+
private $logger;
59+
60+
/**
61+
* OperationRepository constructor.
62+
*
63+
* @param EntityManager $entityManager
64+
* @param CollectionFactory $collectionFactory
65+
* @param SearchResultFactory $searchResultFactory
66+
* @param JoinProcessorInterface $joinProcessor
67+
* @param OperationExtensionInterfaceFactory $operationExtension
68+
* @param CollectionProcessorInterface $collectionProcessor
69+
* @param \Psr\Log\LoggerInterface $logger
70+
*/
71+
public function __construct(
72+
EntityManager $entityManager,
73+
CollectionFactory $collectionFactory,
74+
SearchResultFactory $searchResultFactory,
75+
JoinProcessorInterface $joinProcessor,
76+
OperationExtensionInterfaceFactory $operationExtension,
77+
CollectionProcessorInterface $collectionProcessor,
78+
\Psr\Log\LoggerInterface $logger
79+
) {
80+
$this->entityManager = $entityManager;
81+
$this->collectionFactory = $collectionFactory;
82+
$this->searchResultFactory = $searchResultFactory;
83+
$this->joinProcessor = $joinProcessor;
84+
$this->operationExtensionFactory = $operationExtension;
85+
$this->collectionProcessor = $collectionProcessor;
86+
$this->logger = $logger;
87+
$this->collectionProcessor = $collectionProcessor;
88+
}
89+
90+
/**
91+
* @inheritDoc
92+
*/
93+
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
94+
{
95+
/** @var \Magento\AsynchronousOperations\Api\Data\OperationSearchResultsInterface $searchResult */
96+
$searchResult = $this->searchResultFactory->create();
97+
98+
/** @var \Magento\AsynchronousOperations\Model\ResourceModel\Operation\Collection $collection */
99+
$collection = $this->collectionFactory->create();
100+
$this->joinProcessor->process($collection, \Magento\AsynchronousOperations\Api\Data\OperationInterface::class);
101+
$this->collectionProcessor->process($searchCriteria, $collection);
102+
$searchResult->setSearchCriteria($searchCriteria);
103+
$searchResult->setTotalCount($collection->getSize());
104+
$searchResult->setItems($collection->getItems());
105+
106+
return $searchResult;
107+
}
108+
}

app/code/Magento/AsynchronousOperations/Test/Unit/Model/OperationManagementTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ protected function setUp()
4040
$this->entityManagerMock = $this->createMock(\Magento\Framework\EntityManager\EntityManager::class);
4141
$this->metadataPoolMock = $this->createMock(\Magento\Framework\EntityManager\MetadataPool::class);
4242
$this->operationFactoryMock = $this->createPartialMock(
43-
\Magento\AsynchronousOperations\Api\Data\DetailedOperationStatusInterfaceFactory::class,
43+
\Magento\AsynchronousOperations\Api\Data\OperationInterfaceFactory::class,
4444
['create']
4545
);
4646
$this->operationMock =
47-
$this->createMock(\Magento\AsynchronousOperations\Api\Data\DetailedOperationStatusInterface::class);
47+
$this->createMock(\Magento\AsynchronousOperations\Api\Data\OperationInterface::class);
4848
$this->loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class);
4949
$this->model = new \Magento\AsynchronousOperations\Model\OperationManagement(
5050
$this->entityManagerMock,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
99
<preference for="Magento\AsynchronousOperations\Api\Data\BulkSummaryInterface" type="Magento\AsynchronousOperations\Model\BulkSummary" />
1010
<preference for="Magento\AsynchronousOperations\Api\Data\OperationInterface" type="Magento\AsynchronousOperations\Model\Operation" />
11-
<preference for="Magento\AsynchronousOperations\Api\Data\DetailedOperationStatusInterface" type="Magento\AsynchronousOperations\Model\Operation" />
1211
<preference for="Magento\AsynchronousOperations\Api\Data\OperationListInterface" type="Magento\AsynchronousOperations\Model\OperationList" />
1312
<preference for="Magento\Framework\Bulk\BulkManagementInterface" type="Magento\AsynchronousOperations\Model\BulkManagement" />
1413
<preference for="Magento\AsynchronousOperations\Api\BulkStatusInterface" type="Magento\AsynchronousOperations\Model\BulkOperationsStatus" />
@@ -17,10 +16,12 @@
1716
<preference for="Magento\AsynchronousOperations\Api\Data\SummaryOperationStatusInterface" type="Magento\AsynchronousOperations\Model\OperationStatus" />
1817
<preference for="Magento\AsynchronousOperations\Api\Data\DetailedBulkOperationsStatusInterface" type="Magento\AsynchronousOperations\Model\BulkStatus\Detailed" />
1918
<preference for="Magento\AsynchronousOperations\Api\Data\BulkOperationsStatusInterface" type="Magento\AsynchronousOperations\Model\BulkStatus\Short" />
19+
<preference for="Magento\AsynchronousOperations\Api\Data\OperationSearchResultsInterface" type="Magento\Framework\Api\SearchResults" />
20+
<preference for="Magento\AsynchronousOperations\Api\OperationRepositoryInterface" type="Magento\AsynchronousOperations\Model\OperationRepository" />
2021
<type name="Magento\Framework\EntityManager\MetadataPool">
2122
<arguments>
2223
<argument name="metadata" xsi:type="array">
23-
<item name="Magento\AsynchronousOperations\Api\Data\DetailedOperationStatusInterface" xsi:type="array">
24+
<item name="Magento\AsynchronousOperations\Api\Data\OperationInterface" xsi:type="array">
2425
<item name="entityTableName" xsi:type="string">magento_operation</item>
2526
<item name="identifierField" xsi:type="string">id</item>
2627
</item>
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 © Magento, Inc. 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>

0 commit comments

Comments
 (0)