|
| 1 | +package org.mobilitydata.gtfsvalidator.validator; |
| 2 | + |
| 3 | +import javax.inject.Inject; |
| 4 | +import org.mobilitydata.gtfsvalidator.annotation.GtfsValidator; |
| 5 | +import org.mobilitydata.gtfsvalidator.notice.MissingRecommendedFileNotice; |
| 6 | +import org.mobilitydata.gtfsvalidator.notice.MissingRequiredFileNotice; |
| 7 | +import org.mobilitydata.gtfsvalidator.notice.NoticeContainer; |
| 8 | +import org.mobilitydata.gtfsvalidator.table.GtfsFeedInfo; |
| 9 | +import org.mobilitydata.gtfsvalidator.table.GtfsFeedInfoTableContainer; |
| 10 | +import org.mobilitydata.gtfsvalidator.table.GtfsTranslationTableContainer; |
| 11 | + |
| 12 | +/** |
| 13 | + * The `MissingFeedInfoValidator` class is responsible for validating the presence of the |
| 14 | + * `feed_info.txt` file in a GTFS feed. If the `feed_info.txt` file is missing, it generates |
| 15 | + * appropriate validation notices. |
| 16 | + * |
| 17 | + * <p>The validation logic is as follows: - If the `feed_info.txt` file is missing and the |
| 18 | + * `translations.txt` file is also missing, a `MissingRecommendedFileNotice` is generated. - If the |
| 19 | + * `feed_info.txt` file is missing but the `translations.txt` file is present, a |
| 20 | + * `MissingRequiredFileNotice` is generated. |
| 21 | + * |
| 22 | + * <p>This validator is part of the GTFS validation framework and is annotated with `@GtfsValidator` |
| 23 | + * to indicate its role. |
| 24 | + * |
| 25 | + * <p>Dependencies: - `GtfsFeedInfoTableContainer`: Provides access to the `feed_info.txt` file |
| 26 | + * data. - `GtfsTranslationTableContainer`: Provides access to the `translations.txt` file data. - |
| 27 | + * `NoticeContainer`: Collects validation notices generated during the validation process. |
| 28 | + */ |
| 29 | +@GtfsValidator |
| 30 | +public class MissingFeedInfoValidator extends FileValidator { |
| 31 | + |
| 32 | + private final GtfsFeedInfoTableContainer feedInfoTable; |
| 33 | + private final GtfsTranslationTableContainer translationTable; |
| 34 | + |
| 35 | + @Inject |
| 36 | + public MissingFeedInfoValidator( |
| 37 | + GtfsFeedInfoTableContainer feedInfoTable, GtfsTranslationTableContainer translationTable) { |
| 38 | + this.feedInfoTable = feedInfoTable; |
| 39 | + this.translationTable = translationTable; |
| 40 | + } |
| 41 | + |
| 42 | + @Override |
| 43 | + public void validate(NoticeContainer noticeContainer) { |
| 44 | + if (feedInfoTable.isMissingFile()) { |
| 45 | + if (translationTable.isMissingFile()) { |
| 46 | + noticeContainer.addValidationNotice( |
| 47 | + new MissingRecommendedFileNotice(GtfsFeedInfo.FILENAME)); |
| 48 | + } else { |
| 49 | + noticeContainer.addValidationNotice(new MissingRequiredFileNotice(GtfsFeedInfo.FILENAME)); |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | +} |
0 commit comments