Search in sources :

Example 1 with OtpTransitServiceBuilder

use of org.opentripplanner.model.impl.OtpTransitServiceBuilder in project OpenTripPlanner by opentripplanner.

the class GtfsModule method buildGraph.

@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra, DataImportIssueStore issueStore) {
    this.issueStore = issueStore;
    // we're about to add another agency to the graph, so clear the cached timezone
    // in case it should change
    // OTP doesn't currently support multiple time zones in a single graph;
    // at least this way we catch the error and log it instead of silently ignoring
    // because the time zone from the first agency is cached
    graph.clearTimeZone();
    CalendarServiceData calendarServiceData = new CalendarServiceData();
    try {
        for (GtfsBundle gtfsBundle : gtfsBundles) {
            // apply global defaults to individual GTFSBundles (if globals have been set)
            if (cacheDirectory != null && gtfsBundle.cacheDirectory == null) {
                gtfsBundle.cacheDirectory = cacheDirectory;
            }
            if (useCached != null && gtfsBundle.useCached == null) {
                gtfsBundle.useCached = useCached;
            }
            OtpTransitServiceBuilder builder = mapGtfsDaoToInternalTransitServiceBuilder(loadBundle(gtfsBundle), gtfsBundle.getFeedId().getId(), issueStore);
            builder.limitServiceDays(transitPeriodLimit);
            calendarServiceData.add(builder.buildCalendarServiceData());
            // NB! The calls below have side effects - the builder state is updated!
            if (OTPFeature.FlexRouting.isOn()) {
                FlexTripsMapper.createFlexTrips(builder);
            }
            repairStopTimesForEachTrip(builder.getStopTimesSortedByTrip());
            // NB! The calls below have side effects - the builder state is updated!
            createTripPatterns(graph, builder, calendarServiceData.getServiceIds());
            OtpTransitService transitModel = builder.build();
            addTransitModelToGraph(graph, gtfsBundle, transitModel);
            createGeometryAndBlockProcessor(gtfsBundle, transitModel).run(graph, issueStore);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        // Note the close method of each bundle should NOT throw an exception, so this
        // code should be safe without the try/catch block.
        gtfsBundles.forEach(GtfsBundle::close);
    }
    // We need to save the calendar service data so we can use it later
    graph.putService(org.opentripplanner.model.calendar.CalendarServiceData.class, calendarServiceData);
    graph.updateTransitFeedValidity(calendarServiceData, issueStore);
    graph.hasTransit = true;
    graph.calculateTransitCenter();
}
Also used : CalendarServiceData(org.opentripplanner.model.calendar.CalendarServiceData) OtpTransitServiceBuilder(org.opentripplanner.model.impl.OtpTransitServiceBuilder) GtfsBundle(org.opentripplanner.graph_builder.model.GtfsBundle) OtpTransitService(org.opentripplanner.model.OtpTransitService) IOException(java.io.IOException)

Example 2 with OtpTransitServiceBuilder

use of org.opentripplanner.model.impl.OtpTransitServiceBuilder in project OpenTripPlanner by opentripplanner.

the class NetexBundle method loadBundle.

/**
 * load the bundle, map it to the OTP transit model and return
 */
public OtpTransitServiceBuilder loadBundle(Deduplicator deduplicator, DataImportIssueStore issueStore) {
    LOG.info("Reading {}", hierarchy.description());
    // Store result in a mutable OTP Transit Model
    OtpTransitServiceBuilder transitBuilder = new OtpTransitServiceBuilder();
    // init parser and mapper
    xmlParser = new NetexXmlParser();
    otpMapper = new NetexMapper(transitBuilder, netexFeedId, deduplicator, issueStore);
    // Load data
    loadZipFileEntries();
    return transitBuilder;
}
Also used : OtpTransitServiceBuilder(org.opentripplanner.model.impl.OtpTransitServiceBuilder) NetexMapper(org.opentripplanner.netex.loader.mapping.NetexMapper)

Example 3 with OtpTransitServiceBuilder

use of org.opentripplanner.model.impl.OtpTransitServiceBuilder in project OpenTripPlanner by opentripplanner.

the class NetexModule method buildGraph.

@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra, DataImportIssueStore issueStore) {
    graph.clearTimeZone();
    CalendarServiceData calendarServiceData = new CalendarServiceData();
    try {
        for (NetexBundle netexBundle : netexBundles) {
            netexBundle.checkInputs();
            OtpTransitServiceBuilder transitBuilder = netexBundle.loadBundle(graph.deduplicator, issueStore);
            transitBuilder.limitServiceDays(transitPeriodLimit);
            calendarServiceData.add(transitBuilder.buildCalendarServiceData());
            OtpTransitService otpService = transitBuilder.build();
            // TODO OTP2 - Move this into the AddTransitModelEntitiesToGraph
            // - and make sure thay also work with GTFS feeds - GTFS do no
            // - have operators and notice assignments.
            graph.getOperators().addAll(otpService.getAllOperators());
            graph.addNoticeAssignments(otpService.getNoticeAssignments());
            GtfsFeedId feedId = new GtfsFeedId.Builder().id(netexFeedId).build();
            AddTransitModelEntitiesToGraph.addToGraph(feedId, otpService, subwayAccessTime, graph);
            new GeometryAndBlockProcessor(otpService, fareServiceFactory, MAX_STOP_TO_SHAPE_SNAP_DISTANCE, maxInterlineDistance).run(graph, issueStore);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    graph.putService(CalendarServiceData.class, calendarServiceData);
    graph.updateTransitFeedValidity(calendarServiceData, issueStore);
    graph.hasTransit = true;
    graph.calculateTransitCenter();
}
Also used : CalendarServiceData(org.opentripplanner.model.calendar.CalendarServiceData) OtpTransitServiceBuilder(org.opentripplanner.model.impl.OtpTransitServiceBuilder) GeometryAndBlockProcessor(org.opentripplanner.graph_builder.module.geometry.GeometryAndBlockProcessor) NetexBundle(org.opentripplanner.netex.loader.NetexBundle) GtfsFeedId(org.opentripplanner.graph_builder.module.GtfsFeedId) OtpTransitService(org.opentripplanner.model.OtpTransitService) OtpTransitServiceBuilder(org.opentripplanner.model.impl.OtpTransitServiceBuilder)

Example 4 with OtpTransitServiceBuilder

use of org.opentripplanner.model.impl.OtpTransitServiceBuilder in project OpenTripPlanner by opentripplanner.

the class NetexLoaderSmokeTest method smokeTestOfNetexLoadData.

/**
 * This test load a very simple Netex data set and do assertions on it.
 * For each type we assert some of the most important fields for one element
 * and then check the expected number of that type. This is not a replacement
 * for unit tests on mappers. Try to focus on relation between entities and Netex
 * import integration.
 */
@Test
public void smokeTestOfNetexLoadData() {
    // Given
    NetexBundle netexBundle = ConstantsForTests.createMinimalNetexBundle();
    // Run the check to make sure it does not throw an exception
    netexBundle.checkInputs();
    // When
    OtpTransitServiceBuilder transitBuilder = netexBundle.loadBundle(new Deduplicator(), new DataImportIssueStore(false));
    // Then - smoke test model
    OtpTransitService otpModel = transitBuilder.build();
    assertAgencies(otpModel.getAllAgencies());
    assertMultiModalStations(otpModel.getAllMultiModalStations());
    assertOperators(otpModel.getAllOperators());
    assertStops(otpModel.getAllStops());
    assertStations(otpModel.getAllStations());
    assertTripPatterns(otpModel.getTripPatterns());
    assertTrips(otpModel.getAllTrips());
    assertServiceIds(otpModel.getAllServiceIds());
    assertNoticeAssignments(otpModel.getNoticeAssignments());
    // And then - smoke test service calendar
    assetServiceCalendar(transitBuilder.buildCalendarServiceData());
}
Also used : OtpTransitServiceBuilder(org.opentripplanner.model.impl.OtpTransitServiceBuilder) NetexBundle(org.opentripplanner.netex.loader.NetexBundle) OtpTransitService(org.opentripplanner.model.OtpTransitService) DataImportIssueStore(org.opentripplanner.graph_builder.DataImportIssueStore) Deduplicator(org.opentripplanner.routing.trippattern.Deduplicator) Test(org.junit.Test)

Example 5 with OtpTransitServiceBuilder

use of org.opentripplanner.model.impl.OtpTransitServiceBuilder in project OpenTripPlanner by opentripplanner.

the class RouteMapperTest method mapRouteWithAgencySpecified.

@Test
public void mapRouteWithAgencySpecified() {
    NetexImportDataIndex netexIndex = new NetexImportDataIndex();
    OtpTransitServiceBuilder transitBuilder = new OtpTransitServiceBuilder();
    Network network = new Network().withId(NETWORK_ID).withTransportOrganisationRef(createJaxbElement(new OrganisationRefStructure().withRef(AUTHORITY_ID)));
    netexIndex.networkById.add(network);
    netexIndex.authoritiesById.add(new Authority().withId(AUTHORITY_ID));
    transitBuilder.getAgenciesById().add(createAgency());
    Line line = createExampleLine();
    RouteMapper routeMapper = new RouteMapper(MappingSupport.ID_FACTORY, transitBuilder.getAgenciesById(), transitBuilder.getOperatorsById(), netexIndex.readOnlyView(), TIME_ZONE);
    Route route = routeMapper.mapRoute(line);
    assertEquals(AUTHORITY_ID, route.getAgency().getId().getId());
}
Also used : OtpTransitServiceBuilder(org.opentripplanner.model.impl.OtpTransitServiceBuilder) Line(org.rutebanken.netex.model.Line) OrganisationRefStructure(org.rutebanken.netex.model.OrganisationRefStructure) NetexImportDataIndex(org.opentripplanner.netex.loader.NetexImportDataIndex) Authority(org.rutebanken.netex.model.Authority) Network(org.rutebanken.netex.model.Network) Route(org.opentripplanner.model.Route) Test(org.junit.Test)

Aggregations

OtpTransitServiceBuilder (org.opentripplanner.model.impl.OtpTransitServiceBuilder)10 Test (org.junit.Test)4 DataImportIssueStore (org.opentripplanner.graph_builder.DataImportIssueStore)3 OtpTransitService (org.opentripplanner.model.OtpTransitService)3 Route (org.opentripplanner.model.Route)3 GtfsFeedId (org.opentripplanner.graph_builder.module.GtfsFeedId)2 Trip (org.opentripplanner.model.Trip)2 CalendarServiceData (org.opentripplanner.model.calendar.CalendarServiceData)2 NetexBundle (org.opentripplanner.netex.loader.NetexBundle)2 ServiceJourney (org.rutebanken.netex.model.ServiceJourney)2 IOException (java.io.IOException)1 GtfsBundle (org.opentripplanner.graph_builder.model.GtfsBundle)1 GeometryAndBlockProcessor (org.opentripplanner.graph_builder.module.geometry.GeometryAndBlockProcessor)1 GtfsContextBuilder (org.opentripplanner.gtfs.GtfsContextBuilder)1 Agency (org.opentripplanner.model.Agency)1 FareRule (org.opentripplanner.model.FareRule)1 FeedInfo (org.opentripplanner.model.FeedInfo)1 ShapePoint (org.opentripplanner.model.ShapePoint)1 NetexImportDataIndex (org.opentripplanner.netex.loader.NetexImportDataIndex)1 NetexMapper (org.opentripplanner.netex.loader.mapping.NetexMapper)1