Search in sources :

Example 1 with HierarchicalMapById

use of org.opentripplanner.netex.loader.util.HierarchicalMapById in project OpenTripPlanner by opentripplanner.

the class NoticeAssignmentMapperTest method mapNoticeAssignmentOnStopPoint.

@Test
public void mapNoticeAssignmentOnStopPoint() {
    HierarchicalMultimap<String, TimetabledPassingTime> passingTimeByStopPointId = new HierarchicalMultimap<>();
    HierarchicalMapById<Notice> noticesById = new HierarchicalMapById<>();
    passingTimeByStopPointId.add(STOP_POINT_ID, new TimetabledPassingTime().withId(TIMETABLED_PASSING_TIME1));
    passingTimeByStopPointId.add(STOP_POINT_ID, new TimetabledPassingTime().withId(TIMETABLED_PASSING_TIME2));
    Trip trip = new Trip();
    trip.setId(new FeedScopedId("T", "1"));
    StopTime stopTime1 = createStopTime(1, trip);
    StopTime stopTime2 = createStopTime(2, trip);
    Map<String, StopTime> stopTimesById = new HashMap<>();
    stopTimesById.put(TIMETABLED_PASSING_TIME1, stopTime1);
    stopTimesById.put(TIMETABLED_PASSING_TIME2, stopTime2);
    noticesById.add(NOTICE);
    NoticeAssignment noticeAssignment = new NoticeAssignment().withNoticedObjectRef(new VersionOfObjectRefStructure().withRef(STOP_POINT_ID)).withNoticeRef(new NoticeRefStructure().withRef(NOTICE_ID));
    NoticeAssignmentMapper noticeAssignmentMapper = new NoticeAssignmentMapper(MappingSupport.ID_FACTORY, passingTimeByStopPointId, noticesById, new EntityById<>(), new EntityById<>(), stopTimesById);
    Multimap<TransitEntity<?>, org.opentripplanner.model.Notice> noticesByElement = noticeAssignmentMapper.map(noticeAssignment);
    org.opentripplanner.model.Notice notice2a = noticesByElement.get(stopTime1.getId()).stream().findFirst().orElseThrow(IllegalStateException::new);
    org.opentripplanner.model.Notice notice2b = noticesByElement.get(stopTime2.getId()).stream().findFirst().orElseThrow(IllegalStateException::new);
    assertEquals(NOTICE_ID, notice2a.getId().getId());
    assertEquals(NOTICE_ID, notice2b.getId().getId());
}
Also used : Trip(org.opentripplanner.model.Trip) NoticeRefStructure(org.rutebanken.netex.model.NoticeRefStructure) VersionOfObjectRefStructure(org.rutebanken.netex.model.VersionOfObjectRefStructure) HashMap(java.util.HashMap) TransitEntity(org.opentripplanner.model.TransitEntity) MultilingualString(org.rutebanken.netex.model.MultilingualString) HierarchicalMultimap(org.opentripplanner.netex.loader.util.HierarchicalMultimap) HierarchicalMapById(org.opentripplanner.netex.loader.util.HierarchicalMapById) TimetabledPassingTime(org.rutebanken.netex.model.TimetabledPassingTime) Notice(org.rutebanken.netex.model.Notice) FeedScopedId(org.opentripplanner.model.FeedScopedId) NoticeAssignment(org.rutebanken.netex.model.NoticeAssignment) StopTime(org.opentripplanner.model.StopTime) Test(org.junit.Test)

Example 2 with HierarchicalMapById

use of org.opentripplanner.netex.loader.util.HierarchicalMapById 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 3 with HierarchicalMapById

use of org.opentripplanner.netex.loader.util.HierarchicalMapById in project OpenTripPlanner by opentripplanner.

the class ServiceLinkMapperTest method mapServiceLinks.

