Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mapper for GTFS GraphQL real time state #6099

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.opentripplanner.apis.gtfs.generated.GraphQLDataFetchers;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes;
import org.opentripplanner.apis.gtfs.mapping.NumberMapper;
import org.opentripplanner.apis.gtfs.mapping.RealtimeStateMapper;
import org.opentripplanner.ext.restapi.mapping.LocalDateMapper;
import org.opentripplanner.ext.ridehailing.model.RideEstimate;
import org.opentripplanner.ext.ridehailing.model.RideHailingLeg;
Expand Down Expand Up @@ -191,10 +192,10 @@ public DataFetcher<Boolean> realTime() {
}

@Override
public DataFetcher<String> realtimeState() {
public DataFetcher<GraphQLTypes.GraphQLRealtimeState> realtimeState() {
return environment -> {
var state = getSource(environment).getRealTimeState();
return (state != null) ? state.name() : null;
return RealtimeStateMapper.map(state);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import org.opentripplanner.apis.gtfs.generated.GraphQLDataFetchers;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes;
import org.opentripplanner.apis.gtfs.mapping.RealtimeStateMapper;
import org.opentripplanner.framework.graphql.GraphQLUtils;
import org.opentripplanner.model.StopTime;
import org.opentripplanner.model.TripTimeOnDate;
import org.opentripplanner.transit.model.timetable.RealTimeState;
import org.opentripplanner.transit.model.timetable.Trip;

public class StoptimeImpl implements GraphQLDataFetchers.GraphQLStoptime {
Expand Down Expand Up @@ -67,11 +68,11 @@ public DataFetcher<Integer> realtimeDeparture() {
}

@Override
public DataFetcher<String> realtimeState() {
public DataFetcher<GraphQLTypes.GraphQLRealtimeState> realtimeState() {
return environment ->
getSource(environment).isCanceledEffectively()
? RealTimeState.CANCELED.name()
: getSource(environment).getRealTimeState().name();
? GraphQLTypes.GraphQLRealtimeState.CANCELED
: RealtimeStateMapper.map(getSource(environment).getRealTimeState());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLBikesAllowed;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLInputField;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLOccupancyStatus;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLRealtimeState;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLRelativeDirection;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLRoutingErrorCode;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLTransitMode;
Expand Down Expand Up @@ -504,7 +505,7 @@ public interface GraphQLLeg {

public DataFetcher<Boolean> realTime();

public DataFetcher<String> realtimeState();
public DataFetcher<GraphQLRealtimeState> realtimeState();

public DataFetcher<Boolean> rentedBike();

Expand Down Expand Up @@ -1082,7 +1083,7 @@ public interface GraphQLStoptime {

public DataFetcher<Integer> realtimeDeparture();

public DataFetcher<String> realtimeState();
public DataFetcher<GraphQLRealtimeState> realtimeState();

public DataFetcher<Integer> scheduledArrival();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ config:
PlanConnection: graphql.execution.DataFetcherResult<org.opentripplanner.routing.api.response.RoutingResponse>
PlanEdge: graphql.relay.DefaultEdge#DefaultEdge<Itinerary>
PlanPageInfo: org.opentripplanner.apis.gtfs.model.PlanPageInfo#PlanPageInfo
RealtimeState: String
RealtimeState: org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLRealtimeState#GraphQLRealtimeState
RelativeDirection: org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLRelativeDirection#GraphQLRelativeDirection
Route: org.opentripplanner.transit.model.network.Route#Route
RoutingError: org.opentripplanner.routing.api.response.RoutingError#RoutingError
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.opentripplanner.apis.gtfs.mapping;

import javax.annotation.Nullable;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes;
import org.opentripplanner.transit.model.timetable.RealTimeState;

/**
* Maps from the internal model to the API one.
*/
public class RealtimeStateMapper {

public static GraphQLTypes.GraphQLRealtimeState map(@Nullable RealTimeState state) {
if (state == null) return null;
return switch (state) {
case SCHEDULED -> GraphQLTypes.GraphQLRealtimeState.SCHEDULED;
case UPDATED -> GraphQLTypes.GraphQLRealtimeState.UPDATED;
case CANCELED, DELETED -> GraphQLTypes.GraphQLRealtimeState.CANCELED;
case ADDED -> GraphQLTypes.GraphQLRealtimeState.ADDED;
case MODIFIED -> GraphQLTypes.GraphQLRealtimeState.MODIFIED;
};
}
}
Loading