Skip to content

Commit

Permalink
feat: 1829 flex invalid prior notice day range (#1858)
Browse files Browse the repository at this point in the history
* added PriorNoticeLastDayAfterStartDayNotice and validation logic
  • Loading branch information
qcdyx authored Oct 1, 2024
1 parent be675f3 commit bb23bf3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ public class BookingRulesEntityValidator extends SingleEntityValidator<GtfsBooki
public void validate(GtfsBookingRules entity, NoticeContainer noticeContainer) {
validateForbiddenRealTimeFields(entity, noticeContainer);
validateSameDayFields(entity, noticeContainer);
validatePriorNotice(entity, noticeContainer);
}

private void validatePriorNotice(GtfsBookingRules entity, NoticeContainer noticeContainer) {
if (entity.hasPriorNoticeLastDay()
&& entity.hasPriorNoticeStartDay()
&& entity.priorNoticeLastDay() > entity.priorNoticeStartDay()) {
noticeContainer.addValidationNotice(new PriorNoticeLastDayAfterStartDayNotice(entity));
}
}

private static void validateForbiddenRealTimeFields(
Expand Down Expand Up @@ -144,4 +153,36 @@ static class ForbiddenSameDayBookingFieldValueNotice extends ValidationNotice {
this.fieldNames = String.join(", ", forbiddenFields);
}
}

/**
* Prior notice last day earlier than start day.
*
* <p>Prior notice last day should not be greater than the prior notice start day in
* booking_rules.txt
*/
@GtfsValidationNotice(
severity = SeverityLevel.ERROR,
files = @FileRefs(GtfsBookingRulesSchema.class))
static class PriorNoticeLastDayAfterStartDayNotice extends ValidationNotice {

/** The row number of the faulty record. */
private final int csvRowNumber;

/** The value of the `prior_notice_last_day` of the faulty field. */
private final int priorNoticeLastDay;

/** The value of the `prior_notice_start_day` of the faulty field. */
private final int priorNoticeStartDay;

/**
* Constructs a new validation notice.
*
* @param bookingRule the booking rule entity that triggered this notice
*/
PriorNoticeLastDayAfterStartDayNotice(GtfsBookingRules bookingRule) {
this.csvRowNumber = bookingRule.csvRowNumber();
this.priorNoticeLastDay = bookingRule.priorNoticeLastDay();
this.priorNoticeStartDay = bookingRule.priorNoticeStartDay();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.mobilitydata.gtfsvalidator.table.GtfsBookingType;
import org.mobilitydata.gtfsvalidator.type.GtfsTime;
import org.mobilitydata.gtfsvalidator.validator.BookingRulesEntityValidator.ForbiddenRealTimeBookingFieldValueNotice;
import org.mobilitydata.gtfsvalidator.validator.BookingRulesEntityValidator.PriorNoticeLastDayAfterStartDayNotice;

@RunWith(JUnit4.class)
public class BookingRulesEntityValidatorTest {
Expand Down Expand Up @@ -118,4 +119,17 @@ public void sameDayBookingWithoutForbiddenFieldsShouldNotGenerateNotice() {

assertThat(generateNotices(bookingRule)).isEmpty();
}

@Test
public void priorNoticeLastDayAfterStartDayShouldGenerateNotice() {
GtfsBookingRules bookingRule =
new GtfsBookingRules.Builder()
.setCsvRowNumber(1)
.setPriorNoticeLastDay(5)
.setPriorNoticeStartDay(3)
.build();

assertThat(generateNotices(bookingRule))
.contains(new PriorNoticeLastDayAfterStartDayNotice(bookingRule));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ public void testNoticeClassFieldNames() {
"locationGroupId",
"locationId",
"bookingRuleId",
"fieldNames");
"fieldNames",
"priorNoticeLastDay",
"priorNoticeStartDay");
}

private static List<String> discoverValidationNoticeFieldNames() {
Expand Down

0 comments on commit bb23bf3

Please sign in to comment.