Search in sources :

Example 1 with DayTypeRefsToServiceIdAdapter

use of org.opentripplanner.netex.support.DayTypeRefsToServiceIdAdapter in project OpenTripPlanner by opentripplanner.

the class CalendarMapper method mapToCalendarDates.

Collection<ServiceCalendarDate> mapToCalendarDates(DayTypeRefsToServiceIdAdapter dayTypeRefs) {
    String serviceId = dayTypeRefs.getServiceId();
    // The mapper store intermediate results and need to be initialized every time
    DayTypeAssignmentMapper dayTypeAssignmentMapper = new DayTypeAssignmentMapper(dayTypeById, operatingPeriodById);
    for (String dayTypeId : dayTypeRefs.getDayTypeRefs()) {
        dayTypeAssignmentMapper.mapAll(dayTypeId, dayTypeAssignments(dayTypeId));
    }
    Set<LocalDateTime> dates = dayTypeAssignmentMapper.mergeDates();
    if (dates.isEmpty()) {
        addDataImportIssue(new ServiceCodeDoesNotContainServiceDates(serviceId));
        // Add one date exception when list is empty to ensure serviceId is not lost
        LocalDateTime today = LocalDate.now().atStartOfDay();
        return Collections.singleton(newServiceCalendarDate(today, serviceId, EXCEPTION_TYPE_REMOVE));
    }
    return dates.stream().map(it -> newServiceCalendarDate(it, serviceId, EXCEPTION_TYPE_ADD)).collect(Collectors.toList());
}
Also used : LocalDateTime(java.time.LocalDateTime) EXCEPTION_TYPE_REMOVE(org.opentripplanner.model.calendar.ServiceCalendarDate.EXCEPTION_TYPE_REMOVE) Collection(java.util.Collection) LocalDateTime(java.time.LocalDateTime) Set(java.util.Set) ReadOnlyHierarchicalMapById(org.opentripplanner.netex.loader.util.ReadOnlyHierarchicalMapById) Collectors(java.util.stream.Collectors) ServiceDate(org.opentripplanner.model.calendar.ServiceDate) DayTypeAssignment(org.rutebanken.netex.model.DayTypeAssignment) DataImportIssue(org.opentripplanner.graph_builder.DataImportIssue) ReadOnlyHierarchicalMap(org.opentripplanner.netex.loader.util.ReadOnlyHierarchicalMap) DayTypeRefsToServiceIdAdapter(org.opentripplanner.netex.support.DayTypeRefsToServiceIdAdapter) OperatingPeriod(org.rutebanken.netex.model.OperatingPeriod) ServiceCodeDoesNotContainServiceDates(org.opentripplanner.graph_builder.issues.ServiceCodeDoesNotContainServiceDates) LocalDate(java.time.LocalDate) EXCEPTION_TYPE_ADD(org.opentripplanner.model.calendar.ServiceCalendarDate.EXCEPTION_TYPE_ADD) DataImportIssueStore(org.opentripplanner.graph_builder.DataImportIssueStore) ServiceCalendarDate(org.opentripplanner.model.calendar.ServiceCalendarDate) Collections(java.util.Collections) DayType(org.rutebanken.netex.model.DayType) ServiceCodeDoesNotContainServiceDates(org.opentripplanner.graph_builder.issues.ServiceCodeDoesNotContainServiceDates)

Example 2 with DayTypeRefsToServiceIdAdapter

use of org.opentripplanner.netex.support.DayTypeRefsToServiceIdAdapter in project OpenTripPlanner by opentripplanner.

the class NetexMapper method mapCalendarDayTypes.

private void mapCalendarDayTypes(NetexImportDataIndexReadOnlyView netexIndex) {
    CalendarMapper calMapper = new CalendarMapper(idFactory, netexIndex.getDayTypeAssignmentByDayTypeId(), netexIndex.getOperatingPeriodById(), netexIndex.getDayTypeById(), issueStore);
    for (DayTypeRefsToServiceIdAdapter dayTypeRefs : netexIndex.getDayTypeRefs()) {
        Collection<ServiceCalendarDate> dates = calMapper.mapToCalendarDates(dayTypeRefs);
        transitBuilder.getCalendarDates().addAll(dates);
    }
}
Also used : ServiceCalendarDate(org.opentripplanner.model.calendar.ServiceCalendarDate) DayTypeRefsToServiceIdAdapter(org.opentripplanner.netex.support.DayTypeRefsToServiceIdAdapter)

Example 3 with DayTypeRefsToServiceIdAdapter

