Skip to content

Commit

Permalink
Map missing values to null
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Nov 25, 2021
1 parent 57126c4 commit 130c3f2
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import graphql.schema.DataFetchingEnvironment;
import org.opentripplanner.ext.legacygraphqlapi.LegacyGraphQLRequestContext;
import org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLDataFetchers;
import org.opentripplanner.model.StopTime;
import org.opentripplanner.model.Trip;
import org.opentripplanner.model.TripTimeOnDate;
import org.opentripplanner.routing.RoutingService;
Expand All @@ -17,27 +18,27 @@ public DataFetcher<Object> stop() {

@Override
public DataFetcher<Integer> scheduledArrival() {
return environment -> getSource(environment).getScheduledArrival();
return environment -> missingValueToNull(getSource(environment).getScheduledArrival());
}

@Override
public DataFetcher<Integer> realtimeArrival() {
return environment -> getSource(environment).getRealtimeArrival();
return environment -> missingValueToNull(getSource(environment).getRealtimeArrival());
}

@Override
public DataFetcher<Integer> arrivalDelay() {
return environment -> getSource(environment).getArrivalDelay();
return environment -> missingValueToNull(getSource(environment).getArrivalDelay());
}

@Override
public DataFetcher<Integer> scheduledDeparture() {
return environment -> getSource(environment).getScheduledDeparture();
return environment -> missingValueToNull(getSource(environment).getScheduledDeparture());
}

@Override
public DataFetcher<Integer> realtimeDeparture() {
return environment -> getSource(environment).getRealtimeDeparture();
return environment -> missingValueToNull(getSource(environment).getRealtimeDeparture());
}

@Override
Expand Down Expand Up @@ -108,4 +109,17 @@ private RoutingService getRoutingService(DataFetchingEnvironment environment) {
private TripTimeOnDate getSource(DataFetchingEnvironment environment) {
return environment.getSource();
}

/**
* Generally the missing values are removed during the graph build. However, for flex
* trips they are not and have to be converted to null here.
*/
private Integer missingValueToNull(int value) {
if(value == StopTime.MISSING_VALUE) {
return null;
}
else {
return value;
}
}
}

0 comments on commit 130c3f2

Please sign in to comment.