From ac046c67387920bc977f74281e5e284e0bff8bf4 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Mon, 15 Jul 2024 18:06:11 +0200 Subject: [PATCH] Take missing capacity into account --- .../netex/mapping/NetexMapper.java | 6 ++-- .../netex/mapping/VehicleParkingMapper.java | 21 ++++++++---- .../mapping/VehicleParkingMapperTest.java | 34 +++++++++++++++---- 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/opentripplanner/netex/mapping/NetexMapper.java b/src/main/java/org/opentripplanner/netex/mapping/NetexMapper.java index 8e3fd6e166d..897260fbddb 100644 --- a/src/main/java/org/opentripplanner/netex/mapping/NetexMapper.java +++ b/src/main/java/org/opentripplanner/netex/mapping/NetexMapper.java @@ -522,13 +522,15 @@ private void addEntriesToGroupMapperForPostProcessingLater() { } private void mapVehicleParkings() { - var mapper = new VehicleParkingMapper(idFactory); + var mapper = new VehicleParkingMapper(idFactory, issueStore); currentNetexIndex .getParkingsById() .localKeys() .forEach(id -> { var parking = mapper.map(currentNetexIndex.getParkingsById().lookup(id)); - transitBuilder.vehicleParkings().add(parking); + if (parking != null) { + transitBuilder.vehicleParkings().add(parking); + } }); } diff --git a/src/main/java/org/opentripplanner/netex/mapping/VehicleParkingMapper.java b/src/main/java/org/opentripplanner/netex/mapping/VehicleParkingMapper.java index 84dfc201909..7f78e7191ef 100644 --- a/src/main/java/org/opentripplanner/netex/mapping/VehicleParkingMapper.java +++ b/src/main/java/org/opentripplanner/netex/mapping/VehicleParkingMapper.java @@ -4,10 +4,10 @@ import static org.rutebanken.netex.model.ParkingVehicleEnumeration.E_CYCLE; import static org.rutebanken.netex.model.ParkingVehicleEnumeration.PEDAL_CYCLE; -import java.util.Collection; import java.util.Set; -import java.util.stream.Collectors; +import javax.annotation.Nullable; import org.opentripplanner.framework.i18n.NonLocalizedString; +import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore; import org.opentripplanner.netex.mapping.support.FeedScopedIdFactory; import org.opentripplanner.routing.vehicle_parking.VehicleParking; import org.opentripplanner.routing.vehicle_parking.VehicleParkingSpaces; @@ -26,16 +26,23 @@ class VehicleParkingMapper { E_CYCLE, CYCLE ); + private final DataImportIssueStore issueStore; - VehicleParkingMapper(FeedScopedIdFactory idFactory) { + VehicleParkingMapper(FeedScopedIdFactory idFactory, DataImportIssueStore issueStore) { this.idFactory = idFactory; + this.issueStore = issueStore; } - Collection map(Collection parkings) { - return parkings.stream().map(this::map).collect(Collectors.toUnmodifiableSet()); - } - + @Nullable VehicleParking map(Parking parking) { + if (parking.getTotalCapacity() == null) { + issueStore.add( + "MissingParkingCapacity", + "NeTEx Parking %s does not contain totalCapacity", + parking.getId() + ); + return null; + } return VehicleParking .builder() .id(idFactory.createId(parking.getId())) diff --git a/src/test/java/org/opentripplanner/netex/mapping/VehicleParkingMapperTest.java b/src/test/java/org/opentripplanner/netex/mapping/VehicleParkingMapperTest.java index b81075a5b0e..bf56be1be1b 100644 --- a/src/test/java/org/opentripplanner/netex/mapping/VehicleParkingMapperTest.java +++ b/src/test/java/org/opentripplanner/netex/mapping/VehicleParkingMapperTest.java @@ -1,6 +1,7 @@ package org.opentripplanner.netex.mapping; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.rutebanken.netex.model.ParkingVehicleEnumeration.AGRICULTURAL_VEHICLE; import static org.rutebanken.netex.model.ParkingVehicleEnumeration.ALL_PASSENGER_VEHICLES; @@ -13,9 +14,13 @@ import java.math.BigInteger; import java.util.List; import java.util.Set; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import org.opentripplanner.framework.geometry.WgsCoordinate; +import org.opentripplanner.graph_builder.issue.api.DataImportIssue; +import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore; +import org.opentripplanner.graph_builder.issue.service.DefaultDataImportIssueStore; import org.opentripplanner.netex.mapping.support.FeedScopedIdFactory; import org.opentripplanner.routing.vehicle_parking.VehicleParking; import org.opentripplanner.routing.vehicle_parking.VehicleParkingSpaces; @@ -27,10 +32,6 @@ class VehicleParkingMapperTest { - private static final VehicleParkingMapper MAPPER = new VehicleParkingMapper( - new FeedScopedIdFactory("parking") - ); - public static List> carCases() { return List.of(Set.of(), Set.of(CAR, AGRICULTURAL_VEHICLE, ALL_PASSENGER_VEHICLES)); } @@ -38,7 +39,7 @@ public static List> carCases() { @ParameterizedTest @MethodSource("carCases") void mapCarLot(Set vehicleTypes) { - var vp = MAPPER.map(parking(vehicleTypes)); + var vp = mapper().map(parking(vehicleTypes)); assertCommonProperties(vp); assertTrue(vp.hasAnyCarPlaces()); assertEquals(VehicleParkingSpaces.builder().carSpaces(10).build(), vp.getCapacity()); @@ -51,12 +52,33 @@ public static List> bicycleCases() { @ParameterizedTest @MethodSource("bicycleCases") void mapBicycleLot(Set vehicleTypes) { - var vp = MAPPER.map(parking(vehicleTypes)); + var vp = mapper().map(parking(vehicleTypes)); assertCommonProperties(vp); assertTrue(vp.hasBicyclePlaces()); assertEquals(VehicleParkingSpaces.builder().bicycleSpaces(10).build(), vp.getCapacity()); } + @Test + void dropEmptyCapacity() { + var parking = parking(Set.of(CAR)); + parking.setTotalCapacity(null); + var issueStore = new DefaultDataImportIssueStore(); + var vp = mapper(issueStore).map(parking); + assertNull(vp); + assertEquals( + List.of("MissingParkingCapacity"), + issueStore.listIssues().stream().map(DataImportIssue::getType).toList() + ); + } + + private VehicleParkingMapper mapper() { + return mapper(DataImportIssueStore.NOOP); + } + + private static VehicleParkingMapper mapper(DataImportIssueStore issueStore) { + return new VehicleParkingMapper(new FeedScopedIdFactory("parking"), issueStore); + } + private static void assertCommonProperties(VehicleParking vp) { assertEquals("A name", vp.getName().toString()); assertEquals(new WgsCoordinate(10, 20), vp.getCoordinate());