Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0fcaf9e
push for diff
cswilson252 Mar 2, 2026
ee49572
add to own file
cswilson252 Mar 2, 2026
ffbcca5
add validator functionality
cswilson252 Mar 3, 2026
d078d3b
half baked test +some lint
cswilson252 Mar 4, 2026
abadac7
push up actual notice tests
cswilson252 Mar 4, 2026
5caa4e8
fix to asserttrue?
cswilson252 Mar 8, 2026
e457ddc
assertThat?
cswilson252 Mar 8, 2026
4ca9741
make the non-errors assertFalse
cswilson252 Mar 9, 2026
13e3475
assertThat
cswilson252 Mar 9, 2026
32a2cfd
add import
cswilson252 Mar 9, 2026
4d5f495
other assertThat import
cswilson252 Mar 9, 2026
95a83c6
get rid of assertFalse
cswilson252 Mar 9, 2026
337b917
isFalse
cswilson252 Mar 9, 2026
0e93ab1
Merge branch 'master' into noShapesNoDrt
cswilson252 Mar 9, 2026
6923baf
Merge branch 'master' into noShapesNoDrt
cswilson252 Mar 23, 2026
a1c4524
copilot feedback
cswilson252 Mar 24, 2026
19a3143
missing import
cswilson252 Mar 27, 2026
f5e6311
comparisonfailure
cswilson252 Mar 27, 2026
d5196e4
we have to pass another arg, luckily its nullable
cswilson252 Mar 27, 2026
98c14d0
remove 1f check in favour of 1
cswilson252 Mar 27, 2026
ce9c224
isAtLeast assertation check
cswilson252 Mar 27, 2026
2447088
not 1l?
cswilson252 Mar 27, 2026
528b409
fix semicolon
cswilson252 Mar 27, 2026
8329286
Merge branch 'master' into noShapesNoDrt
cswilson252 Apr 22, 2026
dfe1600
correct tests and validator loop logic
cswilson252 May 4, 2026
22b978b
return, don't break
cswilson252 May 4, 2026
69af53e
lint
cswilson252 May 4, 2026
04c0638
fully remove arguments
cswilson252 May 4, 2026
3763437
0 rows
cswilson252 May 4, 2026
6962ced
-1 rows
cswilson252 May 4, 2026
516dab9
break if rows are -1
cswilson252 May 4, 2026
b86fa31
try returning
cswilson252 May 4, 2026
d7de502
[Skip CI] push method signature WIP
cswilson252 May 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ private <E extends GtfsEntity> int loadUniqueCount(
* "Zone-Based Demand Responsive Transit" feature.
* @return true if at least one trip with only location_id is found, false otherwise.
*/
private boolean hasAtLeastOneTripWithOnlyLocationId(GtfsFeedContainer feedContainer) {
var optionalStopTimeTable = feedContainer.getTableForFilename(GtfsStopTime.FILENAME);
public static <E extends GtfsEntityContainer> boolean hasAtLeastOneTripWithOnlyLocationId(E extendedTable, FeedContainer feedContainer) {
var optionalStopTimeTable = extendedTable.getTableForFilename(GtfsStopTime.FILENAME);
if (optionalStopTimeTable.isPresent()) {
for (GtfsEntity entity : optionalStopTimeTable.get().getEntities()) {
if (entity instanceof GtfsStopTime) {
Expand All @@ -206,8 +206,8 @@ private boolean hasAtLeastOneTripWithOnlyLocationId(GtfsFeedContainer feedContai
* "Fixed-Stops Demand Responsive Transit" feature.
* @return true if at least one trip with only location_group_id is found, false otherwise.
*/
private boolean hasAtLeastOneTripWithOnlyLocationGroupId(GtfsFeedContainer feedContainer) {
var optionalStopTimeTable = feedContainer.getTableForFilename(GtfsStopTime.FILENAME);
public static <E extends GtfsEntityContainer> boolean hasAtLeastOneTripWithOnlyLocationGroupId(E extendedTable, GtfsFeedContainer feedContainer) {
var optionalStopTimeTable = extendedTable.getTableForFilename(GtfsStopTime.FILENAME);
if (optionalStopTimeTable.isPresent()) {
for (GtfsEntity entity : optionalStopTimeTable.get().getEntities()) {
if (entity instanceof GtfsStopTime) {
Expand Down Expand Up @@ -791,9 +791,9 @@ public void loadServiceWindow(
}
}

private boolean hasAtLeastOneRecordInFile(
GtfsFeedContainer feedContainer, String featureFilename) {
var table = feedContainer.getTableForFilename(featureFilename);
public static <E extends GtfsEntityContainer> boolean hasAtLeastOneRecordInFile(
E extendedTable, GtfsFeedContainer feedContainer, String featureFilename) {
var table = extendedTable.getTableForFilename(featureFilename);
return table.isPresent() && table.get().entityCount() > 0;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package org.mobilitydata.gtfsvalidator.validator;

import javax.inject.Inject;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidator;
import org.mobilitydata.gtfsvalidator.notice.MissingRecommendedFileNotice;
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer;
import org.mobilitydata.gtfsvalidator.table.GtfsLocationGroupsTableContainer;
import org.mobilitydata.gtfsvalidator.table.GtfsShapeTableContainer;
import org.mobilitydata.gtfsvalidator.table.GtfsStopTime;
import org.mobilitydata.gtfsvalidator.table.GtfsStopTimeTableContainer;

/**
* Validates that the feed has either a `shapes.txt` file, or uses zone-based DRT or fixed-stops
* DRT.
*
* <p>Generated notice: {@link MissingRecommendedFileNotice}.
*/
@GtfsValidator
public class MissingShapesFileValidator extends FileValidator {
private final GtfsShapeTableContainer shapeTable;
private final GtfsStopTimeTableContainer stopTimeTable;
private final GtfsLocationGroupsTableContainer locationGroupsTable;

@Inject
MissingShapesFileValidator(
GtfsShapeTableContainer shapeTable,
GtfsStopTimeTableContainer stopTimeTable,
GtfsLocationGroupsTableContainer locationGroupsTable) {
this.shapeTable = shapeTable;
this.stopTimeTable = stopTimeTable;
this.locationGroupsTable = locationGroupsTable;
}

@Override
public void validate(NoticeContainer noticeContainer) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] Reuse FeedMetadata logic instead of re-implementing it

The DRT detection logic already exists in FeedMetadata:

  • hasAtLeastOneTripWithOnlyLocationId(), zone-based DRT check
  • hasAtLeastOneTripWithOnlyLocationGroupId() + hasAtLeastOneRecordInFile(), fixed-stops DRT check (mirrors loadFixedStopsDemandResponseTransit)

To reuse them in MissingShapesFileValidator, these three methods need to be made public static and their signatures updated to accept the individual table containers directly (e.g. GtfsStopTimeTableContainer and GtfsLocationGroupsTableContainer).

This avoids duplicating the DRT detection logic and ensures the validator stays consistent with how features are detected elsewhere in the codebase. It would also make the validate() method read clearly:

 boolean hasZoneBasedDrt = FeedMetadata.hasAtLeastOneTripWithOnlyLocationId(stopTimeTable);
 boolean hasFixedStopsDrt = FeedMetadata.hasAtLeastOneRecordInFile(locationGroupsTable)
     && FeedMetadata.hasAtLeastOneTripWithOnlyLocationGroupId(stopTimeTable);
 
 if (shapeTable.isMissingFile() && !hasZoneBasedDrt && !hasFixedStopsDrt) {
     noticeContainer.addValidationNotice(new MissingRecommendedFileNotice("shapes.txt"));
 }

Alternative: add hasZoneBasedDemandResponseService and hasFixedStopsDemandResponseService to FeedMetadata

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in order to update the signatures to accept table containers directly, do I extend GtfsEntityContainer or GtfsTableContainer? i'm unclear on how much abstraction is in play here

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to raise the abstraction level. Most of the changes involve visibility (private -> public) and making some methods static. I quickly went through your latest commit, and it seems you are on the right track.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what I meant to say is that I'm not exactly clear on what the method signatures should be updated to.. :(

Boolean missingShapes = shapeTable.isMissingFile();
Comment thread
cswilson252 marked this conversation as resolved.
if (!missingShapes) {
return;
}

Boolean hasLocationId = stopTimeTable.hasColumn("location_id");
Boolean hasLocationGroupId = stopTimeTable.hasColumn("location_group_id");
Boolean hasLocationGroupsRecord =
!locationGroupsTable.isMissingFile() && locationGroupsTable.entityCount() > 0;
// Detect DRT usage from the data, not just from column presence.
boolean hasLocationIdInData = false;
boolean hasLocationGroupIdInData = false;
for (GtfsStopTime stopTime : stopTimeTable.getEntities()) {
if (stopTime.hasLocationId()) {
hasLocationIdInData = true;
}
if (stopTime.hasLocationGroupId()) {
hasLocationGroupIdInData = true;
}
if (hasLocationIdInData && hasLocationGroupIdInData) {
break;
}
}

// Do we not have: a shapes.txt file and not have a location_id (required for Zone-Based DRT),
// and also not have a record in location_groups.txt and not have a trip in stop_times.txt that
// references location_group_id (required for Fixed-Stop DRT)?
if (missingShapes && !hasLocationId && !hasLocationGroupsRecord && !hasLocationGroupId) {
noticeContainer.addValidationNotice(new MissingRecommendedFileNotice("shapes.txt"));
// This is a feed-level warning; emit it at most once.
return;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package org.mobilitydata.gtfsvalidator.validator;

import static com.google.common.truth.Truth.assertThat;

import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.mobilitydata.gtfsvalidator.notice.MissingRecommendedFileNotice;
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer;
import org.mobilitydata.gtfsvalidator.notice.ValidationNotice;
import org.mobilitydata.gtfsvalidator.table.GtfsLocationGroups;
import org.mobilitydata.gtfsvalidator.table.GtfsLocationGroupsTableContainer;
import org.mobilitydata.gtfsvalidator.table.GtfsShape;
import org.mobilitydata.gtfsvalidator.table.GtfsShapeTableContainer;
import org.mobilitydata.gtfsvalidator.table.GtfsStopTime;
import org.mobilitydata.gtfsvalidator.table.GtfsStopTimeTableContainer;

public class MissingShapesFileValidatorTest {

private static List<GtfsShape> createShapeTable(int rows) {
ArrayList<GtfsShape> shapes = new ArrayList<>();
for (int i = 0; i < rows; i++) {
if (rows == -1) {
return null;
}
shapes.add(new GtfsShape.Builder().setCsvRowNumber(i + 1).setShapeId("s" + i).build());
}
return shapes;
}

private static List<GtfsStopTime> createStopTimesTable(
int rows, String locationGroupId, String locationId) {
ArrayList<GtfsStopTime> stopTimes = new ArrayList<>();
for (int i = 0; i < rows; i++) {
stopTimes.add(
new GtfsStopTime.Builder()
.setCsvRowNumber(i + 1)
.setLocationGroupId(locationGroupId)
.setLocationId(locationId)
.setTripId(locationGroupId)
.setStopSequence(i + 1)
.build());
}
Comment thread
cswilson252 marked this conversation as resolved.
return stopTimes;
}

private static List<GtfsLocationGroups> createLocationGroupsTable(
int rows, String groupId, String groupName) {
ArrayList<GtfsLocationGroups> locationGroups = new ArrayList<>();
for (int i = 0; i < rows; i++) {
locationGroups.add(
new GtfsLocationGroups.Builder()
.setCsvRowNumber(i + 1)
.setLocationGroupId(groupId)
.setLocationGroupName(groupName)
.build());
}
return locationGroups;
}

@Test
public void testShapesFileAndFixedDrtPresent() {
List<ValidationNotice> notices =
generateNotices(
createShapeTable(1),
createStopTimesTable(1, "a", null),
createLocationGroupsTable(1, "b", "testgroup"));
boolean found =
notices.stream().anyMatch(notice -> notice instanceof MissingRecommendedFileNotice);
assertThat(found).isFalse();
}

@Test
public void testShapesFileAndZoneBasedDrtPresent() {
List<ValidationNotice> notices =
generateNotices(
createShapeTable(1),
createStopTimesTable(1, null, "c"),
createLocationGroupsTable(1, "d", "t3stgroup"));
boolean found =
notices.stream().anyMatch(notice -> notice instanceof MissingRecommendedFileNotice);
assertThat(found).isFalse();
}

@Test
public void testNoShapesFileAndNoDrtPresent() {
List<ValidationNotice> notices =
generateNotices(
createShapeTable(-1),
createStopTimesTable(1, null, null),
createLocationGroupsTable(0, null, null));
long missingRecommendedFileNoticesCount =
notices.stream().filter(notice -> notice instanceof MissingRecommendedFileNotice).count();
assertThat(missingRecommendedFileNoticesCount).isAtLeast(1);
}

private static List<ValidationNotice> generateNotices(
Comment thread
cswilson252 marked this conversation as resolved.
List<GtfsShape> shapes,
List<GtfsStopTime> stopTimes,
List<GtfsLocationGroups> locationGroups) {
NoticeContainer noticeContainer = new NoticeContainer();
new MissingShapesFileValidator(
GtfsShapeTableContainer.forEntities(shapes, noticeContainer),
GtfsStopTimeTableContainer.forEntities(stopTimes, noticeContainer),
GtfsLocationGroupsTableContainer.forEntities(locationGroups, noticeContainer))
.validate(noticeContainer);
return noticeContainer.getValidationNotices();
}
}
Loading