Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Task] Create csv export for folder with grid config #477

Merged
merged 12 commits into from
Oct 14, 2024
3 changes: 2 additions & 1 deletion config/assets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ services:
Pimcore\Bundle\StudioBackendBundle\Asset\ExecutionEngine\AutomationAction\Messenger\Handler\AssetCloneHandler: ~
Pimcore\Bundle\StudioBackendBundle\Asset\ExecutionEngine\AutomationAction\Messenger\Handler\AssetUploadHandler: ~
Pimcore\Bundle\StudioBackendBundle\Asset\ExecutionEngine\AutomationAction\Messenger\Handler\CsvCreationHandler: ~
Pimcore\Bundle\StudioBackendBundle\Asset\ExecutionEngine\AutomationAction\Messenger\Handler\CsvDataCollectionHandler: ~
Pimcore\Bundle\StudioBackendBundle\Asset\ExecutionEngine\AutomationAction\Messenger\Handler\CsvAssetDataCollectionHandler: ~
Pimcore\Bundle\StudioBackendBundle\Asset\ExecutionEngine\AutomationAction\Messenger\Handler\CsvFolderDataCollectionHandler: ~
Pimcore\Bundle\StudioBackendBundle\Asset\ExecutionEngine\AutomationAction\Messenger\Handler\ZipDownloadHandler: ~
Pimcore\Bundle\StudioBackendBundle\Asset\ExecutionEngine\AutomationAction\Messenger\Handler\ZipUploadHandler: ~

Expand Down
3 changes: 3 additions & 0 deletions config/data_index_filters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ services:
Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\PqlFilter:
tags: [ 'pimcore.studio_backend.open_search.filter' ]

Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\UserFilter:
tags: [ 'pimcore.studio_backend.open_search.filter' ]

# DataObject
Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\DataObject\ClassNameFilter:
tags: [ 'pimcore.studio_backend.open_search.data_object.filter' ]
Expand Down
8 changes: 7 additions & 1 deletion config/mappers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ services:

Pimcore\Bundle\StudioBackendBundle\Property\Mapper\PropertiesParametersMapper: ~

Pimcore\Bundle\StudioBackendBundle\Filter\Mapper\CollectionParametersMapper: ~
Pimcore\Bundle\StudioBackendBundle\Filter\Mapper\CollectionParametersMapper: ~

Pimcore\Bundle\StudioBackendBundle\Grid\Mapper\ColumnMapperInterface:
class: Pimcore\Bundle\StudioBackendBundle\Grid\Mapper\ColumnMapper

