Skip to content

Commit

Permalink
[Task] Rename and move Csv enums (#505)
Browse files Browse the repository at this point in the history
* Rename and move Csv enums

* Remove private const
  • Loading branch information
mattamon authored Oct 18, 2024
1 parent 97eed10 commit 505ea58
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 78 deletions.
10 changes: 5 additions & 5 deletions src/Asset/Attribute/Request/CsvExportAssetRequestBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use OpenApi\Attributes\JsonContent;
use OpenApi\Attributes\Property;
use OpenApi\Attributes\RequestBody;
use Pimcore\Bundle\StudioBackendBundle\Asset\Util\Constant\Csv;
use Pimcore\Bundle\StudioBackendBundle\Asset\Util\Constant\StepConfig;
use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column;

/**
Expand All @@ -42,12 +42,12 @@ public function __construct()
items: new Items(ref: Column::class)
),
new Property(property: 'config', properties: [
new Property(property: Csv::SETTINGS_DELIMITER->value, type: 'string', example: ';'),
new Property(property: StepConfig::SETTINGS_DELIMITER->value, type: 'string', example: ';'),
new Property(
property: Csv::SETTINGS_HEADER->value,
property: StepConfig::SETTINGS_HEADER->value,
type: 'enum',
enum: Csv::values(),
example: Csv::SETTINGS_HEADER_TITLE->value
enum: StepConfig::values(),
example: StepConfig::SETTINGS_HEADER_TITLE->value
),
], type: 'object'),
],
Expand Down
10 changes: 5 additions & 5 deletions src/Asset/Attribute/Request/CsvExportFolderRequestBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use OpenApi\Attributes\JsonContent;
use OpenApi\Attributes\Property;
use OpenApi\Attributes\RequestBody;
use Pimcore\Bundle\StudioBackendBundle\Asset\Util\Constant\Csv;
use Pimcore\Bundle\StudioBackendBundle\Asset\Util\Constant\StepConfig;
use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column;
use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Filter;

Expand All @@ -48,12 +48,12 @@ public function __construct()
type: 'object'
),
new Property(property: 'config', properties: [
new Property(property: Csv::SETTINGS_DELIMITER->value, type: 'string', example: ';'),
new Property(property: StepConfig::SETTINGS_DELIMITER->value, type: 'string', example: ';'),
new Property(
property: Csv::SETTINGS_HEADER->value,
property: StepConfig::SETTINGS_HEADER->value,
type: 'enum',
enum: Csv::values(),
example: Csv::SETTINGS_HEADER_TITLE->value
enum: StepConfig::values(),
example: StepConfig::SETTINGS_HEADER_TITLE->value
),
], type: 'object'),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Pimcore\Bundle\StaticResolverBundle\Models\User\UserResolverInterface;
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\Asset\Util\Constant\StepConfig;
use Pimcore\Bundle\StudioBackendBundle\ExecutionEngine\AutomationAction\AbstractHandler;
use Pimcore\Bundle\StudioBackendBundle\ExecutionEngine\Util\Config;
use Pimcore\Bundle\StudioBackendBundle\ExecutionEngine\Util\Trait\HandlerProgressTrait;
Expand All @@ -37,8 +37,6 @@ final class CsvAssetDataCollectionHandler extends AbstractHandler
{
use HandlerProgressTrait;

private const ARRAY_TYPE = 'array';

public function __construct(
private readonly PublishServiceInterface $publishService,
private readonly UserResolverInterface $userResolver,
Expand Down Expand Up @@ -69,7 +67,7 @@ public function __invoke(CsvAssetCollectionMessage $message): void
));
}

$jobAsset = $this->extractConfigFieldFromJobStepConfig($message, Csv::ASSET_TO_EXPORT->value);
$jobAsset = $this->extractConfigFieldFromJobStepConfig($message, StepConfig::ASSET_TO_EXPORT->value);

$asset = $this->assetService->getAssetForUser($jobAsset['id'], $user);

Expand All @@ -84,7 +82,7 @@ public function __invoke(CsvAssetCollectionMessage $message): void
return;
}

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

$columnCollection = $this->gridService->getConfigurationFromArray(
$columns,
Expand All @@ -100,7 +98,7 @@ public function __invoke(CsvAssetCollectionMessage $message): void
),
];

$this->updateContextArrayValues($jobRun, Csv::ASSET_EXPORT_DATA->value, $assetData);
$this->updateContextArrayValues($jobRun, StepConfig::ASSET_EXPORT_DATA->value, $assetData);
} catch (Exception $e) {
$this->abort($this->getAbortData(
Config::CSV_DATA_COLLECTION_FAILED_MESSAGE->value,
Expand All @@ -116,15 +114,15 @@ public function __invoke(CsvAssetCollectionMessage $message): void

protected function configureStep(): void
{
$this->stepConfiguration->setRequired(Csv::ASSET_TO_EXPORT->value);
$this->stepConfiguration->setRequired(StepConfig::ASSET_TO_EXPORT->value);
$this->stepConfiguration->setAllowedTypes(
Csv::ASSET_TO_EXPORT->value,
self::ARRAY_TYPE
StepConfig::ASSET_TO_EXPORT->value,
StepConfig::CONFIG_TYPE_ARRAY->value
);
$this->stepConfiguration->setRequired(Csv::JOB_STEP_CONFIG_COLUMNS->value);
$this->stepConfiguration->setRequired(StepConfig::CONFIG_COLUMNS->value);
$this->stepConfiguration->setAllowedTypes(
Csv::JOB_STEP_CONFIG_COLUMNS->value,
self::ARRAY_TYPE
StepConfig::CONFIG_COLUMNS->value,
StepConfig::CONFIG_TYPE_ARRAY->value
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use League\Flysystem\FilesystemException;
use Pimcore\Bundle\StudioBackendBundle\Asset\ExecutionEngine\AutomationAction\Messenger\Messages\CsvCreationMessage;
use Pimcore\Bundle\StudioBackendBundle\Asset\Service\ExecutionEngine\CsvServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Asset\Util\Constant\Csv;
use Pimcore\Bundle\StudioBackendBundle\Asset\Util\Constant\StepConfig;
use Pimcore\Bundle\StudioBackendBundle\ExecutionEngine\AutomationAction\AbstractHandler;
use Pimcore\Bundle\StudioBackendBundle\ExecutionEngine\Util\Config;
use Pimcore\Bundle\StudioBackendBundle\ExecutionEngine\Util\Trait\HandlerProgressTrait;
Expand All @@ -36,8 +36,6 @@ final class CsvCreationHandler extends AbstractHandler
{
use HandlerProgressTrait;

private const ARRAY_TYPE = 'array';

public function __construct(
private readonly PublishServiceInterface $publishService,
private readonly CsvServiceInterface $csvService,
Expand All @@ -56,21 +54,21 @@ public function __invoke(CsvCreationMessage $message): void
return;
}

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

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

if (!isset($jobRun->getContext()[Csv::ASSET_EXPORT_DATA->value])) {
if (!isset($jobRun->getContext()[StepConfig::ASSET_EXPORT_DATA->value])) {
$this->abort($this->getAbortData(
Config::CSV_CREATION_FAILED_MESSAGE->value,
['message' => 'Asset export data not found in job run context']
));
}
$assetData = $jobRun->getContext()[Csv::ASSET_EXPORT_DATA->value];
$assetData = $jobRun->getContext()[StepConfig::ASSET_EXPORT_DATA->value];

try {
$this->csvService->createCsvFile(
Expand All @@ -91,15 +89,15 @@ public function __invoke(CsvCreationMessage $message): void

protected function configureStep(): void
{
$this->stepConfiguration->setRequired(Csv::JOB_STEP_CONFIG_CONFIGURATION->value);
$this->stepConfiguration->setRequired(StepConfig::CONFIG_CONFIGURATION->value);
$this->stepConfiguration->setAllowedTypes(
Csv::JOB_STEP_CONFIG_CONFIGURATION->value,
self::ARRAY_TYPE
StepConfig::CONFIG_CONFIGURATION->value,
StepConfig::CONFIG_TYPE_ARRAY->value
);
$this->stepConfiguration->setRequired(Csv::JOB_STEP_CONFIG_COLUMNS->value);
$this->stepConfiguration->setRequired(StepConfig::CONFIG_COLUMNS->value);
$this->stepConfiguration->setAllowedTypes(
Csv::JOB_STEP_CONFIG_COLUMNS->value,
self::ARRAY_TYPE
StepConfig::CONFIG_COLUMNS->value,
StepConfig::CONFIG_TYPE_ARRAY->value
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Exception;
use Pimcore\Bundle\StaticResolverBundle\Models\User\UserResolverInterface;
use Pimcore\Bundle\StudioBackendBundle\Asset\ExecutionEngine\AutomationAction\Messenger\Messages\CsvFolderCollectionMessage;
use Pimcore\Bundle\StudioBackendBundle\Asset\Util\Constant\Csv;
use Pimcore\Bundle\StudioBackendBundle\Asset\Util\Constant\StepConfig;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Grid\GridSearchInterface;
use Pimcore\Bundle\StudioBackendBundle\ExecutionEngine\AutomationAction\AbstractHandler;
use Pimcore\Bundle\StudioBackendBundle\ExecutionEngine\Util\Config;
Expand All @@ -40,8 +40,6 @@ final class CsvFolderDataCollectionHandler extends AbstractHandler
{
use HandlerProgressTrait;

private const ARRAY_TYPE = 'array';

public function __construct(
private readonly FilterParameterMapperInterface $filterParameterMapper,
private readonly PublishServiceInterface $publishService,
Expand Down Expand Up @@ -73,11 +71,11 @@ public function __invoke(CsvFolderCollectionMessage $message): void
));
}

$jobFolder = $this->extractConfigFieldFromJobStepConfig($message, Csv::FOLDER_TO_EXPORT->value);
$jobFolder = $this->extractConfigFieldFromJobStepConfig($message, StepConfig::FOLDER_TO_EXPORT->value);

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

$filters = $this->extractConfigFieldFromJobStepConfig($message, Csv::JOB_STEP_CONFIG_FILTERS->value);
$filters = $this->extractConfigFieldFromJobStepConfig($message, StepConfig::CONFIG_FILTERS->value);

$assets = $this->gridSearch->searchAssetsForUser(
new GridParameter(
Expand Down Expand Up @@ -109,7 +107,7 @@ public function __invoke(CsvFolderCollectionMessage $message): void
),
];

$this->updateContextArrayValues($jobRun, Csv::ASSET_EXPORT_DATA->value, $assetData);
$this->updateContextArrayValues($jobRun, StepConfig::ASSET_EXPORT_DATA->value, $assetData);
} catch (Exception $e) {
$this->abort($this->getAbortData(
Config::CSV_DATA_COLLECTION_FAILED_MESSAGE->value,
Expand All @@ -126,20 +124,20 @@ public function __invoke(CsvFolderCollectionMessage $message): void

protected function configureStep(): void
{
$this->stepConfiguration->setRequired(Csv::FOLDER_TO_EXPORT->value);
$this->stepConfiguration->setRequired(StepConfig::FOLDER_TO_EXPORT->value);
$this->stepConfiguration->setAllowedTypes(
Csv::FOLDER_TO_EXPORT->value,
self::ARRAY_TYPE
StepConfig::FOLDER_TO_EXPORT->value,
StepConfig::CONFIG_TYPE_ARRAY->value
);
$this->stepConfiguration->setRequired(Csv::JOB_STEP_CONFIG_COLUMNS->value);
$this->stepConfiguration->setRequired(StepConfig::CONFIG_COLUMNS->value);
$this->stepConfiguration->setAllowedTypes(
Csv::JOB_STEP_CONFIG_COLUMNS->value,
self::ARRAY_TYPE
StepConfig::CONFIG_COLUMNS->value,
StepConfig::CONFIG_TYPE_ARRAY->value
);
$this->stepConfiguration->setRequired(Csv::JOB_STEP_CONFIG_FILTERS->value);
$this->stepConfiguration->setRequired(StepConfig::CONFIG_FILTERS->value);
$this->stepConfiguration->setAllowedTypes(
Csv::JOB_STEP_CONFIG_FILTERS->value,
self::ARRAY_TYPE
StepConfig::CONFIG_FILTERS->value,
StepConfig::CONFIG_TYPE_ARRAY->value
);
}
}
32 changes: 16 additions & 16 deletions src/Asset/Service/ExecutionEngine/CsvService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
use Pimcore\Bundle\StudioBackendBundle\Asset\ExecutionEngine\Util\JobSteps;
use Pimcore\Bundle\StudioBackendBundle\Asset\MappedParameter\ExportAssetParameter;
use Pimcore\Bundle\StudioBackendBundle\Asset\MappedParameter\ExportFolderParameter;
use Pimcore\Bundle\StudioBackendBundle\Asset\Util\Constant\Csv;
use Pimcore\Bundle\StudioBackendBundle\Asset\Util\Constant\StepConfig;
use Pimcore\Bundle\StudioBackendBundle\Element\Service\StorageServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\ExecutionEngine\Util\Config;
use Pimcore\Bundle\StudioBackendBundle\ExecutionEngine\Util\Jobs;
Expand Down Expand Up @@ -56,12 +56,12 @@ public function __construct(
public function generateCsvFileForAssets(ExportAssetParameter $exportAssetParameter): int
{
$collectionSettings = [
Csv::JOB_STEP_CONFIG_COLUMNS->value => $exportAssetParameter->getColumns(),
StepConfig::CONFIG_COLUMNS->value => $exportAssetParameter->getColumns(),
];

$creationSettings = [
Csv::JOB_STEP_CONFIG_COLUMNS->value => $exportAssetParameter->getColumns(),
Csv::JOB_STEP_CONFIG_CONFIGURATION->value => $exportAssetParameter->getConfig(),
StepConfig::CONFIG_COLUMNS->value => $exportAssetParameter->getColumns(),
StepConfig::CONFIG_CONFIGURATION->value => $exportAssetParameter->getConfig(),
];

return $this->generateCsvFileJob(
Expand All @@ -75,21 +75,21 @@ public function generateCsvFileForAssets(ExportAssetParameter $exportAssetParame
public function generateCsvFileForFolders(ExportFolderParameter $exportFolderParameter): int
{
$collectionSettings = [
Csv::JOB_STEP_CONFIG_COLUMNS->value => $exportFolderParameter->getColumns(),
Csv::JOB_STEP_CONFIG_FILTERS->value => $exportFolderParameter->getFilters(),
StepConfig::CONFIG_COLUMNS->value => $exportFolderParameter->getColumns(),
StepConfig::CONFIG_FILTERS->value => $exportFolderParameter->getFilters(),
];

$creationSettings = [
Csv::JOB_STEP_CONFIG_COLUMNS->value => $exportFolderParameter->getColumns(),
Csv::JOB_STEP_CONFIG_CONFIGURATION->value => $exportFolderParameter->getConfig(),
StepConfig::CONFIG_COLUMNS->value => $exportFolderParameter->getColumns(),
StepConfig::CONFIG_CONFIGURATION->value => $exportFolderParameter->getConfig(),
];

return $this->generateCsvFileJob(
$exportFolderParameter->getFolders(),
$collectionSettings,
$creationSettings,
CsvFolderCollectionMessage::class,
Csv::FOLDER_TO_EXPORT
StepConfig::FOLDER_TO_EXPORT
);
}

Expand All @@ -108,9 +108,9 @@ public function createCsvFile(
if ($delimiter === null) {
$delimiter = $this->defaultDelimiter;
}
$data[] = implode($delimiter, $headers) . Csv::NEW_LINE->value;
$data[] = implode($delimiter, $headers) . StepConfig::NEW_LINE->value;
foreach ($assetData as $row) {
$data[] = implode($delimiter, array_map([$this, 'encodeFunc'], $row)) . Csv::NEW_LINE->value;
$data[] = implode($delimiter, array_map([$this, 'encodeFunc'], $row)) . StepConfig::NEW_LINE->value;
}

$storage->write(
Expand All @@ -124,7 +124,7 @@ private function generateCsvFileJob(
array $collectionSettings,
array $creationSettings,
string $messageFQCN,
Csv $export = Csv::ASSET_TO_EXPORT
StepConfig $export = StepConfig::ASSET_TO_EXPORT
): int {

$jobSteps = [
Expand Down Expand Up @@ -163,22 +163,22 @@ private function encodeFunc(?string $value): string

private function getHeaders(ColumnCollection $columnCollection, array $settings): array
{
$header = $settings[Csv::SETTINGS_HEADER->value] ?? Csv::SETTINGS_HEADER_NO_HEADER->value;
if ($header === Csv::SETTINGS_HEADER_NO_HEADER->value) {
$header = $settings[StepConfig::SETTINGS_HEADER->value] ?? StepConfig::SETTINGS_HEADER_NO_HEADER->value;
if ($header === StepConfig::SETTINGS_HEADER_NO_HEADER->value) {
return [];
}

return $this->gridService->getColumnKeys(
$columnCollection,
$header === Csv::SETTINGS_HEADER_NAME->value
$header === StepConfig::SETTINGS_HEADER_NAME->value
);
}

private function mapJobSteps(
array $elements,
array $collectionSettings,
string $messageFQCN,
Csv $export
StepConfig $export
): array {
return array_map(
static fn (ElementDescriptor $asset) => new JobStep(
Expand Down
4 changes: 2 additions & 2 deletions src/Asset/Util/Trait/CsvConfigValidationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace Pimcore\Bundle\StudioBackendBundle\Asset\Util\Trait;

use Pimcore\Bundle\StudioBackendBundle\Asset\Util\Constant\Csv;
use Pimcore\Bundle\StudioBackendBundle\Asset\Util\Constant\StepConfig;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException;

trait CsvConfigValidationTrait
Expand All @@ -32,7 +32,7 @@ private function validateConfig(): void
throw new InvalidArgumentException('No settings provided');
}

if (!isset($this->getConfig()[Csv::SETTINGS_DELIMITER->value])) {
if (!isset($this->getConfig()[StepConfig::SETTINGS_DELIMITER->value])) {
throw new InvalidArgumentException('No delimiter provided');
}
}
Expand Down
Loading

0 comments on commit 505ea58

Please sign in to comment.