diff --git a/src/Infrastructure/Litteralis/LitteralisExtractor.php b/src/Infrastructure/Litteralis/LitteralisExtractor.php index f2c3263ec..27c13824e 100644 --- a/src/Infrastructure/Litteralis/LitteralisExtractor.php +++ b/src/Infrastructure/Litteralis/LitteralisExtractor.php @@ -4,6 +4,7 @@ namespace App\Infrastructure\Litteralis; +use App\Infrastructure\IntegrationReport\CommonRecordEnum; use App\Infrastructure\IntegrationReport\Reporter; final class LitteralisExtractor @@ -44,9 +45,9 @@ public function extractFeaturesByRegulation(\DateTimeInterface $laterThan, Repor if (empty($feature['geometry'])) { // Parfois la 'geometry' est absente $reporter->addWarning(LitteralisRecordEnum::WARNING_MISSING_GEOMETRY->value, [ + CommonRecordEnum::ATTR_REGULATION_ID->value => $identifier, + CommonRecordEnum::ATTR_URL->value => $feature['properties']['shorturl'], 'idemprise' => $feature['properties']['idemprise'], - 'arretesrcid' => $identifier, - 'shorturl' => $feature['properties']['shorturl'], ]); continue; } diff --git a/src/Infrastructure/Litteralis/LitteralisPeriodParser.php b/src/Infrastructure/Litteralis/LitteralisPeriodParser.php index cc7a5c8df..85470dda0 100644 --- a/src/Infrastructure/Litteralis/LitteralisPeriodParser.php +++ b/src/Infrastructure/Litteralis/LitteralisPeriodParser.php @@ -7,6 +7,7 @@ use App\Application\Regulation\Command\Period\SavePeriodCommand; use App\Application\Regulation\Command\Period\SaveTimeSlotCommand; use App\Domain\Condition\Period\Enum\PeriodRecurrenceTypeEnum; +use App\Infrastructure\IntegrationReport\CommonRecordEnum; use App\Infrastructure\IntegrationReport\Reporter; final class LitteralisPeriodParser @@ -52,9 +53,9 @@ private function setPeriodDates(SavePeriodCommand $periodCommand, array $propert $reporter->addError( LitteralisRecordEnum::ERROR_DATE_PARSING_FAILED->value, [ + CommonRecordEnum::ATTR_REGULATION_ID->value => $properties['arretesrcid'], + CommonRecordEnum::ATTR_URL->value => $properties['shorturl'], 'idemprise' => $properties['idemprise'], - 'arretesrcid' => $properties['arretesrcid'], - 'shorturl' => $properties['shorturl'], $startDateProperty => $properties[$startDateProperty], 'format' => $dateFormat, ], @@ -79,9 +80,9 @@ private function setPeriodDates(SavePeriodCommand $periodCommand, array $propert $reporter->addError( LitteralisRecordEnum::ERROR_DATE_PARSING_FAILED->value, [ + CommonRecordEnum::ATTR_REGULATION_ID->value => $properties['arretesrcid'], + CommonRecordEnum::ATTR_URL->value => $properties['shorturl'], 'idemprise' => $properties['idemprise'], - 'arretesrcid' => $properties['arretesrcid'], - 'shorturl' => $properties['shorturl'], $endDateProperty => $properties[$endDateProperty], 'format' => $dateFormat, ], @@ -165,9 +166,9 @@ public function parseTimeSlots(string $value, array $properties, Reporter $repor // * 'de 21h00 à 06h00 du lundi soir au samedi matin' $reporter->addError(LitteralisRecordEnum::ERROR_PERIOD_UNPARSABLE->value, [ + CommonRecordEnum::ATTR_REGULATION_ID->value => $properties['arretesrcid'], + CommonRecordEnum::ATTR_URL->value => $properties['shorturl'], 'idemprise' => $properties['idemprise'], - 'arretesrcid' => $properties['arretesrcid'], - 'shorturl' => $properties['shorturl'], 'jours et horaires' => $value, ]); diff --git a/src/Infrastructure/Litteralis/LitteralisTransformer.php b/src/Infrastructure/Litteralis/LitteralisTransformer.php index 55ac28791..721861f65 100644 --- a/src/Infrastructure/Litteralis/LitteralisTransformer.php +++ b/src/Infrastructure/Litteralis/LitteralisTransformer.php @@ -17,6 +17,7 @@ use App\Domain\Regulation\Enum\VehicleTypeEnum; use App\Domain\Regulation\Specification\CanUseRawGeoJSON; use App\Domain\User\Organization; +use App\Infrastructure\IntegrationReport\CommonRecordEnum; use App\Infrastructure\IntegrationReport\Reporter; final readonly class LitteralisTransformer @@ -95,8 +96,8 @@ public function transform( // Il faut donc zapper cet arrêté. if (\count($measureCommands) === 0) { $reporter->addNotice(LitteralisRecordEnum::NOTICE_NO_MEASURES_FOUND->value, [ - 'arretesrcid' => $properties['arretesrcid'], - 'shorturl' => $properties['shorturl'], + CommonRecordEnum::ATTR_REGULATION_ID->value => $properties['arretesrcid'], + CommonRecordEnum::ATTR_URL->value => $properties['shorturl'], ]); return null; @@ -170,8 +171,8 @@ private function setRegulationDates(SaveRegulationGeneralInfoCommand $command, a $command->startDate = $startDate; } else { $reporter->addError(LitteralisRecordEnum::ERROR_REGULATION_START_DATE_PARSING_FAILED->value, [ - 'arretesrcid' => $properties['arretesrcid'], - 'shorturl' => $properties['shorturl'], + CommonRecordEnum::ATTR_REGULATION_ID->value => $properties['arretesrcid'], + CommonRecordEnum::ATTR_URL->value => $properties['shorturl'], 'arretedebut' => $properties['arretedebut'], ]); } @@ -187,8 +188,8 @@ private function setRegulationDates(SaveRegulationGeneralInfoCommand $command, a $command->endDate = $endDate; } else { $reporter->addError(LitteralisRecordEnum::ERROR_REGULATION_END_DATE_PARSING_FAILED->value, [ - 'arretesrcid' => $properties['arretesrcid'], - 'shorturl' => $properties['shorturl'], + CommonRecordEnum::ATTR_REGULATION_ID->value => $properties['arretesrcid'], + CommonRecordEnum::ATTR_URL->value => $properties['shorturl'], 'arretefin' => $properties['arretefin'], ]); } @@ -257,9 +258,9 @@ private function gatherMeasureParameters(array $properties, Reporter $reporter): foreach ($allMeasureNames as $name) { if (!\array_key_exists($name, self::MEASURE_MAP)) { $reporter->addNotice(LitteralisRecordEnum::NOTICE_UNSUPPORTED_MEASURE->value, [ + CommonRecordEnum::ATTR_REGULATION_ID->value => $properties['arretesrcid'], 'name' => $name, 'idemprise' => $properties['idemprise'], - 'arretesrcid' => $properties['arretesrcid'], ]); continue; } @@ -316,9 +317,9 @@ private function gatherMeasureParameters(array $properties, Reporter $reporter): // Le numéro indiqué ne correspond pas au 1-index de la mesure dans 'mesures'. // On traite ce cas comme une erreur car on ne peut pas savoir à quelle mesure ces paramètres se rattachent. $reporter->addError(LitteralisRecordEnum::ERROR_MEASURE_PARAMETER_INCONSISTENT_NUMBER->value, [ + CommonRecordEnum::ATTR_REGULATION_ID->value => $properties['arretesrcid'], + CommonRecordEnum::ATTR_URL->value => $properties['shorturl'], 'idemprise' => $properties['idemprise'], - 'arretesrcid' => $properties['arretesrcid'], - 'shorturl' => $properties['shorturl'], 'measureName' => $name, 'expected' => $index + 1, 'actual' => $number, @@ -415,9 +416,9 @@ private function parseMaxSpeed(array $properties, array $parameters, Reporter $r if (!$value) { $reporter->addError(LitteralisRecordEnum::ERROR_MAX_SPEED_VALUE_MISSING->value, [ + CommonRecordEnum::ATTR_REGULATION_ID->value => $properties['arretesrcid'], + CommonRecordEnum::ATTR_URL->value => $properties['shorturl'], 'idemprise' => $properties['idemprise'], - 'arretesrcid' => $properties['arretesrcid'], - 'shorturl' => $properties['shorturl'], 'mesures' => $properties['mesures'], ]); @@ -426,9 +427,9 @@ private function parseMaxSpeed(array $properties, array $parameters, Reporter $r if (!preg_match('/^(?P\d+)/i', $value, $matches)) { $reporter->addError(LitteralisRecordEnum::ERROR_MAX_SPEED_VALUE_INVALID->value, [ + CommonRecordEnum::ATTR_REGULATION_ID->value => $properties['arretesrcid'], + CommonRecordEnum::ATTR_URL->value => $properties['shorturl'], 'idemprise' => $properties['idemprise'], - 'arretesrcid' => $properties['arretesrcid'], - 'shorturl' => $properties['shorturl'], 'limite de vitesse' => $value, ]); diff --git a/tests/Unit/Infrastructure/Litteralis/LitteralisExtractorTest.php b/tests/Unit/Infrastructure/Litteralis/LitteralisExtractorTest.php index 41c32ec50..f14053be5 100644 --- a/tests/Unit/Infrastructure/Litteralis/LitteralisExtractorTest.php +++ b/tests/Unit/Infrastructure/Litteralis/LitteralisExtractorTest.php @@ -4,6 +4,7 @@ namespace App\Tests\Unit\Infrastructure\Litteralis; +use App\Infrastructure\IntegrationReport\CommonRecordEnum; use App\Infrastructure\IntegrationReport\Reporter; use App\Infrastructure\Litteralis\LitteralisClient; use App\Infrastructure\Litteralis\LitteralisExtractor; @@ -95,8 +96,8 @@ public function testExtractFeaturesByRegulation(): void ->method('addWarning') ->with(LitteralisRecordEnum::WARNING_MISSING_GEOMETRY->value, [ 'idemprise' => 'emprise4', - 'arretesrcid' => 'arrete3', - 'shorturl' => 'https://dl.sogelink.fr/?n3omzTyS', + CommonRecordEnum::ATTR_REGULATION_ID->value => 'arrete3', + CommonRecordEnum::ATTR_URL->value => 'https://dl.sogelink.fr/?n3omzTyS', ]); $extractor = new LitteralisExtractor($this->client); diff --git a/tests/Unit/Infrastructure/Litteralis/LitteralisTransformerTest.php b/tests/Unit/Infrastructure/Litteralis/LitteralisTransformerTest.php index 5e951aa55..745359611 100644 --- a/tests/Unit/Infrastructure/Litteralis/LitteralisTransformerTest.php +++ b/tests/Unit/Infrastructure/Litteralis/LitteralisTransformerTest.php @@ -20,6 +20,7 @@ use App\Domain\Regulation\Enum\VehicleTypeEnum; use App\Domain\Regulation\Specification\CanUseRawGeoJSON; use App\Domain\User\Organization; +use App\Infrastructure\IntegrationReport\CommonRecordEnum; use App\Infrastructure\IntegrationReport\RecordTypeEnum; use App\Infrastructure\IntegrationReport\Reporter; use App\Infrastructure\Litteralis\LitteralisPeriodParser; @@ -285,28 +286,28 @@ public function testTransformWithErrors(): void RecordTypeEnum::ERROR->value, [ RecordTypeEnum::ERROR->value => LitteralisRecordEnum::ERROR_REGULATION_START_DATE_PARSING_FAILED->value, + CommonRecordEnum::ATTR_REGULATION_ID->value => '24-A-0126', + CommonRecordEnum::ATTR_URL->value => 'https://dl.sogelink.fr/?n3omzTyS', 'arretedebut' => 'BAD FORMAT', - 'arretesrcid' => '24-A-0126', - 'shorturl' => 'https://dl.sogelink.fr/?n3omzTyS', ], ], [ RecordTypeEnum::ERROR->value, [ RecordTypeEnum::ERROR->value => LitteralisRecordEnum::ERROR_REGULATION_END_DATE_PARSING_FAILED->value, + CommonRecordEnum::ATTR_REGULATION_ID->value => '24-A-0126', + CommonRecordEnum::ATTR_URL->value => 'https://dl.sogelink.fr/?n3omzTyS', 'arretefin' => 'BAD FORMAT', - 'arretesrcid' => '24-A-0126', - 'shorturl' => 'https://dl.sogelink.fr/?n3omzTyS', ], ], [ RecordTypeEnum::ERROR->value, [ RecordTypeEnum::ERROR->value => LitteralisRecordEnum::ERROR_DATE_PARSING_FAILED->value, + CommonRecordEnum::ATTR_REGULATION_ID->value => '24-A-0126', + CommonRecordEnum::ATTR_URL->value => 'https://dl.sogelink.fr/?n3omzTyS', 'arretedebut' => 'BAD FORMAT', 'idemprise' => 493136, - 'arretesrcid' => '24-A-0126', - 'shorturl' => 'https://dl.sogelink.fr/?n3omzTyS', 'format' => \DateTimeInterface::ISO8601, ], ], @@ -314,10 +315,10 @@ public function testTransformWithErrors(): void RecordTypeEnum::ERROR->value, [ RecordTypeEnum::ERROR->value => LitteralisRecordEnum::ERROR_DATE_PARSING_FAILED->value, + CommonRecordEnum::ATTR_REGULATION_ID->value => '24-A-0126', + CommonRecordEnum::ATTR_URL->value => 'https://dl.sogelink.fr/?n3omzTyS', 'arretefin' => 'BAD FORMAT', 'idemprise' => 493136, - 'arretesrcid' => '24-A-0126', - 'shorturl' => 'https://dl.sogelink.fr/?n3omzTyS', 'format' => \DateTimeInterface::ISO8601, ], ], @@ -325,9 +326,9 @@ public function testTransformWithErrors(): void RecordTypeEnum::ERROR->value, [ RecordTypeEnum::ERROR->value => LitteralisRecordEnum::ERROR_MAX_SPEED_VALUE_MISSING->value, + CommonRecordEnum::ATTR_REGULATION_ID->value => '24-A-0126', + CommonRecordEnum::ATTR_URL->value => 'https://dl.sogelink.fr/?n3omzTyS', 'idemprise' => 493136, - 'arretesrcid' => '24-A-0126', - 'shorturl' => 'https://dl.sogelink.fr/?n3omzTyS', 'mesures' => 'Limitation de vitesse', ], ], @@ -335,9 +336,9 @@ public function testTransformWithErrors(): void RecordTypeEnum::ERROR->value, [ RecordTypeEnum::ERROR->value => LitteralisRecordEnum::ERROR_MAX_SPEED_VALUE_INVALID->value, + CommonRecordEnum::ATTR_REGULATION_ID->value => '24-A-0126', + CommonRecordEnum::ATTR_URL->value => 'https://dl.sogelink.fr/?n3omzTyS', 'idemprise' => 493136, - 'arretesrcid' => '24-A-0126', - 'shorturl' => 'https://dl.sogelink.fr/?n3omzTyS', 'limite de vitesse' => 'foo km/h', ], ], @@ -345,9 +346,9 @@ public function testTransformWithErrors(): void RecordTypeEnum::ERROR->value, [ RecordTypeEnum::ERROR->value => LitteralisRecordEnum::ERROR_MEASURE_PARAMETER_INCONSISTENT_NUMBER->value, + CommonRecordEnum::ATTR_REGULATION_ID->value => '24-A-0126', + CommonRecordEnum::ATTR_URL->value => 'https://dl.sogelink.fr/?n3omzTyS', 'idemprise' => 493136, - 'arretesrcid' => '24-A-0126', - 'shorturl' => 'https://dl.sogelink.fr/?n3omzTyS', 'measureName' => 'Circulation interdite 4', 'expected' => 1, 'actual' => 4, @@ -357,9 +358,9 @@ public function testTransformWithErrors(): void RecordTypeEnum::ERROR->value, [ RecordTypeEnum::ERROR->value => LitteralisRecordEnum::ERROR_PERIOD_UNPARSABLE->value, + CommonRecordEnum::ATTR_REGULATION_ID->value => '24-A-0126', + CommonRecordEnum::ATTR_URL->value => 'https://dl.sogelink.fr/?n3omzTyS', 'idemprise' => 493136, - 'arretesrcid' => '24-A-0126', - 'shorturl' => 'https://dl.sogelink.fr/?n3omzTyS', 'jours et horaires' => 'foo', ], ], @@ -380,17 +381,17 @@ public function testTransformNoMeasuresFound(): void RecordTypeEnum::NOTICE->value, [ RecordTypeEnum::NOTICE->value => LitteralisRecordEnum::NOTICE_UNSUPPORTED_MEASURE->value, + CommonRecordEnum::ATTR_REGULATION_ID->value => '24-A-0126', 'name' => 'unknown measure', 'idemprise' => 493136, - 'arretesrcid' => '24-A-0126', ], ], [ RecordTypeEnum::NOTICE->value, [ RecordTypeEnum::NOTICE->value => LitteralisRecordEnum::NOTICE_NO_MEASURES_FOUND->value, - 'arretesrcid' => '24-A-0126', - 'shorturl' => 'https://dl.sogelink.fr/?n3omzTyS', + CommonRecordEnum::ATTR_REGULATION_ID->value => '24-A-0126', + CommonRecordEnum::ATTR_URL->value => 'https://dl.sogelink.fr/?n3omzTyS', ], ], ], $this->reporter->getRecords());