Pimcore\Bundle\StudioBackendBundle\Grid\Mapper\FilterParameterMapperInterface:
class: Pimcore\Bundle\StudioBackendBundle\Grid\Mapper\FilterParameterMapper
3 changes: 2 additions & 1 deletion config/pimcore/execution_engine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ pimcore_generic_execution_engine:
framework:
messenger:
routing:
Pimcore\Bundle\StudioBackendBundle\Asset\ExecutionEngine\AutomationAction\Messenger\Messages\CsvCollectionMessage: pimcore_generic_execution_engine
Pimcore\Bundle\StudioBackendBundle\Asset\ExecutionEngine\AutomationAction\Messenger\Messages\CsvAssetCollectionMessage: pimcore_generic_execution_engine
Pimcore\Bundle\StudioBackendBundle\Asset\ExecutionEngine\AutomationAction\Messenger\Messages\CsvFolderCollectionMessage: pimcore_generic_execution_engine
Pimcore\Bundle\StudioBackendBundle\Asset\ExecutionEngine\AutomationAction\Messenger\Messages\CsvCreationMessage: pimcore_generic_execution_engine
Pimcore\Bundle\StudioBackendBundle\Asset\ExecutionEngine\AutomationAction\Messenger\Messages\AssetCloneMessage: pimcore_generic_execution_engine
Pimcore\Bundle\StudioBackendBundle\Asset\ExecutionEngine\AutomationAction\Messenger\Messages\AssetUploadMessage: pimcore_generic_execution_engine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @internal
*/
#[Attribute(Attribute::TARGET_METHOD)]
final class CsvExportRequestBody extends RequestBody
final class CsvExportAssetRequestBody extends RequestBody
{
public function __construct()
{
Expand All @@ -37,11 +37,11 @@ public function __construct()
properties: [
new Property(property: 'assets', type: 'array', items: new Items(type: 'integer'), example: [83]),
new Property(
property: 'gridConfig',
property: 'columns',
type: 'array',
items: new Items(ref: Column::class)
),
new Property(property: 'settings', properties: [
new Property(property: 'config', properties: [
new Property(property: Csv::SETTINGS_DELIMITER->value, type: 'string', example: ';'),
new Property(
property: Csv::SETTINGS_HEADER->value,
Expand Down
64 changes: 64 additions & 0 deletions src/Asset/Attribute/Request/CsvExportFolderRequestBody.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Request;

use Attribute;
use OpenApi\Attributes\Items;
use OpenApi\Attributes\JsonContent;
use OpenApi\Attributes\Property;
use OpenApi\Attributes\RequestBody;
use Pimcore\Bundle\StudioBackendBundle\Asset\Util\Constant\Csv;
use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column;
use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Filter;

/**
* @internal
*/
#[Attribute(Attribute::TARGET_METHOD)]
final class CsvExportFolderRequestBody extends RequestBody
{
public function __construct()
{
parent::__construct(
content: new JsonContent(
properties: [
new Property(property: 'folders', type: 'array', items: new Items(type: 'integer'), example: [83]),
new Property(
property: 'columns',
type: 'array',
items: new Items(ref: Column::class)
),
new Property(
property: 'filters',
ref: Filter::class,
type: 'object'
),
new Property(property: 'config', properties: [
new Property(property: Csv::SETTINGS_DELIMITER->value, type: 'string', example: ';'),
new Property(
property: Csv::SETTINGS_HEADER->value,
type: 'enum',
enum: Csv::values(),
example: Csv::SETTINGS_HEADER_TITLE->value
),
], type: 'object'),
],
type: 'object'
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Asset\Controller\Download;
namespace Pimcore\Bundle\StudioBackendBundle\Asset\Controller\Export;

use OpenApi\Attributes\Post;
use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Request\CsvExportRequestBody;
use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Request\CsvExportAssetRequestBody;
use Pimcore\Bundle\StudioBackendBundle\Asset\MappedParameter\ExportAssetParameter;
use Pimcore\Bundle\StudioBackendBundle\Asset\Service\ExecutionEngine\CsvServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
Expand All @@ -36,7 +36,7 @@
/**
* @internal
*/
final class CreateCsvController extends AbstractApiController
final class CsvAssetController extends AbstractApiController
{
public function __construct(
SerializerInterface $serializer,
Expand All @@ -45,29 +45,29 @@ public function __construct(
parent::__construct($serializer);
}

#[Route('/assets/csv/create', name: 'pimcore_studio_api_create_csv_asset', methods: ['POST'])]
#[Route('/assets/export/csv/asset', name: 'pimcore_studio_api_asset_export_csv_asset', methods: ['POST'])]
#[IsGranted(UserPermissions::ASSETS->value)]
#[Post(
path: self::PREFIX . '/assets/csv/create',
operationId: 'asset_create_csv',
description: 'asset_create_csv_description',
summary: 'asset_create_csv_summary',
path: self::PREFIX . '/assets/export/csv/asset',
operationId: 'asset_export_csv_asset',
description: 'asset_export_csv_asset_description',
summary: 'asset_export_csv_asset_summary',
tags: [Tags::Assets->name]
)]
#[CsvExportRequestBody]
#[CsvExportAssetRequestBody]
#[CreatedResponse(
description: 'asset_create_csv_created_response',
description: 'asset_export_csv_created_response',
content: new IdJson('ID of created jobRun', 'jobRunId')
)]
#[DefaultResponses([
HttpResponseCodes::UNAUTHORIZED,
HttpResponseCodes::NOT_FOUND,
])]
public function assetCreateCsv(
public function assetExportCsvAsset(
#[MapRequestPayload] ExportAssetParameter $exportAssetParameter
): Response {
return $this->jsonResponse(
['jobRunId' => $this->csvService->generateCsvFile($exportAssetParameter)],
['jobRunId' => $this->csvService->generateCsvFileForAssets($exportAssetParameter)],
HttpResponseCodes::CREATED->value
);
}
Expand Down
74 changes: 74 additions & 0 deletions src/Asset/Controller/Export/CsvFolderController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Asset\Controller\Export;

use OpenApi\Attributes\Post;
use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Request\CsvExportFolderRequestBody;
use Pimcore\Bundle\StudioBackendBundle\Asset\MappedParameter\ExportFolderParameter;
use Pimcore\Bundle\StudioBackendBundle\Asset\Service\ExecutionEngine\CsvServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\IdJson;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\CreatedResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Component\Serializer\SerializerInterface;

/**
* @internal
*/
final class CsvFolderController extends AbstractApiController
{
public function __construct(
SerializerInterface $serializer,
private readonly CsvServiceInterface $csvService
) {
parent::__construct($serializer);
}

#[Route('/assets/export/csv/folder', name: 'pimcore_studio_api_asset_export_csv_folder', methods: ['POST'])]
#[IsGranted(UserPermissions::ASSETS->value)]
#[Post(
path: self::PREFIX . '/assets/export/csv/folder',
operationId: 'asset_export_csv_folder',
description: 'asset_export_csv_folder_description',
summary: 'asset_export_csv_folder_summary',
tags: [Tags::Assets->name]
)]
#[CsvExportFolderRequestBody]
#[CreatedResponse(
description: 'asset_export_csv_created_response',
content: new IdJson('ID of created jobRun', 'jobRunId')
)]
#[DefaultResponses([
HttpResponseCodes::UNAUTHORIZED,
HttpResponseCodes::NOT_FOUND,
])]
public function assetExportCsvFolder(
#[MapRequestPayload] ExportFolderParameter $exportFolderParameter
): Response {
return $this->jsonResponse(
['jobRunId' => $this->csvService->generateCsvFileForFolders($exportFolderParameter)],
HttpResponseCodes::CREATED->value
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use Exception;
use Pimcore\Bundle\StaticResolverBundle\Models\User\UserResolverInterface;
use Pimcore\Bundle\StudioBackendBundle\Asset\ExecutionEngine\AutomationAction\Messenger\Messages\CsvCollectionMessage;
use Pimcore\Bundle\StudioBackendBundle\Asset\ExecutionEngine\AutomationAction\Messenger\Messages\CsvAssetCollectionMessage;
use Pimcore\Bundle\StudioBackendBundle\Asset\Service\AssetServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Asset\Util\Constant\Csv;
use Pimcore\Bundle\StudioBackendBundle\ExecutionEngine\AutomationAction\AbstractHandler;
Expand All @@ -33,7 +33,7 @@
* @internal
*/
#[AsMessageHandler]
final class CsvDataCollectionHandler extends AbstractHandler
final class CsvAssetDataCollectionHandler extends AbstractHandler
{
use HandlerProgressTrait;

Expand All @@ -51,7 +51,7 @@ public function __construct(
/**
* @throws Exception
*/
public function __invoke(CsvCollectionMessage $message): void
public function __invoke(CsvAssetCollectionMessage $message): void
{
$jobRun = $this->getJobRun($message);
if (!$this->shouldBeExecuted($jobRun)) {
Expand Down Expand Up @@ -84,8 +84,10 @@ public function __invoke(CsvCollectionMessage $message): void
return;
}

$columns = $this->extractConfigFieldFromJobStepConfig($message, Csv::JOB_STEP_CONFIG_COLUMNS->value);

$columnCollection = $this->gridService->getConfigurationFromArray(
$this->extractConfigFieldFromJobStepConfig($message, Csv::JOB_STEP_CONFIG_CONFIGURATION->value),
$columns,
true
);

Expand Down Expand Up @@ -119,9 +121,9 @@ protected function configureStep(): void
Csv::ASSET_TO_EXPORT->value,
self::ARRAY_TYPE
);
$this->stepConfiguration->setRequired(Csv::JOB_STEP_CONFIG_CONFIGURATION->value);
$this->stepConfiguration->setRequired(Csv::JOB_STEP_CONFIG_COLUMNS->value);
$this->stepConfiguration->setAllowedTypes(
Csv::JOB_STEP_CONFIG_CONFIGURATION->value,
Csv::JOB_STEP_CONFIG_COLUMNS->value,
self::ARRAY_TYPE
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ public function __invoke(CsvCreationMessage $message): void
if (!$this->shouldBeExecuted($jobRun)) {
return;
}
$settings = $this->extractConfigFieldFromJobStepConfig($message, Csv::JOB_STEP_CONFIG_SETTINGS->value);

$columns = $this->extractConfigFieldFromJobStepConfig($message, Csv::JOB_STEP_CONFIG_COLUMNS->value);

$settings = $this->extractConfigFieldFromJobStepConfig($message, Csv::JOB_STEP_CONFIG_CONFIGURATION->value);
$columnCollection = $this->gridService->getConfigurationFromArray(
$this->extractConfigFieldFromJobStepConfig($message, Csv::JOB_STEP_CONFIG_CONFIGURATION->value),
$columns,
true
);

Expand Down Expand Up @@ -88,14 +91,14 @@ public function __invoke(CsvCreationMessage $message): void

protected function configureStep(): void
{
$this->stepConfiguration->setRequired(Csv::JOB_STEP_CONFIG_SETTINGS->value);
$this->stepConfiguration->setRequired(Csv::JOB_STEP_CONFIG_CONFIGURATION->value);
$this->stepConfiguration->setAllowedTypes(
Csv::JOB_STEP_CONFIG_SETTINGS->value,
Csv::JOB_STEP_CONFIG_CONFIGURATION->value,
self::ARRAY_TYPE
);
$this->stepConfiguration->setRequired(Csv::JOB_STEP_CONFIG_CONFIGURATION->value);
$this->stepConfiguration->setRequired(Csv::JOB_STEP_CONFIG_COLUMNS->value);
$this->stepConfiguration->setAllowedTypes(
Csv::JOB_STEP_CONFIG_CONFIGURATION->value,
Csv::JOB_STEP_CONFIG_COLUMNS->value,
self::ARRAY_TYPE
);
}
Expand Down
Loading
Loading