Search in sources :

Example 1 with ServiceJourney

use of org.rutebanken.netex.model.ServiceJourney in project OpenTripPlanner by opentripplanner.

the class TripMapperTest method mapTripWithRouteRefViaJourneyPattern.

@Test
public void mapTripWithRouteRefViaJourneyPattern() {
    OtpTransitServiceBuilder transitBuilder = new OtpTransitServiceBuilder();
    Route route = new Route();
    route.setId(ID_FACTORY.createId(ROUTE_ID));
    transitBuilder.getRoutes().add(route);
    JourneyPattern journeyPattern = new JourneyPattern().withId(JOURNEY_PATTERN_ID);
    journeyPattern.setRouteRef(new RouteRefStructure().withRef(ROUTE_ID));
    ServiceJourney serviceJourney = createExampleServiceJourney();
    serviceJourney.setJourneyPatternRef(MappingSupport.createWrappedRef(JOURNEY_PATTERN_ID, JourneyPatternRefStructure.class));
    org.rutebanken.netex.model.Route netexRoute = new org.rutebanken.netex.model.Route();
    netexRoute.setLineRef(LINE_REF);
    netexRoute.setId(ROUTE_ID);
    HierarchicalMapById<org.rutebanken.netex.model.Route> routeById = new HierarchicalMapById<>();
    routeById.add(netexRoute);
    HierarchicalMapById<JourneyPattern> journeyPatternById = new HierarchicalMapById<>();
    journeyPatternById.add(journeyPattern);
    TripMapper tripMapper = new TripMapper(ID_FACTORY, transitBuilder.getRoutes(), routeById, journeyPatternById, Collections.emptySet());
    Trip trip = tripMapper.mapServiceJourney(serviceJourney);
    assertEquals(trip.getId(), ID_FACTORY.createId("RUT:ServiceJourney:1"));
}
Also used : OtpTransitServiceBuilder(org.opentripplanner.model.impl.OtpTransitServiceBuilder) ServiceJourney(org.rutebanken.netex.model.ServiceJourney) Trip(org.opentripplanner.model.Trip) HierarchicalMapById(org.opentripplanner.netex.loader.util.HierarchicalMapById) JourneyPattern(org.rutebanken.netex.model.JourneyPattern) JourneyPatternRefStructure(org.rutebanken.netex.model.JourneyPatternRefStructure) RouteRefStructure(org.rutebanken.netex.model.RouteRefStructure) Route(org.opentripplanner.model.Route) Test(org.junit.Test)

Example 2 with ServiceJourney

use of org.rutebanken.netex.model.ServiceJourney in project OpenTripPlanner by opentripplanner.

the class TripMapperTest method mapTrip.

@Test
public void mapTrip() {
    OtpTransitServiceBuilder transitBuilder = new OtpTransitServiceBuilder();
    Route route = new Route();
    route.setId(ID_FACTORY.createId(ROUTE_ID));
    transitBuilder.getRoutes().add(route);
    TripMapper tripMapper = new TripMapper(ID_FACTORY, transitBuilder.getRoutes(), new HierarchicalMapById<>(), new HierarchicalMapById<>(), Collections.emptySet());
    ServiceJourney serviceJourney = createExampleServiceJourney();
    serviceJourney.setLineRef(LINE_REF);
    Trip trip = tripMapper.mapServiceJourney(serviceJourney);
    assertEquals(trip.getId(), ID_FACTORY.createId(SERVICE_JOURNEY_ID));
}
Also used : OtpTransitServiceBuilder(org.opentripplanner.model.impl.OtpTransitServiceBuilder) ServiceJourney(org.rutebanken.netex.model.ServiceJourney) Trip(org.opentripplanner.model.Trip) Route(org.opentripplanner.model.Route) Test(org.junit.Test)

Example 3 with ServiceJourney

use of org.rutebanken.netex.model.ServiceJourney in project OpenTripPlanner by opentripplanner.

the class TripMapperTest method createExampleServiceJourney.

