Skip to content

Commit 2919b7c

Browse files
authored
feat: 2051 stop access update schema and add notice for forbidden (#2087)
* added GtfsStopAccessEnum and StopAccessValidator
1 parent 6bc222e commit 2919b7c

File tree

5 files changed

+208
-1
lines changed

5 files changed

+208
-1
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.mobilitydata.gtfsvalidator.table;
2+
3+
import org.mobilitydata.gtfsvalidator.annotation.GtfsEnumValue;
4+
5+
@GtfsEnumValue(name = "ACCESSIBLE_VIA_PATHWAYS", value = 0)
6+
@GtfsEnumValue(name = "NOT_ACCESSIBLE_VIA_PATHWAYS", value = 1)
7+
public interface GtfsStopAccessEnum {}

main/src/main/java/org/mobilitydata/gtfsvalidator/table/GtfsStopSchema.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,6 @@ public interface GtfsStopSchema extends GtfsEntity {
7171
String levelId();
7272

7373
String platformCode();
74+
75+
GtfsStopAccess stopAccess();
7476
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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+
}

main/src/test/java/org/mobilitydata/gtfsvalidator/validator/NoticeFieldsTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ public void testNoticeClassFieldNames() {
230230
"fareProductId",
231231
"riderCategoryId1",
232232
"riderCategoryId2",
233-
"currencyCode");
233+
"currencyCode",
234+
"stopAccess");
234235
}
235236

236237
private static List<String> discoverValidationNoticeFieldNames() {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package org.mobilitydata.gtfsvalidator.validator;
2+
3+
import static com.google.common.truth.Truth.assertThat;
4+
5+
import java.util.List;
6+
import org.junit.Test;
7+
import org.junit.runner.RunWith;
8+
import org.junit.runners.JUnit4;
9+
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer;
10+
import org.mobilitydata.gtfsvalidator.notice.ValidationNotice;
11+
import org.mobilitydata.gtfsvalidator.table.GtfsLocationType;
12+
import org.mobilitydata.gtfsvalidator.table.GtfsStop;
13+
import org.mobilitydata.gtfsvalidator.table.GtfsStopAccess;
14+
15+
@RunWith(JUnit4.class)
16+
public class StopAccessValidatorTest {
17+
private static List<ValidationNotice> generateNotices(GtfsStop stop) {
18+
NoticeContainer noticeContainer = new NoticeContainer();
19+
new StopAccessValidator().validate(stop, noticeContainer);
20+
return noticeContainer.getValidationNotices();
21+
}
22+
23+
@Test
24+
public void stopLocationWithoutParentStation_generatesNotice() {
25+
GtfsStop stop =
26+
new GtfsStop.Builder()
27+
.setCsvRowNumber(7)
28+
.setStopId("S1")
29+
.setLocationType(GtfsLocationType.STOP)
30+
.setStopName("Stop 1")
31+
.setStopAccess(GtfsStopAccess.NOT_ACCESSIBLE_VIA_PATHWAYS)
32+
.build();
33+
34+
assertThat(generateNotices(stop))
35+
.containsExactly(
36+
new StopAccessValidator.StopAccessSpecifiedForStopWithNoParentStationNotice(
37+
7,
38+
"S1",
39+
"Stop 1",
40+
GtfsStopAccess.NOT_ACCESSIBLE_VIA_PATHWAYS,
41+
GtfsLocationType.STOP));
42+
}
43+
44+
@Test
45+
public void nonStopLocationWithStopAccess_generatesIncorrectLocationNotice() {
46+
GtfsStop stop =
47+
new GtfsStop.Builder()
48+
.setCsvRowNumber(9)
49+
.setStopId("S2")
50+
.setLocationType(GtfsLocationType.STATION)
51+
.setStopName("Stop 2")
52+
.setStopAccess(GtfsStopAccess.NOT_ACCESSIBLE_VIA_PATHWAYS)
53+
.build();
54+
55+
assertThat(generateNotices(stop))
56+
.containsExactly(
57+
new StopAccessValidator.StopAccessSpecifiedForIncorrectLocationNotice(
58+
9,
59+
"S2",
60+
"Stop 2",
61+
GtfsStopAccess.NOT_ACCESSIBLE_VIA_PATHWAYS,
62+
GtfsLocationType.STATION));
63+
}
64+
}

0 commit comments

Comments
 (0)