use of org.opentripplanner.model.TransitEntity in project OpenTripPlanner by opentripplanner.
the class NoticeAssignmentMapper method map.
Multimap<TransitEntity<?>, Notice> map(NoticeAssignment noticeAssignment) {
// TODO OTP2 - Idealy this should en up as one key,value pair.
// The `StopPointInJourneyPattern` witch result in more than one key/valye pair,
// can be replaced with a new compound key type.
Multimap<TransitEntity<?>, Notice> noticiesByEntity = ArrayListMultimap.create();
String noticedObjectId = noticeAssignment.getNoticedObjectRef().getRef();
Notice otpNotice = getOrMapNotice(noticeAssignment);
if (otpNotice == null) {
LOG.warn("Notice in notice assignment is missing for assignment {}", noticeAssignment);
return noticiesByEntity;
}
// Special case for StopPointInJourneyPattern. The OTP model do not have this element, so we
// attach the notice to all StopTimes for the pattern at the given stop.
Collection<TimetabledPassingTime> times = passingTimeByStopPointId.lookup(noticedObjectId);
if (!times.isEmpty()) {
for (TimetabledPassingTime time : times) {
noticiesByEntity.put(lookupStopTimeKey(time.getId()), otpNotice);
}
} else if (stopTimesByNetexId.containsKey(noticedObjectId)) {
noticiesByEntity.put(lookupStopTimeKey(noticedObjectId), otpNotice);
} else {
FeedScopedId otpId = idFactory.createId(noticedObjectId);
if (routesById.containsKey(otpId)) {
noticiesByEntity.put(routesById.get(otpId), otpNotice);
} else if (tripsById.containsKey(otpId)) {
noticiesByEntity.put(tripsById.get(otpId), otpNotice);
} else {
LOG.warn("Could not map noticeAssignment for element with id {}", noticedObjectId);
}
}
return noticiesByEntity;
}
use of org.opentripplanner.model.TransitEntity in project OpenTripPlanner by opentripplanner.
the class NoticeAssignmentMapperTest method mapNoticeAssignment.
@Test
public void mapNoticeAssignment() {
NoticeAssignment noticeAssignment = new NoticeAssignment();
noticeAssignment.setNoticedObjectRef(new VersionOfObjectRefStructure().withRef(ROUTE_ID));
noticeAssignment.setNotice(NOTICE);
Route route = new Route();
route.setId(MappingSupport.ID_FACTORY.createId(ROUTE_ID));
EntityById<FeedScopedId, Route> routesById = new EntityById<>();
routesById.add(route);
NoticeAssignmentMapper noticeAssignmentMapper = new NoticeAssignmentMapper(MappingSupport.ID_FACTORY, new HierarchicalMultimap<>(), new HierarchicalMapById<>(), routesById, new EntityById<>(), new HashMap<>());
Multimap<TransitEntity<?>, org.opentripplanner.model.Notice> noticesByElement = noticeAssignmentMapper.map(noticeAssignment);
org.opentripplanner.model.Notice notice2 = noticesByElement.get(route).iterator().next();
assertEquals(NOTICE_ID, notice2.getId().getId());
}
use of org.opentripplanner.model.TransitEntity 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());
}
use of org.opentripplanner.model.TransitEntity in project OpenTripPlanner by opentripplanner.
the class NetexMapper method mapNoticeAssignments.
private void mapNoticeAssignments(NetexImportDataIndexReadOnlyView netexIndex) {
NoticeAssignmentMapper noticeAssignmentMapper = new NoticeAssignmentMapper(idFactory, netexIndex.getPassingTimeByStopPointId(), netexIndex.getNoticeById(), transitBuilder.getRoutes(), transitBuilder.getTripsById(), stopTimesByNetexId);
for (NoticeAssignment noticeAssignment : netexIndex.getNoticeAssignmentById().localValues()) {
Multimap<TransitEntity<?>, Notice> noticesByElementId;
noticesByElementId = noticeAssignmentMapper.map(noticeAssignment);
transitBuilder.getNoticeAssignments().putAll(noticesByElementId);
}
}
Aggregations