Skip to content

Commit

Permalink
CC-20636: Added missing PublisherTriggerPlugin plugins - Part 1. (#9773)
Browse files Browse the repository at this point in the history
Added missing PublisherTriggerPlugin plugins - Part 1.
  • Loading branch information
kkicheglovspryker authored Jan 20, 2023
1 parent d4efaaa commit 97a679c
Show file tree
Hide file tree
Showing 12 changed files with 189 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"spryker/kernel": "^3.30.0",
"spryker/locale": "^3.0.0",
"spryker/propel-orm": "^1.0.0",
"spryker/transfer": "^3.25.0"
"spryker/transfer": "^3.27.0"
},
"require-dev": {
"spryker/code-sniffer": "*",
Expand Down
14 changes: 14 additions & 0 deletions src/Spryker/Shared/FileManager/Transfer/file_manager.transfer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,18 @@
<transfer name="FileInfoLocalizedAttributes">
</transfer>

<transfer name="FileCriteria" strict="true">
<property name="pagination" type="Pagination"/>
</transfer>

<transfer name="FileCollection" strict="true">
<property name="files" type="File[]" singular="file"/>
<property name="pagination" type="Pagination"/>
</transfer>

<transfer name="Pagination">
<property name="limit" type="int"/>
<property name="offset" type="int"/>
<property name="nbResults" type="int"/>
</transfer>
</transfers>
16 changes: 16 additions & 0 deletions src/Spryker/Zed/FileManager/Business/FileManagerFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Spryker\Zed\FileManager\Business;

use Generated\Shared\Transfer\FileCollectionTransfer;
use Generated\Shared\Transfer\FileCriteriaTransfer;
use Generated\Shared\Transfer\FileDirectoryTransfer;
use Generated\Shared\Transfer\FileDirectoryTreeTransfer;
use Generated\Shared\Transfer\FileManagerDataTransfer;
Expand Down Expand Up @@ -298,4 +300,18 @@ public function getFileInfoVersionsCount(int $idFile): int
{
return $this->getRepository()->getFileInfoVersionsCount($idFile);
}

/**
* {@inheritDoc}
*
* @api
*
* @param \Generated\Shared\Transfer\FileCriteriaTransfer $fileCriteriaTransfer
*
* @return \Generated\Shared\Transfer\FileCollectionTransfer
*/
public function getFileCollection(FileCriteriaTransfer $fileCriteriaTransfer): FileCollectionTransfer
{
return $this->getRepository()->getFileCollection($fileCriteriaTransfer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Spryker\Zed\FileManager\Business;

use Generated\Shared\Transfer\FileCollectionTransfer;
use Generated\Shared\Transfer\FileCriteriaTransfer;
use Generated\Shared\Transfer\FileDirectoryTransfer;
use Generated\Shared\Transfer\FileDirectoryTreeTransfer;
use Generated\Shared\Transfer\FileManagerDataTransfer;
Expand Down Expand Up @@ -251,4 +253,18 @@ public function getFilesByIds(array $idFiles): array;
* @return int
*/
public function getFileInfoVersionsCount(int $idFile): int;

/**
* Specification:
* - Fetches a collection of files from the Persistence.
* - Uses `FileCriteriaTransfer.pagination.limit` and `FileCriteriaTransfer.pagination.offset` to paginate results with limit and offset.
* - Returns `FileCollectionTransfer` filled with found files.
*
* @api
*
* @param \Generated\Shared\Transfer\FileCriteriaTransfer $fileCriteriaTransfer
*
* @return \Generated\Shared\Transfer\FileCollectionTransfer
*/
public function getFileCollection(FileCriteriaTransfer $fileCriteriaTransfer): FileCollectionTransfer;
}
42 changes: 42 additions & 0 deletions src/Spryker/Zed/FileManager/Persistence/FileManagerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
namespace Spryker\Zed\FileManager\Persistence;

use ArrayObject;
use Generated\Shared\Transfer\FileCollectionTransfer;
use Generated\Shared\Transfer\FileCriteriaTransfer;
use Generated\Shared\Transfer\FileDirectoryTransfer;
use Generated\Shared\Transfer\FileInfoTransfer;
use Generated\Shared\Transfer\FileTransfer;
use Generated\Shared\Transfer\MimeTypeCollectionTransfer;
use Generated\Shared\Transfer\MimeTypeTransfer;
use Generated\Shared\Transfer\PaginationTransfer;
use Orm\Zed\FileManager\Persistence\Map\SpyFileInfoTableMap;
use Orm\Zed\FileManager\Persistence\SpyFileQuery;
use Propel\Runtime\ActiveQuery\Criteria;
use Spryker\Zed\Kernel\Persistence\AbstractRepository;

Expand Down Expand Up @@ -306,4 +310,42 @@ public function getFileInfoVersionsCount(int $idFile): int
->filterByFkFile($idFile)
->count();
}

/**
* @param \Generated\Shared\Transfer\FileCriteriaTransfer $fileCriteriaTransfer
*
* @return \Generated\Shared\Transfer\FileCollectionTransfer
*/
public function getFileCollection(FileCriteriaTransfer $fileCriteriaTransfer): FileCollectionTransfer
{
$fileCollectionTransfer = new FileCollectionTransfer();
$fileQuery = $this->getFactory()->createFileQuery();

$paginationTransfer = $fileCriteriaTransfer->getPagination();
if ($paginationTransfer !== null) {
$fileQuery = $this->applyFilePagination($fileQuery, $paginationTransfer);
$fileCollectionTransfer->setPagination($paginationTransfer);
}

return $this->getFactory()->createFileManagerMapper()
->mapFileEntitiesToFileCollectionTransfer($fileQuery->find(), $fileCollectionTransfer);
}

/**
* @param \Orm\Zed\FileManager\Persistence\SpyFileQuery $fileQuery
* @param \Generated\Shared\Transfer\PaginationTransfer $paginationTransfer
*
* @return \Orm\Zed\FileManager\Persistence\SpyFileQuery
*/
protected function applyFilePagination(SpyFileQuery $fileQuery, PaginationTransfer $paginationTransfer): SpyFileQuery
{
$paginationTransfer->setNbResults($fileQuery->count());
if ($paginationTransfer->getOffset() !== null && $paginationTransfer->getLimit() !== null) {
return $fileQuery
->limit($paginationTransfer->getLimit())
->offset($paginationTransfer->getOffset());
}

return $fileQuery;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Spryker\Zed\FileManager\Persistence;

use Generated\Shared\Transfer\FileCollectionTransfer;
use Generated\Shared\Transfer\FileCriteriaTransfer;
use Generated\Shared\Transfer\MimeTypeTransfer;

interface FileManagerRepositoryInterface
Expand Down Expand Up @@ -92,4 +94,11 @@ public function getFilesByIds(array $idFiles): array;
* @return int
*/
public function getFileInfoVersionsCount(int $idFile): int;

/**
* @param \Generated\Shared\Transfer\FileCriteriaTransfer $fileCriteriaTransfer
*
* @return \Generated\Shared\Transfer\FileCollectionTransfer
*/
public function getFileCollection(FileCriteriaTransfer $fileCriteriaTransfer): FileCollectionTransfer;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Spryker\Zed\FileManager\Persistence\Mapper;

use ArrayObject;
use Generated\Shared\Transfer\FileCollectionTransfer;
use Generated\Shared\Transfer\FileDirectoryLocalizedAttributesTransfer;
use Generated\Shared\Transfer\FileDirectoryTransfer;
use Generated\Shared\Transfer\FileInfoTransfer;
Expand All @@ -22,6 +23,7 @@
use Orm\Zed\FileManager\Persistence\SpyFileInfo;
use Orm\Zed\FileManager\Persistence\SpyFileLocalizedAttributes;
use Orm\Zed\FileManager\Persistence\SpyMimeType;
use Propel\Runtime\Collection\ObjectCollection;

class FileManagerMapper implements FileManagerMapperInterface
{
Expand Down Expand Up @@ -64,6 +66,23 @@ public function mapFileTransferToEntity(FileTransfer $fileTransfer, SpyFile $fil
return $file;
}

/**
* @param \Propel\Runtime\Collection\ObjectCollection<\Orm\Zed\FileManager\Persistence\SpyFile> $fileEntities
* @param \Generated\Shared\Transfer\FileCollectionTransfer $fileCollectionTransfer
*
* @return \Generated\Shared\Transfer\FileCollectionTransfer
*/
public function mapFileEntitiesToFileCollectionTransfer(
ObjectCollection $fileEntities,
FileCollectionTransfer $fileCollectionTransfer
): FileCollectionTransfer {
foreach ($fileEntities as $fileEntity) {
$fileCollectionTransfer->addFile($this->mapFileEntityToTransfer($fileEntity, new FileTransfer()));
}

return $fileCollectionTransfer;
}

/**
* @param \Orm\Zed\FileManager\Persistence\SpyFileInfo $fileInfo
* @param \Generated\Shared\Transfer\FileInfoTransfer $fileInfoTransfer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Spryker\Zed\FileManager\Persistence\Mapper;

use Generated\Shared\Transfer\FileCollectionTransfer;
use Generated\Shared\Transfer\FileDirectoryLocalizedAttributesTransfer;
use Generated\Shared\Transfer\FileDirectoryTransfer;
use Generated\Shared\Transfer\FileInfoTransfer;
Expand All @@ -20,6 +21,7 @@
use Orm\Zed\FileManager\Persistence\SpyFileInfo;
use Orm\Zed\FileManager\Persistence\SpyFileLocalizedAttributes;
use Orm\Zed\FileManager\Persistence\SpyMimeType;
use Propel\Runtime\Collection\ObjectCollection;

interface FileManagerMapperInterface
{
Expand All @@ -39,6 +41,17 @@ public function mapFileEntityToTransfer(SpyFile $file, FileTransfer $fileTransfe
*/
public function mapFileTransferToEntity(FileTransfer $fileTransfer, SpyFile $file);

/**
* @param \Propel\Runtime\Collection\ObjectCollection<\Orm\Zed\FileManager\Persistence\SpyFile> $fileEntities
* @param \Generated\Shared\Transfer\FileCollectionTransfer $fileCollectionTransfer
*
* @return \Generated\Shared\Transfer\FileCollectionTransfer
*/
public function mapFileEntitiesToFileCollectionTransfer(
ObjectCollection $fileEntities,
FileCollectionTransfer $fileCollectionTransfer
): FileCollectionTransfer;

/**
* @param \Orm\Zed\FileManager\Persistence\SpyFileInfo $fileInfo
* @param \Generated\Shared\Transfer\FileInfoTransfer $fileInfoTransfer
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace SprykerTest\Zed\FileManager\Business\Facade;

use Codeception\Test\Unit;
use Generated\Shared\Transfer\FileCriteriaTransfer;
use Generated\Shared\Transfer\PaginationTransfer;
use SprykerTest\Zed\FileManager\FileManagerBusinessTester;

/**
* Auto-generated group annotations
*
* @group SprykerTest
* @group Zed
* @group FileManager
* @group Business
* @group Facade
* @group GetFileCollectionTest
* Add your own group annotations below this line
*/
class GetFileCollectionTest extends Unit
{
/**
* @var \SprykerTest\Zed\FileManager\FileManagerBusinessTester
*/
protected FileManagerBusinessTester $tester;

/**
* @return void
*/
public function testGetFileCollectionReturnsCollectionWithFiveFilesWhileHavingLimitOffsetPaginationApplied(): void
{
// Arrange
$this->tester->insertFilesCollection(15);
$fileCriteriaTransfer = (new FileCriteriaTransfer())
->setPagination(
(new PaginationTransfer())->setLimit(5)->setOffset(10),
);

// Act
$fileCollectionTransfer = $this->tester->getFacade()
->getFileCollection($fileCriteriaTransfer);

// Assert
$this->assertCount(5, $fileCollectionTransfer->getFiles());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public function testDeleteMimeType(): void
public function testGetFilesByIds(): void
{
// Arrange
$idFiles = $this->tester->insertFilesCollection();
$idFiles = $this->tester->insertFilesCollection(9);

// Act
$fileManagerDataTransfers = $this->facade->getFilesByIds($idFiles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,14 @@ public function getIdSubFileDirectory(): int
}

/**
* @return array<int>
* @param int $count
*
* @return list<int>
*/
public function insertFilesCollection(): array
public function insertFilesCollection(int $count = 10): array
{
$idFiles = [];
for ($i = 1; $i < 10; $i++) {
for ($i = 1; $i <= $count; $i++) {
file_put_contents($this->getDocumentFullFileName($i . '_v1.txt'), 'file content');

$file = new SpyFile();
Expand Down
1 change: 1 addition & 0 deletions tests/SprykerTest/Zed/FileManager/codeception.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ suites:
- \SprykerTest\Shared\Testify\Helper\LocatorHelper
- \SprykerTest\Shared\Testify\Helper\DependencyHelper
- \SprykerTest\Shared\Propel\Helper\TransactionHelper
- \SprykerTest\Zed\Testify\Helper\Business\BusinessHelper

0 comments on commit 97a679c

Please sign in to comment.