Skip to content

Commit

Permalink
Corrige import Litteralis : Undefined array key "regulationId" (#1000)
Browse files Browse the repository at this point in the history
  • Loading branch information
florimondmanca authored Oct 10, 2024
1 parent 33101e0 commit b0a9185
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 42 deletions.
5 changes: 3 additions & 2 deletions src/Infrastructure/Litteralis/LitteralisExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Infrastructure\Litteralis;

use App\Infrastructure\IntegrationReport\CommonRecordEnum;
use App\Infrastructure\IntegrationReport\Reporter;

final class LitteralisExtractor
Expand Down Expand Up @@ -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;
}
Expand Down
13 changes: 7 additions & 6 deletions src/Infrastructure/Litteralis/LitteralisPeriodParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
],
Expand All @@ -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,
],
Expand Down Expand Up @@ -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,
]);

Expand Down
27 changes: 14 additions & 13 deletions src/Infrastructure/Litteralis/LitteralisTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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'],
]);
}
Expand All @@ -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'],
]);
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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'],
]);

Expand All @@ -426,9 +427,9 @@ private function parseMaxSpeed(array $properties, array $parameters, Reporter $r

if (!preg_match('/^(?P<speed>\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,
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
39 changes: 20 additions & 19 deletions tests/Unit/Infrastructure/Litteralis/LitteralisTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -285,69 +286,69 @@ 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,
],
],
[
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,
],
],
[
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',
],
],
[
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',
],
],
[
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,
Expand All @@ -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',
],
],
Expand All @@ -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());
Expand Down

0 comments on commit b0a9185

Please sign in to comment.