org.opentripplanner.ext.legacygraphqlapi.datafetchers.LegacyGraphQLAlertImpl Maven / Gradle / Ivy
package org.opentripplanner.ext.legacygraphqlapi.datafetchers;
import graphql.relay.Relay;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import org.opentripplanner.ext.legacygraphqlapi.LegacyGraphQLRequestContext;
import org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLDataFetchers;
import org.opentripplanner.model.Agency;
import org.opentripplanner.model.Route;
import org.opentripplanner.model.Trip;
import org.opentripplanner.model.TripPattern;
import org.opentripplanner.routing.RoutingService;
import org.opentripplanner.routing.alertpatch.EntitySelector;
import org.opentripplanner.routing.alertpatch.TransitAlert;
import org.opentripplanner.util.TranslatedString;
import java.util.Collections;
import java.util.Date;
import java.util.Map;
public class LegacyGraphQLAlertImpl implements LegacyGraphQLDataFetchers.LegacyGraphQLAlert {
@Override
public DataFetcher id() {
return environment -> new Relay.ResolvedGlobalId(
"Alert",
getSource(environment).getId()
);
}
// TODO
@Override
public DataFetcher alertHash() {
return environment -> null;
}
@Override
public DataFetcher feed() {
return environment -> getSource(environment).getFeedId();
}
@Override
public DataFetcher agency() {
return environment -> getSource(environment)
.getEntities()
.stream()
.filter(entitySelector -> entitySelector instanceof EntitySelector.Agency)
.findAny()
.map(EntitySelector.Agency.class::cast)
.map(entitySelector -> getRoutingService(environment).getAgencyForId(entitySelector.agencyId))
.orElse(null);
}
@Override
public DataFetcher route() {
return environment -> getSource(environment)
.getEntities()
.stream()
.filter(entitySelector -> entitySelector instanceof EntitySelector.Route)
.findAny()
.map(EntitySelector.Route.class::cast)
.map(entitySelector -> getRoutingService(environment).getRouteForId(entitySelector.routeId))
.orElse(null);
}
@Override
public DataFetcher trip() {
return environment -> getSource(environment)
.getEntities()
.stream()
.filter(entitySelector -> entitySelector instanceof EntitySelector.Trip)
.findAny()
.map(EntitySelector.Trip.class::cast)
.map(entitySelector -> getRoutingService(environment).getTripForId().get(entitySelector.tripId))
.orElse(null);
}
@Override
public DataFetcher