Search in sources :

Example 1 with EntitySelector

use of org.opentripplanner.routing.alertpatch.EntitySelector in project OpenTripPlanner by opentripplanner.

the class TransitAlertServiceImpl method setAlerts.

@Override
public void setAlerts(Collection<TransitAlert> alerts) {
    Multimap<EntitySelector, TransitAlert> newAlerts = HashMultimap.create();
    for (TransitAlert alert : alerts) {
        for (EntitySelector entity : alert.getEntities()) {
            newAlerts.put(entity, alert);
        }
    }
    this.alerts = newAlerts;
}
Also used : EntitySelector(org.opentripplanner.routing.alertpatch.EntitySelector) TransitAlert(org.opentripplanner.routing.alertpatch.TransitAlert)

Example 2 with EntitySelector

use of org.opentripplanner.routing.alertpatch.EntitySelector in project OpenTripPlanner by opentripplanner.

the class PtSituationElementType method create.

public static GraphQLObjectType create(GraphQLOutputType authorityType, GraphQLOutputType quayType, GraphQLOutputType lineType, GraphQLOutputType serviceJourneyType, GraphQLOutputType multilingualStringType, GraphQLObjectType validityPeriodType, GraphQLObjectType infoLinkType, Relay relay) {
    return GraphQLObjectType.newObject().name(NAME).description("Simple public transport situation element").field(GraphQLFieldDefinition.newFieldDefinition().name("id").type(new GraphQLNonNull(Scalars.GraphQLID)).dataFetcher(environment -> relay.toGlobalId(NAME, ((TransitAlert) environment.getSource()).getId())).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("authority").type(authorityType).description("Get affected authority for this situation element").dataFetcher(environment -> {
        return GqlUtil.getRoutingService(environment).getAgencyForId(((TransitAlert) environment.getSource()).getEntities().stream().filter(EntitySelector.Agency.class::isInstance).map(EntitySelector.Agency.class::cast).findAny().map(entitySelector -> entitySelector.agencyId).orElse(null));
    }).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("lines").type(new GraphQLNonNull(new GraphQLList(lineType))).dataFetcher(environment -> {
        RoutingService routingService = GqlUtil.getRoutingService(environment);
        return ((TransitAlert) environment.getSource()).getEntities().stream().filter(EntitySelector.Route.class::isInstance).map(EntitySelector.Route.class::cast).map(entitySelector -> entitySelector.routeId).map(routeId -> routingService.getRouteForId(routeId)).collect(Collectors.toList());
    }).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("serviceJourneys").type(new GraphQLNonNull(new GraphQLList(serviceJourneyType))).dataFetcher(environment -> {
        RoutingService routingService = GqlUtil.getRoutingService(environment);
        return ((TransitAlert) environment.getSource()).getEntities().stream().filter(EntitySelector.Trip.class::isInstance).map(EntitySelector.Trip.class::cast).map(entitySelector -> entitySelector.tripId).map(tripId -> routingService.getTripForId().get(tripId)).collect(Collectors.toList());
    }).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("quays").type(new GraphQLNonNull(new GraphQLList(quayType))).dataFetcher(environment -> {
        RoutingService routingService = GqlUtil.getRoutingService(environment);
        return ((TransitAlert) environment.getSource()).getEntities().stream().filter(EntitySelector.Stop.class::isInstance).map(EntitySelector.Stop.class::cast).map(entitySelector -> entitySelector.stopId).map(stopId -> routingService.getStopForId(stopId)).collect(Collectors.toList());
    }).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("summary").type(new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(multilingualStringType)))).description("Summary of situation in all different translations available").dataFetcher(environment -> {
        TransitAlert alert = environment.getSource();
        if (alert.alertHeaderText instanceof TranslatedString) {
            return ((TranslatedString) alert.alertHeaderText).getTranslations();
        } else if (alert.alertHeaderText != null) {
            return List.of(new AbstractMap.SimpleEntry<>(null, alert.alertHeaderText.toString()));
        } else {
            return emptyList();
        }
    }).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("description").type(new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(multilingualStringType)))).description("Description of situation in all different translations available").dataFetcher(environment -> {
        TransitAlert alert = environment.getSource();
        if (alert.alertDescriptionText instanceof TranslatedString) {
            return ((TranslatedString) alert.alertDescriptionText).getTranslations();
        } else if (alert.alertDescriptionText != null) {
            return List.of(new AbstractMap.SimpleEntry<>(null, alert.alertDescriptionText.toString()));
        } else {
            return emptyList();
        }
    }).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("advice").type(new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(multilingualStringType)))).description("Advice of situation in all different translations available").dataFetcher(environment -> {
        TransitAlert alert = environment.getSource();
        if (alert.alertAdviceText instanceof TranslatedString) {
            return ((TranslatedString) alert.alertAdviceText).getTranslations();
        } else if (alert.alertAdviceText != null) {
            return List.of(new AbstractMap.SimpleEntry<>(null, alert.alertAdviceText.toString()));
        } else {
            return emptyList();
        }
    }).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("infoLinks").type(new GraphQLList(infoLinkType)).description("Optional links to more information.").dataFetcher(environment -> null).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("validityPeriod").type(validityPeriodType).description("Period this situation is in effect").dataFetcher(environment -> {
        TransitAlert alert = environment.getSource();
        Long startTime = alert.getEffectiveStartDate() != null ? alert.getEffectiveEndDate().getTime() : null;
        Long endTime = alert.getEffectiveEndDate() != null ? alert.getEffectiveEndDate().getTime() : null;
        return Pair.of(startTime, endTime);
    }).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("reportType").type(EnumTypes.REPORT_TYPE).description("ReportType of this situation").dataFetcher(environment -> ((TransitAlert) environment.getSource()).alertType).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("situationNumber").type(Scalars.GraphQLString).description("Operator's internal id for this situation").dataFetcher(environment -> null).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("reportAuthority").type(authorityType).description("Authority that reported this situation").deprecate("Not yet officially supported. May be removed or renamed.").dataFetcher(environment -> {
        return GqlUtil.getRoutingService(environment).getAgencyForId(((TransitAlert) environment.getSource()).getEntities().stream().filter(EntitySelector.Agency.class::isInstance).map(EntitySelector.Agency.class::cast).findAny().map(entitySelector -> entitySelector.agencyId).orElse(null));
    }).build()).build();
}
Also used : GraphQLObjectType(graphql.schema.GraphQLObjectType) EnumTypes(org.opentripplanner.ext.transmodelapi.model.EnumTypes) RoutingService(org.opentripplanner.routing.RoutingService) GqlUtil(org.opentripplanner.ext.transmodelapi.support.GqlUtil) Collections.emptyList(java.util.Collections.emptyList) GraphQLNonNull(graphql.schema.GraphQLNonNull) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) EntitySelector(org.opentripplanner.routing.alertpatch.EntitySelector) GraphQLOutputType(graphql.schema.GraphQLOutputType) Collectors(java.util.stream.Collectors) TranslatedString(org.opentripplanner.util.TranslatedString) TransitAlert(org.opentripplanner.routing.alertpatch.TransitAlert) Scalars(graphql.Scalars) AbstractMap(java.util.AbstractMap) List(java.util.List) GraphQLList(graphql.schema.GraphQLList) GraphQLTypeReference(graphql.schema.GraphQLTypeReference) Pair(org.apache.commons.lang3.tuple.Pair) Relay(graphql.relay.Relay) GraphQLList(graphql.schema.GraphQLList) TranslatedString(org.opentripplanner.util.TranslatedString) EntitySelector(org.opentripplanner.routing.alertpatch.EntitySelector) TransitAlert(org.opentripplanner.routing.alertpatch.TransitAlert) RoutingService(org.opentripplanner.routing.RoutingService) AbstractMap(java.util.AbstractMap) GraphQLNonNull(graphql.schema.GraphQLNonNull)

Aggregations

EntitySelector (org.opentripplanner.routing.alertpatch.EntitySelector)2 TransitAlert (org.opentripplanner.routing.alertpatch.TransitAlert)2 Scalars (graphql.Scalars)1 Relay (graphql.relay.Relay)1 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)1 GraphQLList (graphql.schema.GraphQLList)1 GraphQLNonNull (graphql.schema.GraphQLNonNull)1 GraphQLObjectType (graphql.schema.GraphQLObjectType)1 GraphQLOutputType (graphql.schema.GraphQLOutputType)1 GraphQLTypeReference (graphql.schema.GraphQLTypeReference)1 AbstractMap (java.util.AbstractMap)1 Collections.emptyList (java.util.Collections.emptyList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Pair (org.apache.commons.lang3.tuple.Pair)1 EnumTypes (org.opentripplanner.ext.transmodelapi.model.EnumTypes)1 GqlUtil (org.opentripplanner.ext.transmodelapi.support.GqlUtil)1 RoutingService (org.opentripplanner.routing.RoutingService)1 TranslatedString (org.opentripplanner.util.TranslatedString)1