Skip to content

Commit

Permalink
Supprime la saisie de dates globales sur l'arrêté
Browse files Browse the repository at this point in the history
  • Loading branch information
florimondmanca committed Oct 17, 2024
1 parent a79d93e commit e7fb12f
Show file tree
Hide file tree
Showing 29 changed files with 108 additions and 349 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ private function duplicateRegulationOrderRecord(
$generalInfo->organization = $organization;
$generalInfo->identifier = $identifier;
$generalInfo->description = $originalRegulationOrder->getDescription();
$generalInfo->startDate = $originalRegulationOrder->getStartDate();
$generalInfo->endDate = $originalRegulationOrder->getEndDate();
$generalInfo->additionalVisas = $originalRegulationOrder->getAdditionalVisas();
$generalInfo->additionalReasons = $originalRegulationOrder->getAdditionalReasons();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ final class SaveRegulationGeneralInfoCommand implements CommandInterface
public ?string $otherCategoryText = null;
public ?string $description;
public ?Organization $organization;
public ?\DateTimeInterface $startDate;
public ?\DateTimeInterface $endDate = null;
public array $additionalVisas = [];
public array $additionalReasons = [];

Expand All @@ -40,8 +38,6 @@ public static function create(
$command->category = $regulationOrder?->getCategory();
$command->otherCategoryText = $regulationOrder?->getOtherCategoryText();
$command->description = $regulationOrder?->getDescription();
$command->startDate = $startDate ?? $regulationOrder?->getStartDate();
$command->endDate = $regulationOrder?->getEndDate();
$command->additionalVisas = $regulationOrder?->getAdditionalVisas() ?? [];
$command->additionalReasons = $regulationOrder?->getAdditionalReasons() ?? [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ public function __invoke(SaveRegulationGeneralInfoCommand $command): RegulationO
identifier: $command->identifier,
category: $command->category,
description: $command->description,
startDate: $command->startDate,
endDate: $command->endDate,
otherCategoryText: $command->otherCategoryText,
additionalVisas: $command->additionalVisas,
additionalReasons: $command->additionalReasons,
Expand All @@ -60,8 +58,6 @@ public function __invoke(SaveRegulationGeneralInfoCommand $command): RegulationO
identifier: $command->identifier,
category: $command->category,
description: $command->description,
startDate: $command->startDate,
endDate: $command->endDate,
otherCategoryText: $command->otherCategoryText,
additionalVisas: $command->additionalVisas,
additionalReasons: $command->additionalReasons,
Expand Down
13 changes: 12 additions & 1 deletion src/Application/Regulation/Query/GetGeneralInfoQueryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ public function __invoke(GetGeneralInfoQuery $query): GeneralInfoView
throw new RegulationOrderRecordNotFoundException();
}

return $row[0];
return new GeneralInfoView(
uuid: $row['uuid'],
identifier: $row['identifier'],
organizationName: $row['organizationName'],
organizationUuid: $row['organizationUuid'],
status: $row['status'],
category: $row['category'],
otherCategoryText: $row['otherCategoryText'],
description: $row['description'],
startDate: $row['overallStartDate'] ? new \DateTimeImmutable($row['overallStartDate']) : null,
endDate: $row['overallEndDate'] ? new \DateTimeImmutable($row['overallEndDate']) : null,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public function __invoke(GetRegulationsQuery $query): Pagination
organizationName: $row['organizationName'],
organizationUuid: $row['organizationUuid'],
location: $locationView,
startDate: $row['startDate'],
endDate: $row['endDate'],
startDate: $row['overallStartDate'] ? new \DateTimeImmutable($row['overallStartDate']) : null,
endDate: $row['overallEndDate'] ? new \DateTimeImmutable($row['overallEndDate']) : null,
);
}

Expand Down
16 changes: 7 additions & 9 deletions src/Domain/Regulation/RegulationOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Domain\Regulation;

use App\Domain\Regulation\Enum\RegulationOrderCategoryEnum;
use App\Domain\VisaModel\VisaModel;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
Expand All @@ -18,8 +19,6 @@ public function __construct(
private string $identifier,
private string $category,
private string $description,
private ?\DateTimeInterface $startDate,
private ?\DateTimeInterface $endDate = null,
private ?string $otherCategoryText = null,
private ?VisaModel $visaModel = null,
private ?array $additionalVisas = [],
Expand Down Expand Up @@ -53,14 +52,16 @@ public function getDescription(): string
return $this->description;
}

// TODO used in DATEX and CIFS exports only, replace with dedicated queries
public function getStartDate(): ?\DateTimeInterface
{
return $this->startDate;
return new \DateTimeImmutable('2024-10-01');
}

// TODO used in DATEX and CIFS exports only, replace with dedicated queries
public function getEndDate(): ?\DateTimeInterface
{
return $this->endDate;
return new \DateTimeImmutable('2024-10-02');
}

public function getMeasures(): iterable
Expand All @@ -80,9 +81,10 @@ public function getRegulationOrderRecord(): ?RegulationOrderRecord
return $this->regulationOrderRecord;
}

