org.opentripplanner.ext.legacygraphqlapi.datafetchers.LegacyGraphQLTripImpl Maven / Gradle / Ivy
package org.opentripplanner.ext.legacygraphqlapi.datafetchers;
import graphql.relay.Relay;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import org.locationtech.jts.geom.LineString;
import org.opentripplanner.ext.legacygraphqlapi.LegacyGraphQLRequestContext;
import org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLDataFetchers;
import org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLTypes;
import org.opentripplanner.model.Route;
import org.opentripplanner.model.Stop;
import org.opentripplanner.model.Timetable;
import org.opentripplanner.model.Trip;
import org.opentripplanner.model.TripPattern;
import org.opentripplanner.model.TripTimeShort;
import org.opentripplanner.model.calendar.ServiceDate;
import org.opentripplanner.routing.RoutingService;
import org.opentripplanner.routing.alertpatch.TransitAlert;
import org.opentripplanner.routing.core.ServiceDay;
import org.opentripplanner.routing.trippattern.TripTimes;
import org.opentripplanner.util.PolylineEncoder;
import org.opentripplanner.util.model.EncodedPolylineBean;
import java.text.ParseException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class LegacyGraphQLTripImpl implements LegacyGraphQLDataFetchers.LegacyGraphQLTrip {
@Override
public DataFetcher id() {
return environment -> new Relay.ResolvedGlobalId("Trip",
getSource(environment).getId().toString());
}
@Override
public DataFetcher gtfsId() {
return environment -> getSource(environment).getId().toString();
}
@Override
public DataFetcher route() {
return environment -> getSource(environment).getRoute();
}
@Override
public DataFetcher serviceId() {
return environment -> getSource(environment).getServiceId().toString();
}
@Override
public DataFetcher> activeDates() {
return environment -> getRoutingService(environment).getCalendarService()
.getServiceDatesForServiceId(getSource(environment).getServiceId())
.stream()
.map(ServiceDate::asCompactString)
.collect(Collectors.toList());
}
@Override
public DataFetcher tripShortName() {
return environment -> getSource(environment).getTripShortName();
}
@Override
public DataFetcher tripHeadsign() {
return environment -> getSource(environment).getTripHeadsign();
}
@Override
public DataFetcher routeShortName() {
return environment -> {
Trip trip = getSource(environment);
return trip.getRouteShortName() != null ? trip.getRouteShortName() : trip.getRoute().getShortName();
};
}
@Override
public DataFetcher directionId() {
return environment -> getSource(environment).getDirectionId();
}
@Override
public DataFetcher blockId() {
return environment -> getSource(environment).getBlockId();
}
@Override
public DataFetcher shapeId() {
return environment -> getSource(environment).getShapeId().toString();
}
@Override
public DataFetcher