diff --git a/main/src/main/java/org/mobilitydata/gtfsvalidator/table/GtfsFeedInfoSchema.java b/main/src/main/java/org/mobilitydata/gtfsvalidator/table/GtfsFeedInfoSchema.java index ac8957631d..b98f1df2fd 100644 --- a/main/src/main/java/org/mobilitydata/gtfsvalidator/table/GtfsFeedInfoSchema.java +++ b/main/src/main/java/org/mobilitydata/gtfsvalidator/table/GtfsFeedInfoSchema.java @@ -17,16 +17,11 @@ package org.mobilitydata.gtfsvalidator.table; import java.util.Locale; -import org.mobilitydata.gtfsvalidator.annotation.EndRange; -import org.mobilitydata.gtfsvalidator.annotation.FieldType; -import org.mobilitydata.gtfsvalidator.annotation.FieldTypeEnum; -import org.mobilitydata.gtfsvalidator.annotation.GtfsTable; -import org.mobilitydata.gtfsvalidator.annotation.Recommended; -import org.mobilitydata.gtfsvalidator.annotation.Required; +import org.mobilitydata.gtfsvalidator.annotation.*; import org.mobilitydata.gtfsvalidator.type.GtfsDate; @GtfsTable(value = "feed_info.txt", singleRow = true) -@Recommended +@ConditionallyRequired public interface GtfsFeedInfoSchema extends GtfsEntity { @Required String feedPublisherName(); diff --git a/main/src/main/java/org/mobilitydata/gtfsvalidator/validator/MissingFeedInfoValidator.java b/main/src/main/java/org/mobilitydata/gtfsvalidator/validator/MissingFeedInfoValidator.java new file mode 100644 index 0000000000..37a673a84e --- /dev/null +++ b/main/src/main/java/org/mobilitydata/gtfsvalidator/validator/MissingFeedInfoValidator.java @@ -0,0 +1,53 @@ +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.MissingRequiredFileNotice; +import org.mobilitydata.gtfsvalidator.notice.NoticeContainer; +import org.mobilitydata.gtfsvalidator.table.GtfsFeedInfo; +import org.mobilitydata.gtfsvalidator.table.GtfsFeedInfoTableContainer; +import org.mobilitydata.gtfsvalidator.table.GtfsTranslationTableContainer; + +/** + * The `MissingFeedInfoValidator` class is responsible for validating the presence of the + * `feed_info.txt` file in a GTFS feed. If the `feed_info.txt` file is missing, it generates + * appropriate validation notices. + * + *
The validation logic is as follows: - If the `feed_info.txt` file is missing and the + * `translations.txt` file is also missing, a `MissingRecommendedFileNotice` is generated. - If the + * `feed_info.txt` file is missing but the `translations.txt` file is present, a + * `MissingRequiredFileNotice` is generated. + * + *
This validator is part of the GTFS validation framework and is annotated with `@GtfsValidator` + * to indicate its role. + * + *
Dependencies: - `GtfsFeedInfoTableContainer`: Provides access to the `feed_info.txt` file
+ * data. - `GtfsTranslationTableContainer`: Provides access to the `translations.txt` file data. -
+ * `NoticeContainer`: Collects validation notices generated during the validation process.
+ */
+@GtfsValidator
+public class MissingFeedInfoValidator extends FileValidator {
+
+ private final GtfsFeedInfoTableContainer feedInfoTable;
+ private final GtfsTranslationTableContainer translationTable;
+
+ @Inject
+ public MissingFeedInfoValidator(
+ GtfsFeedInfoTableContainer feedInfoTable, GtfsTranslationTableContainer translationTable) {
+ this.feedInfoTable = feedInfoTable;
+ this.translationTable = translationTable;
+ }
+
+ @Override
+ public void validate(NoticeContainer noticeContainer) {
+ if (feedInfoTable.isMissingFile()) {
+ if (translationTable.isMissingFile()) {
+ noticeContainer.addValidationNotice(
+ new MissingRecommendedFileNotice(GtfsFeedInfo.FILENAME));
+ } else {
+ noticeContainer.addValidationNotice(new MissingRequiredFileNotice(GtfsFeedInfo.FILENAME));
+ }
+ }
+ }
+}
diff --git a/main/src/test/java/org/mobilitydata/gtfsvalidator/validator/MissingFeedInfoValidatorTest.java b/main/src/test/java/org/mobilitydata/gtfsvalidator/validator/MissingFeedInfoValidatorTest.java
new file mode 100644
index 0000000000..0dd0553dff
--- /dev/null
+++ b/main/src/test/java/org/mobilitydata/gtfsvalidator/validator/MissingFeedInfoValidatorTest.java
@@ -0,0 +1,54 @@
+package org.mobilitydata.gtfsvalidator.validator;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import java.util.List;
+import org.junit.Test;
+import org.mobilitydata.gtfsvalidator.notice.MissingRecommendedFileNotice;
+import org.mobilitydata.gtfsvalidator.notice.MissingRequiredFileNotice;
+import org.mobilitydata.gtfsvalidator.notice.NoticeContainer;
+import org.mobilitydata.gtfsvalidator.notice.ValidationNotice;
+import org.mobilitydata.gtfsvalidator.table.*;
+
+public class MissingFeedInfoValidatorTest {
+
+ private static List