diff --git a/app/code/Magento/AsynchronousOperations/Api/BulkStatusInterface.php b/app/code/Magento/AsynchronousOperations/Api/BulkStatusInterface.php index 88db2d6d801..76410794900 100644 --- a/app/code/Magento/AsynchronousOperations/Api/BulkStatusInterface.php +++ b/app/code/Magento/AsynchronousOperations/Api/BulkStatusInterface.php @@ -9,7 +9,8 @@ namespace Magento\AsynchronousOperations\Api; /** - * Interface BulkStatusInterface + * Interface BulkStatusInterface. + * * Bulk summary data with list of operations items short data. * * @api diff --git a/app/code/Magento/AsynchronousOperations/Api/Data/DetailedBulkOperationsStatusInterface.php b/app/code/Magento/AsynchronousOperations/Api/Data/DetailedBulkOperationsStatusInterface.php index 3edc5167e09..6e391776308 100644 --- a/app/code/Magento/AsynchronousOperations/Api/Data/DetailedBulkOperationsStatusInterface.php +++ b/app/code/Magento/AsynchronousOperations/Api/Data/DetailedBulkOperationsStatusInterface.php @@ -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); diff --git a/app/code/Magento/AsynchronousOperations/Api/Data/DetailedOperationStatusInterface.php b/app/code/Magento/AsynchronousOperations/Api/Data/DetailedOperationStatusInterface.php deleted file mode 100644 index 217d4ad9279..00000000000 --- a/app/code/Magento/AsynchronousOperations/Api/Data/DetailedOperationStatusInterface.php +++ /dev/null @@ -1,30 +0,0 @@ -entityManager = $entityManager; @@ -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()); diff --git a/app/code/Magento/AsynchronousOperations/Model/OperationRepository.php b/app/code/Magento/AsynchronousOperations/Model/OperationRepository.php new file mode 100644 index 00000000000..1312b939f25 --- /dev/null +++ b/app/code/Magento/AsynchronousOperations/Model/OperationRepository.php @@ -0,0 +1,107 @@ +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; + } +} diff --git a/app/code/Magento/AsynchronousOperations/Test/Unit/Model/OperationManagementTest.php b/app/code/Magento/AsynchronousOperations/Test/Unit/Model/OperationManagementTest.php index 0a4e5f2f3ec..4c3e240da2a 100644 --- a/app/code/Magento/AsynchronousOperations/Test/Unit/Model/OperationManagementTest.php +++ b/app/code/Magento/AsynchronousOperations/Test/Unit/Model/OperationManagementTest.php @@ -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, diff --git a/app/code/Magento/AsynchronousOperations/etc/di.xml b/app/code/Magento/AsynchronousOperations/etc/di.xml index c8fee29cd68..42b62ff8ea3 100644 --- a/app/code/Magento/AsynchronousOperations/etc/di.xml +++ b/app/code/Magento/AsynchronousOperations/etc/di.xml @@ -8,7 +8,6 @@ - @@ -17,10 +16,12 @@ + + - + magento_operation id diff --git a/app/code/Magento/AsynchronousOperations/etc/extension_attributes.xml b/app/code/Magento/AsynchronousOperations/etc/extension_attributes.xml new file mode 100644 index 00000000000..dcce3f27028 --- /dev/null +++ b/app/code/Magento/AsynchronousOperations/etc/extension_attributes.xml @@ -0,0 +1,19 @@ + + + + + + + + + + start_time + + + + diff --git a/app/code/Magento/AsynchronousOperations/etc/webapi.xml b/app/code/Magento/AsynchronousOperations/etc/webapi.xml index 253dedd1c7a..4c10a5756c8 100644 --- a/app/code/Magento/AsynchronousOperations/etc/webapi.xml +++ b/app/code/Magento/AsynchronousOperations/etc/webapi.xml @@ -29,4 +29,11 @@ + + + + + + + diff --git a/dev/tests/api-functional/testsuite/Magento/AsynchronousOperations/Api/OperationRepositoryInterfaceTest.php b/dev/tests/api-functional/testsuite/Magento/AsynchronousOperations/Api/OperationRepositoryInterfaceTest.php new file mode 100644 index 00000000000..8eab6c9fd86 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/AsynchronousOperations/Api/OperationRepositoryInterfaceTest.php @@ -0,0 +1,124 @@ + [ + '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']); + } + } +} diff --git a/dev/tests/integration/testsuite/Magento/AsynchronousOperations/_files/bulk.php b/dev/tests/integration/testsuite/Magento/AsynchronousOperations/_files/bulk.php index 787d2c10a44..c6c58d47e5a 100644 --- a/dev/tests/integration/testsuite/Magento/AsynchronousOperations/_files/bulk.php +++ b/dev/tests/integration/testsuite/Magento/AsynchronousOperations/_files/bulk.php @@ -44,7 +44,7 @@ 'user_id' => 1, 'description' => 'Bulk Description', 'operation_count' => 2, - ] + ], ]; // Only processed operations are saved into database (i.e. operations that are not in 'open' state) $operations = [ @@ -88,7 +88,6 @@ 'error_code' => 2222, 'result_message' => 'Entity with ID=4 does not exist', ], - ]; $bulkQuery = "INSERT INTO {$bulkTable} (`uuid`, `user_id`, `description`, `operation_count`)" diff --git a/dev/tests/integration/testsuite/Magento/AsynchronousOperations/_files/operation_searchable.php b/dev/tests/integration/testsuite/Magento/AsynchronousOperations/_files/operation_searchable.php new file mode 100644 index 00000000000..e74f995f8b5 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/AsynchronousOperations/_files/operation_searchable.php @@ -0,0 +1,69 @@ +get(\Magento\Framework\App\ResourceConnection::class); +$connection = $resource->getConnection(); +$bulkTable = $resource->getTableName('magento_bulk'); +$operationTable = $resource->getTableName('magento_operation'); + +$bulks = [ + 'started_searchable' => [ + 'uuid' => 'bulk-uuid-searchable-6', + 'user_id' => 1, + 'description' => 'Bulk Description', + 'operation_count' => 3, + 'start_time' => '2009-10-10 00:00:00', + ], +]; +// Only processed operations are saved into database (i.e. operations that are not in 'open' state) +$operations = [ + [ + 'bulk_uuid' => 'bulk-uuid-searchable-6', + 'topic_name' => 'topic-5', + 'serialized_data' => json_encode(['entity_id' => 5]), + 'status' => OperationInterface::STATUS_TYPE_COMPLETE, + 'error_code' => null, + 'result_message' => null, + ], + [ + 'bulk_uuid' => 'bulk-uuid-searchable-6', + 'topic_name' => 'topic-5', + 'serialized_data' => json_encode(['entity_id' => 5, 'meta_information' => 'Test']), + 'status' => OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED, + 'error_code' => 1111, + 'result_message' => 'Something went wrong during your request', + ], + [ + 'bulk_uuid' => 'bulk-uuid-searchable-6', + 'topic_name' => 'topic-5', + 'serialized_data' => json_encode(['entity_id' => 5]), + 'status' => OperationInterface::STATUS_TYPE_RETRIABLY_FAILED, + 'error_code' => 2222, + 'result_message' => 'Entity with ID=4 does not exist', + ], + +]; + +$bulkQuery = "INSERT INTO {$bulkTable} (`uuid`, `user_id`, `description`, `operation_count`, `start_time`)" + . " VALUES (:uuid, :user_id, :description, :operation_count, :start_time);"; +foreach ($bulks as $bulk) { + $connection->query($bulkQuery, $bulk); +} + +$operationQuery = "INSERT INTO {$operationTable}" + . " (`bulk_uuid`, `topic_name`, `serialized_data`, `status`, `error_code`, `result_message`)" + . " VALUES (:bulk_uuid, :topic_name, :serialized_data, :status, :error_code, :result_message);"; +foreach ($operations as $operation) { + $connection->query($operationQuery, $operation); +} diff --git a/lib/internal/Magento/Framework/Bulk/OperationInterface.php b/lib/internal/Magento/Framework/Bulk/OperationInterface.php index 4b626ac6596..c1cac9f1714 100644 --- a/lib/internal/Magento/Framework/Bulk/OperationInterface.php +++ b/lib/internal/Magento/Framework/Bulk/OperationInterface.php @@ -10,7 +10,7 @@ * @api * @since 100.2.0 */ -interface OperationInterface +interface OperationInterface extends \Magento\Framework\Api\ExtensibleDataInterface { /**#@+ * Constants for keys of data array. Identical to the name of the getter in snake case