Search in sources :

Example 16 with OccurrenceModel

use of edu.usf.cutr.gtfsrtvalidator.lib.model.OccurrenceModel in project gtfs-realtime-validator by CUTR-at-USF.

the class HeaderValidator method validate.

@Override
public List<ErrorListHelperModel> validate(long currentTimeMillis, GtfsDaoImpl gtfsData, GtfsMetadata gtfsMetadata, GtfsRealtime.FeedMessage feedMessage, GtfsRealtime.FeedMessage previousFeedMessage, GtfsRealtime.FeedMessage combinedFeedMessage) {
    List<OccurrenceModel> errorListE038 = new ArrayList<>();
    List<OccurrenceModel> errorListE039 = new ArrayList<>();
    List<OccurrenceModel> errorListE049 = new ArrayList<>();
    if (!GtfsUtils.isValidVersion(feedMessage.getHeader())) {
        // E038 - Invalid header.gtfs_realtime_version
        RuleUtils.addOccurrence(E038, "header.gtfs_realtime_version of " + feedMessage.getHeader().getGtfsRealtimeVersion(), errorListE038, _log);
    }
    try {
        if (GtfsUtils.isV2orHigher(feedMessage.getHeader()) && !feedMessage.getHeader().hasIncrementality()) {
            // E049 - header incrementality not populated
            RuleUtils.addOccurrence(E049, "", errorListE049, _log);
        }
    } catch (Exception e) {
        _log.error("Error checking header version for E049: " + e);
    }
    if (feedMessage.getHeader().getIncrementality().equals(GtfsRealtime.FeedHeader.Incrementality.FULL_DATASET)) {
        for (GtfsRealtime.FeedEntity entity : feedMessage.getEntityList()) {
            if (entity.hasIsDeleted()) {
                // E039 - FULL_DATASET feeds should not include entity.is_deleted
                RuleUtils.addOccurrence(E039, "entity ID " + entity.getId() + " has is_deleted=" + entity.getIsDeleted(), errorListE039, _log);
            }
        }
    }
    List<ErrorListHelperModel> errors = new ArrayList<>();
    if (!errorListE038.isEmpty()) {
        errors.add(new ErrorListHelperModel(new MessageLogModel(E038), errorListE038));
    }
    if (!errorListE039.isEmpty()) {
        errors.add(new ErrorListHelperModel(new MessageLogModel(E039), errorListE039));
    }
    if (!errorListE049.isEmpty()) {
        errors.add(new ErrorListHelperModel(new MessageLogModel(E049), errorListE049));
    }
    return errors;
}
Also used : ErrorListHelperModel(edu.usf.cutr.gtfsrtvalidator.lib.model.helper.ErrorListHelperModel) MessageLogModel(edu.usf.cutr.gtfsrtvalidator.lib.model.MessageLogModel) ArrayList(java.util.ArrayList) OccurrenceModel(edu.usf.cutr.gtfsrtvalidator.lib.model.OccurrenceModel) GtfsRealtime(com.google.transit.realtime.GtfsRealtime)

Aggregations

OccurrenceModel (edu.usf.cutr.gtfsrtvalidator.lib.model.OccurrenceModel)16 MessageLogModel (edu.usf.cutr.gtfsrtvalidator.lib.model.MessageLogModel)14 ErrorListHelperModel (edu.usf.cutr.gtfsrtvalidator.lib.model.helper.ErrorListHelperModel)14 GtfsRealtime (com.google.transit.realtime.GtfsRealtime)9 ArrayList (java.util.ArrayList)8 ValidationRule (edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule)4 Test (org.junit.Test)4 Stop (org.onebusaway.gtfs.model.Stop)2 StopTime (org.onebusaway.gtfs.model.StopTime)2 HashSet (java.util.HashSet)1 List (java.util.List)1 Session (org.hibernate.Session)1 Frequency (org.onebusaway.gtfs.model.Frequency)1 Trip (org.onebusaway.gtfs.model.Trip)1