From e6b2c719f854f407ae9dd09ccb4cb5b84f5d9667 Mon Sep 17 00:00:00 2001 From: Holger Bruch Date: Wed, 24 Jul 2024 08:23:57 +0200 Subject: [PATCH 1/2] fix: map current_range_meters as provided Fixing upstream feed issues (missing current_range_meters) would need to check the vehicle_type's propulsion_type, which is not available here --- .../mapper/feedmapper/v2/FreeBikeStatusFeedMapper.java | 4 +--- .../lamassu/mapper/feedmapper/v3/VehicleStatusFeedMapper.java | 4 +--- .../mapper/feedmapper/v2/FreeBikeStatusFeedMapperTest.java | 3 ++- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/entur/lamassu/mapper/feedmapper/v2/FreeBikeStatusFeedMapper.java b/src/main/java/org/entur/lamassu/mapper/feedmapper/v2/FreeBikeStatusFeedMapper.java index 8cb5706e..7c3213ea 100644 --- a/src/main/java/org/entur/lamassu/mapper/feedmapper/v2/FreeBikeStatusFeedMapper.java +++ b/src/main/java/org/entur/lamassu/mapper/feedmapper/v2/FreeBikeStatusFeedMapper.java @@ -80,9 +80,7 @@ protected GBFSBike mapBike(GBFSBike bike, FeedProvider feedProvider) { mapped.setRentalUris(bike.getRentalUris()); mapped.setVehicleTypeId(mapVehicleTypeId(bike.getVehicleTypeId(), feedProvider)); mapped.setLastReported(bike.getLastReported()); - mapped.setCurrentRangeMeters( - bike.getCurrentRangeMeters() != null ? bike.getCurrentRangeMeters() : 0 - ); + mapped.setCurrentRangeMeters(bike.getCurrentRangeMeters()); mapped.setCurrentFuelPercent(bike.getCurrentFuelPercent()); mapped.setStationId(mapStationId(bike.getStationId(), feedProvider)); mapped.setHomeStationId(mapStationId(bike.getHomeStationId(), feedProvider)); diff --git a/src/main/java/org/entur/lamassu/mapper/feedmapper/v3/VehicleStatusFeedMapper.java b/src/main/java/org/entur/lamassu/mapper/feedmapper/v3/VehicleStatusFeedMapper.java index 6d1b462e..cb300999 100644 --- a/src/main/java/org/entur/lamassu/mapper/feedmapper/v3/VehicleStatusFeedMapper.java +++ b/src/main/java/org/entur/lamassu/mapper/feedmapper/v3/VehicleStatusFeedMapper.java @@ -78,9 +78,7 @@ protected GBFSVehicle mapVehicle(GBFSVehicle vehicle, FeedProvider feedProvider) mapped.setRentalUris(vehicle.getRentalUris()); mapped.setVehicleTypeId(mapVehicleTypeId(vehicle.getVehicleTypeId(), feedProvider)); mapped.setLastReported(vehicle.getLastReported()); - mapped.setCurrentRangeMeters( - vehicle.getCurrentRangeMeters() != null ? vehicle.getCurrentRangeMeters() : 0 - ); + mapped.setCurrentRangeMeters(vehicle.getCurrentRangeMeters()); mapped.setCurrentFuelPercent(vehicle.getCurrentFuelPercent()); mapped.setStationId(mapStationId(vehicle.getStationId(), feedProvider)); mapped.setHomeStationId(mapStationId(vehicle.getHomeStationId(), feedProvider)); diff --git a/src/test/java/org/entur/lamassu/mapper/feedmapper/v2/FreeBikeStatusFeedMapperTest.java b/src/test/java/org/entur/lamassu/mapper/feedmapper/v2/FreeBikeStatusFeedMapperTest.java index 344c24bb..17c8bb78 100644 --- a/src/test/java/org/entur/lamassu/mapper/feedmapper/v2/FreeBikeStatusFeedMapperTest.java +++ b/src/test/java/org/entur/lamassu/mapper/feedmapper/v2/FreeBikeStatusFeedMapperTest.java @@ -41,7 +41,8 @@ void prepare() { void testMissingCurrentRangeMeters() { var feedProvider = getTestProvider(); var mapped = mapper.mapBike(new GBFSBike(), feedProvider); - Assertions.assertNotNull(mapped.getCurrentRangeMeters()); + // if no current_range_meters is provided, we explicitly don't want Lamassu to fill it in + Assertions.assertNull(mapped.getCurrentRangeMeters()); } @Test From b09c92c9d01dc35103ff5056ffa9c0aeb8866969 Mon Sep 17 00:00:00 2001 From: Holger Bruch Date: Mon, 29 Jul 2024 12:20:37 +0200 Subject: [PATCH 2/2] fix: map missing currentRangeMeters to 0.0 as we want to stay backward compatible with mandatory currentRangeMeters in the graphql schema. --- .../org/entur/lamassu/mapper/entitymapper/VehicleMapper.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/entur/lamassu/mapper/entitymapper/VehicleMapper.java b/src/main/java/org/entur/lamassu/mapper/entitymapper/VehicleMapper.java index 33c2eeb5..cbf7894e 100644 --- a/src/main/java/org/entur/lamassu/mapper/entitymapper/VehicleMapper.java +++ b/src/main/java/org/entur/lamassu/mapper/entitymapper/VehicleMapper.java @@ -50,7 +50,9 @@ public Vehicle mapVehicle( mappedVehicle.setLon(vehicle.getLon()); mappedVehicle.setReserved(vehicle.getIsReserved()); mappedVehicle.setDisabled(vehicle.getIsDisabled()); - mappedVehicle.setCurrentRangeMeters(vehicle.getCurrentRangeMeters()); + mappedVehicle.setCurrentRangeMeters( + vehicle.getCurrentRangeMeters() == null ? 0.0 : vehicle.getCurrentRangeMeters() + ); mappedVehicle.setCurrentFuelPercent(vehicle.getCurrentFuelPercent()); mappedVehicle.setVehicleType(vehicleType); mappedVehicle.setPricingPlan(pricingPlan);