Skip to content

Commit

Permalink
Make filter behavior configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
testower committed Jan 24, 2025
1 parent 18c093f commit 6c66619
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.mobilitydata.gbfs.v3_0.vehicle_status.GBFSVehicle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
Expand All @@ -37,6 +38,11 @@ class VehicleFilter implements Predicate<GBFSVehicle> {
private final EntityCache<VehicleType> vehicleTypeCache;
private final EntityCache<Station> stationCache;

@Value(
"#{new Boolean('${org.entur.lamssu.vehicle-filter.include-vehicles-assigned-to-non-virtual-stations:false}')}"
)
private Boolean includeVehiclesAssignedToNonVirtualStations;

public VehicleFilter(
EntityCache<PricingPlan> pricingPlanCache,
EntityCache<VehicleType> vehicleTypeCache,
Expand All @@ -51,7 +57,11 @@ public VehicleFilter(
public boolean test(GBFSVehicle vehicle) {
if (vehicle.getStationId() != null) {
var station = stationCache.get(vehicle.getStationId());
if (station != null && !station.getVirtualStation()) {
if (
station != null &&
!station.getVirtualStation() &&
!includeVehiclesAssignedToNonVirtualStations
) {
logger.info(
"Skipping vehicle {} currently assigned to non-virtual station {}",
vehicle.getVehicleId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ public void testVehicleWithoutPricingPlanButDefaultPricingPlanIsntSkipped() {

vehicleTypeCache.updateAll(vehicleTypesWithPricingPlan("pricingPlanId"), 0, null);

VehicleFilter filter = new VehicleFilter(pricingPlanCache, vehicleTypeCache, stationCache);
VehicleFilter filter = new VehicleFilter(
pricingPlanCache,
vehicleTypeCache,
stationCache
);

GBFSVehicle vehicle = new GBFSVehicle();
vehicle.setVehicleId("VehicleWithoutPricingPlan");
Expand All @@ -48,7 +52,11 @@ public void testVehicleWithoutPricingPlanAndWithoutDefaultPricingPlanIsSkipped()

vehicleTypeCache.updateAll(vehicleTypesWithPricingPlan(null), 0, null);

VehicleFilter filter = new VehicleFilter(pricingPlanCache, vehicleTypeCache, stationCache);
VehicleFilter filter = new VehicleFilter(
pricingPlanCache,
vehicleTypeCache,
stationCache
);

GBFSVehicle vehicle = new GBFSVehicle();
vehicle.setVehicleId("VehicleWithoutPricingPlan");
Expand Down

0 comments on commit 6c66619

Please sign in to comment.