Skip to content

Commit

Permalink
Add support for filtering alerts with route ID and stop ID
Browse files Browse the repository at this point in the history
  • Loading branch information
mjaakko committed Nov 19, 2019
1 parent cd3c259 commit d268d1a
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 d268d1a

Please sign in to comment.