use of org.opentripplanner.netex.support.DayTypeRefsToServiceIdAdapter in project OpenTripPlanner by opentripplanner.

the class NetexImportDataIndex method readOnlyView.

public NetexImportDataIndexReadOnlyView readOnlyView() {
    return new NetexImportDataIndexReadOnlyView() {

        /**
         * Lookup a Network given a GroupOfLine id or an Network id. If the given
         * {@code groupOfLineOrNetworkId} is a GroupOfLine ID, we lookup the GroupOfLine, and then
         * lookup its Network. If the given {@code groupOfLineOrNetworkId} is a Network ID then we
         * can lookup the Network directly.
         * <p/>
         * If no Network is found {@code null} is returned.
         */
        public Network lookupNetworkForLine(String groupOfLineOrNetworkId) {
            GroupOfLines groupOfLines = groupOfLinesById.lookup(groupOfLineOrNetworkId);
            String networkId = groupOfLines == null ? groupOfLineOrNetworkId : networkIdByGroupOfLineId.lookup(groupOfLines.getId());
            return networkById.lookup(networkId);
        }

        public ReadOnlyHierarchicalMapById<Authority> getAuthoritiesById() {
            return authoritiesById;
        }

        public ReadOnlyHierarchicalMapById<DayType> getDayTypeById() {
            return dayTypeById;
        }

        public ReadOnlyHierarchicalMap<String, Collection<DayTypeAssignment>> getDayTypeAssignmentByDayTypeId() {
            return dayTypeAssignmentByDayTypeId;
        }

        public Iterable<DayTypeRefsToServiceIdAdapter> getDayTypeRefs() {
            return Collections.unmodifiableSet(dayTypeRefs);
        }

        public ReadOnlyHierarchicalMapById<DestinationDisplay> getDestinationDisplayById() {
            return destinationDisplayById;
        }

        public ReadOnlyHierarchicalMapById<GroupOfStopPlaces> getGroupOfStopPlacesById() {
            return groupOfStopPlacesById;
        }

        public ReadOnlyHierarchicalMapById<JourneyPattern> getJourneyPatternsById() {
            return journeyPatternsById;
        }

        public ReadOnlyHierarchicalMapById<Line> getLineById() {
            return lineById;
        }

        public ReadOnlyHierarchicalMapById<StopPlace> getMultiModalStopPlaceById() {
            return multiModalStopPlaceById;
        }

        public ReadOnlyHierarchicalMapById<Notice> getNoticeById() {
            return noticeById;
        }

        public ReadOnlyHierarchicalMapById<NoticeAssignment> getNoticeAssignmentById() {
            return noticeAssignmentById;
        }

        public ReadOnlyHierarchicalMapById<OperatingPeriod> getOperatingPeriodById() {
            return operatingPeriodById;
        }

        public ReadOnlyHierarchicalMapById<Operator> getOperatorsById() {
            return operatorsById;
        }

        public ReadOnlyHierarchicalMap<String, Collection<TimetabledPassingTime>> getPassingTimeByStopPointId() {
            return passingTimeByStopPointId;
        }

        public ReadOnlyHierarchicalVersionMapById<Quay> getQuayById() {
            return quayById;
        }

        public ReadOnlyHierarchicalMap<String, String> getQuayIdByStopPointRef() {
            return quayIdByStopPointRef;
        }

        public ReadOnlyHierarchicalMapById<Route> getRouteById() {
            return routeById;
        }

        public ReadOnlyHierarchicalMap<String, Collection<ServiceJourney>> getServiceJourneyByPatternId() {
            return serviceJourneyByPatternId;
        }

        public ReadOnlyHierarchicalMapById<ServiceLink> getServiceLinkById() {
            return serviceLinkById;
        }

        public ReadOnlyHierarchicalVersionMapById<StopPlace> getStopPlaceById() {
            return stopPlaceById;
        }

        public ReadOnlyHierarchicalMapById<TariffZone> getTariffZonesById() {
            return tariffZonesById;
        }

        public String getTimeZone() {
            return timeZone.get();
        }
    };
}
Also used : Operator(org.rutebanken.netex.model.Operator) StopPlace(org.rutebanken.netex.model.StopPlace) TariffZone(org.rutebanken.netex.model.TariffZone) DestinationDisplay(org.rutebanken.netex.model.DestinationDisplay) GroupOfStopPlaces(org.rutebanken.netex.model.GroupOfStopPlaces) Authority(org.rutebanken.netex.model.Authority) DayType(org.rutebanken.netex.model.DayType) GroupOfLines(org.rutebanken.netex.model.GroupOfLines) Line(org.rutebanken.netex.model.Line) JourneyPattern(org.rutebanken.netex.model.JourneyPattern) Notice(org.rutebanken.netex.model.Notice) DayTypeRefsToServiceIdAdapter(org.opentripplanner.netex.support.DayTypeRefsToServiceIdAdapter) OperatingPeriod(org.rutebanken.netex.model.OperatingPeriod) Collection(java.util.Collection) NoticeAssignment(org.rutebanken.netex.model.NoticeAssignment) Quay(org.rutebanken.netex.model.Quay) ServiceLink(org.rutebanken.netex.model.ServiceLink) Route(org.rutebanken.netex.model.Route)

