Search in sources :

Example 16 with RoutingService

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);
}
Also used : TransitAlertService(org.opentripplanner.routing.services.TransitAlertService) GtfsRealtimeFuzzyTripMatcher(org.opentripplanner.updater.GtfsRealtimeFuzzyTripMatcher) RoutingService(org.opentripplanner.routing.RoutingService) TransitAlertServiceImpl(org.opentripplanner.routing.impl.TransitAlertServiceImpl)

Example 17 with RoutingService

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;
}
Also used : HashMap(java.util.HashMap) GraphQL(graphql.GraphQL) RoutingService(org.opentripplanner.routing.RoutingService) ExecutionResult(graphql.ExecutionResult) ExecutionInput(graphql.ExecutionInput) MaxQueryComplexityInstrumentation(graphql.analysis.MaxQueryComplexityInstrumentation)

Example 18 with RoutingService

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;
}
Also used : HashMap(java.util.HashMap) GraphQL(graphql.GraphQL) RoutingService(org.opentripplanner.routing.RoutingService) ExecutionResult(graphql.ExecutionResult) ExecutionInput(graphql.ExecutionInput) MaxQueryComplexityInstrumentation(graphql.analysis.MaxQueryComplexityInstrumentation)

Example 19 with RoutingService

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);
}
Also used : DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) StopAtDistance(org.opentripplanner.routing.graphfinder.StopAtDistance) RoutingService(org.opentripplanner.routing.RoutingService) StopTimesInPattern(org.opentripplanner.model.StopTimesInPattern) Function(java.util.function.Function) LegacyGraphQLTypes(org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLTypes) ServiceDate(org.opentripplanner.model.calendar.ServiceDate) LegacyGraphQLRequestContext(org.opentripplanner.ext.legacygraphqlapi.LegacyGraphQLRequestContext) ArrayList(java.util.ArrayList) TripTimeShort(org.opentripplanner.model.TripTimeShort) Map(java.util.Map) DataFetcher(graphql.schema.DataFetcher) ParseException(java.text.ParseException) FeedScopedId(org.opentripplanner.model.FeedScopedId) Station(org.opentripplanner.model.Station) TripPattern(org.opentripplanner.model.TripPattern) Stop(org.opentripplanner.model.Stop) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) GeometryUtils(org.opentripplanner.common.geometry.GeometryUtils) TransitAlert(org.opentripplanner.routing.alertpatch.TransitAlert) List(java.util.List) Route(org.opentripplanner.model.Route) Stream(java.util.stream.Stream) SimpleTransfer(org.opentripplanner.model.SimpleTransfer) LegacyGraphQLDataFetchers(org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLDataFetchers) Relay(graphql.relay.Relay) Comparator(java.util.Comparator) Edge(org.opentripplanner.routing.graph.Edge) RoutingService(org.opentripplanner.routing.RoutingService) TripPattern(org.opentripplanner.model.TripPattern) LegacyGraphQLTypes(org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLTypes)

Example 20 with RoutingService

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;
}
Also used : MultiModalStation(org.opentripplanner.model.MultiModalStation) Station(org.opentripplanner.model.Station) RoutingService(org.opentripplanner.routing.RoutingService) MultiModalStation(org.opentripplanner.model.MultiModalStation)

Aggregations

RoutingService (org.opentripplanner.routing.RoutingService)32 GET (javax.ws.rs.GET)17 Path (javax.ws.rs.Path)16 Stop (org.opentripplanner.model.Stop)13 FeedScopedId (org.opentripplanner.model.FeedScopedId)12 TripPattern (org.opentripplanner.model.TripPattern)9 List (java.util.List)8 ApiStop (org.opentripplanner.api.model.ApiStop)8 Trip (org.opentripplanner.model.Trip)8 HashSet (java.util.HashSet)7 Collectors (java.util.stream.Collectors)7 Collection (java.util.Collection)5 Stream (java.util.stream.Stream)5 AlertMapper (org.opentripplanner.api.mapping.AlertMapper)5 Route (org.opentripplanner.model.Route)5 StopTimesInPattern (org.opentripplanner.model.StopTimesInPattern)5 TripTimeShort (org.opentripplanner.model.TripTimeShort)5 Relay (graphql.relay.Relay)4 ArrayList (java.util.ArrayList)4 Objects (java.util.Objects)4