use of org.opentripplanner.model.FeedScopedId in project OpenTripPlanner by opentripplanner.
the class GeometryAndBlockProcessor method run.
/**
* Generate the edges. Assumes that there are already vertices in the graph for the stops.
*/
@SuppressWarnings("Convert2MethodRef")
public void run(Graph graph, DataImportIssueStore issueStore) {
this.issueStore = issueStore;
fareServiceFactory.processGtfs(transitService);
/* Assign 0-based numeric codes to all GTFS service IDs. */
for (FeedScopedId serviceId : transitService.getAllServiceIds()) {
// TODO: FIX Service code collision for multiple feeds.
graph.getServiceCodes().put(serviceId, graph.getServiceCodes().size());
}
LOG.info("Processing geometries and blocks on graph...");
// Wwe have to build the hop geometries before we throw away the modified stopTimes, saving
// only the tripTimes (which don't have enough information to build a geometry). So we keep
// them here. In the current design, a trip pattern does not have a single geometry, but
// one per hop, so we store them in an array.
Map<TripPattern, LineString[]> geometriesByTripPattern = Maps.newHashMap();
Collection<TripPattern> tripPatterns = transitService.getTripPatterns();
/* Generate unique short IDs for all the TableTripPatterns. */
if (!TripPattern.idsAreUniqueAndNotNull(tripPatterns)) {
TripPattern.generateUniqueIds(tripPatterns);
}
/* Generate unique human-readable names for all the TableTripPatterns. */
TripPattern.generateUniqueNames(tripPatterns, issueStore);
/* Loop over all new TripPatterns, creating edges, setting the service codes and geometries, etc. */
ProgressTracker progress = ProgressTracker.track("Generate TripPattern geometries", 100, tripPatterns.size());
LOG.info(progress.startMessage());
for (TripPattern tripPattern : tripPatterns) {
for (Trip trip : tripPattern.getTrips()) {
// there would be a trip pattern with no geometry yet because it failed some of these tests
if (!geometriesByTripPattern.containsKey(tripPattern) && trip.getShapeId() != null && trip.getShapeId().getId() != null && !trip.getShapeId().getId().equals("")) {
// save the geometry to later be applied to the hops
geometriesByTripPattern.put(tripPattern, createGeometry(trip.getShapeId(), transitService.getStopTimesForTrip(trip)));
}
}
// Keep lambda! A method-ref would causes incorrect class and line number to be logged
progress.step(m -> LOG.info(m));
}
LOG.info(progress.completeMessage());
/* Loop over all new TripPatterns setting the service codes and geometries, etc. */
for (TripPattern tripPattern : tripPatterns) {
LineString[] hopGeometries = geometriesByTripPattern.get(tripPattern);
if (hopGeometries != null) {
// Make a single unified geometry, and also store the per-hop split geometries.
tripPattern.setHopGeometries(hopGeometries);
}
// TODO this could be more elegant
tripPattern.setServiceCodes(graph.getServiceCodes());
// Store the tripPattern in the Graph so it will be serialized and usable in routing.
graph.tripPatternForId.put(tripPattern.getId(), tripPattern);
}
/* Identify interlined trips and create the necessary edges. */
interline(tripPatterns, graph);
// it is already done at deserialization, but standalone mode allows using graphs without serializing them.
for (TripPattern tableTripPattern : tripPatterns) {
tableTripPattern.scheduledTimetable.finish();
}
graph.putService(FareService.class, fareServiceFactory.makeFareService());
}
use of org.opentripplanner.model.FeedScopedId in project OpenTripPlanner by opentripplanner.
the class TransmodelGraphQLSchema method create.
@SuppressWarnings("unchecked")
private GraphQLSchema create() {
/*
multilingualStringType, validityPeriodType, infoLinkType, bookingArrangementType, systemNoticeType,
linkGeometryType, serverInfoType, authorityType, operatorType, noticeType
*/
// Framework
GraphQLOutputType multilingualStringType = MultilingualStringType.create();
GraphQLObjectType validityPeriodType = ValidityPeriodType.create(gqlUtil);
GraphQLObjectType infoLinkType = InfoLinkType.create();
GraphQLOutputType bookingArrangementType = BookingArrangementType.create(gqlUtil);
GraphQLOutputType systemNoticeType = SystemNoticeType.create();
GraphQLOutputType linkGeometryType = PointsOnLinkType.create();
GraphQLOutputType serverInfoType = ServerInfoType.create();
GraphQLOutputType authorityType = AuthorityType.create(LineType.REF, PtSituationElementType.REF);
GraphQLOutputType operatorType = OperatorType.create(LineType.REF, ServiceJourneyType.REF);
GraphQLOutputType noticeType = NoticeType.create();
// Stop
GraphQLOutputType tariffZoneType = TariffZoneType.createTZ();
GraphQLInterfaceType placeInterface = PlaceInterfaceType.create(QuayType.REF, new GraphQLTypeReference(BikeRentalStationType.NAME), new GraphQLTypeReference(BikeParkType.NAME));
GraphQLOutputType bikeRentalStationType = BikeRentalStationType.create(placeInterface);
GraphQLOutputType bikeParkType = BikeParkType.createB(placeInterface);
// GraphQLOutputType carParkType = new GraphQLTypeReference("CarPark");
GraphQLOutputType stopPlaceType = StopPlaceType.create(placeInterface, QuayType.REF, tariffZoneType, EstimatedCallType.REF, gqlUtil);
GraphQLOutputType quayType = QuayType.create(placeInterface, stopPlaceType, LineType.REF, JourneyPatternType.REF, EstimatedCallType.REF, PtSituationElementType.REF, tariffZoneType, gqlUtil);
GraphQLNamedOutputType quayAtDistance = QuayAtDistanceType.createQD(quayType, relay);
// GraphQLNamedOutputType placeAtDistanceType = PlaceAtDistanceType.create(relay);
// Network
GraphQLObjectType presentationType = PresentationType.create();
GraphQLOutputType destinationDisplayType = DestinationDisplayType.create();
GraphQLOutputType lineType = LineType.create(bookingArrangementType, authorityType, operatorType, noticeType, quayType, presentationType, JourneyPatternType.REF, ServiceJourneyType.REF, PtSituationElementType.REF);
GraphQLOutputType interchangeType = InterchangeType.create(lineType, ServiceJourneyType.REF);
// Timetable
GraphQLNamedOutputType ptSituationElementType = PtSituationElementType.create(authorityType, quayType, lineType, ServiceJourneyType.REF, multilingualStringType, validityPeriodType, infoLinkType, relay);
GraphQLOutputType journeyPatternType = JourneyPatternType.create(linkGeometryType, noticeType, quayType, lineType, ServiceJourneyType.REF, ptSituationElementType, gqlUtil);
GraphQLOutputType estimatedCallType = EstimatedCallType.create(bookingArrangementType, noticeType, quayType, destinationDisplayType, ptSituationElementType, ServiceJourneyType.REF, gqlUtil);
GraphQLOutputType serviceJourneyType = ServiceJourneyType.create(bookingArrangementType, linkGeometryType, operatorType, noticeType, quayType, lineType, ptSituationElementType, journeyPatternType, estimatedCallType, TimetabledPassingTimeType.REF, gqlUtil);
GraphQLOutputType timetabledPassingTime = TimetabledPassingTimeType.create(bookingArrangementType, noticeType, quayType, destinationDisplayType, serviceJourneyType, gqlUtil);
GraphQLInputObjectType modesInputType = GraphQLInputObjectType.newInputObject().name("Modes").description("Input format for specifying which modes will be allowed for this search. " + "If this element is not present, it will default to accessMode/egressMode/directMode " + "of foot and all transport modes will be allowed.").field(GraphQLInputObjectField.newInputObjectField().name("accessMode").description("The mode used to get from the origin to the access stops in the transit " + "network the transit network (first-mile). If the element is not present or null," + "only transit that can be immediately boarded from the origin will be used.").type(STREET_MODE).build()).field(GraphQLInputObjectField.newInputObjectField().name("egressMode").description("The mode used to get from the egress stops in the transit network to" + "the destination (last-mile). If the element is not present or null," + "only transit that can immediately arrive at the origin will be used.").type(STREET_MODE).build()).field(GraphQLInputObjectField.newInputObjectField().name("directMode").description("The mode used to get from the origin to the destination directly, " + "without using the transit network. If the element is not present or null," + "direct travel without using transit will be disallowed.").type(STREET_MODE).build()).field(GraphQLInputObjectField.newInputObjectField().name("transportMode").description("The allowed modes for the transit part of the trip. Use an empty list " + "to disallow transit for this search. If the element is not present or null, " + "it will default to all transport modes.").type(new GraphQLList(TRANSPORT_MODE)).build()).build();
GraphQLOutputType tripType = createPlanType(bookingArrangementType, interchangeType, linkGeometryType, systemNoticeType, authorityType, operatorType, bikeRentalStationType, quayType, estimatedCallType, lineType, serviceJourneyType, ptSituationElementType);
GraphQLInputObjectType preferredInputType = GraphQLInputObjectType.newInputObject().name("InputPreferred").description("Preferences for trip search.").field(GqlUtil.newIdListInputField("lines", "Set of ids of lines preferred by user.")).field(GqlUtil.newIdListInputField("authorities", "Set of ids of authorities preferred by user.")).field(GraphQLInputObjectField.newInputObjectField().name("otherThanPreferredLinesPenalty").description("Penalty added for using a line that is not preferred if user has set any line as preferred. In number of seconds that user is willing to wait for preferred line.").type(Scalars.GraphQLInt).defaultValue(routing.request.otherThanPreferredRoutesPenalty).build()).build();
GraphQLInputObjectType unpreferredInputType = GraphQLInputObjectType.newInputObject().name("InputUnpreferred").description("Negative preferences for trip search. Unpreferred elements may still be used in suggested trips if alternatives are not desirable, see InputBanned for hard limitations.").field(GqlUtil.newIdListInputField("lines", "Set of ids of lines user prefers not to use.")).field(GqlUtil.newIdListInputField("authorities", "Set of ids of authorities user prefers not to use.")).build();
GraphQLInputObjectType bannedInputType = GraphQLInputObjectType.newInputObject().name("InputBanned").description("Filter trips by disallowing lines involving certain " + "elements. If both lines and authorities are specified, only one must be valid " + "for each line to be banned. If a line is both banned and whitelisted, " + "it will be counted as banned.").field(GqlUtil.newIdListInputField("lines", "Set of ids for lines that should not be used")).field(GqlUtil.newIdListInputField("authorities", "Set of ids for authorities that should not be used")).field(GqlUtil.newIdListInputField("quays", "Set of ids of quays that should not be allowed for boarding or alighting. Trip patterns that travel through the quay will still be permitted.")).field(GqlUtil.newIdListInputField("quaysHard", "Set of ids of quays that should not be allowed for boarding, alighting or traveling thorugh.")).field(GqlUtil.newIdListInputField("serviceJourneys", "Set of ids of service journeys that should not be used.")).build();
/*
GraphQLInputObjectType transportSubmodeFilterInputType = GraphQLInputObjectType.newInputObject()
.name("TransportSubmodeFilter")
.description("Filter trips by allowing only certain transport submodes per mode.")
.field(GraphQLInputObjectField.newInputObjectField()
.name("transportMode")
.description("Set of ids for lines that should be used")
.type(new GraphQLNonNull(TRANSPORT_MODE))
.build())
.field(GraphQLInputObjectField.newInputObjectField()
.name("transportSubmodes")
.description("Set of transport submodes allowed for transport mode.")
.type(new GraphQLNonNull(new GraphQLList(TRANSPORT_SUBMODE)))
.build())
.build();
*/
GraphQLFieldDefinition tripFieldType = GraphQLFieldDefinition.newFieldDefinition().name("trip").description("Input type for executing a travel search for a trip between two locations. Returns trip patterns describing suggested alternatives for the trip.").type(tripType).argument(GraphQLArgument.newArgument().name("dateTime").description("Date and time for the earliest time the user is willing to start the journey (if arriveBy=false/not set) or the latest acceptable time of arriving (arriveBy=true). Defaults to now").type(gqlUtil.dateTimeScalar).build()).argument(GraphQLArgument.newArgument().name("searchWindow").description("The length of the search-window in minutes. This is normally dynamically calculated by the server, but you may override this by setting it. The search-window used in a request is returned in the response metadata. To get the \"next page\" of trips use the metadata(searchWindowUsed and nextWindowDateTime) to create a new request. If not provided the value is resolved depending on the other input parameters, available transit options and realtime changes.").type(Scalars.GraphQLInt).build()).argument(GraphQLArgument.newArgument().name("from").description("The start location").type(new GraphQLNonNull(LocationInputType.INPUT_TYPE)).build()).argument(GraphQLArgument.newArgument().name("to").description("The end location").type(new GraphQLNonNull(LocationInputType.INPUT_TYPE)).build()).argument(GraphQLArgument.newArgument().name("wheelchairAccessible").description("Whether the trip must be wheelchair accessible. NOT IMPLEMENTED").type(Scalars.GraphQLBoolean).defaultValue(routing.request.wheelchairAccessible).build()).argument(GraphQLArgument.newArgument().name("numTripPatterns").description("The maximum number of trip patterns to return for this search " + "window. This may cause relevant trips to be missed, so it is preferable " + "to set this high and use other filtering options instead.").defaultValue(routing.request.numItineraries).type(Scalars.GraphQLInt).build()).argument(GraphQLArgument.newArgument().name("walkSpeed").description("The maximum walk speed along streets, in meters per second").type(Scalars.GraphQLFloat).defaultValue(routing.request.walkSpeed).build()).argument(GraphQLArgument.newArgument().name("bikeSpeed").description("The maximum bike speed along streets, in meters per second").type(Scalars.GraphQLFloat).defaultValue(routing.request.bikeSpeed).build()).argument(GraphQLArgument.newArgument().name("bicycleOptimisationMethod").description("The set of characteristics that the user wants to optimise for during bicycle searches -- defaults to " + reverseMapEnumVal(EnumTypes.BICYCLE_OPTIMISATION_METHOD, routing.request.optimize)).type(EnumTypes.BICYCLE_OPTIMISATION_METHOD).defaultValue(routing.request.optimize).build()).argument(GraphQLArgument.newArgument().name("arriveBy").description("Whether the trip should depart at dateTime (false, the default), or arrive at dateTime.").type(Scalars.GraphQLBoolean).defaultValue(routing.request.arriveBy).build()).argument(GraphQLArgument.newArgument().name("preferred").description("Parameters for indicating authorities or lines that preferably should be used in trip patters. A cost is applied to boarding nonpreferred authorities or lines (otherThanPreferredRoutesPenalty).").type(preferredInputType).build()).argument(GraphQLArgument.newArgument().name("unpreferred").description("Parameters for indicating authorities or lines that preferably should not be used in trip patters. A cost is applied to boarding nonpreferred authorities or lines (otherThanPreferredRoutesPenalty).").type(unpreferredInputType).build()).argument(GraphQLArgument.newArgument().name("banned").description("Banned").description("Parameters for indicating authorities, lines or quays not be used in the trip patterns").type(bannedInputType).build()).argument(GraphQLArgument.newArgument().name("whiteListed").description("Whitelisted").description("Parameters for indicating the only authorities, lines or quays to be used in the trip patterns").type(JourneyWhiteListed.INPUT_TYPE).build()).argument(GraphQLArgument.newArgument().name("transferPenalty").description("An extra penalty added on transfers (i.e. all boardings except the first one). The transferPenalty is used when a user requests even less transfers. In the latter case, we don't actually optimise for fewest transfers, as this can lead to absurd results. Consider a trip in New York from Grand Army Plaza (the one in Brooklyn) to Kalustyan's at noon. The true lowest transfers trip pattern is to wait until midnight, when the 4 train runs local the whole way. The actual fastest trip pattern is the 2/3 to the 4/5 at Nevins to the 6 at Union Square, which takes half an hour. Even someone optimise for fewest transfers doesn't want to wait until midnight. Maybe they would be willing to walk to 7th Ave and take the Q to Union Square, then transfer to the 6. If this takes less than transferPenalty seconds, then that's what we'll return.").type(Scalars.GraphQLInt).defaultValue(routing.request.transferCost).build()).argument(GraphQLArgument.newArgument().name("modes").description("The set of access/egress/direct/transit modes to be used for " + "this search.").type(modesInputType).build()).argument(GraphQLArgument.newArgument().name("transferSlack").description("An expected transfer time (in seconds) that specifies the amount of time that must pass between exiting one public transport vehicle and boarding another. This time is in addition to time it might take to walk between stops.").type(Scalars.GraphQLInt).defaultValue(routing.request.transferSlack).build()).argument(GraphQLArgument.newArgument().name("boardSlackDefault").description(TransportModeSlack.boardSlackDescription("boardSlackList")).type(Scalars.GraphQLInt).defaultValue(routing.request.boardSlack).build()).argument(GraphQLArgument.newArgument().name("boardSlackList").description(TransportModeSlack.slackByGroupDescription("boardSlack", routing.request.boardSlackForMode)).type(TransportModeSlack.SLACK_LIST_INPUT_TYPE).build()).argument(GraphQLArgument.newArgument().name("alightSlackDefault").description(TransportModeSlack.alightSlackDescription("alightSlackList")).type(Scalars.GraphQLInt).defaultValue(routing.request.alightSlack).build()).argument(GraphQLArgument.newArgument().name("alightSlackList").description(TransportModeSlack.slackByGroupDescription("alightSlack", routing.request.alightSlackForMode)).type(TransportModeSlack.SLACK_LIST_INPUT_TYPE).build()).argument(GraphQLArgument.newArgument().name("maximumTransfers").description("Maximum number of transfers").type(Scalars.GraphQLInt).defaultValue(routing.request.maxTransfers).build()).argument(GraphQLArgument.newArgument().name("ignoreRealtimeUpdates").description("When true, realtime updates are ignored during this search.").type(Scalars.GraphQLBoolean).defaultValue(routing.request.ignoreRealtimeUpdates).build()).argument(GraphQLArgument.newArgument().name("locale").type(EnumTypes.LOCALE).defaultValue("no").build()).argument(GraphQLArgument.newArgument().name("transitGeneralizedCostLimit").description("Set a relative limit for all transit itineraries. The limit " + "is calculated based on the best transit itinerary generalized-cost. " + "Itineraries without transit legs are excluded from this filter. " + "Example: f(x) = 3600 + 2.0 x. If the lowest cost returned is 10 000, " + "then the limit is set to: 3 600 + 2 * 10 000 = 26 600. Then all " + "itineraries with at least one transit leg and a cost above 26 600 " + "is removed from the result. Default: " + RequestFunctions.serialize(routing.request.transitGeneralizedCostLimit)).type(gqlUtil.doubleFunctionScalar).build()).argument(GraphQLArgument.newArgument().name("walkReluctance").description("Walk cost is multiplied by this value. This is the main parameter to use for limiting walking.").type(Scalars.GraphQLFloat).defaultValue(routing.request.walkReluctance).build()).argument(GraphQLArgument.newArgument().name("debugItineraryFilter").description("Debug the itinerary-filter-chain. The filters will mark itineraries as deleted, but NOT delete them when this is enabled.").type(Scalars.GraphQLBoolean).defaultValue(routing.request.debugItineraryFilter).build()).dataFetcher(environment -> new TransmodelGraphQLPlanner().plan(environment)).build();
// carParkType = GraphQLObjectType.newObject()
// .name("CarPark")
// .withInterface(placeInterface)
// .field(GraphQLFieldDefinition.newFieldDefinition()
// .name("id")
// .type(new GraphQLNonNull(Scalars.GraphQLID))
// .dataFetcher(environment -> ((CarPark) environment.getSource()).id)
// .build())
// .field(GraphQLFieldDefinition.newFieldDefinition()
// .name("name")
// .type(new GraphQLNonNull(Scalars.GraphQLString))
// .dataFetcher(environment -> ((CarPark) environment.getSource()).name)
// .build())
// .field(GraphQLFieldDefinition.newFieldDefinition()
// .name("capacity")
// .type(Scalars.GraphQLInt)
// .dataFetcher(environment -> ((CarPark) environment.getSource()).maxCapacity)
// .build())
// .field(GraphQLFieldDefinition.newFieldDefinition()
// .name("spacesAvailable")
// .type(Scalars.GraphQLInt)
// .dataFetcher(environment -> ((CarPark) environment.getSource()).spacesAvailable)
// .build())
// .field(GraphQLFieldDefinition.newFieldDefinition()
// .name("realtimeOccupancyAvailable")
// .type(Scalars.GraphQLBoolean)
// .dataFetcher(environment -> ((CarPark) environment.getSource()).realTimeData)
// .build())
// .field(GraphQLFieldDefinition.newFieldDefinition()
// .name("longitude")
// .type(Scalars.GraphQLFloat)
// .dataFetcher(environment -> ((CarPark) environment.getSource()).x)
// .build())
// .field(GraphQLFieldDefinition.newFieldDefinition()
// .name("latitude")
// .type(Scalars.GraphQLFloat)
// .dataFetcher(environment -> ((CarPark) environment.getSource()).y)
// .build())
// .build();
// GraphQLInputObjectType filterInputType = GraphQLInputObjectType.newInputObject()
// .name("InputFilters")
// .field(GraphQLInputObjectField.newInputObjectField()
// .name("quays")
// .description("Quays to include by id.")
// .type(new GraphQLList(Scalars.GraphQLString))
// .build())
// .field(GraphQLInputObjectField.newInputObjectField()
// .name("lines")
// .description("Lines to include by id.")
// .type(new GraphQLList(Scalars.GraphQLString))
// .build())
// .field(GraphQLInputObjectField.newInputObjectField()
// .name("bikeRentalStations")
// .description("Bike rentals to include by id.")
// .type(new GraphQLList(Scalars.GraphQLString))
// .build())
// .field(GraphQLInputObjectField.newInputObjectField()
// .name("bikeParks")
// .description("Bike parks to include by id.")
// .type(new GraphQLList(Scalars.GraphQLString))
// .build())
// .field(GraphQLInputObjectField.newInputObjectField()
// .name("carParks")
// .description("Car parks to include by id.")
// .type(new GraphQLList(Scalars.GraphQLString))
// .build())
// .build();
// String multiModalMode=environment.getArgument("multiModalMode");
// if ("parent".equals(multiModalMode)){
// stops = stops.map(s -> getParentStopPlace(s).orElse(s));
// }
// List<Stop> stopList=stops.distinct().collect(Collectors.toList());
// if ("all".equals(multiModalMode)) {
// stopList.addAll(stopList.stream().map(s -> getParentStopPlace(s).orElse(null)).filter(Objects::nonNull).distinct().collect(Collectors.toList()));
// }
// return stopList;
// else {
// return index.getLuceneIndex().query(environment.getArgument("name"), true, true, false)
// .stream()
// .map(result -> index.stopForId.get(mapper.fromIdString(result.id)));
// }
// .field(GraphQLFieldDefinition.newFieldDefinition()
// .name("nearest")
// .description(
// "Get all places (quays, stop places, car parks etc. with coordinates) within the specified radius from a location. The returned type has two fields place and distance. The search is done by walking so the distance is according to the network of walkables.")
// .type(relay.connectionType("placeAtDistance",
// relay.edgeType("placeAtDistance", placeAtDistanceType, null, new ArrayList<>()),
// new ArrayList<>()))
// .argument(GraphQLArgument.newArgument()
// .name("latitude")
// .description("Latitude of the location")
// .type(new GraphQLNonNull(Scalars.GraphQLFloat))
// .build())
// .argument(GraphQLArgument.newArgument()
// .name("longitude")
// .description("Longitude of the location")
// .type(new GraphQLNonNull(Scalars.GraphQLFloat))
// .build())
// .argument(GraphQLArgument.newArgument()
// .name("maximumDistance")
// .description("Maximum distance (in meters) to search for from the specified location. Default is 2000m.")
// .defaultValue(2000)
// .type(Scalars.GraphQLInt)
// .build())
// .argument(GraphQLArgument.newArgument()
// .name("maximumResults")
// .description("Maximum number of results. Search is stopped when this limit is reached. Default is 20.")
// .defaultValue(20)
// .type(Scalars.GraphQLInt)
// .build())
// .argument(GraphQLArgument.newArgument()
// .name("filterByPlaceTypes")
// .description("Only include places of given types if set. Default accepts all types")
// .defaultValue(Arrays.asList(TransmodelPlaceType.values()))
// .type(new GraphQLList(filterPlaceTypeEnum))
// .build())
// .argument(GraphQLArgument.newArgument()
// .name("filterByModes")
// .description("Only include places that include this mode. Only checked for places with mode i.e. quays, departures.")
// .type(new GraphQLList(modeEnum))
// .build())
// .argument(GraphQLArgument.newArgument()
// .name("filterByInUse")
// .description("Only affects queries for quays and stop places. If true only quays and stop places with at least one visiting line are included.")
// .type(Scalars.GraphQLBoolean)
// .defaultValue(Boolean.FALSE)
// .build())
// .argument(GraphQLArgument.newArgument()
// .name("filterByIds")
// .description("Only include places that match one of the given ids.")
// .type(filterInputType)
// .build())
// .argument(GraphQLArgument.newArgument()
// .name("multiModalMode")
// .type(multiModalModeEnum)
// .description("MultiModalMode for query. To control whether multi modal parent stop places, their mono modal children or both are included in the response." +
// " Does not affect mono modal stop places that do not belong to a multi modal stop place. Only applicable for placeType StopPlace")
// .defaultValue("parent")
// .build())
// .argument(relay.getConnectionFieldArguments())
// .dataFetcher(environment -> {
// List<FeedScopedId> filterByStops = null;
// List<FeedScopedId> filterByRoutes = null;
// List<String> filterByBikeRentalStations = null;
// List<String> filterByBikeParks = null;
// List<String> filterByCarParks = null;
// @SuppressWarnings("rawtypes")
// Map filterByIds = environment.getArgument("filterByIds");
// if (filterByIds != null) {
// filterByStops = toIdList(((List<String>) filterByIds.get("quays")));
// filterByRoutes = toIdList(((List<String>) filterByIds.get("lines")));
// filterByBikeRentalStations = filterByIds.get("bikeRentalStations") != null ? (List<String>) filterByIds.get("bikeRentalStations") : Collections.emptyList();
// filterByBikeParks = filterByIds.get("bikeParks") != null ? (List<String>) filterByIds.get("bikeParks") : Collections.emptyList();
// filterByCarParks = filterByIds.get("carParks") != null ? (List<String>) filterByIds.get("carParks") : Collections.emptyList();
// }
//
// List<TraverseMode> filterByTransportModes = environment.getArgument("filterByModes");
// List<TransmodelPlaceType> placeTypes = environment.getArgument("filterByPlaceTypes");
// if (CollectionUtils.isEmpty(placeTypes)) {
// placeTypes = Arrays.asList(TransmodelPlaceType.values());
// }
// List<GraphIndex.PlaceType> filterByPlaceTypes = mapper.mapPlaceTypes(placeTypes);
//
// // Need to fetch more than requested no of places if stopPlaces are allowed, as this requires fetching potentially multiple quays for the same stop place and mapping them to unique stop places.
// int orgMaxResults = environment.getArgument("maximumResults");
// int maxResults = orgMaxResults;
// if (placeTypes != null && placeTypes.contains(TransmodelPlaceType.STOP_PLACE)) {
// maxResults *= 5;
// }
//
// List<GraphIndex.PlaceAndDistance> places;
// try {
// places = index.findClosestPlacesByWalking(
// environment.getArgument("latitude"),
// environment.getArgument("longitude"),
// environment.getArgument("maximumDistance"),
// maxResults,
// filterByTransportModes,
// filterByPlaceTypes,
// filterByStops,
// filterByRoutes,
// filterByBikeRentalStations,
// filterByBikeParks,
// filterByCarParks,
// environment.getArgument("filterByInUse")
// );
// } catch (VertexNotFoundException e) {
// LOG.warn("findClosestPlacesByWalking failed with exception, returning empty list of places. " , e);
// places = Collections.emptyList();
// }
//
// places = convertQuaysToStopPlaces(placeTypes, places, environment.getArgument("multiModalMode")).stream().limit(orgMaxResults).collect(Collectors.toList());
// if (CollectionUtils.isEmpty(places)) {
// return new DefaultConnection<>(Collections.emptyList(), new DefaultPageInfo(null, null, false, false));
// }
// return new SimpleListConnection(places).get(environment);
// })
// .build())
// TODO OTP2 - FIX THIS, THIS IS A BUG
// List<String> privateCodes=environment.getArgument("privateCodes");
// TODO OTP2 - Use FeedScoped ID
// .filter(t -> CollectionUtils.isEmpty(privateCodes) || privateCodes.contains(t.getTripPrivateCode()))
// .field(GraphQLFieldDefinition.newFieldDefinition()
// .name("carPark")
// .description("Get a single car park based on its id")
// .type(carParkType)
// .argument(GraphQLArgument.newArgument()
// .name("id")
// .type(new GraphQLNonNull(Scalars.GraphQLString))
// .build())
// .dataFetcher(environment -> index.graph.getService(CarParkService.class)
// .getCarParks()
// .stream()
// .filter(carPark -> carPark.id.equals(environment.getArgument("id")))
// .findFirst()
// .orElse(null))
// .build())
// .field(GraphQLFieldDefinition.newFieldDefinition()
// .name("carParks")
// .description("Get all car parks")
// .type(new GraphQLNonNull(new GraphQLList(carParkType)))
// .argument(GraphQLArgument.newArgument()
// .name("ids")
// .type(new GraphQLList(Scalars.GraphQLString))
// .build())
// .dataFetcher(environment -> {
// if ((environment.getArgument("ids") instanceof List)) {
// Map<String, CarPark> carParks = index.graph.getService(CarParkService.class).getCarParkById();
// return ((List<String>) environment.getArgument("ids"))
// .stream()
// .map(carParks::get)
// .collect(Collectors.toList());
// }
// return new ArrayList<>(index.graph.getService(CarParkService.class).getCarParks());
// })
// .build())
// .field(GraphQLFieldDefinition.newFieldDefinition()
// .name("notices")
// .description("Get all notices")
// .type(new GraphQLNonNull(new GraphQLList(noticeType)))
// .dataFetcher(environment -> index.getNoticesByEntity().values())
// .build())
GraphQLObjectType queryType = GraphQLObjectType.newObject().name("QueryType").field(tripFieldType).field(GraphQLFieldDefinition.newFieldDefinition().name("stopPlace").description("Get a single stopPlace based on its id)").type(stopPlaceType).argument(GraphQLArgument.newArgument().name("id").type(new GraphQLNonNull(Scalars.GraphQLString)).build()).dataFetcher(env -> StopPlaceType.fetchStopPlaceById(TransitIdMapper.mapIDToDomain(env.getArgument("id")), env)).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("stopPlaces").description("Get all stopPlaces").type(new GraphQLNonNull(new GraphQLList(stopPlaceType))).argument(GraphQLArgument.newArgument().name("ids").type(new GraphQLList(Scalars.GraphQLString)).build()).dataFetcher(env -> {
if ((env.getArgument("ids") instanceof List)) {
return ((List<String>) env.getArgument("ids")).stream().map(TransitIdMapper::mapIDToDomain).map(id -> StopPlaceType.fetchStopPlaceById(id, env)).collect(Collectors.toList());
}
return new ArrayList<>(GqlUtil.getRoutingService(env).getStations());
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("stopPlacesByBbox").description("Get all stop places within the specified bounding box").type(new GraphQLNonNull(new GraphQLList(stopPlaceType))).argument(GraphQLArgument.newArgument().name("minimumLatitude").type(new GraphQLNonNull(Scalars.GraphQLFloat)).build()).argument(GraphQLArgument.newArgument().name("minimumLongitude").type(new GraphQLNonNull(Scalars.GraphQLFloat)).build()).argument(GraphQLArgument.newArgument().name("maximumLatitude").type(new GraphQLNonNull(Scalars.GraphQLFloat)).build()).argument(GraphQLArgument.newArgument().name("maximumLongitude").type(new GraphQLNonNull(Scalars.GraphQLFloat)).build()).argument(GraphQLArgument.newArgument().name("authority").type(Scalars.GraphQLString).build()).argument(GraphQLArgument.newArgument().name("multiModalMode").type(EnumTypes.MULTI_MODAL_MODE).description("MultiModalMode for query. To control whether multi modal parent stop places, their mono modal children or both are included in the response." + " Does not affect mono modal stop places that do not belong to a multi modal stop place.").defaultValue("parent").build()).argument(GraphQLArgument.newArgument().name("filterByInUse").description("If true only stop places with at least one visiting line are included.").type(Scalars.GraphQLBoolean).defaultValue(Boolean.FALSE).build()).dataFetcher(env -> {
double minLat = env.getArgument("minimumLatitude");
double minLon = env.getArgument("minimumLongitude");
double maxLat = env.getArgument("maximumLatitude");
double maxLon = env.getArgument("maximumLongitude");
String authority = env.getArgument("authority");
boolean filterByInUse = TRUE.equals(env.getArgument("filterByInUse"));
String multiModalMode = env.getArgument("multiModalMode");
return StopPlaceType.fetchStopPlaces(minLat, minLon, maxLat, maxLon, authority, filterByInUse, multiModalMode, env);
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("quay").description("Get a single quay based on its id)").type(quayType).argument(GraphQLArgument.newArgument().name("id").type(new GraphQLNonNull(Scalars.GraphQLString)).build()).dataFetcher(environment -> {
return GqlUtil.getRoutingService(environment).getStopForId(TransitIdMapper.mapIDToDomain(environment.getArgument("id")));
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("quays").description("Get all quays").type(new GraphQLNonNull(new GraphQLList(quayType))).argument(GraphQLArgument.newArgument().name("ids").type(new GraphQLList(Scalars.GraphQLString)).build()).argument(GraphQLArgument.newArgument().name("name").type(Scalars.GraphQLString).build()).dataFetcher(environment -> {
if ((environment.getArgument("ids") instanceof List)) {
if (environment.getArguments().entrySet().stream().filter(stringObjectEntry -> stringObjectEntry.getValue() != null).collect(Collectors.toList()).size() != 1) {
throw new IllegalArgumentException("Unable to combine other filters with ids");
}
RoutingService routingService = GqlUtil.getRoutingService(environment);
return ((List<String>) environment.getArgument("ids")).stream().map(id -> routingService.getStopForId(TransitIdMapper.mapIDToDomain(id))).collect(Collectors.toList());
}
if (environment.getArgument("name") == null) {
return GqlUtil.getRoutingService(environment).getAllStops();
}
// }
return emptyList();
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("quaysByBbox").description("Get all quays within the specified bounding box").type(new GraphQLNonNull(new GraphQLList(quayType))).argument(GraphQLArgument.newArgument().name("minimumLatitude").type(new GraphQLNonNull(Scalars.GraphQLFloat)).build()).argument(GraphQLArgument.newArgument().name("minimumLongitude").type(new GraphQLNonNull(Scalars.GraphQLFloat)).build()).argument(GraphQLArgument.newArgument().name("maximumLatitude").type(new GraphQLNonNull(Scalars.GraphQLFloat)).build()).argument(GraphQLArgument.newArgument().name("maximumLongitude").type(new GraphQLNonNull(Scalars.GraphQLFloat)).build()).argument(GraphQLArgument.newArgument().name("authority").type(Scalars.GraphQLString).build()).argument(GraphQLArgument.newArgument().name("filterByInUse").description("If true only quays with at least one visiting line are included.").type(Scalars.GraphQLBoolean).defaultValue(Boolean.FALSE).build()).dataFetcher(environment -> {
return GqlUtil.getRoutingService(environment).getStopsByBoundingBox(environment.getArgument("minimumLatitude"), environment.getArgument("minimumLongitude"), environment.getArgument("maximumLatitude"), environment.getArgument("maximumLongitude")).stream().filter(stop -> environment.getArgument("authority") == null || stop.getId().getFeedId().equalsIgnoreCase(environment.getArgument("authority"))).filter(stop -> {
boolean filterByInUse = TRUE.equals(environment.getArgument("filterByInUse"));
boolean inUse = !GqlUtil.getRoutingService(environment).getPatternsForStop(stop, true).isEmpty();
return !filterByInUse || inUse;
}).collect(Collectors.toList());
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("quaysByRadius").description("Get all quays within the specified walking radius from a location. The returned type has two fields quay and distance").type(relay.connectionType("quayAtDistance", relay.edgeType("quayAtDistance", quayAtDistance, null, new ArrayList<>()), new ArrayList<>())).argument(GraphQLArgument.newArgument().name("latitude").description("Latitude of the location").type(new GraphQLNonNull(Scalars.GraphQLFloat)).build()).argument(GraphQLArgument.newArgument().name("longitude").description("Longitude of the location").type(new GraphQLNonNull(Scalars.GraphQLFloat)).build()).argument(GraphQLArgument.newArgument().name("radius").description("Radius via streets (in meters) to search for from the specified location").type(new GraphQLNonNull(Scalars.GraphQLFloat)).build()).argument(GraphQLArgument.newArgument().name("authority").type(Scalars.GraphQLString).build()).arguments(relay.getConnectionFieldArguments()).dataFetcher(environment -> {
List<StopAtDistance> stops;
try {
stops = GqlUtil.getRoutingService(environment).findClosestStops(environment.getArgument("latitude"), environment.getArgument("longitude"), environment.getArgument("radius")).stream().filter(stopAtDistance -> environment.getArgument("authority") == null || stopAtDistance.stop.getId().getFeedId().equalsIgnoreCase(environment.getArgument("authority"))).sorted(Comparator.comparing(s -> s.distance)).collect(Collectors.toList());
} catch (RoutingValidationException e) {
LOG.warn("findClosestPlacesByWalking failed with exception, returning empty list of places. ", e);
stops = List.of();
}
if (CollectionUtils.isEmpty(stops)) {
return new DefaultConnection<>(Collections.emptyList(), new DefaultPageInfo(null, null, false, false));
}
return new SimpleListConnection<>(stops).get(environment);
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("authority").description("Get an authority by ID").type(authorityType).argument(GraphQLArgument.newArgument().name("id").type(new GraphQLNonNull(Scalars.GraphQLString)).build()).dataFetcher(environment -> {
return GqlUtil.getRoutingService(environment).getAgencyForId(TransitIdMapper.mapIDToDomain(environment.getArgument("id")));
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("authorities").description("Get all authorities").type(new GraphQLNonNull(new GraphQLList(authorityType))).dataFetcher(environment -> {
return new ArrayList<>(GqlUtil.getRoutingService(environment).getAgencies());
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("operator").description("Get a operator by ID").type(operatorType).argument(GraphQLArgument.newArgument().name("id").type(new GraphQLNonNull(Scalars.GraphQLString)).build()).dataFetcher(environment -> {
return GqlUtil.getRoutingService(environment).getOperatorForId().get(TransitIdMapper.mapIDToDomain(environment.getArgument("id")));
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("operators").description("Get all operators").type(new GraphQLNonNull(new GraphQLList(operatorType))).dataFetcher(environment -> {
return new ArrayList<>(GqlUtil.getRoutingService(environment).getAllOperators());
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("line").description("Get a single line based on its id").type(lineType).argument(GraphQLArgument.newArgument().name("id").type(new GraphQLNonNull(Scalars.GraphQLID)).build()).dataFetcher(environment -> {
return GqlUtil.getRoutingService(environment).getRouteForId(TransitIdMapper.mapIDToDomain(environment.getArgument("id")));
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("lines").description("Get all lines").type(new GraphQLNonNull(new GraphQLList(lineType))).argument(GraphQLArgument.newArgument().name("ids").type(new GraphQLList(Scalars.GraphQLID)).build()).argument(GraphQLArgument.newArgument().name("name").type(Scalars.GraphQLString).build()).argument(GraphQLArgument.newArgument().name("publicCode").type(Scalars.GraphQLString).build()).argument(GraphQLArgument.newArgument().name("publicCodes").type(new GraphQLList(Scalars.GraphQLString)).build()).argument(GraphQLArgument.newArgument().name("transportModes").type(new GraphQLList(TRANSPORT_MODE)).build()).argument(GraphQLArgument.newArgument().name("authorities").description("Set of ids of authorities to fetch lines for.").type(new GraphQLList(Scalars.GraphQLString)).build()).dataFetcher(environment -> {
if ((environment.getArgument("ids") instanceof List)) {
if (environment.getArguments().entrySet().stream().filter(it -> it.getValue() != null).count() != 1) {
throw new IllegalArgumentException("Unable to combine other filters with ids");
}
return ((List<String>) environment.getArgument("ids")).stream().map(id1 -> TransitIdMapper.mapIDToDomain(id1)).map(id -> {
return GqlUtil.getRoutingService(environment).getRouteForId(id);
}).collect(Collectors.toList());
}
Stream<Route> stream = GqlUtil.getRoutingService(environment).getAllRoutes().stream();
if (environment.getArgument("name") != null) {
stream = stream.filter(route -> route.getLongName() != null).filter(route -> route.getLongName().toLowerCase().startsWith(((String) environment.getArgument("name")).toLowerCase()));
}
if (environment.getArgument("publicCode") != null) {
stream = stream.filter(route -> route.getShortName() != null).filter(route -> route.getShortName().equals(environment.getArgument("publicCode")));
}
if (environment.getArgument("publicCodes") instanceof List) {
Set<String> publicCodes = Set.copyOf(environment.getArgument("publicCodes"));
stream = stream.filter(route -> route.getShortName() != null).filter(route -> publicCodes.contains(route.getShortName()));
}
if (environment.getArgument("transportModes") != null) {
Set<TraverseMode> modes = ((List<TraverseMode>) environment.getArgument("transportModes")).stream().filter(TraverseMode::isTransit).collect(Collectors.toSet());
// TODO OTP2 - FIX THIS, THIS IS A BUG
stream = stream.filter(route -> modes.contains(route.getMode()));
}
if ((environment.getArgument("authorities") instanceof Collection)) {
Collection<String> authorityIds = environment.getArgument("authorities");
stream = stream.filter(route -> route.getAgency() != null && authorityIds.contains(route.getAgency().getId().getId()));
}
return stream.collect(Collectors.toList());
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("serviceJourney").description("Get a single service journey based on its id").type(serviceJourneyType).argument(GraphQLArgument.newArgument().name("id").type(new GraphQLNonNull(Scalars.GraphQLString)).build()).dataFetcher(environment -> {
return GqlUtil.getRoutingService(environment).getTripForId().get(TransitIdMapper.mapIDToDomain(environment.getArgument("id")));
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("serviceJourneys").description("Get all service journeys").type(new GraphQLNonNull(new GraphQLList(serviceJourneyType))).argument(GraphQLArgument.newArgument().name("lines").description("Set of ids of lines to fetch serviceJourneys for.").type(new GraphQLList(Scalars.GraphQLID)).build()).argument(GraphQLArgument.newArgument().name("privateCodes").description("Set of ids of private codes to fetch serviceJourneys for.").type(new GraphQLList(Scalars.GraphQLString)).build()).argument(GraphQLArgument.newArgument().name("activeDates").description("Set of ids of active dates to fetch serviceJourneys for.").type(new GraphQLList(gqlUtil.dateScalar)).build()).argument(GraphQLArgument.newArgument().name("authorities").description("Set of ids of authorities to fetch serviceJourneys for.").type(new GraphQLList(Scalars.GraphQLString)).build()).dataFetcher(environment -> {
List<FeedScopedId> lineIds = mapIDsToDomain(environment.getArgument("lines"));
// List<String> privateCodes=environment.getArgument("privateCodes");
List<Long> activeDates = environment.getArgument("activeDates");
// TODO OTP2 - Use FeedScoped ID
List<String> authorities = environment.getArgument("authorities");
return GqlUtil.getRoutingService(environment).getTripForId().values().stream().filter(t -> CollectionUtils.isEmpty(lineIds) || lineIds.contains(t.getRoute().getId())).filter(t -> CollectionUtils.isEmpty(authorities) || authorities.contains(t.getRoute().getAgency().getId().getId())).filter(t -> {
return CollectionUtils.isEmpty(activeDates) || GqlUtil.getRoutingService(environment).getCalendarService().getServiceDatesForServiceId(t.getServiceId()).stream().anyMatch(sd -> activeDates.contains(gqlUtil.serviceDateMapper.serviceDateToSecondsSinceEpoch(sd)));
}).collect(Collectors.toList());
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("bikeRentalStations").description("Get all bike rental stations").argument(GraphQLArgument.newArgument().name("ids").type(new GraphQLList(Scalars.GraphQLString)).build()).type(new GraphQLNonNull(new GraphQLList(bikeRentalStationType))).dataFetcher(environment -> {
Collection<BikeRentalStation> all = new ArrayList<>(GqlUtil.getRoutingService(environment).getBikerentalStationService().getBikeRentalStations());
List<String> filterByIds = environment.getArgument("ids");
if (!CollectionUtils.isEmpty(filterByIds)) {
return all.stream().filter(station -> filterByIds.contains(station.id)).collect(Collectors.toList());
}
return all;
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("bikeRentalStation").description("Get all bike rental stations").type(bikeRentalStationType).argument(GraphQLArgument.newArgument().name("id").type(new GraphQLNonNull(Scalars.GraphQLString)).build()).dataFetcher(environment -> {
return GqlUtil.getRoutingService(environment).getBikerentalStationService().getBikeRentalStations().stream().filter(bikeRentalStation -> bikeRentalStation.id.equals(environment.getArgument("id"))).findFirst().orElse(null);
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("bikeRentalStationsByBbox").description("Get all bike rental stations within the specified bounding box. NOT IMPLEMENTED").type(new GraphQLNonNull(new GraphQLList(bikeRentalStationType))).argument(GraphQLArgument.newArgument().name("minimumLatitude").type(Scalars.GraphQLFloat).build()).argument(GraphQLArgument.newArgument().name("minimumLongitude").type(Scalars.GraphQLFloat).build()).argument(GraphQLArgument.newArgument().name("maximumLatitude").type(Scalars.GraphQLFloat).build()).argument(GraphQLArgument.newArgument().name("maximumLongitude").type(Scalars.GraphQLFloat).build()).dataFetcher(environment -> Collections.emptyList()).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("bikePark").description("Get a single bike park based on its id").type(bikeParkType).argument(GraphQLArgument.newArgument().name("id").type(new GraphQLNonNull(Scalars.GraphQLString)).build()).dataFetcher(environment -> {
return GqlUtil.getRoutingService(environment).getBikerentalStationService().getBikeParks().stream().filter(bikePark -> bikePark.id.equals(environment.getArgument("id"))).findFirst().orElse(null);
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("bikeParks").description("Get all bike parks").type(new GraphQLNonNull(new GraphQLList(bikeParkType))).dataFetcher(environment -> {
return new ArrayList<>(GqlUtil.getRoutingService(environment).getBikerentalStationService().getBikeParks());
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("routingParameters").description("Get default routing parameters.").type(this.routing.graphQLType).dataFetcher(environment -> routing.request).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("situations").description("Get all active situations.").type(new GraphQLNonNull(new GraphQLList(ptSituationElementType))).argument(GraphQLArgument.newArgument().name("authorities").description("Filter by reporting authorities.").type(new GraphQLList(Scalars.GraphQLString)).build()).argument(GraphQLArgument.newArgument().name("severities").description("Filter by severity.").type(new GraphQLList(EnumTypes.SEVERITY)).build()).dataFetcher(environment -> {
Collection<TransitAlert> alerts = GqlUtil.getRoutingService(environment).getTransitAlertService().getAllAlerts();
if ((environment.getArgument("authorities") instanceof List)) {
List<String> authorities = environment.getArgument("authorities");
alerts = alerts.stream().filter(alert -> authorities.contains(alert.getFeedId())).collect(Collectors.toSet());
}
if ((environment.getArgument("severities") instanceof List)) {
List<String> severities = environment.getArgument("severities");
alerts = alerts.stream().filter(alert -> severities.contains(alert.severity)).collect(Collectors.toSet());
}
return alerts;
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("serverInfo").description("Get OTP server information").type(new GraphQLNonNull(serverInfoType)).dataFetcher(e -> MavenVersion.VERSION).build()).build();
Set<GraphQLType> dictionary = new HashSet<>();
dictionary.add(placeInterface);
dictionary.add(timetabledPassingTime);
dictionary.add(Relay.pageInfoType);
return GraphQLSchema.newSchema().query(queryType).build(dictionary);
}
use of org.opentripplanner.model.FeedScopedId in project OpenTripPlanner by opentripplanner.
the class SiriTimetableSnapshotSource method getTripForJourney.
/**
* Finds the correct trip based on OTP-ServiceDate and SIRI-DepartureTime
* @param trips
* @param journey
* @return
*/
private Set<Trip> getTripForJourney(Set<Trip> trips, EstimatedVehicleJourney journey) {
List<RecordedCall> recordedCalls = (journey.getRecordedCalls() != null ? journey.getRecordedCalls().getRecordedCalls() : new ArrayList<>());
List<EstimatedCall> estimatedCalls = journey.getEstimatedCalls().getEstimatedCalls();
ZonedDateTime date;
int stopNumber = 1;
String firstStopId;
if (recordedCalls != null && !recordedCalls.isEmpty()) {
RecordedCall recordedCall = recordedCalls.get(0);
date = recordedCall.getAimedDepartureTime();
firstStopId = recordedCall.getStopPointRef().getValue();
} else if (estimatedCalls != null && !estimatedCalls.isEmpty()) {
EstimatedCall estimatedCall = estimatedCalls.get(0);
if (estimatedCall.getOrder() != null) {
stopNumber = estimatedCall.getOrder().intValue();
} else if (estimatedCall.getVisitNumber() != null) {
stopNumber = estimatedCall.getVisitNumber().intValue();
}
firstStopId = estimatedCall.getStopPointRef().getValue();
date = estimatedCall.getAimedDepartureTime();
} else {
return null;
}
if (date == null) {
// If no date is set - assume Realtime-data is reported for 'today'.
date = ZonedDateTime.now();
}
ServiceDate serviceDate = new ServiceDate(date.getYear(), date.getMonthValue(), date.getDayOfMonth());
int departureInSecondsSinceMidnight = calculateSecondsSinceMidnight(date);
Set<Trip> result = new HashSet<>();
for (Iterator<Trip> iterator = trips.iterator(); iterator.hasNext(); ) {
Trip trip = iterator.next();
Set<ServiceDate> serviceDatesForServiceId = routingService.getCalendarService().getServiceDatesForServiceId(trip.getServiceId());
if (serviceDatesForServiceId.contains(serviceDate)) {
TripPattern pattern = routingService.getPatternForTrip().get(trip);
if (stopNumber < pattern.stopPattern.stops.length) {
boolean firstReportedStopIsFound = false;
Stop stop = pattern.stopPattern.stops[stopNumber - 1];
if (firstStopId.equals(stop.getId().getId())) {
firstReportedStopIsFound = true;
} else {
String agencyId = stop.getId().getFeedId();
if (stop.isPartOfStation()) {
Stop alternativeStop = routingService.getStopForId(new FeedScopedId(agencyId, firstStopId));
if (stop.isPartOfSameStationAs(alternativeStop)) {
firstReportedStopIsFound = true;
}
}
}
if (firstReportedStopIsFound) {
for (TripTimes times : getCurrentTimetable(pattern, serviceDate).tripTimes) {
if (times.getScheduledDepartureTime(stopNumber - 1) == departureInSecondsSinceMidnight) {
if (routingService.getCalendarService().getServiceDatesForServiceId(times.trip.getServiceId()).contains(serviceDate)) {
result.add(times.trip);
}
}
}
}
}
}
}
if (result.size() >= 1) {
return result;
} else {
return null;
}
}
use of org.opentripplanner.model.FeedScopedId in project OpenTripPlanner by opentripplanner.
the class SiriTimetableSnapshotSource method cancelPreviouslyAddedTrip.
/**
* Cancel previously added trip from buffer if there is a previously added trip with given trip
* id (without agency id) on service date
*
* @param feedId feed id the trip id belongs to
* @param tripId trip id without agency id
* @param serviceDate service date
* @return true if a previously added trip was cancelled
*/
private boolean cancelPreviouslyAddedTrip(final String feedId, final String tripId, final ServiceDate serviceDate) {
boolean success = false;
final TripPattern pattern = buffer.getLastAddedTripPattern(new FeedScopedId(feedId, tripId), serviceDate);
if (pattern != null) {
// Cancel trip times for this trip in this pattern
final Timetable timetable = buffer.resolve(pattern, serviceDate);
final int tripIndex = timetable.getTripIndex(tripId);
if (tripIndex == -1) {
LOG.warn("Could not cancel previously added trip {}", tripId);
} else {
final TripTimes newTripTimes = new TripTimes(timetable.getTripTimes(tripIndex));
newTripTimes.cancel();
buffer.update(pattern, newTripTimes, serviceDate);
// buffer.removeLastAddedTripPattern(feedId, tripId, serviceDate);
success = true;
}
}
return success;
}
use of org.opentripplanner.model.FeedScopedId in project OpenTripPlanner by opentripplanner.
the class SiriTimetableSnapshotSource method handleAddedTrip.
private boolean handleAddedTrip(Graph graph, String feedId, EstimatedVehicleJourney estimatedVehicleJourney) {
// Verifying values required in SIRI Profile
// Added ServiceJourneyId
String newServiceJourneyRef = estimatedVehicleJourney.getEstimatedVehicleJourneyCode();
Preconditions.checkNotNull(newServiceJourneyRef, "EstimatedVehicleJourneyCode is required");
// Replaced/duplicated ServiceJourneyId
// VehicleJourneyRef existingServiceJourneyRef = estimatedVehicleJourney.getVehicleJourneyRef();
// Preconditions.checkNotNull(existingServiceJourneyRef, "VehicleJourneyRef is required");
// LineRef of added trip
Preconditions.checkNotNull(estimatedVehicleJourney.getLineRef(), "LineRef is required");
String lineRef = estimatedVehicleJourney.getLineRef().getValue();
// OperatorRef of added trip
Preconditions.checkNotNull(estimatedVehicleJourney.getOperatorRef(), "OperatorRef is required");
String operatorRef = estimatedVehicleJourney.getOperatorRef().getValue();
// Required in SIRI, but currently not in use by OTP
// Preconditions.checkNotNull(estimatedVehicleJourney.getRouteRef(), "RouteRef is required");
// String routeRef = estimatedVehicleJourney.getRouteRef().getValue();
// Preconditions.checkNotNull(estimatedVehicleJourney.getGroupOfLinesRef(), "GroupOfLinesRef is required");
// String groupOfLines = estimatedVehicleJourney.getGroupOfLinesRef().getValue();
// Preconditions.checkNotNull(estimatedVehicleJourney.getExternalLineRef(), "ExternalLineRef is required");
String externalLineRef = estimatedVehicleJourney.getExternalLineRef().getValue();
// TODO - SIRI: Where is the Operator?
// Operator operator = graphIndex.operatorForId.get(new FeedScopedId(feedId, operatorRef));
// Preconditions.checkNotNull(operator, "Operator " + operatorRef + " is unknown");
FeedScopedId tripId = new FeedScopedId(feedId, newServiceJourneyRef);
FeedScopedId serviceId = new FeedScopedId(feedId, newServiceJourneyRef);
Route replacedRoute = null;
if (externalLineRef != null) {
replacedRoute = graph.index.getRouteForId(new FeedScopedId(feedId, externalLineRef));
}
FeedScopedId routeId = new FeedScopedId(feedId, lineRef);
Route route = graph.index.getRouteForId(routeId);
if (route == null) {
// Route is unknown - create new
route = new Route();
route.setId(routeId);
route.setType(getRouteType(estimatedVehicleJourney.getVehicleModes()));
// route.setOperator(operator);
// TODO - SIRI: Is there a better way to find authority/Agency?
// Finding first Route with same Operator, and using same Authority
Agency agency = graph.index.getAllRoutes().stream().findFirst().get().getAgency();
route.setAgency(agency);
if (estimatedVehicleJourney.getPublishedLineNames() != null && !estimatedVehicleJourney.getPublishedLineNames().isEmpty()) {
route.setShortName("" + estimatedVehicleJourney.getPublishedLineNames().get(0).getValue());
}
LOG.info("Adding route {} to graph.", routeId);
graph.index.addRoutes(route);
}
Trip trip = new Trip();
trip.setId(tripId);
trip.setRoute(route);
// TODO - SIRI: Set transport-submode based on replaced- and replacement-route
if (replacedRoute != null) {
if (replacedRoute.getType() >= 100 && replacedRoute.getType() < 200) {
// Replaced-route is RAIL
if (route.getType() == 100) {
// Replacement-route is also RAIL
// trip.setTransportSubmode(TransmodelTransportSubmode.REPLACEMENT_RAIL_SERVICE);
} else if (route.getType() == 700) {
// Replacement-route is BUS
// trip.setTransportSubmode(TransmodelTransportSubmode.RAIL_REPLACEMENT_BUS);
}
}
}
trip.setServiceId(serviceId);
// TODO - SIRI: PublishedLineName not defined in SIRI-profile
if (estimatedVehicleJourney.getPublishedLineNames() != null && !estimatedVehicleJourney.getPublishedLineNames().isEmpty()) {
trip.setRouteShortName("" + estimatedVehicleJourney.getPublishedLineNames().get(0).getValue());
}
// trip.setTripOperator(operator);
// TODO - SIRI: Populate these?
// Replacement-trip has different shape
trip.setShapeId(null);
// trip.setTripPrivateCode(null);
// trip.setTripPublicCode(null);
trip.setBlockId(null);
trip.setTripShortName(null);
trip.setTripHeadsign(null);
// trip.setKeyValues(null);
List<Stop> addedStops = new ArrayList<>();
List<StopTime> aimedStopTimes = new ArrayList<>();
List<EstimatedCall> estimatedCalls = estimatedVehicleJourney.getEstimatedCalls().getEstimatedCalls();
for (int i = 0; i < estimatedCalls.size(); i++) {
EstimatedCall estimatedCall = estimatedCalls.get(i);
Stop stop = getStopForStopId(feedId, estimatedCall.getStopPointRef().getValue());
StopTime stopTime = new StopTime();
stopTime.setStop(stop);
stopTime.setStopSequence(i);
stopTime.setTrip(trip);
ZonedDateTime aimedArrivalTime = estimatedCall.getAimedArrivalTime();
ZonedDateTime aimedDepartureTime = estimatedCall.getAimedDepartureTime();
if (aimedArrivalTime != null) {
stopTime.setArrivalTime(calculateSecondsSinceMidnight(aimedArrivalTime));
}
if (aimedDepartureTime != null) {
stopTime.setDepartureTime(calculateSecondsSinceMidnight(aimedDepartureTime));
}
if (estimatedCall.getArrivalBoardingActivity() == ArrivalBoardingActivityEnumeration.ALIGHTING) {
stopTime.setDropOffType(PICKDROP_SCHEDULED);
} else {
stopTime.setDropOffType(PICKDROP_NONE);
}
if (estimatedCall.getDepartureBoardingActivity() == DepartureBoardingActivityEnumeration.BOARDING) {
stopTime.setPickupType(PICKDROP_SCHEDULED);
} else {
stopTime.setPickupType(PICKDROP_NONE);
}
if (estimatedCall.getDestinationDisplaies() != null && !estimatedCall.getDestinationDisplaies().isEmpty()) {
NaturalLanguageStringStructure destinationDisplay = estimatedCall.getDestinationDisplaies().get(0);
stopTime.setStopHeadsign(destinationDisplay.getValue());
}
if (i == 0) {
// Fake arrival on first stop
stopTime.setArrivalTime(stopTime.getDepartureTime());
} else if (i == (estimatedCalls.size() - 1)) {
// Fake departure from last stop
stopTime.setDepartureTime(stopTime.getArrivalTime());
}
addedStops.add(stop);
aimedStopTimes.add(stopTime);
}
StopPattern stopPattern = new StopPattern(aimedStopTimes);
TripPattern pattern = new TripPattern(trip.getRoute(), stopPattern);
TripTimes tripTimes = new TripTimes(trip, aimedStopTimes, graph.deduplicator);
boolean isJourneyPredictionInaccurate = (estimatedVehicleJourney.isPredictionInaccurate() != null && estimatedVehicleJourney.isPredictionInaccurate());
// If added trip is updated with realtime - loop through and add delays
for (int i = 0; i < estimatedCalls.size(); i++) {
EstimatedCall estimatedCall = estimatedCalls.get(i);
ZonedDateTime expectedArrival = estimatedCall.getExpectedArrivalTime();
ZonedDateTime expectedDeparture = estimatedCall.getExpectedDepartureTime();
int aimedArrivalTime = aimedStopTimes.get(i).getArrivalTime();
int aimedDepartureTime = aimedStopTimes.get(i).getDepartureTime();
if (expectedArrival != null) {
int expectedArrivalTime = calculateSecondsSinceMidnight(expectedArrival);
tripTimes.updateArrivalDelay(i, expectedArrivalTime - aimedArrivalTime);
}
if (expectedDeparture != null) {
int expectedDepartureTime = calculateSecondsSinceMidnight(expectedDeparture);
tripTimes.updateDepartureDelay(i, expectedDepartureTime - aimedDepartureTime);
}
if (estimatedCall.isCancellation() != null) {
tripTimes.setCancelledStop(i, estimatedCall.isCancellation());
}
boolean isCallPredictionInaccurate = estimatedCall.isPredictionInaccurate() != null && estimatedCall.isPredictionInaccurate();
tripTimes.setPredictionInaccurate(i, (isJourneyPredictionInaccurate | isCallPredictionInaccurate));
if (i == 0) {
// Fake arrival on first stop
tripTimes.updateArrivalTime(i, tripTimes.getDepartureTime(i));
} else if (i == (estimatedCalls.size() - 1)) {
// Fake departure from last stop
tripTimes.updateDepartureTime(i, tripTimes.getArrivalTime(i));
}
}
// Adding trip to index necessary to include values in graphql-queries
// TODO - SIRI: should more data be added to index?
graph.index.getTripForId().put(tripId, trip);
graph.index.getPatternForTrip().put(trip, pattern);
if (estimatedVehicleJourney.isCancellation() != null && estimatedVehicleJourney.isCancellation()) {
tripTimes.cancel();
} else {
tripTimes.setRealTimeState(RealTimeState.ADDED);
}
if (!graph.getServiceCodes().containsKey(serviceId)) {
graph.getServiceCodes().put(serviceId, graph.getServiceCodes().size());
}
tripTimes.serviceCode = graph.getServiceCodes().get(serviceId);
pattern.add(tripTimes);
Preconditions.checkState(tripTimes.timesIncreasing(), "Non-increasing triptimes for added trip");
ServiceDate serviceDate = getServiceDateForEstimatedVehicleJourney(estimatedVehicleJourney);
if (graph.getCalendarService().getServiceDatesForServiceId(serviceId) == null || graph.getCalendarService().getServiceDatesForServiceId(serviceId).isEmpty()) {
LOG.info("Adding serviceId {} to CalendarService", serviceId);
// TODO - SIRI: Need to add the ExtraJourney as a Trip - alerts may be attached to it
// graph.getCalendarService().addServiceIdAndServiceDates(serviceId, Arrays.asList(serviceDate));
}
return addTripToGraphAndBuffer(feedId, graph, trip, aimedStopTimes, addedStops, tripTimes, serviceDate);
}
Aggregations