private ServiceJourney createExampleServiceJourney() {
    ServiceJourney serviceJourney = new ServiceJourney();
    serviceJourney.setId("RUT:ServiceJourney:1");
    serviceJourney.setDayTypes(NetexTestDataSample.createEveryDayRefs());
    serviceJourney.setJourneyPatternRef(createWrappedRef("RUT:JourneyPattern:1", JourneyPatternRefStructure.class));
    return serviceJourney;
}
Also used : ServiceJourney(org.rutebanken.netex.model.ServiceJourney) JourneyPatternRefStructure(org.rutebanken.netex.model.JourneyPatternRefStructure)

Example 4 with ServiceJourney

use of org.rutebanken.netex.model.ServiceJourney in project OpenTripPlanner by opentripplanner.

the class NetexImportDataIndexTest method lookupServiceJourneysById.

@Test
public void lookupServiceJourneysById() {
    ServiceJourney value = new ServiceJourney().withId(ID_2);
    root.serviceJourneyByPatternId.add(ID, value);
    assertEquals(singletonList(value), child.serviceJourneyByPatternId.lookup(ID));
}
Also used : ServiceJourney(org.rutebanken.netex.model.ServiceJourney) Test(org.junit.Test)

Example 5 with ServiceJourney

use of org.rutebanken.netex.model.ServiceJourney in project OpenTripPlanner by opentripplanner.

the class TripPatternMapper method mapTripPattern.

Result mapTripPattern(JourneyPattern journeyPattern) {
    // Make sure the result is clean, by creating a new object.
    result = new Result();
    Collection<ServiceJourney> serviceJourneys = serviceJourneyByPatternId.lookup(journeyPattern.getId());
    if (serviceJourneys == null || serviceJourneys.isEmpty()) {
        LOG.warn("ServiceJourneyPattern " + journeyPattern.getId() + " does not contain any serviceJourneys.");
        return null;
    }
    List<Trip> trips = new ArrayList<>();
    for (ServiceJourney serviceJourney : serviceJourneys) {
        Trip trip = tripMapper.mapServiceJourney(serviceJourney);
        // Unable to map ServiceJourney, problem logged by the mapper above
        if (trip == null)
            continue;
        StopTimesMapper.MappedStopTimes stopTimes = stopTimesMapper.mapToStopTimes(journeyPattern, trip, serviceJourney.getPassingTimes().getTimetabledPassingTime());
        // Unable to map StopTimes, problem logged by the mapper above
        if (stopTimes == null)
            continue;
        result.tripStopTimes.put(trip, stopTimes.stopTimes);
        result.stopTimeByNetexId.putAll(stopTimes.stopTimeByNetexId);
        trip.setTripHeadsign(getHeadsign(stopTimes.stopTimes));
        trips.add(trip);
    }
    // No trips successfully mapped
    if (trips.isEmpty())
        return result;
    // Create StopPattern from any trip (since they are part of the same JourneyPattern)
    StopPattern stopPattern = new StopPattern(result.tripStopTimes.get(trips.get(0)));
    TripPattern tripPattern = new TripPattern(lookupRoute(journeyPattern), stopPattern);
    tripPattern.setId(idFactory.createId(journeyPattern.getId()));
    tripPattern.name = journeyPattern.getName() == null ? "" : journeyPattern.getName().getValue();
    createTripTimes(trips, tripPattern);
    result.tripPatterns.add(tripPattern);
    return result;
}
Also used : StopPattern(org.opentripplanner.model.StopPattern) ServiceJourney(org.rutebanken.netex.model.ServiceJourney) Trip(org.opentripplanner.model.Trip) ArrayList(java.util.ArrayList) TripPattern(org.opentripplanner.model.TripPattern)

Aggregations

ServiceJourney (org.rutebanken.netex.model.ServiceJourney)5 Test (org.junit.Test)3 Trip (org.opentripplanner.model.Trip)3 Route (org.opentripplanner.model.Route)2 OtpTransitServiceBuilder (org.opentripplanner.model.impl.OtpTransitServiceBuilder)2 JourneyPatternRefStructure (org.rutebanken.netex.model.JourneyPatternRefStructure)2 ArrayList (java.util.ArrayList)1 StopPattern (org.opentripplanner.model.StopPattern)1 TripPattern (org.opentripplanner.model.TripPattern)1 HierarchicalMapById (org.opentripplanner.netex.loader.util.HierarchicalMapById)1 JourneyPattern (org.rutebanken.netex.model.JourneyPattern)1 RouteRefStructure (org.rutebanken.netex.model.RouteRefStructure)1