org.opentripplanner.ext.legacygraphqlapi.datafetchers.LegacyGraphQLPlanImpl 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.PlannerErrorMapper;
import org.opentripplanner.api.resource.DebugOutput;
import org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLDataFetchers;
import org.opentripplanner.model.plan.Itinerary;
import org.opentripplanner.model.plan.StopArrival;
import org.opentripplanner.routing.api.response.RoutingResponse;
import org.opentripplanner.routing.api.response.TripSearchMetadata;
import java.util.stream.Collectors;
public class LegacyGraphQLPlanImpl implements LegacyGraphQLDataFetchers.LegacyGraphQLPlan {
@Override
public DataFetcher date() {
return environment -> getSource(environment).getTripPlan().date.getTime();
}
@Override
public DataFetcher from() {
return environment -> new StopArrival(getSource(environment).getTripPlan().from, null, null);
}
@Override
public DataFetcher to() {
return environment -> new StopArrival(getSource(environment).getTripPlan().to, null, null);
}
@Override
public DataFetcher> itineraries() {
return environment -> getSource(environment).getTripPlan().itineraries;
}
@Override
public DataFetcher> messageEnums() {
return environment -> getSource(environment)
.getRoutingErrors()
.stream()
.map(routingError -> routingError.code)
.map(Enum::name)
.collect(Collectors.toList());
}
@Override
public DataFetcher> messageStrings() {
return environment -> getSource(environment)
.getRoutingErrors()
.stream()
.map(PlannerErrorMapper::mapMessage)
.map(plannerError -> plannerError.message.get(environment.getLocale()))
.collect(Collectors.toList());
}
@Override
public DataFetcher prevDateTime() {
return environment -> {
TripSearchMetadata metadata = getSource(environment).getMetadata();
if ( metadata == null || metadata.prevDateTime == null ) { return null; }
return metadata.prevDateTime.getEpochSecond() * 1000;
};
}
@Override
public DataFetcher nextDateTime() {
return environment -> {
TripSearchMetadata metadata = getSource(environment).getMetadata();
if ( metadata == null || metadata.nextDateTime == null ) { return null; }
return metadata.nextDateTime.getEpochSecond() * 1000;
};
}
@Override
public DataFetcher searchWindowUsed() {
return environment -> {
TripSearchMetadata metadata = getSource(environment).getMetadata();
if ( metadata == null || metadata.searchWindowUsed == null ) { return null; }
return metadata.searchWindowUsed.toSeconds();
};
}
@Override
public DataFetcher debugOutput() {
return environment -> getSource(environment).getDebugAggregator().finishedRendering();
}
private RoutingResponse getSource(DataFetchingEnvironment environment) {
return environment.getSource();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy