Skip to content

Commit

Permalink
Ajoute le type Route nationale
Browse files Browse the repository at this point in the history
  • Loading branch information
florimondmanca committed Nov 27, 2024
1 parent 3eb3382 commit f4e92f2
Show file tree
Hide file tree
Showing 40 changed files with 1,259 additions and 424 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
<property name="namedStreet">
<constraint name="Valid" />
</property>
<property name="numberedRoad">
<property name="departmentalRoad">
<constraint name="Valid" />
</property>
<property name="nationalRoad">
<constraint name="Valid" />
</property>
<property name="rawGeoJSON">
<constraint name="Valid" />
</property>
<constraint name="App\Infrastructure\Validator\SaveLocationCommandConstraint" />
</class>
</constraint-mapping>
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,25 @@
<constraint name="Length">
<option name="max">255</option>
</constraint>
<constraint name="When">
<option name="expression"> this.roadType === 'departmentalRoad' </option>
<option name="constraints">
<constraint name="NotBlank" />
</option>
</constraint>
</property>
<property name="roadNumber">
<constraint name="When">
<option name="expression"> this.roadType === 'departmentalRoad' </option>
<option name="constraints">
<constraint name="NotBlank" />
<constraint name="Length">
<option name="max">50</option>
</constraint>
</option>
</constraint>
</property>
<property name="fromPointNumber">
<constraint name="When">
<option name="expression"> this.roadType === 'departmentalRoad' </option>
<option name="constraints">
<constraint name="NotBlank"/>
</option>
</constraint>
</property>
<property name="toPointNumber">
<constraint name="When">
<option name="expression"> this.roadType === 'departmentalRoad' </option>
<option name="constraints">
<constraint name="NotBlank"/>
</option>
<constraint name="Length">
<option name="max">50</option>
</constraint>
</property>
<property name="fromAbscissa">
<constraint name="When">
<option name="expression"> this.roadType === 'departmentalRoad' </option>
<option name="constraints">
<constraint name="Type">
<option name="type">integer</option>
</constraint>
<constraint name="Type">
<option name="type">
<value>null</value>
<value>integer</value>
</option>
</constraint>
</property>
<property name="toAbscissa">
<constraint name="When">
<option name="expression"> this.roadType === 'departmentalRoad' </option>
<option name="constraints">
<constraint name="Type">
<option name="type">integer</option>
</constraint>
<constraint name="Type">
<option name="type">
<value>null</value>
<value>integer</value>
</option>
</constraint>
</property>
Expand Down
428 changes: 415 additions & 13 deletions data/gestionnaires.txt

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/Application/Exception/AbscissaOutOfRangeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@

class AbscissaOutOfRangeException extends GeocodingFailureException
{
public function __construct(
public readonly string $roadType,
string $message = '',
?int $locationIndex = null,
?\Exception $previous = null,
) {
parent::__construct($message, $locationIndex, $previous);
}
}
8 changes: 8 additions & 0 deletions src/Application/Exception/RoadGeocodingFailureException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@

