-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #342 from conveyal/dev
Fix release January 7, 2022
- Loading branch information
Showing
9 changed files
with
87 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/com/conveyal/gtfs/validator/ParentStationValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.conveyal.gtfs.validator; | ||
|
||
import com.conveyal.gtfs.error.NewGTFSError; | ||
import com.conveyal.gtfs.error.SQLErrorStorage; | ||
import com.conveyal.gtfs.loader.Feed; | ||
import com.conveyal.gtfs.loader.Table; | ||
import com.conveyal.gtfs.model.Stop; | ||
import com.google.common.collect.HashMultimap; | ||
import com.google.common.collect.Multimap; | ||
import com.google.common.collect.Sets; | ||
|
||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import static com.conveyal.gtfs.error.NewGTFSErrorType.REFERENTIAL_INTEGRITY; | ||
|
||
/** | ||
* Find stop#parent_station values that reference non-existent stop_ids. Unfortunately, we cannot perform this check | ||
* while the stops.txt table is being loaded because we do not yet have the full set of stop_ids available to check | ||
* parent_station values against. | ||
*/ | ||
public class ParentStationValidator extends FeedValidator { | ||
|
||
public ParentStationValidator(Feed feed, SQLErrorStorage errorStorage) { | ||
super(feed, errorStorage); | ||
} | ||
|
||
@Override | ||
public void validate () { | ||
Multimap<String, Stop> stopsForParentStations = HashMultimap.create(); | ||
Set<String> stopIds = new HashSet<>(); | ||
for (Stop stop : feed.stops) { | ||
// Collect all stop_ids found in feed. | ||
stopIds.add(stop.stop_id); | ||
// Collect all non-null parent_station values. | ||
if (stop.parent_station != null) { | ||
stopsForParentStations.put(stop.parent_station, stop); | ||
} | ||
} | ||
// Find parent_station values that do not reference a valid stop_id from feed. | ||
Sets.SetView<String> badReferences = Sets.difference(stopsForParentStations.keySet(), stopIds); | ||
for (String parentStation : badReferences) { | ||
// For any bad parent_station ref (this could be more than one stop), add an error to the error storage. | ||
Collection<Stop> stops = stopsForParentStations.get(parentStation); | ||
for (Stop stop : stops) { | ||
registerError( | ||
NewGTFSError | ||
.forLine(Table.STOPS, stop.id, REFERENTIAL_INTEGRITY, parentStation) | ||
.setEntityId(stop.stop_id) | ||
); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters