Skip to content
This repository has been archived by the owner on May 20, 2019. It is now read-only.

Operations Status Search API Endpoint #12

Merged
merged 10 commits into from
Jun 27, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
namespace Magento\AsynchronousOperations\Api;

/**
* Interface BulkStatusInterface
* Interface BulkStatusInterface.
*
* Bulk summary data with list of operations items short data.
*
* @api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ interface DetailedBulkOperationsStatusInterface extends BulkSummaryInterface
/**
* Retrieve operations list.
*
* @return \Magento\AsynchronousOperations\Api\Data\DetailedOperationStatusInterface[]
* @return \Magento\AsynchronousOperations\Api\Data\OperationInterface[]
*/
public function getOperationsList();

/**
* Set operations list.
*
* @param \Magento\AsynchronousOperations\Api\Data\DetailedOperationStatusInterface[] $operationStatusList
* @param \Magento\AsynchronousOperations\Api\Data\OperationInterface[] $operationStatusList
* @return $this
*/
public function setOperationsList($operationStatusList);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\AsynchronousOperations\Api\Data;

/**
* Bulk operation search result interface.
*
* An bulk is a group of queue messages. An bulk operation item is a queue message.
* @api
*/
interface OperationSearchResultsInterface extends \Magento\Framework\Api\SearchResultsInterface
{
/**
* Get list of operations.
*
* @return \Magento\AsynchronousOperations\Api\Data\OperationInterface[]
*/
public function getItems();

/**
* Set list of operations.
*
* @param \Magento\AsynchronousOperations\Api\Data\OperationInterface[] $items
* @return $this
*/
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\AsynchronousOperations\Api;

/**
* Bulk operation item repository interface.
*
* An bulk is a group of queue messages. An bulk operation item is a queue message.
* @api
*/
interface OperationRepositoryInterface
{
/**
* Lists the bulk operation items that match specified search criteria.
*
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
* @return \Magento\AsynchronousOperations\Api\Data\OperationSearchResultsInterface
*/
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria);
}
5 changes: 2 additions & 3 deletions app/code/Magento/AsynchronousOperations/Model/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
*/
namespace Magento\AsynchronousOperations\Model;

use Magento\AsynchronousOperations\Api\Data\DetailedOperationStatusInterface;
use Magento\AsynchronousOperations\Api\Data\OperationInterface;
use Magento\Framework\DataObject;
use Magento\Framework\Api\ExtensibleDataInterface;

