public static WrappedGTFSEntity<Pattern> fromTrip(DataFetchingEnvironment env) { WrappedGTFSEntity<Trip> trip = (WrappedGTFSEntity<Trip>) env.getSource(); FeedSource fs = ApiMain.getFeedSource(trip.feedUniqueId); if (fs == null) return null; Pattern patt = fs.feed.patterns.get(fs.feed.tripPatternMap.get(trip.entity.trip_id)); return new WrappedGTFSEntity<>(fs.id, patt); }
@Override public Object get(DataFetchingEnvironment environment) { if (!(environment.getSource() instanceof EObject)) { return null; } EObject context = (EObject) environment.getSource(); try { IServiceExecutor serviceExecutor = serviceExecutorProvider.getServiceExecutor(); serviceExecutor.init(context); serviceExecutor.execute(serviceName, environment.getArguments()); Object[] values = serviceExecutor.getObjects(); if (environment.getFieldType() instanceof GraphQLList) { return Arrays.asList(values); } return (values != null && values.length > 0 ? values[0] : null); } catch (Exception e) { return null; } }
public static Long fromRouteCount(DataFetchingEnvironment env) { WrappedGTFSEntity<Route> route = (WrappedGTFSEntity<Route>) env.getSource(); FeedSource fs = ApiMain.getFeedSource(route.feedUniqueId); if (fs == null) return null; return fs.feed .patterns .values() .stream() .filter(p -> p.route_id.equals(route.entity.route_id)) .count(); }
public static List<WrappedGTFSEntity<Pattern>> fromRoute(DataFetchingEnvironment env) { WrappedGTFSEntity<Route> route = (WrappedGTFSEntity<Route>) env.getSource(); FeedSource fs = ApiMain.getFeedSource(route.feedUniqueId); if (fs == null) return null; List<String> stopIds = env.getArgument("stop_id"); List<String> patternId = env.getArgument("pattern_id"); Long limit = env.getArgument("limit"); List<WrappedGTFSEntity<Pattern>> patterns = fs.feed .patterns .values() .stream() .filter(p -> p.route_id.equals(route.entity.route_id)) .map(p -> new WrappedGTFSEntity<>(fs.id, p)) .collect(Collectors.toList()); if (patternId != null) { patterns .stream() .filter(p -> patternId.contains(p.entity.pattern_id)) .collect(Collectors.toList()); } if (stopIds != null) { patterns .stream() .filter( p -> !Collections.disjoint( p.entity.orderedStops, stopIds)) // disjoint returns true if no elements in common .collect(Collectors.toList()); } if (limit != null) { return patterns.stream().limit(limit).collect(Collectors.toList()); } return patterns; }