use of org.opentripplanner.routing.RoutingService in project OpenTripPlanner by opentripplanner.
the class GtfsRealtimeAlertsUpdater method setup.
@Override
public void setup(Graph graph) {
TransitAlertService transitAlertService = new TransitAlertServiceImpl(graph);
if (fuzzyTripMatching) {
this.fuzzyTripMatcher = new GtfsRealtimeFuzzyTripMatcher(new RoutingService(graph));
}
this.transitAlertService = transitAlertService;
if (updateHandler == null) {
updateHandler = new AlertsUpdateHandler();
}
updateHandler.setEarlyStart(earlyStart);
updateHandler.setFeedId(feedId);
updateHandler.setTransitAlertService(transitAlertService);
updateHandler.setFuzzyTripMatcher(fuzzyTripMatcher);
}
use of org.opentripplanner.routing.RoutingService in project OpenTripPlanner by opentripplanner.
the class LegacyGraphQLIndex method getGraphQLExecutionResult.
static HashMap<String, Object> getGraphQLExecutionResult(String query, Router router, Map<String, Object> variables, String operationName, int maxResolves, int timeoutMs, Locale locale) {
MaxQueryComplexityInstrumentation instrumentation = new MaxQueryComplexityInstrumentation(maxResolves);
GraphQL graphQL = GraphQL.newGraphQL(indexSchema).instrumentation(instrumentation).build();
if (variables == null) {
variables = new HashMap<>();
}
LegacyGraphQLRequestContext requestContext = new LegacyGraphQLRequestContext(router, new RoutingService(router.graph));
ExecutionInput executionInput = ExecutionInput.newExecutionInput().query(query).operationName(operationName).context(requestContext).root(router).variables(variables).locale(locale).build();
HashMap<String, Object> content = new HashMap<>();
ExecutionResult executionResult;
try {
executionResult = graphQL.executeAsync(executionInput).get(timeoutMs, TimeUnit.MILLISECONDS);
if (!executionResult.getErrors().isEmpty()) {
content.put("errors", mapErrors(executionResult.getErrors()));
}
if (executionResult.getData() != null) {
content.put("data", executionResult.getData());
}
} catch (Exception e) {
Throwable reason = e;
if (e.getCause() != null) {
reason = e.getCause();
}
LOG.warn("Exception during graphQL.execute: " + reason.getMessage(), reason);
content.put("errors", mapErrors(List.of(reason)));
}
return content;
}
use of org.opentripplanner.routing.RoutingService in project OpenTripPlanner by opentripplanner.
the class TransmodelGraph method getGraphQLExecutionResult.
HashMap<String, Object> getGraphQLExecutionResult(String query, Router router, Map<String, Object> variables, String operationName, int maxResolves) {
MaxQueryComplexityInstrumentation instrumentation = new MaxQueryComplexityInstrumentation(maxResolves);
GraphQL graphQL = GraphQL.newGraphQL(indexSchema).instrumentation(instrumentation).build();
if (variables == null) {
variables = new HashMap<>();
}
TransmodelRequestContext transmodelRequestContext = new TransmodelRequestContext(router, new RoutingService(router.graph));
ExecutionInput executionInput = ExecutionInput.newExecutionInput().query(query).operationName(operationName).context(transmodelRequestContext).root(router).variables(variables).build();
HashMap<String, Object> content = new HashMap<>();
ExecutionResult executionResult;
try {
executionResult = graphQL.execute(executionInput);
if (!executionResult.getErrors().isEmpty()) {
content.put("errors", mapErrors(executionResult.getErrors()));
}
if (executionResult.getData() != null) {
content.put("data", executionResult.getData());
}
} catch (RuntimeException ge) {
LOG.warn("Exception during graphQL.execute: " + ge.getMessage(), ge);
content.put("errors", mapErrors(Arrays.asList(ge)));
}
return content;
}
use of org.opentripplanner.routing.RoutingService in project OpenTripPlanner by opentripplanner.
the class LegacyGraphQLStopImpl method stopTimesForPattern.
@Override
public DataFetcher<Iterable<TripTimeShort>> stopTimesForPattern() {
return environment -> getValue(environment, stop -> {
RoutingService routingService = getRoutingService(environment);
LegacyGraphQLTypes.LegacyGraphQLStopStopTimesForPatternArgs args = new LegacyGraphQLTypes.LegacyGraphQLStopStopTimesForPatternArgs(environment.getArguments());
TripPattern pattern = routingService.getTripPatternForId(FeedScopedId.parseId(args.getLegacyGraphQLId()));
if (pattern == null) {
return null;
}
;
return routingService.stopTimesForPatternAtStop(stop, pattern, args.getLegacyGraphQLStartTime(), args.getLegacyGraphQLTimeRange(), args.getLegacyGraphQLNumberOfDepartures(), args.getLegacyGraphQLOmitNonPickups());
}, station -> null);
}
use of org.opentripplanner.routing.RoutingService in project OpenTripPlanner by opentripplanner.
the class StopPlaceType method fetchStopPlaceById.
public static MonoOrMultiModalStation fetchStopPlaceById(FeedScopedId id, DataFetchingEnvironment environment) {
RoutingService routingService = GqlUtil.getRoutingService(environment);
Station station = routingService.getStationById(id);
if (station != null) {
return new MonoOrMultiModalStation(station, routingService.getMultiModalStationForStations().get(station));
}
MultiModalStation multiModalStation = routingService.getMultiModalStation(id);
if (multiModalStation != null) {
return new MonoOrMultiModalStation(multiModalStation);
}
return null;
}
Aggregations