// TODO force-set category in migration when regulation order had no endDate
public function isPermanent(): bool
{
return !$this->endDate;
return $this->category === RegulationOrderCategoryEnum::PERMANENT_REGULATION->value;
}

public function getVisaModel(): ?VisaModel
Expand All @@ -104,17 +106,13 @@ public function update(
string $identifier,
string $category,
string $description,
\DateTimeInterface $startDate,
?\DateTimeInterface $endDate = null,
?string $otherCategoryText = null,
array $additionalVisas = [],
array $additionalReasons = [],
): void {
$this->identifier = $identifier;
$this->category = $category;
$this->description = $description;
$this->startDate = $startDate;
$this->endDate = $endDate;
$this->otherCategoryText = $otherCategoryText;
$this->additionalVisas = $additionalVisas;
$this->additionalReasons = $additionalReasons;
Expand Down
4 changes: 2 additions & 2 deletions src/Infrastructure/BacIdf/BacIdfTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function transform(array $row): BacIdfTransformerResult
]);
}

$generalInfo->startDate = new \DateTimeImmutable($date); // $date already contains the timezone (UTC)
$overallStartDate = new \DateTimeImmutable($date); // $date already contains the timezone (UTC)

$inseeCode = $row['ARR_COMMUNE']['ARR_INSEE'];
$siret = $this->cityProcessor->getSiretFromInseeCode($inseeCode);
Expand Down Expand Up @@ -150,7 +150,7 @@ public function transform(array $row): BacIdfTransformerResult
continue;
}

$periodCommands = $this->parsePeriods($circReg, startDate: $generalInfo->startDate);
$periodCommands = $this->parsePeriods($circReg, startDate: $overallStartDate);

foreach ($periodCommands as $periodCommand) {
$measureCommand->periods[] = $periodCommand;
Expand Down
40 changes: 0 additions & 40 deletions src/Infrastructure/EudonetParis/EudonetParisTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,6 @@ public function transform(array $row, Organization $organization): EudonetParisT
return new EudonetParisTransformerResult($command, $errors);
}

private function parseDate(string $value): ?\DateTimeInterface
{
if ($date = \DateTimeImmutable::createFromFormat('Y/m/d H:i:s', $value, new \DateTimeZone('Europe/Paris'))) {
return $date;
}

if (\DateTimeImmutable::createFromFormat('Y/m/d', $value, new \DateTimeZone('Europe/Paris'))) {
// Need to add a datetime otherwise PHP would use the current server time, not midnight.
return $this->parseDate($value . ' 00:00:00');
}

if (\DateTimeImmutable::createFromFormat('d/m/Y', $value, new \DateTimeZone('Europe/Paris'))) {
// This format is somtimes used by some Eudonet Paris data input users.
// Again, we need to ensure there is a datetime.
return \DateTimeImmutable::createFromFormat('d/m/Y H:i:s', $value . ' 00:00:00', new \DateTimeZone('Europe/Paris'));
}

return null;
}