final class RoadGeocodingFailureException extends GeocodingFailureException
{
public function __construct(
public readonly string $roadType,
string $message = '',
?int $locationIndex = null,
?\Exception $previous = null,
) {
parent::__construct($message, $locationIndex, $previous);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,18 @@ public function __invoke(DuplicateMeasureCommand $command): Measure
$cmd->roadType = $location->getRoadType();

if ($numberedRoad = $location->getNumberedRoad()) {
$cmd->numberedRoad = new SaveNumberedRoadCommand();
$cmd->numberedRoad->geometry = $location->getGeometry();
$cmd->numberedRoad->roadType = $location->getRoadType();
$cmd->numberedRoad->administrator = $numberedRoad->getAdministrator();
$cmd->numberedRoad->roadNumber = $numberedRoad->getRoadNumber();
$cmd->numberedRoad->fromPointNumber = $numberedRoad->getFromPointNumber();
$cmd->numberedRoad->fromSide = $numberedRoad->getFromSide();
$cmd->numberedRoad->fromAbscissa = $numberedRoad->getFromAbscissa();
$cmd->numberedRoad->toPointNumber = $numberedRoad->getToPointNumber();
$cmd->numberedRoad->toAbscissa = $numberedRoad->getToAbscissa();
$cmd->numberedRoad->toSide = $numberedRoad->getToSide();
$numberedRoadCmd = new SaveNumberedRoadCommand();
$numberedRoadCmd->geometry = $location->getGeometry();
$numberedRoadCmd->roadType = $location->getRoadType();
$numberedRoadCmd->administrator = $numberedRoad->getAdministrator();
$numberedRoadCmd->roadNumber = $numberedRoad->getRoadNumber();
$numberedRoadCmd->fromPointNumber = $numberedRoad->getFromPointNumber();
$numberedRoadCmd->fromSide = $numberedRoad->getFromSide();
$numberedRoadCmd->fromAbscissa = $numberedRoad->getFromAbscissa();
$numberedRoadCmd->toPointNumber = $numberedRoad->getToPointNumber();
$numberedRoadCmd->toAbscissa = $numberedRoad->getToAbscissa();
$numberedRoadCmd->toSide = $numberedRoad->getToSide();
$cmd->assignNumberedRoad($numberedRoadCmd);
} elseif ($namedStreet = $location->getNamedStreet()) {
$cmd->namedStreet = new SaveNamedStreetCommand();
$cmd->namedStreet->geometry = $location->getGeometry();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ final class SaveLocationCommand implements CommandInterface
{
public ?string $roadType = null;
public ?Measure $measure = null;
public ?SaveNumberedRoadCommand $numberedRoad = null;
public ?SaveNumberedRoadCommand $departmentalRoad = null;
public ?SaveNumberedRoadCommand $nationalRoad = null;
public ?SaveNamedStreetCommand $namedStreet = null;
public ?SaveRawGeoJSONCommand $rawGeoJSON = null;
public array $permissions = []; // For validation
Expand All @@ -28,35 +29,74 @@ public function __construct(
}

if ($location?->getNumberedRoad()) {
$this->numberedRoad = new SaveNumberedRoadCommand($location->getNumberedRoad());
$this->assignNumberedRoad(new SaveNumberedRoadCommand($location->getNumberedRoad()));
}

if ($location?->getRawGeoJSON()) {
$this->rawGeoJSON = new SaveRawGeoJSONCommand($location->getRawGeoJSON());
}
}

public function assignNumberedRoad(SaveNumberedRoadCommand $numberedRoad): void
{
if ($this->roadType === RoadTypeEnum::DEPARTMENTAL_ROAD->value) {
$this->departmentalRoad = $numberedRoad;
} else {
$this->nationalRoad = $numberedRoad;
}
}

public function clean(): void
{
if ($this->roadType === RoadTypeEnum::DEPARTMENTAL_ROAD->value) {
// /!\ (**) Il y a déjà une NumberedRoad en DB qui correspond à une départementale.
// On recopie la référence vers la commande qui va la transformer en nationale.
if ($numberedRoad = $this->nationalRoad?->getNumberedRoad()) {
// $this->departmentalRoad->copyTo($this->nationalRoad);
// $this->departmentalRoad = $this->nationalRoad;
$this->departmentalRoad->setNumberedRoad($numberedRoad);
}

$this->namedStreet = null;
$this->nationalRoad = null;
$this->rawGeoJSON = null;
}

if ($this->roadType === RoadTypeEnum::NATIONAL_ROAD->value) {
// /!\ Idem que (**) ci-dessus.
if ($numberedRoad = $this->departmentalRoad?->getNumberedRoad()) {
// $this->nationalRoad->copyTo($this->departmentalRoad);
// $this->nationalRoad = $this->departmentalRoad;
$this->nationalRoad->setNumberedRoad($numberedRoad);
}

$this->namedStreet = null;
$this->departmentalRoad = null;
$this->rawGeoJSON = null;
}

if ($this->roadType === RoadTypeEnum::LANE->value) {
$this->numberedRoad = null;
$this->departmentalRoad = null;
$this->nationalRoad = null;
$this->rawGeoJSON = null;
}

if ($this->roadType == RoadTypeEnum::RAW_GEOJSON->value) {
$this->namedStreet = null;
$this->numberedRoad = null;
$this->departmentalRoad = null;
$this->nationalRoad = null;
}
}

public function getRoadCommand(): RoadCommandInterface
{
return $this->namedStreet ?? $this->numberedRoad ?? $this->rawGeoJSON ?? throw new \LogicException('No road command');
return match ($this->roadType) {
RoadTypeEnum::LANE->value => $this->namedStreet,
RoadTypeEnum::DEPARTMENTAL_ROAD->value => $this->departmentalRoad,
RoadTypeEnum::NATIONAL_ROAD->value => $this->nationalRoad,
RoadTypeEnum::RAW_GEOJSON->value => $this->rawGeoJSON,
default => throw new \LogicException('No road command'),
};
}

public function getRoadDeleteCommand(): ?CommandInterface
Expand All @@ -65,7 +105,7 @@ public function getRoadDeleteCommand(): ?CommandInterface
return new DeleteNamedStreetCommand($namedStreet);
}

if (!$this->numberedRoad && $numberedRoad = $this->location->getNumberedRoad()) {
if (!$this->departmentalRoad && !$this->nationalRoad && $numberedRoad = $this->location->getNumberedRoad()) {
return new DeleteNumberedRoadCommand($numberedRoad);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class SaveNumberedRoadCommand implements RoadCommandInterface
public ?Location $location = null;

public function __construct(
public readonly ?NumberedRoad $numberedRoad = null,
private ?NumberedRoad $numberedRoad = null,
) {
$this->administrator = $numberedRoad?->getAdministrator();
$this->roadNumber = $numberedRoad?->getRoadNumber();
Expand All @@ -39,6 +39,28 @@ public function __construct(
$this->roadType = $numberedRoad?->getLocation()?->getRoadType();
}

public function getNumberedRoad(): ?NumberedRoad
{
return $this->numberedRoad;
}

public function setNumberedRoad(NumberedRoad $numberedRoad): void
{
$this->numberedRoad = $numberedRoad;
}

public function copyTo(SaveNumberedRoadCommand $other): void
{
$other->administrator = $this->administrator;
$other->roadNumber = $this->roadNumber;
$other->fromPointNumber = $this->fromPointNumber;
$other->fromSide = $this->fromSide;
$other->fromAbscissa = $this->fromAbscissa;
$other->toPointNumber = $this->toPointNumber;
$other->toAbscissa = $this->toAbscissa;
$other->toSide = $this->toSide;
}

// Road command interface

public function setLocation(Location $location): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(

public function __invoke(SaveNumberedRoadCommand $command): NumberedRoad
{
if (!$command->numberedRoad instanceof NumberedRoad) {
if (!$command->getNumberedRoad() instanceof NumberedRoad) {
$numberedRoad = $this->numberedRoadRepository->add(
new NumberedRoad(
uuid: $this->idFactory->make(),
Expand All @@ -39,7 +39,7 @@ public function __invoke(SaveNumberedRoadCommand $command): NumberedRoad
return $numberedRoad;
}

$command->numberedRoad->update(
$command->getNumberedRoad()->update(
administrator: $command->administrator,
roadNumber: $command->roadNumber,
fromPointNumber: $command->fromPointNumber,
Expand All @@ -50,6 +50,6 @@ public function __invoke(SaveNumberedRoadCommand $command): NumberedRoad
toSide: $command->toSide,
);

return $command->numberedRoad;
return $command->getNumberedRoad();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ private function computeGeometry(GetNumberedRoadGeometryQuery $query): string
{
$command = $query->command;

$fullDepartmentalRoadGeometry = $this->roadGeocoder->computeRoad($command->roadNumber, $command->administrator);
$fullRoadGeometry = $this->roadGeocoder->computeRoad($command->roadType, $command->administrator, $command->roadNumber);

return $this->roadSectionMaker->computeSection(
$fullDepartmentalRoadGeometry,
$fullRoadGeometry,
$command->roadType,
$command->administrator,
$command->roadNumber,
$command->fromPointNumber,
Expand All @@ -51,15 +52,16 @@ private function computeGeometry(GetNumberedRoadGeometryQuery $query): string
private function shouldRecomputeGeometry(GetNumberedRoadGeometryQuery $query): bool
{
$command = $query->command;
$numberedRoad = $command->getNumberedRoad();

return !$command->numberedRoad
|| $command->roadNumber !== $command->numberedRoad->getRoadNumber()
|| $command->administrator !== $command->numberedRoad->getAdministrator()
|| $command->fromPointNumber !== $command->numberedRoad->getFromPointNumber()
|| $command->toPointNumber !== $command->numberedRoad->getToPointNumber()
|| $command->fromAbscissa !== $command->numberedRoad->getFromAbscissa()
|| $command->toAbscissa !== $command->numberedRoad->getToAbscissa()
|| $command->fromSide !== $command->numberedRoad->getFromSide()
|| $command->toSide !== $command->numberedRoad->getToSide();
return !$numberedRoad
|| $command->roadNumber !== $numberedRoad->getRoadNumber()
|| $command->administrator !== $numberedRoad->getAdministrator()
|| $command->fromPointNumber !== $numberedRoad->getFromPointNumber()
|| $command->toPointNumber !== $numberedRoad->getToPointNumber()
|| $command->fromAbscissa !== $numberedRoad->getFromAbscissa()
|| $command->toAbscissa !== $numberedRoad->getToAbscissa()
|| $command->fromSide !== $numberedRoad->getFromSide()
|| $command->toSide !== $numberedRoad->getToSide();
}
}
5 changes: 3 additions & 2 deletions src/Application/RoadGeocoderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ interface RoadGeocoderInterface

public function computeRoadLine(string $roadName, string $inseeCode): string;

public function findRoads(string $search, string $administrator): array;
public function findRoads(string $search, string $roadType, string $administrator): array;

public function computeRoad(string $roadNumber, string $administrator): string;
public function computeRoad(string $roadType, string $administrator, string $roadNumber): string;

public function computeReferencePoint(
string $roadType,
string $administrator,
string $roadNumber,
string $pointNumber,
Expand Down
3 changes: 2 additions & 1 deletion src/Application/RoadSectionMakerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
interface RoadSectionMakerInterface
{
public function computeSection(
string $fullDepartmentalRoadGeometry,
string $fullRoadGeometry,
string $roadType,
string $administrator,
string $roadNumber,
string $fromPointNumber,
Expand Down
1 change: 1 addition & 0 deletions src/Domain/Regulation/Enum/RoadTypeEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ enum RoadTypeEnum: string
{
case LANE = 'lane';
case DEPARTMENTAL_ROAD = 'departmentalRoad';
case NATIONAL_ROAD = 'nationalRoad';
case RAW_GEOJSON = 'rawGeoJSON';
}
Loading

0 comments on commit f4e92f2

Please sign in to comment.