Example 4 with DayTypeRefsToServiceIdAdapter

use of org.opentripplanner.netex.support.DayTypeRefsToServiceIdAdapter in project OpenTripPlanner by opentripplanner.

the class TimeTableFrameParser method parseServiceJourney.

private void parseServiceJourney(ServiceJourney sj) {
    DayTypeRefsToServiceIdAdapter serviceAdapter = DayTypeRefsToServiceIdAdapter.create(sj.getDayTypes());
    if (serviceAdapter == null) {
        LOG.warn("Skipping ServiceJourney with empty dayTypes. Service Journey id : {}", sj.getId());
        return;
    }
    dayTypeRefs.add(serviceAdapter);
    String journeyPatternId = sj.getJourneyPatternRef().getValue().getRef();
    JourneyPattern journeyPattern = journeyPatternById.lookup(journeyPatternId);
    if (journeyPattern != null) {
        int nStopPointsInJourneyPattern = journeyPattern.getPointsInSequence().getPointInJourneyPatternOrStopPointInJourneyPatternOrTimingPointInJourneyPattern().size();
        int nTimetablePassingTimes = sj.getPassingTimes().getTimetabledPassingTime().size();
        // - is know at this point.
        if (nStopPointsInJourneyPattern == nTimetablePassingTimes) {
            serviceJourneyByPatternId.put(journeyPatternId, sj);
            for (TimetabledPassingTime it : sj.getPassingTimes().getTimetabledPassingTime()) {
                passingTimeByStopPointId.put(it.getPointInJourneyPatternRef().getValue().getRef(), it);
            }
        } else {
            LOG.warn("Mismatch between ServiceJourney and JourneyPattern. " + "ServiceJourney will be skipped. - " + sj.getId());
        }
    } else {
        LOG.warn("JourneyPattern not found. " + journeyPatternId);
    }
}
Also used : JourneyPattern(org.rutebanken.netex.model.JourneyPattern) DayTypeRefsToServiceIdAdapter(org.opentripplanner.netex.support.DayTypeRefsToServiceIdAdapter) TimetabledPassingTime(org.rutebanken.netex.model.TimetabledPassingTime)

Aggregations

DayTypeRefsToServiceIdAdapter (org.opentripplanner.netex.support.DayTypeRefsToServiceIdAdapter)4 Collection (java.util.Collection)2 ServiceCalendarDate (org.opentripplanner.model.calendar.ServiceCalendarDate)2 DayType (org.rutebanken.netex.model.DayType)2 JourneyPattern (org.rutebanken.netex.model.JourneyPattern)2 OperatingPeriod (org.rutebanken.netex.model.OperatingPeriod)2 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 Collections (java.util.Collections)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 DataImportIssue (org.opentripplanner.graph_builder.DataImportIssue)1 DataImportIssueStore (org.opentripplanner.graph_builder.DataImportIssueStore)1 ServiceCodeDoesNotContainServiceDates (org.opentripplanner.graph_builder.issues.ServiceCodeDoesNotContainServiceDates)1 EXCEPTION_TYPE_ADD (org.opentripplanner.model.calendar.ServiceCalendarDate.EXCEPTION_TYPE_ADD)1 EXCEPTION_TYPE_REMOVE (org.opentripplanner.model.calendar.ServiceCalendarDate.EXCEPTION_TYPE_REMOVE)1 ServiceDate (org.opentripplanner.model.calendar.ServiceDate)1 ReadOnlyHierarchicalMap (org.opentripplanner.netex.loader.util.ReadOnlyHierarchicalMap)1 ReadOnlyHierarchicalMapById (org.opentripplanner.netex.loader.util.ReadOnlyHierarchicalMapById)1 Authority (org.rutebanken.netex.model.Authority)1