org.opentripplanner.ext.legacygraphqlapi.datafetchers.LegacyGraphQLLegImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of otp Show documentation
Show all versions of otp Show documentation
The OpenTripPlanner multimodal journey planning system
package org.opentripplanner.ext.legacygraphqlapi.datafetchers;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import org.opentripplanner.api.mapping.ServiceDateMapper;
import org.opentripplanner.ext.legacygraphqlapi.LegacyGraphQLRequestContext;
import org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLDataFetchers;
import org.opentripplanner.model.Agency;
import org.opentripplanner.model.Route;
import org.opentripplanner.model.Trip;
import org.opentripplanner.model.plan.Leg;
import org.opentripplanner.model.plan.StopArrival;
import org.opentripplanner.model.plan.WalkStep;
import org.opentripplanner.routing.RoutingService;
import org.opentripplanner.util.model.EncodedPolylineBean;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
public class LegacyGraphQLLegImpl implements LegacyGraphQLDataFetchers.LegacyGraphQLLeg {
@Override
public DataFetcher startTime() {
return environment -> getSource(environment).startTime.getTime().getTime();
}
@Override
public DataFetcher endTime() {
return environment -> getSource(environment).endTime.getTime().getTime();
}
@Override
public DataFetcher departureDelay() {
return environment -> getSource(environment).departureDelay;
}
@Override
public DataFetcher arrivalDelay() {
return environment -> getSource(environment).arrivalDelay;
}
@Override
public DataFetcher mode() {
return environment -> getSource(environment).mode.name();
}
@Override
public DataFetcher duration() {
return environment -> (double) getSource(environment).getDuration();
}
@Override
public DataFetcher legGeometry() {
return environment -> getSource(environment).legGeometry;
}
@Override
public DataFetcher agency() {
return environment -> getSource(environment).getAgency();
}
@Override
public DataFetcher realTime() {
return environment -> getSource(environment).realTime;
}
// TODO
@Override
public DataFetcher realtimeState() {
return environment -> null;
}
@Override
public DataFetcher distance() {
return environment -> getSource(environment).distanceMeters;
}
@Override
public DataFetcher transitLeg() {
return environment -> getSource(environment).isTransitLeg();
}
@Override
public DataFetcher rentedBike() {
return environment -> getSource(environment).rentedBike;
}
@Override
public DataFetcher from() {
return environment -> {
Leg source = getSource(environment);
return new StopArrival(source.from, source.startTime, source.startTime);
};
}
@Override
public DataFetcher to() {
return environment -> {
Leg source = getSource(environment);
return new StopArrival(source.to, source.endTime, source.endTime);
};
}
@Override
public DataFetcher route() {
return environment -> getSource(environment).getRoute();
}
@Override
public DataFetcher trip() {
return environment -> getSource(environment).getTrip();
}
@Override
public DataFetcher serviceDate() {
return environment -> ServiceDateMapper.mapToApi(getSource(environment).serviceDate);
}
@Override
public DataFetcher> intermediateStops() {
return environment -> {
List intermediateStops = getSource(environment).intermediateStops;
if (intermediateStops == null) return null;
RoutingService routingService = getRoutingService(environment);
return intermediateStops.stream()
.map(intermediateStop -> intermediateStop.place)
.filter(place -> place.stopId != null)
.map(place -> routingService.getStopForId(place.stopId))
.filter(Objects::nonNull)
.collect(Collectors.toList());
};
}
@Override
public DataFetcher> intermediatePlaces() {
return environment -> getSource(environment).intermediateStops;
}
// TODO
@Override
public DataFetcher intermediatePlace() {
return environment -> false;
}
@Override
public DataFetcher> steps() {
return environment -> getSource(environment).walkSteps;
}
@Override
public DataFetcher pickupType() {
return environment -> {
if (getSource(environment).boardRule == null) return "SCHEDULED";
switch (getSource(environment).boardRule) {
case "impossible": return "NONE";
case "mustPhone": return "CALL_AGENCY";
case "coordinateWithDriver": return "COORDINATE_WITH_DRIVER";
default: return "SCHEDULED";
}
};
}
@Override
public DataFetcher dropoffType() {
return environment -> {
if (getSource(environment).alightRule == null) return "SCHEDULED";
switch (getSource(environment).alightRule) {
case "impossible": return "NONE";
case "mustPhone": return "CALL_AGENCY";
case "coordinateWithDriver": return "COORDINATE_WITH_DRIVER";
default: return "SCHEDULED";
}
};
}
@Override
public DataFetcher interlineWithPreviousLeg() {
return environment -> getSource(environment).interlineWithPreviousLeg;
}
private RoutingService getRoutingService(DataFetchingEnvironment environment) {
return environment.getContext().getRoutingService();
}
private Leg getSource(DataFetchingEnvironment environment) {
return environment.getSource();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy