Skip to content

Commit

Permalink
Merge pull request #326 from HSLdevcom/filter_alerts_by_route_and_stop
Browse files Browse the repository at this point in the history
Add support for filtering alerts with route ID and stop ID
  • Loading branch information
optionsome authored Nov 20, 2019
2 parents cd3c259 + d268d1a commit dd74f1f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/org/opentripplanner/index/IndexGraphQLSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -3355,12 +3355,24 @@ else if (minDate.compareTo(maxDate) == 0) {
.description("Only return alerts with these causes")
.type(new GraphQLList(new GraphQLNonNull(alertCauseEnum)))
.build())
.argument(GraphQLArgument.newArgument()
.name("route")
.description("Only return alerts affecting these routes")
.type(new GraphQLList(new GraphQLNonNull(Scalars.GraphQLString)))
.build())
.argument(GraphQLArgument.newArgument()
.name("stop")
.description("Only return alerts affecting these stops")
.type(new GraphQLList(new GraphQLNonNull(Scalars.GraphQLString)))
.build())
.dataFetcher(environment -> {
return index.getAlerts().stream()
.filter(alert -> environment.getArgument("feeds") == null || ((List)environment.getArgument("feeds")).contains(alert.getFeedId()))
.filter(alert -> environment.getArgument("severityLevel") == null || ((List)environment.getArgument("severityLevel")).contains(alert.getAlert().severityLevel))
.filter(alert -> environment.getArgument("effect") == null || ((List)environment.getArgument("effect")).contains(alert.getAlert().effect))
.filter(alert -> environment.getArgument("cause") == null || ((List)environment.getArgument("cause")).contains(alert.getAlert().cause))
.filter(alert -> environment.getArgument("route") == null || (alert.getRoute() != null && ((List)environment.getArgument("route")).contains(FeedScopedId.convertToString(alert.getRoute()))))
.filter(alert -> environment.getArgument("stop") == null || (alert.getStop() != null && ((List)environment.getArgument("stop")).contains(FeedScopedId.convertToString(alert.getStop()))))
.collect(Collectors.toList());
})
.build())
Expand Down

0 comments on commit dd74f1f

Please sign in to comment.