diff --git a/src/main/java/ch/naviqore/gtfs/schedule/GtfsScheduleFile.java b/src/main/java/ch/naviqore/gtfs/schedule/GtfsScheduleFile.java index 8c924b59..f4f442ed 100644 --- a/src/main/java/ch/naviqore/gtfs/schedule/GtfsScheduleFile.java +++ b/src/main/java/ch/naviqore/gtfs/schedule/GtfsScheduleFile.java @@ -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 + } } diff --git a/src/main/java/ch/naviqore/gtfs/schedule/GtfsScheduleReader.java b/src/main/java/ch/naviqore/gtfs/schedule/GtfsScheduleReader.java index 86ce17b6..9f364bd0 100644 --- a/src/main/java/ch/naviqore/gtfs/schedule/GtfsScheduleReader.java +++ b/src/main/java/ch/naviqore/gtfs/schedule/GtfsScheduleReader.java @@ -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; @@ -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"); } } } @@ -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"); } } }