/**
* Class Operation
*/
class Operation extends DataObject implements DetailedOperationStatusInterface, ExtensibleDataInterface
class Operation extends DataObject implements OperationInterface
{
/**
* @inheritDoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Magento\AsynchronousOperations\Model;

use Magento\AsynchronousOperations\Api\Data\DetailedOperationStatusInterfaceFactory;
use Magento\AsynchronousOperations\Api\Data\OperationInterfaceFactory;
use Magento\Framework\EntityManager\EntityManager;

/**
Expand All @@ -20,7 +20,7 @@ class OperationManagement implements \Magento\Framework\Bulk\OperationManagement
private $entityManager;

/**
* @var DetailedOperationStatusInterfaceFactory
* @var OperationInterfaceFactory
*/
private $operationFactory;

Expand All @@ -33,12 +33,12 @@ class OperationManagement implements \Magento\Framework\Bulk\OperationManagement
* OperationManagement constructor.
*
* @param EntityManager $entityManager
* @param DetailedOperationStatusInterfaceFactory $operationFactory
* @param OperationInterfaceFactory $operationFactory
* @param \Psr\Log\LoggerInterface $logger
*/
public function __construct(
EntityManager $entityManager,
DetailedOperationStatusInterfaceFactory $operationFactory,
OperationInterfaceFactory $operationFactory,
\Psr\Log\LoggerInterface $logger
) {
$this->entityManager = $entityManager;
Expand All @@ -65,7 +65,6 @@ public function changeOperationStatus(
$operationEntity->setResultMessage($message);
$operationEntity->setSerializedData($data);
$operationEntity->setResultSerializedData($resultData);
$operationEntity->setResultSerializedData($resultData);
$this->entityManager->save($operationEntity);
} catch (\Exception $exception) {
$this->logger->critical($exception->getMessage());
Expand Down
107 changes: 107 additions & 0 deletions app/code/Magento/AsynchronousOperations/Model/OperationRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\AsynchronousOperations\Model;

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;

/**
* Repository class for @see \Magento\AsynchronousOperations\Api\OperationRepositoryInterface
*/
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 $operationExtension
* @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,
\Psr\Log\LoggerInterface $logger
) {
$this->entityManager = $entityManager;
$this->collectionFactory = $collectionFactory;
$this->searchResultFactory = $searchResultFactory;
$this->joinProcessor = $joinProcessor;
$this->operationExtensionFactory = $operationExtension;
$this->collectionProcessor = $collectionProcessor;
$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());
$searchResult->setItems($collection->getItems());

return $searchResult;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ protected function setUp()
$this->entityManagerMock = $this->createMock(\Magento\Framework\EntityManager\EntityManager::class);
$this->metadataPoolMock = $this->createMock(\Magento\Framework\EntityManager\MetadataPool::class);
$this->operationFactoryMock = $this->createPartialMock(
\Magento\AsynchronousOperations\Api\Data\DetailedOperationStatusInterfaceFactory::class,
\Magento\AsynchronousOperations\Api\Data\OperationInterfaceFactory::class,
['create']
);
$this->operationMock =
$this->createMock(\Magento\AsynchronousOperations\Api\Data\DetailedOperationStatusInterface::class);
$this->createMock(\Magento\AsynchronousOperations\Api\Data\OperationInterface::class);
$this->loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class);
$this->model = new \Magento\AsynchronousOperations\Model\OperationManagement(
$this->entityManagerMock,
Expand Down
5 changes: 3 additions & 2 deletions app/code/Magento/AsynchronousOperations/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\AsynchronousOperations\Api\Data\BulkSummaryInterface" type="Magento\AsynchronousOperations\Model\BulkSummary" />
<preference for="Magento\AsynchronousOperations\Api\Data\OperationInterface" type="Magento\AsynchronousOperations\Model\Operation" />
<preference for="Magento\AsynchronousOperations\Api\Data\DetailedOperationStatusInterface" type="Magento\AsynchronousOperations\Model\Operation" />
<preference for="Magento\AsynchronousOperations\Api\Data\OperationListInterface" type="Magento\AsynchronousOperations\Model\OperationList" />
<preference for="Magento\Framework\Bulk\BulkManagementInterface" type="Magento\AsynchronousOperations\Model\BulkManagement" />
<preference for="Magento\AsynchronousOperations\Api\BulkStatusInterface" type="Magento\AsynchronousOperations\Model\BulkOperationsStatus" />
Expand All @@ -17,10 +16,12 @@
<preference for="Magento\AsynchronousOperations\Api\Data\SummaryOperationStatusInterface" type="Magento\AsynchronousOperations\Model\OperationStatus" />
<preference for="Magento\AsynchronousOperations\Api\Data\DetailedBulkOperationsStatusInterface" type="Magento\AsynchronousOperations\Model\BulkStatus\Detailed" />
<preference for="Magento\AsynchronousOperations\Api\Data\BulkOperationsStatusInterface" type="Magento\AsynchronousOperations\Model\BulkStatus\Short" />
<preference for="Magento\AsynchronousOperations\Api\Data\OperationSearchResultsInterface" type="Magento\Framework\Api\SearchResults" />
<preference for="Magento\AsynchronousOperations\Api\OperationRepositoryInterface" type="Magento\AsynchronousOperations\Model\OperationRepository" />
<type name="Magento\Framework\EntityManager\MetadataPool">
<arguments>
<argument name="metadata" xsi:type="array">
<item name="Magento\AsynchronousOperations\Api\Data\DetailedOperationStatusInterface" xsi:type="array">
<item name="Magento\AsynchronousOperations\Api\Data\OperationInterface" xsi:type="array">
<item name="entityTableName" xsi:type="string">magento_operation</item>
<item name="identifierField" xsi:type="string">id</item>
</item>
Expand Down
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>
7 changes: 7 additions & 0 deletions app/code/Magento/AsynchronousOperations/etc/webapi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,11 @@
</resources>
</route>

<route url="/V1/bulk" method="GET">
<service class="Magento\AsynchronousOperations\Api\OperationRepositoryInterface" method="getList"/>
<resources>
<resource ref="Magento_Logging::system_magento_logging_bulk_operations" />
</resources>
</route>

</routes>
Loading