@Test
public void mapServiceLinks() {
    JourneyPattern journeyPattern = new JourneyPattern().withId("RUT:JourneyPattern:1300");
    journeyPattern.setLinksInSequence(new LinksInJourneyPattern_RelStructure().withServiceLinkInJourneyPatternOrTimingLinkInJourneyPattern(new ServiceLinkInJourneyPattern_VersionedChildStructure().withServiceLinkRef(new ServiceLinkRefStructure().withRef("RUT:ServiceLink:1"))).withServiceLinkInJourneyPatternOrTimingLinkInJourneyPattern(new ServiceLinkInJourneyPattern_VersionedChildStructure().withServiceLinkRef(new ServiceLinkRefStructure().withRef("RUT:ServiceLink:2"))));
    ServiceLink serviceLink1 = createServiceLink("RUT:ServiceLink:1", 200.0, new Double[] { COORDINATES[0], COORDINATES[1], COORDINATES[2], COORDINATES[3] });
    ServiceLink serviceLink2 = createServiceLink("RUT:ServiceLink:2", 100.0, new Double[] { COORDINATES[2], COORDINATES[3], COORDINATES[4], COORDINATES[5] });
    HierarchicalMapById<ServiceLink> serviceLinksById = new HierarchicalMapById<>();
    serviceLinksById.add(serviceLink1);
    serviceLinksById.add(serviceLink2);
    Quay quay1 = new Quay().withId("NSR:Quay:1");
    Quay quay2 = new Quay().withId("NSR:Quay:2");
    Quay quay3 = new Quay().withId("NSR:Quay:3");
    HierarchicalVersionMapById<Quay> quaysById = new HierarchicalVersionMapById<>();
    quaysById.add(quay1);
    quaysById.add(quay2);
    quaysById.add(quay3);
    HierarchicalMap<String, String> quayIdByStopPointRef = new HierarchicalMap<>();
    quayIdByStopPointRef.add("RUT:StopPoint:1", "NSR:Quay:1");
    quayIdByStopPointRef.add("RUT:StopPoint:2", "NSR:Quay:2");
    quayIdByStopPointRef.add("RUT:StopPoint:3", "NSR:Quay:3");
    ServiceLinkMapper serviceLinkMapper = new ServiceLinkMapper(new FeedScopedIdFactory("RB"), new DataImportIssueStore(false));
    Collection<ShapePoint> shapePoints = serviceLinkMapper.getShapePointsByJourneyPattern(journeyPattern, serviceLinksById, quayIdByStopPointRef, quaysById);
    List<ShapePoint> shapePointList = shapePoints.stream().sorted(Comparator.comparing(ShapePoint::getSequence)).collect(Collectors.toList());
    Assert.assertEquals(COORDINATES[0], shapePointList.get(0).getLat(), 0.0001);
    Assert.assertEquals(COORDINATES[1], shapePointList.get(0).getLon(), 0.0001);
    Assert.assertEquals(COORDINATES[2], shapePointList.get(1).getLat(), 0.0001);
    Assert.assertEquals(COORDINATES[3], shapePointList.get(1).getLon(), 0.0001);
    Assert.assertEquals(COORDINATES[2], shapePointList.get(2).getLat(), 0.0001);
    Assert.assertEquals(COORDINATES[3], shapePointList.get(2).getLon(), 0.0001);
    Assert.assertEquals(COORDINATES[4], shapePointList.get(3).getLat(), 0.0001);
    Assert.assertEquals(COORDINATES[5], shapePointList.get(3).getLon(), 0.0001);
}
Also used : ServiceLinkRefStructure(org.rutebanken.netex.model.ServiceLinkRefStructure) HierarchicalVersionMapById(org.opentripplanner.netex.loader.util.HierarchicalVersionMapById) HierarchicalMapById(org.opentripplanner.netex.loader.util.HierarchicalMapById) JourneyPattern(org.rutebanken.netex.model.JourneyPattern) ShapePoint(org.opentripplanner.model.ShapePoint) LinksInJourneyPattern_RelStructure(org.rutebanken.netex.model.LinksInJourneyPattern_RelStructure) ServiceLink(org.rutebanken.netex.model.ServiceLink) Quay(org.rutebanken.netex.model.Quay) DataImportIssueStore(org.opentripplanner.graph_builder.DataImportIssueStore) HierarchicalMap(org.opentripplanner.netex.loader.util.HierarchicalMap) ServiceLinkInJourneyPattern_VersionedChildStructure(org.rutebanken.netex.model.ServiceLinkInJourneyPattern_VersionedChildStructure) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 HierarchicalMapById (org.opentripplanner.netex.loader.util.HierarchicalMapById)3 Trip (org.opentripplanner.model.Trip)2 JourneyPattern (org.rutebanken.netex.model.JourneyPattern)2 HashMap (java.util.HashMap)1 DataImportIssueStore (org.opentripplanner.graph_builder.DataImportIssueStore)1 FeedScopedId (org.opentripplanner.model.FeedScopedId)1 Route (org.opentripplanner.model.Route)1 ShapePoint (org.opentripplanner.model.ShapePoint)1 StopTime (org.opentripplanner.model.StopTime)1 TransitEntity (org.opentripplanner.model.TransitEntity)1 OtpTransitServiceBuilder (org.opentripplanner.model.impl.OtpTransitServiceBuilder)1 HierarchicalMap (org.opentripplanner.netex.loader.util.HierarchicalMap)1 HierarchicalMultimap (org.opentripplanner.netex.loader.util.HierarchicalMultimap)1 HierarchicalVersionMapById (org.opentripplanner.netex.loader.util.HierarchicalVersionMapById)1 JourneyPatternRefStructure (org.rutebanken.netex.model.JourneyPatternRefStructure)1 LinksInJourneyPattern_RelStructure (org.rutebanken.netex.model.LinksInJourneyPattern_RelStructure)1 MultilingualString (org.rutebanken.netex.model.MultilingualString)1 Notice (org.rutebanken.netex.model.Notice)1 NoticeAssignment (org.rutebanken.netex.model.NoticeAssignment)1