private function buildGeneralInfoCommand(array $row, Organization $organization): array
{
$command = new SaveRegulationGeneralInfoCommand();
Expand All @@ -98,26 +78,6 @@ private function buildGeneralInfoCommand(array $row, Organization $organization)

$command->organization = $organization;

$startDate = $this->parseDate($row['fields'][EudonetParisExtractor::ARRETE_DATE_DEBUT]);

if (!$startDate) {
$error = ['loc' => ['fieldname' => 'ARRETE_DATE_DEBUT'], 'reason' => EudonetParisErrorEnum::PARSING_FAILED->value, 'value' => $row['fields'][EudonetParisExtractor::ARRETE_DATE_DEBUT]];

return [null, $error];
}

$command->startDate = $startDate;

$endDate = $this->parseDate($row['fields'][EudonetParisExtractor::ARRETE_DATE_FIN]);

if (!$endDate) {
$error = ['loc' => ['fieldname' => 'ARRETE_DATE_FIN'], 'reason' => EudonetParisErrorEnum::PARSING_FAILED->value, 'value' => $row['fields'][EudonetParisExtractor::ARRETE_DATE_FIN]];

return [null, $error];
}

$command->endDate = $endDate;

return [$command, null];
}

Expand Down
23 changes: 0 additions & 23 deletions src/Infrastructure/Form/Regulation/GeneralInfoFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Symfony\Component\Form\CallbackTransformer;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
Expand All @@ -22,7 +21,6 @@
final class GeneralInfoFormType extends AbstractType
{
public function __construct(
private string $clientTimezone,
private EntityManagerInterface $entityManager,
) {
}
Expand All @@ -38,27 +36,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'help' => 'regulation.general_info.identifier.help',
],
)
->add(
'startDate',
DateType::class,
options: [
'label' => 'regulation.general_info.start_date',
'help' => 'regulation.general_info.start_date.help',
'widget' => 'single_text',
'view_timezone' => $this->clientTimezone,
],
)
->add(
'endDate',
DateType::class,
options: [
'label' => 'regulation.general_info.end_date',
'help' => 'regulation.general_info.end_date.help',
'widget' => 'single_text',
'view_timezone' => $this->clientTimezone,
'required' => false,
],
)
->add(
'organization',
ChoiceType::class,
Expand Down
3 changes: 0 additions & 3 deletions src/Infrastructure/JOP/JOPTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ public function transform(array $geoJSON, Organization $organization): ImportJOP
$measureCommands[] = $measureCommand;
}

$generalInfoCommand->startDate = min($startDates);
$generalInfoCommand->endDate = max($endDates);

return new ImportJOPRegulationCommand($generalInfoCommand, $measureCommands);
}
}
33 changes: 0 additions & 33 deletions src/Infrastructure/Litteralis/LitteralisTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public function transform(
$this->setCategory($generalInfoCommand, $properties);
$generalInfoCommand->description = $this->buildDescription($properties);
$generalInfoCommand->organization = $organization;
$this->setRegulationDates($generalInfoCommand, $properties, $reporter);

// (2) Parsing des mesures et leur contenu

Expand Down Expand Up @@ -163,38 +162,6 @@ private function parseRegulationParameters(array $properties): array
return $parameters;
}

private function setRegulationDates(SaveRegulationGeneralInfoCommand $command, array $properties, Reporter $reporter): void
{
$startDate = \DateTimeImmutable::createFromFormat(\DateTimeInterface::ISO8601, $properties['arretedebut']);

if ($startDate) {
$command->startDate = $startDate;
} else {
$reporter->addError(LitteralisRecordEnum::ERROR_REGULATION_START_DATE_PARSING_FAILED->value, [
CommonRecordEnum::ATTR_REGULATION_ID->value => $properties['arretesrcid'],
CommonRecordEnum::ATTR_URL->value => $properties['shorturl'],
'arretedebut' => $properties['arretedebut'],
]);
}

if ($properties['arretefin'] === null) {
// It's a temporary regulation
return;
}

$endDate = \DateTimeImmutable::createFromFormat(\DateTimeInterface::ISO8601, $properties['arretefin']);

if ($endDate) {
$command->endDate = $endDate;
} else {
$reporter->addError(LitteralisRecordEnum::ERROR_REGULATION_END_DATE_PARSING_FAILED->value, [
CommonRecordEnum::ATTR_REGULATION_ID->value => $properties['arretesrcid'],
CommonRecordEnum::ATTR_URL->value => $properties['shorturl'],
'arretefin' => $properties['arretefin'],
]);
}
}

private function parseLocation(array $feature): SaveLocationCommand
{
$properties = $feature['properties'];
Expand Down
Loading

0 comments on commit e7fb12f

Please sign in to comment.