Skip to content

Commit

Permalink
ENH: NAV-14 - Add presence to GTFS file type
Browse files Browse the repository at this point in the history
- Introduce presence enum with levels: REQUIRED, OPTIONAL, CONDITIONALLY_REQUIRED, CONDITIONALLY_FORBIDDEN, RECOMMENDED.
- Throw FileNotFoundException if a required file is not provided.
  • Loading branch information
munterfi committed May 3, 2024
1 parent 0cc5f65 commit 050da21
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
30 changes: 19 additions & 11 deletions src/main/java/ch/naviqore/gtfs/schedule/GtfsScheduleFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,25 @@
@RequiredArgsConstructor
@Getter
public enum GtfsScheduleFile {
AGENCY("agency.txt"),
CALENDAR("calendar.txt"),
CALENDAR_DATES("calendar_dates.txt"),
// FARE_ATTRIBUTES("fare_attributes.txt"),
// FARE_RULES("fare_rules.txt"),
// FREQUENCIES("frequencies.txt"),
STOPS("stops.txt"),
ROUTES("routes.txt"),
// SHAPES("shapes.txt"),
TRIPS("trips.txt"),
STOP_TIMES("stop_times.txt");
// FEED_INFO("feed_info.txt", Presence.OPTIONAL),
// ATTRIBUTIONS("attributions.txt", Presence.OPTIONAL),
AGENCY("agency.txt", Presence.REQUIRED),
CALENDAR("calendar.txt", Presence.CONDITIONALLY_REQUIRED),
CALENDAR_DATES("calendar_dates.txt", Presence.CONDITIONALLY_REQUIRED),
// FARE_ATTRIBUTES("fare_attributes.txt", Presence.OPTIONAL),
// FARE_RULES("fare_rules.txt", Presence.OPTIONAL),
// FREQUENCIES("frequencies.txt", Presence.OPTIONAL),
STOPS("stops.txt", Presence.REQUIRED),
ROUTES("routes.txt", Presence.REQUIRED),
// SHAPES("shapes.txt", Presence.OPTIONAL),
TRIPS("trips.txt", Presence.REQUIRED),
STOP_TIMES("stop_times.txt", Presence.REQUIRED);
// TRANSFERS("transfers.txt", Presence.OPTIONAL);

private final String fileName;
private final Presence presence;

public enum Presence {
REQUIRED, OPTIONAL, CONDITIONALLY_REQUIRED, CONDITIONALLY_FORBIDDEN, RECOMMENDED
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -44,8 +45,8 @@ private static void readFromDirectory(File directory, GtfsScheduleParser parser)
if (csvFile.exists()) {
log.info("Reading GTFS CSV file: {}", csvFile.getAbsolutePath());
readCsvFile(csvFile, parser, fileType);
} else {
log.warn("GTFS CSV file {} not found", csvFile.getAbsolutePath());
} else if (fileType.getPresence() == GtfsScheduleFile.Presence.REQUIRED) {
throw new FileNotFoundException("Required GTFS CSV file" + csvFile.getAbsolutePath() + " not found");
}
}
}
Expand All @@ -63,8 +64,8 @@ private static void readFromZip(File zipFile, GtfsScheduleParser parser) throws
.get(), StandardCharsets.UTF_8)) {
readCsvRecords(reader, parser, fileType);
}
} else {
log.warn("GTFS file {} not found in ZIP", fileType.getFileName());
} else if (fileType.getPresence() == GtfsScheduleFile.Presence.REQUIRED) {
throw new FileNotFoundException("Required GTFS CSV file" + fileType.getFileName() + " not found in ZIP");
}
}
}
Expand Down

0 comments on commit 050da21

Please sign in to comment.