Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for groupOfLines in top level Transmodel API [changelog skip] #4232

Merged
merged 2 commits into from Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/sandbox/TransmodelApi.md
Expand Up @@ -49,6 +49,8 @@
[#4161](https://github.com/opentripplanner/OpenTripPlanner/pull/4161)
- Add possibility to filter dated service journeys by replacementFor
[#4198](https://github.com/opentripplanner/OpenTripPlanner/pull/4198)
- Add support for groupOfLines in top level query
[#4232](https://github.com/opentripplanner/OpenTripPlanner/pull/4232)

## Documentation

Expand Down
Expand Up @@ -757,7 +757,7 @@ private GraphQLSchema create() {

if (stops.isEmpty()) {
return new DefaultConnection<>(
Collections.emptyList(),
emptyList(),
new DefaultPageInfo(null, null, false, false)
);
}
Expand Down Expand Up @@ -1183,6 +1183,35 @@ private GraphQLSchema create() {
})
.build()
)
.field(
GraphQLFieldDefinition
.newFieldDefinition()
.name("groupOfLines")
.description("Get a single group of lines based on its id")
.type(groupOfLinesType)
.argument(
GraphQLArgument
.newArgument()
.name("id")
.type(new GraphQLNonNull(Scalars.GraphQLString))
.build()
)
.dataFetcher(environment ->
GqlUtil
.getTransitService(environment)
.getGroupOfRoutesForId(TransitIdMapper.mapIDToDomain(environment.getArgument("id")))
)
.build()
)
.field(
GraphQLFieldDefinition
.newFieldDefinition()
.name("groupsOfLines")
.description("Get all groups of lines")
.type(new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(groupOfLinesType))))
.dataFetcher(environment -> GqlUtil.getTransitService(environment).getGroupsOfRoutes())
.build()
)
.field(
GraphQLFieldDefinition
.newFieldDefinition()
Expand Down
Expand Up @@ -2,9 +2,11 @@

import graphql.Scalars;
import graphql.schema.GraphQLFieldDefinition;
import graphql.schema.GraphQLList;
import graphql.schema.GraphQLNonNull;
import graphql.schema.GraphQLObjectType;
import org.opentripplanner.ext.transmodelapi.mapping.TransitIdMapper;
import org.opentripplanner.ext.transmodelapi.support.GqlUtil;
import org.opentripplanner.transit.model.network.GroupOfRoutes;

public class GroupOfLinesType {
Expand Down Expand Up @@ -62,6 +64,17 @@ public static GraphQLObjectType create() {
.dataFetcher(env -> ((GroupOfRoutes) env.getSource()).getDescription())
.build()
)
.field(
GraphQLFieldDefinition
.newFieldDefinition()
.name("lines")
.description("All lines part of this group of lines")
.type(new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(LineType.REF))))
.dataFetcher(env ->
GqlUtil.getTransitService(env).getRoutesForGroupOfRoutes(env.getSource())
)
.build()
)
.build();
}
}
17 changes: 17 additions & 0 deletions src/main/java/org/opentripplanner/routing/graph/GraphIndex.java
Expand Up @@ -27,6 +27,7 @@
import org.opentripplanner.model.calendar.ServiceDate;
import org.opentripplanner.routing.vertextype.TransitStopVertex;
import org.opentripplanner.transit.model.framework.FeedScopedId;
import org.opentripplanner.transit.model.network.GroupOfRoutes;
import org.opentripplanner.transit.model.network.Route;
import org.opentripplanner.transit.model.organization.Agency;
import org.opentripplanner.transit.model.organization.Operator;
Expand Down Expand Up @@ -58,6 +59,8 @@ public class GraphIndex {
private final Map<ServiceDate, TIntSet> serviceCodesRunningForDate = new HashMap<>();
private final Map<FeedScopedId, TripOnServiceDate> tripOnServiceDateById = new HashMap<>();
private final Map<TripIdAndServiceDate, TripOnServiceDate> tripOnServiceDateForTripAndDay = new HashMap<>();
private final Multimap<GroupOfRoutes, Route> routesForGroupOfRoutes = ArrayListMultimap.create();
private final Map<FeedScopedId, GroupOfRoutes> groupOfRoutesForId = new HashMap<>();
private FlexIndex flexIndex = null;

public GraphIndex(Graph graph) {
Expand Down Expand Up @@ -101,6 +104,12 @@ public GraphIndex(Graph graph) {
}
for (Route route : patternsForRoute.asMap().keySet()) {
routeForId.put(route.getId(), route);
for (GroupOfRoutes groupOfRoutes : route.getGroupsOfRoutes()) {
routesForGroupOfRoutes.put(groupOfRoutes, route);
}
}
for (GroupOfRoutes groupOfRoutes : routesForGroupOfRoutes.keySet()) {
groupOfRoutesForId.put(groupOfRoutes.getId(), groupOfRoutes);
}
for (MultiModalStation multiModalStation : graph.multiModalStationById.values()) {
for (Station childStation : multiModalStation.getChildStations()) {
Expand Down Expand Up @@ -244,6 +253,14 @@ public Map<Station, MultiModalStation> getMultiModalStationForStations() {
return multiModalStationForStations;
}

public Multimap<GroupOfRoutes, Route> getRoutesForGroupOfRoutes() {
return routesForGroupOfRoutes;
}

public Map<FeedScopedId, GroupOfRoutes> getGroupOfRoutesForId() {
return groupOfRoutesForId;
}

public HashGridSpatialIndex<TransitStopVertex> getStopSpatialIndex() {
return stopSpatialIndex;
}
Expand Down
Expand Up @@ -34,6 +34,7 @@
import org.opentripplanner.transit.model.basic.WgsCoordinate;
import org.opentripplanner.transit.model.framework.FeedScopedId;
import org.opentripplanner.transit.model.framework.TransitEntity;
import org.opentripplanner.transit.model.network.GroupOfRoutes;
import org.opentripplanner.transit.model.network.Route;
import org.opentripplanner.transit.model.network.TransitMode;
import org.opentripplanner.transit.model.organization.Agency;
Expand Down Expand Up @@ -393,6 +394,21 @@ public Collection<TripPattern> getPatternsForStop(
);
}

@Override
public Collection<GroupOfRoutes> getGroupsOfRoutes() {
return graphIndex.getRoutesForGroupOfRoutes().keySet();
}

@Override
public Collection<Route> getRoutesForGroupOfRoutes(GroupOfRoutes groupOfRoutes) {
return graphIndex.getRoutesForGroupOfRoutes().get(groupOfRoutes);
}

@Override
public GroupOfRoutes getGroupOfRoutesForId(FeedScopedId id) {
return graphIndex.getGroupOfRoutesForId().get(id);
}

/**
* Get the most up-to-date timetable for the given TripPattern, as of right now. There should
* probably be a less awkward way to do this that just gets the latest entry from the resolver
Expand Down
Expand Up @@ -27,6 +27,7 @@
import org.opentripplanner.transit.model.basic.WgsCoordinate;
import org.opentripplanner.transit.model.framework.FeedScopedId;
import org.opentripplanner.transit.model.framework.TransitEntity;
import org.opentripplanner.transit.model.network.GroupOfRoutes;
import org.opentripplanner.transit.model.network.Route;
import org.opentripplanner.transit.model.network.TransitMode;
import org.opentripplanner.transit.model.organization.Agency;
Expand Down Expand Up @@ -138,6 +139,12 @@ List<TripTimeOnDate> stopTimesForPatternAtStop(

Collection<TripPattern> getPatternsForStop(StopLocation stop, boolean includeRealtimeUpdates);

Collection<GroupOfRoutes> getGroupsOfRoutes();

Collection<Route> getRoutesForGroupOfRoutes(GroupOfRoutes groupOfRoutes);

GroupOfRoutes getGroupOfRoutesForId(FeedScopedId id);

Timetable getTimetableForTripPattern(TripPattern tripPattern, ServiceDate serviceDate);

TripOnServiceDate getTripOnServiceDateForTripAndDay(FeedScopedId tripId, ServiceDate serviceDate);
Expand Down