Skip to content

Commit afb98cd

Browse files
committed
Revert "Revert "Revert new filter API temporarily""
This reverts commit 04d2cb4.
1 parent 4d633b1 commit afb98cd

File tree

12 files changed

+12
-561
lines changed

12 files changed

+12
-561
lines changed

application/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -5110,72 +5110,6 @@ public void setGraphQLSlack(java.time.Duration slack) {
51105110
}
51115111
}
51125112

5113-
public static class GraphQLTransitFilterInput {
5114-
5115-
private List<GraphQLTransitFilterSelectInput> exclude;
5116-
private List<GraphQLTransitFilterSelectInput> include;
5117-
5118-
public GraphQLTransitFilterInput(Map<String, Object> args) {
5119-
if (args != null) {
5120-
if (args.get("exclude") != null) {
5121-
this.exclude = ((List<Map<String, Object>>) args.get("exclude")).stream()
5122-
.map(o -> o == null ? null : new GraphQLTransitFilterSelectInput(o))
5123-
.collect(Collectors.toList());
5124-
}
5125-
if (args.get("include") != null) {
5126-
this.include = ((List<Map<String, Object>>) args.get("include")).stream()
5127-
.map(o -> o == null ? null : new GraphQLTransitFilterSelectInput(o))
5128-
.collect(Collectors.toList());
5129-
}
5130-
}
5131-
}
5132-
5133-
public List<GraphQLTransitFilterSelectInput> getGraphQLExclude() {
5134-
return this.exclude;
5135-
}
5136-
5137-
public List<GraphQLTransitFilterSelectInput> getGraphQLInclude() {
5138-
return this.include;
5139-
}
5140-
5141-
public void setGraphQLExclude(List<GraphQLTransitFilterSelectInput> exclude) {
5142-
this.exclude = exclude;
5143-
}
5144-
5145-
public void setGraphQLInclude(List<GraphQLTransitFilterSelectInput> include) {
5146-
this.include = include;
5147-
}
5148-
}
5149-
5150-
public static class GraphQLTransitFilterSelectInput {
5151-
5152-
private List<String> agencies;
5153-
private List<String> routes;
5154-
5155-
public GraphQLTransitFilterSelectInput(Map<String, Object> args) {
5156-
if (args != null) {
5157-
this.agencies = (List<String>) args.get("agencies");
5158-
this.routes = (List<String>) args.get("routes");
5159-
}
5160-
}
5161-
5162-
public List<String> getGraphQLAgencies() {
5163-
return this.agencies;
5164-
}
5165-
5166-
public List<String> getGraphQLRoutes() {
5167-
return this.routes;
5168-
}
5169-
5170-
public void setGraphQLAgencies(List<String> agencies) {
5171-
this.agencies = agencies;
5172-
}
5173-
5174-
public void setGraphQLRoutes(List<String> routes) {
5175-
this.routes = routes;
5176-
}
5177-
}
5178-
51795113
/**
51805114
* Transit modes include modes that are used within organized transportation networks
51815115
* run by public transportation authorities, taxi companies etc.
@@ -5221,19 +5155,13 @@ public static class GraphQLTransitPreferencesInput {
52215155

52225156
private GraphQLAlightPreferencesInput alight;
52235157
private GraphQLBoardPreferencesInput board;
5224-
private List<GraphQLTransitFilterInput> filters;
52255158
private GraphQLTimetablePreferencesInput timetable;
52265159
private GraphQLTransferPreferencesInput transfer;
52275160

52285161
public GraphQLTransitPreferencesInput(Map<String, Object> args) {
52295162
if (args != null) {
52305163
this.alight = new GraphQLAlightPreferencesInput((Map<String, Object>) args.get("alight"));
52315164
this.board = new GraphQLBoardPreferencesInput((Map<String, Object>) args.get("board"));
5232-
if (args.get("filters") != null) {
5233-
this.filters = ((List<Map<String, Object>>) args.get("filters")).stream()
5234-
.map(o -> o == null ? null : new GraphQLTransitFilterInput(o))
5235-
.collect(Collectors.toList());
5236-
}
52375165
this.timetable = new GraphQLTimetablePreferencesInput(
52385166
(Map<String, Object>) args.get("timetable")
52395167
);
@@ -5251,10 +5179,6 @@ public GraphQLBoardPreferencesInput getGraphQLBoard() {
52515179
return this.board;
52525180
}
52535181

5254-
public List<GraphQLTransitFilterInput> getGraphQLFilters() {
5255-
return this.filters;
5256-
}
5257-
52585182
public GraphQLTimetablePreferencesInput getGraphQLTimetable() {
52595183
return this.timetable;
52605184
}
@@ -5271,10 +5195,6 @@ public void setGraphQLBoard(GraphQLBoardPreferencesInput board) {
52715195
this.board = board;
52725196
}
52735197

5274-
public void setGraphQLFilters(List<GraphQLTransitFilterInput> filters) {
5275-
this.filters = filters;
5276-
}
5277-
52785198
public void setGraphQLTimetable(GraphQLTimetablePreferencesInput timetable) {
52795199
this.timetable = timetable;
52805200
}

application/src/main/java/org/opentripplanner/apis/gtfs/mapping/routerequest/FilterMapper.java

Lines changed: 0 additions & 60 deletions
This file was deleted.

application/src/main/java/org/opentripplanner/apis/gtfs/mapping/routerequest/ModePreferencesMapper.java

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import graphql.schema.DataFetchingEnvironment;
88
import java.util.List;
9-
import java.util.Optional;
109
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes;
1110
import org.opentripplanner.apis.gtfs.mapping.TransitModeMapper;
1211
import org.opentripplanner.routing.api.request.StreetMode;
@@ -16,7 +15,6 @@
1615
import org.opentripplanner.routing.api.request.request.filter.SelectRequest;
1716
import org.opentripplanner.routing.api.request.request.filter.TransitFilterRequest;
1817
import org.opentripplanner.transit.model.basic.MainAndSubMode;
19-
import org.opentripplanner.utils.collection.CollectionUtils;
2018

2119
public class ModePreferencesMapper {
2220

@@ -25,10 +23,9 @@ public class ModePreferencesMapper {
2523
*/
2624
static void setModes(
2725
JourneyRequestBuilder journey,
28-
GraphQLTypes.GraphQLQueryTypePlanConnectionArgs args,
26+
GraphQLTypes.GraphQLPlanModesInput modesInput,
2927
DataFetchingEnvironment environment
3028
) {
31-
var modesInput = args.getGraphQLModes();
3229
var direct = modesInput.getGraphQLDirect();
3330
if (Boolean.TRUE.equals(modesInput.getGraphQLTransitOnly())) {
3431
journey.withDirect(new StreetRequest(StreetMode.NOT_SET));
@@ -43,11 +40,7 @@ static void setModes(
4340
var transit = modesInput.getGraphQLTransit();
4441
if (Boolean.TRUE.equals(modesInput.getGraphQLDirectOnly())) {
4542
journey.withTransit(TransitRequestBuilder::disable);
46-
} else if (transit == null) {
47-
// even if there are no transit modes set, we need to set the filter to get the route/agency
48-
// filters for flex
49-
setTransitFilters(journey, MainAndSubMode.all(), args);
50-
} else {
43+
} else if (transit != null) {
5144
var access = transit.getGraphQLAccess();
5245
if (access != null) {
5346
if (access.isEmpty()) {
@@ -79,14 +72,11 @@ static void setModes(
7972
validateStreetModes(journey.build());
8073

8174
var transitModes = getTransitModes(environment);
82-
if (transitModes == null) {
83-
// even when there are no transit modes set we need to set the filters because of the route/agency
84-
// includes/excludes
85-
setTransitFilters(journey, MainAndSubMode.all(), args);
86-
} else {
75+
if (transitModes != null) {
8776
if (transitModes.isEmpty()) {
8877
throw new IllegalArgumentException("Transit modes must not be empty.");
8978
}
79+
var filterRequestBuilder = TransitFilterRequest.of();
9080
var mainAndSubModes = transitModes
9181
.stream()
9282
.map(mode ->
@@ -97,36 +87,13 @@ static void setModes(
9787
)
9888
)
9989
.toList();
100-
setTransitFilters(journey, mainAndSubModes, args);
90+
filterRequestBuilder.addSelect(
91+
SelectRequest.of().withTransportModes(mainAndSubModes).build()
92+
);
93+
journey.withTransit(transitRequestBuilder ->
94+
transitRequestBuilder.setFilters(List.of(filterRequestBuilder.build()))
95+
);
10196
}
10297
}
10398
}
104-
105-
/**
106-
* It may be a little surprising that the transit filters are mapped here. This
107-
* is because the mapping function needs to know the modes to build the correct
108-
* select request as it needs to be the first one in each transit filter request.
109-
*/
110-
private static void setTransitFilters(
111-
JourneyRequestBuilder journey,
112-
List<MainAndSubMode> modes,
113-
GraphQLTypes.GraphQLQueryTypePlanConnectionArgs args
114-
) {
115-
var graphQlFilters = Optional.ofNullable(args.getGraphQLPreferences())
116-
.map(GraphQLTypes.GraphQLPlanPreferencesInput::getGraphQLTransit)
117-
.map(GraphQLTypes.GraphQLTransitPreferencesInput::getGraphQLFilters)
118-
.orElse(List.of());
119-
if (CollectionUtils.hasValue(graphQlFilters)) {
120-
var filters = FilterMapper.mapFilters(modes, graphQlFilters);
121-
journey.withTransit(b -> b.setFilters(filters));
122-
}
123-
// if there isn't a transit filter or a mode set, then we can keep the default which is to include
124-
// everything
125-
else if (!modes.equals(MainAndSubMode.all())) {
126-
var filter = TransitFilterRequest.of()
127-
.addSelect(SelectRequest.of().withTransportModes(modes).build())
128-
.build();
129-
journey.withTransit(b -> b.setFilters(List.of(filter)));
130-
}
131-
}
13299
}

application/src/main/java/org/opentripplanner/apis/gtfs/mapping/routerequest/RouteRequestMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static RouteRequest toRouteRequest(
7171
);
7272

7373
request.withJourney(journeyRequestBuilder ->
74-
setModes(journeyRequestBuilder, args, environment)
74+
setModes(journeyRequestBuilder, args.getGraphQLModes(), environment)
7575
);
7676

7777
// sadly we need to use the raw collection because it is cast to the wrong type

application/src/main/java/org/opentripplanner/apis/gtfs/mapping/routerequest/SelectRequestMapper.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)