|
| 1 | +package org.mobilitydata.gtfsvalidator.validator; |
| 2 | + |
| 3 | +import static org.mobilitydata.gtfsvalidator.notice.SeverityLevel.ERROR; |
| 4 | + |
| 5 | +import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice; |
| 6 | +import org.mobilitydata.gtfsvalidator.annotation.GtfsValidator; |
| 7 | +import org.mobilitydata.gtfsvalidator.notice.NoticeContainer; |
| 8 | +import org.mobilitydata.gtfsvalidator.notice.ValidationNotice; |
| 9 | +import org.mobilitydata.gtfsvalidator.table.GtfsLocationType; |
| 10 | +import org.mobilitydata.gtfsvalidator.table.GtfsStop; |
| 11 | +import org.mobilitydata.gtfsvalidator.table.GtfsStopAccess; |
| 12 | +import org.mobilitydata.gtfsvalidator.table.GtfsStopSchema; |
| 13 | + |
| 14 | +/** |
| 15 | + * Validates {@code stops.stop_access} for a single {@code GtfsStop}. |
| 16 | + * |
| 17 | + * <p>Generated notices: |
| 18 | + * |
| 19 | + * <ul> |
| 20 | + * <li>{@link StopAccessSpecifiedForStopWithNoParentStationNotice} |
| 21 | + * <li>{@link StopAccessSpecifiedForIncorrectLocationNotice} |
| 22 | + * </ul> |
| 23 | + */ |
| 24 | +@GtfsValidator |
| 25 | +public class StopAccessValidator extends SingleEntityValidator<GtfsStop> { |
| 26 | + @Override |
| 27 | + public void validate(GtfsStop entity, NoticeContainer noticeContainer) { |
| 28 | + if (entity.stopAccess() == null) { |
| 29 | + return; |
| 30 | + } |
| 31 | + if (entity.locationType() == GtfsLocationType.STOP) { |
| 32 | + if (!entity.hasParentStation()) { |
| 33 | + noticeContainer.addValidationNotice( |
| 34 | + new StopAccessSpecifiedForStopWithNoParentStationNotice( |
| 35 | + entity.csvRowNumber(), |
| 36 | + entity.stopId(), |
| 37 | + entity.stopName(), |
| 38 | + entity.stopAccess(), |
| 39 | + entity.locationType())); |
| 40 | + } |
| 41 | + } else { |
| 42 | + noticeContainer.addValidationNotice( |
| 43 | + new StopAccessSpecifiedForIncorrectLocationNotice( |
| 44 | + entity.csvRowNumber(), |
| 45 | + entity.stopId(), |
| 46 | + entity.stopName(), |
| 47 | + entity.stopAccess(), |
| 48 | + entity.locationType())); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public boolean shouldCallValidate(ColumnInspector header) { |
| 54 | + return header.hasColumn(GtfsStop.STOP_ACCESS_FIELD_NAME); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * A stop without a value for parent station has stop_access specified. |
| 59 | + * |
| 60 | + * <p>stops.stop_access is forbidden for stops that are not associated with a parent station. |
| 61 | + */ |
| 62 | + @GtfsValidationNotice( |
| 63 | + severity = ERROR, |
| 64 | + files = @GtfsValidationNotice.FileRefs(GtfsStopSchema.class)) |
| 65 | + static class StopAccessSpecifiedForStopWithNoParentStationNotice extends ValidationNotice { |
| 66 | + /** The row of the faulty record. */ |
| 67 | + private final long csvRowNumber; |
| 68 | + |
| 69 | + /** The `stops.stop_id` of the faulty record. */ |
| 70 | + private final String stopId; |
| 71 | + |
| 72 | + /** The 'stops.stop_name' of the faulty record. */ |
| 73 | + private final String stopName; |
| 74 | + |
| 75 | + /** The `stops.stop_access` of the faulty record. */ |
| 76 | + private final GtfsStopAccess stopAccess; |
| 77 | + |
| 78 | + /** `stops.location_type` of the faulty record. */ |
| 79 | + private final GtfsLocationType locationType; |
| 80 | + |
| 81 | + public StopAccessSpecifiedForStopWithNoParentStationNotice( |
| 82 | + long csvRowNumber, |
| 83 | + String stopId, |
| 84 | + String stopName, |
| 85 | + GtfsStopAccess stopAccess, |
| 86 | + GtfsLocationType locationType) { |
| 87 | + this.csvRowNumber = csvRowNumber; |
| 88 | + this.stopId = stopId; |
| 89 | + this.stopName = stopName; |
| 90 | + this.stopAccess = stopAccess; |
| 91 | + this.locationType = locationType; |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * A location that is not a stop has stop_access specified. |
| 97 | + * |
| 98 | + * <p>Stops.stop_access is forbidden for locations that are stations, entrances, generic nodes or |
| 99 | + * boarding areas. It can only be specific when a stop is associated with a parent station. |
| 100 | + */ |
| 101 | + @GtfsValidationNotice( |
| 102 | + severity = ERROR, |
| 103 | + files = @GtfsValidationNotice.FileRefs(GtfsStopSchema.class)) |
| 104 | + static class StopAccessSpecifiedForIncorrectLocationNotice extends ValidationNotice { |
| 105 | + /** The row of the faulty record. */ |
| 106 | + private final long csvRowNumber; |
| 107 | + |
| 108 | + /** The `stops.stop_id` of the faulty record. */ |
| 109 | + private final String stopId; |
| 110 | + |
| 111 | + /** The 'stops.stop_name' of the faulty record. */ |
| 112 | + private final String stopName; |
| 113 | + |
| 114 | + /** The `stops.stop_access` of the faulty record. */ |
| 115 | + private final GtfsStopAccess stopAccess; |
| 116 | + |
| 117 | + /** `stops.location_type` of the faulty record. */ |
| 118 | + private final GtfsLocationType locationType; |
| 119 | + |
| 120 | + public StopAccessSpecifiedForIncorrectLocationNotice( |
| 121 | + long csvRowNumber, |
| 122 | + String stopId, |
| 123 | + String stopName, |
| 124 | + GtfsStopAccess stopAccess, |
| 125 | + GtfsLocationType locationType) { |
| 126 | + this.csvRowNumber = csvRowNumber; |
| 127 | + this.stopId = stopId; |
| 128 | + this.stopName = stopName; |
| 129 | + this.stopAccess = stopAccess; |
| 130 | + this.locationType = locationType; |
| 131 | + } |
| 132 | + } |
| 133 | +} |
0 commit comments