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 23, 2024
1 parent c58f06b commit f8e9012
Show file tree
Hide file tree
Showing 64 changed files with 537 additions and 658 deletions.
2 changes: 2 additions & 0 deletions config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ doctrine:
dql:
string_functions:
FIRST: App\Infrastructure\Persistence\Doctrine\DBAL\FirstFunction
COALESCE: App\Infrastructure\Persistence\Doctrine\DBAL\CoalesceFunction
INFDATE: App\Infrastructure\Persistence\Doctrine\DBAL\InfDateFunction
# Doctrine functions for PostgreSQL
# https://github.com/martin-georgiev/postgresql-for-doctrine
PG_ILIKE: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Ilike
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
</property>
<property name="periods">
<constraint name="Valid"/>
<constraint name="NotBlank">
<option name="message">measure.periods.error.not_blank</option>
<option name="groups">
<value>html_form</value>
</option>
</constraint>
</property>
<property name="locations">
<constraint name="NotBlank">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,6 @@
<option name="max">255</option>
</constraint>
</property>
<property name="startDate">
<constraint name="NotBlank">
<option name="groups">
<value>html_form</value>
</option>
</constraint>
<constraint name="Type">
<option name="type">\DateTimeInterface</option>
</constraint>
</property>
<property name="endDate">
<constraint name="Type">
<option name="type">\DateTimeInterface</option>
</constraint>
</property>
<property name="additionalVisas">
<constraint name="All">
<option name="constraints">
Expand Down
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() ?? [];
$generalInfo->visaModelUuid = $originalRegulationOrder->getVisaModel()?->getUuid();
Expand Down
1 change: 1 addition & 0 deletions src/Application/Regulation/Command/SaveMeasureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public static function create(
}
} else {
$command->addLocation(new SaveLocationCommand());
$command->periods[] = new SavePeriodCommand();
}

return $command;
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 = [];
public ?string $visaModelUuid = null;
Expand All @@ -41,8 +39,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() ?? [];
$command->visaModelUuid = $regulationOrder?->getVisaModel()?->getUuid();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,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 @@ -67,8 +65,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
27 changes: 22 additions & 5 deletions src/Application/Regulation/Query/GetCifsIncidentsQueryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,21 @@ public function __invoke(GetCifsIncidentsQuery $query): array
$this->cifsFilterSet->allowedLocationIds,
);

$uuids = [];

/** @var RegulationOrderRecord $regulationOrderRecord */
foreach ($regulationOrderRecords as $regulationOrderRecord) {
$uuids[] = $regulationOrderRecord->getUuid();
}

$overallDates = $this->repository->getOverallDatesByRegulationUuids($uuids);

// Reference: https://developers.google.com/waze/data-feed/cifs-specification?hl=fr
$incidents = [];

/** @var RegulationOrderRecord $regulationOrderRecord */
foreach ($regulationOrderRecords as $regulationOrderRecord) {
$uuid = $regulationOrderRecord->getUuid();
$regulationOrder = $regulationOrderRecord->getRegulationOrder();
$identifier = $regulationOrder->getIdentifier();

Expand All @@ -51,8 +61,8 @@ public function __invoke(GetCifsIncidentsQuery $query): array
};

$incidentCreationTime = $regulationOrderRecord->getCreatedAt();
$regulationStart = $regulationOrder->getStartDate();
$regulationEnd = $regulationOrder->getEndDate();
$regulationStart = $overallDates[$uuid]['overallStartDate'];
$regulationEnd = $overallDates[$uuid]['overallEndDate'];

