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"));
}
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));
}
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;
}
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));
}
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;
}
Aggregations