/** @var Measure $measure */
foreach ($regulationOrder->getMeasures() as $measure) {
Expand All @@ -72,11 +82,15 @@ public function __invoke(GetCifsIncidentsQuery $query): array
/** @var TimeSlot[] $timeSlots */
$timeSlots = $period->getTimeSlots();

$isEveryDay = false;
$isAllTheTime = false;

if (!$applicableDays && $timeSlots) {
$isEveryDay = true;
$applicableDays = ['everyday'];
}

if ($timeSlots) {
if (\count($timeSlots) > 0) {
$timeSpans = [];

foreach ($timeSlots as $timeSlot) {
Expand All @@ -86,13 +100,16 @@ public function __invoke(GetCifsIncidentsQuery $query): array
];
}
} else {
$isAllTheTime = true;
$timeSpans = [['startTime' => new \DateTimeImmutable('00:00'), 'endTime' => new \DateTimeImmutable('23:59')]];
}

$schedule = [];

foreach ($applicableDays as $day) {
$schedule[$day] = $timeSpans;
if (!$isEveryDay || !$isAllTheTime) {
foreach ($applicableDays as $day) {
$schedule[$day] = $timeSpans;
}
}

// Adhere to key order in CIFS <schedule> XML element
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 @@ -26,10 +26,20 @@ public function __invoke(GetRegulationOrdersToDatexFormatQuery $query): array
{
$regulationOrderRecords = $this->repository->findRegulationOrdersForDatexFormat();

$uuids = [];

/** @var RegulationOrderRecord $regulationOrderRecord */
foreach ($regulationOrderRecords as $regulationOrderRecord) {
$uuids[] = $regulationOrderRecord->getUuid();
}

$overallDates = $this->repository->getOverallDatesByRegulationUuids($uuids);

$regulationOrderViews = [];

/** @var RegulationOrderRecord $regulationOrderRecord */
foreach ($regulationOrderRecords as $regulationOrderRecord) {
$uuid = $regulationOrderRecord->getUuid();
$regulationOrder = $regulationOrderRecord->getRegulationOrder();

$trafficRegulations = [];
Expand Down Expand Up @@ -108,7 +118,7 @@ public function __invoke(GetRegulationOrdersToDatexFormatQuery $query): array
$dailyRange = $period->getDailyRange();
$timeSlots = $period->getTimeSlots() ?? [];

if ($dailyRange || $timeSlots) {
if ($dailyRange || \count($timeSlots) > 0) {
$recurringTimePeriods = [];

foreach ($timeSlots as $timeSlot) {
Expand Down Expand Up @@ -139,13 +149,13 @@ public function __invoke(GetRegulationOrdersToDatexFormatQuery $query): array

$regulationOrderViews[] = new RegulationOrderDatexListItemView(
uuid: $regulationOrder->getUuid(),
regulationOrderRecordUuid: $regulationOrderRecord->getUuid(),
regulationOrderRecordUuid: $uuid,
regulationId: $regulationOrder->getIdentifier() . '#' . $regulationOrderRecord->getOrganizationUuid(),
organization: $regulationOrderRecord->getOrganizationName(),
source: $regulationOrderRecord->getSource(),
description: $regulationOrder->getDescription(),
startDate: $regulationOrder->getStartDate(),
endDate: $regulationOrder->getEndDate(),
startDate: $overallDates[$uuid]['overallStartDate'],
endDate: $overallDates[$uuid]['overallEndDate'],
trafficRegulations: $trafficRegulations,
);
}
Expand Down
13 changes: 11 additions & 2 deletions src/Application/Regulation/Query/GetRegulationsQueryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Application\Regulation\View\RawGeoJSONView;
use App\Application\Regulation\View\RegulationOrderListItemView;
use App\Domain\Pagination;
use App\Domain\Regulation\Enum\RegulationOrderCategoryEnum;
use App\Domain\Regulation\Repository\RegulationOrderRecordRepositoryInterface;

final class GetRegulationsQueryHandler
Expand Down Expand Up @@ -38,6 +39,14 @@ public function __invoke(GetRegulationsQuery $query): Pagination
$locationView = new RawGeoJSONView($label);
}

$startDate = $row['overallStartDate'] ? new \DateTimeImmutable($row['overallStartDate']) : null;
$endDate = null;

// Returning overallEndDate = NULL for permanent regulation orders is too complex in SQL, we do it here in PHP.
if ($row['overallEndDate'] && $row['category'] !== RegulationOrderCategoryEnum::PERMANENT_REGULATION->value) {
$endDate = new \DateTimeImmutable($row['overallEndDate']);
}

$regulationOrderViews[] = new RegulationOrderListItemView(
uuid: $row['uuid'],
identifier: $row['identifier'],
Expand All @@ -46,8 +55,8 @@ public function __invoke(GetRegulationsQuery $query): Pagination
organizationName: $row['organizationName'],
organizationUuid: $row['organizationUuid'],
location: $locationView,
startDate: $row['startDate'],
endDate: $row['endDate'],
startDate: $startDate,
endDate: $endDate,
);
}

Expand Down
19 changes: 2 additions & 17 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,16 +52,6 @@ public function getDescription(): string
return $this->description;
}

public function getStartDate(): ?\DateTimeInterface
{
return $this->startDate;
}

public function getEndDate(): ?\DateTimeInterface
{
return $this->endDate;
}

public function getMeasures(): iterable
{
return $this->measures;
Expand All @@ -82,7 +71,7 @@ public function getRegulationOrderRecord(): ?RegulationOrderRecord

public function isPermanent(): bool
{
return !$this->endDate;
return $this->category === RegulationOrderCategoryEnum::PERMANENT_REGULATION->value;
}

public function getVisaModel(): ?VisaModel
Expand All @@ -104,8 +93,6 @@ public function update(
string $identifier,
string $category,
string $description,
\DateTimeInterface $startDate,
?\DateTimeInterface $endDate = null,
?string $otherCategoryText = null,
array $additionalVisas = [],
array $additionalReasons = [],
Expand All @@ -114,8 +101,6 @@ public function update(
$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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public function findOrganizationUuid(string $uuid): ?string;

public function findRegulationOrdersForDatexFormat(): array;

public function getOverallDatesByRegulationUuids(array $uuids): array;

public function findRegulationOrdersForCifsIncidentFormat(
array $allowedSources = [],
array $excludedIdentifiers = [],
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public function __invoke(Request $request, string $uuid): Response
/** @var FlashBagAwareSessionInterface */
$session = $request->getSession();
$regulationOrderRecord = $this->getRegulationOrderRecord($uuid);
$regulationOrder = $regulationOrderRecord->getRegulationOrder();

try {
$duplicatedRegulationOrderRecord = $this->commandBus->handle(
Expand All @@ -65,9 +64,7 @@ public function __invoke(Request $request, string $uuid): Response
}

return new RedirectResponse(
url: $this->router->generate('app_regulations_list', [
'tab' => $regulationOrder->getEndDate() ? 'temporary' : 'permanent',
]),
url: $this->router->generate('app_regulations_list'),
status: Response::HTTP_SEE_OTHER,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function __invoke(string $uuid): Response
'canDelete' => !$isReadOnly && $this->canDeleteMeasures->isSatisfiedBy(new ArrayRegulationMeasures($measures)),
'isReadOnly' => $isReadOnly,
'generalInfo' => $generalInfo,
'isPermanent' => $regulationOrderRecord->getRegulationOrder()->isPermanent(),
'measures' => $measures,
'regulationOrderRecord' => $regulationOrderRecord,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ enum EudonetParisErrorEnum: string
{
case NO_MEASURES_FOUND = 'no_measures_found';
case MEASURE_ERRORS = 'measure_errors';
case PARSING_FAILED = 'parsing_failed';
case MEASURE_MAY_CONTAIN_DATES = 'measure_may_contain_dates';
case VALUE_DOES_NOT_MATCH_PATTERN = 'value_does_not_match_pattern';
case UNSUPPORTED_LOCATION_FIELDSET = 'unsupported_location_fieldset';
Expand Down
Loading

0 comments on commit f8e9012

Please sign in to comment.