Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Initial entry for @GtfsValidationNotice annotation #1361

Merged
merged 4 commits into from
Mar 27, 2023
Next Next commit
Initial entry for @GtfsValidationNotice annotation, which will be use…
…d to configure and document validation notices in source code.
  • Loading branch information
bdferris-v2 committed Mar 23, 2023
commit 99fd979bb2916252364631e7bb6a619b5a62ec73
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org.mobilitydata.gtfsvalidator.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.mobilitydata.gtfsvalidator.notice.SeverityLevel;
import org.mobilitydata.gtfsvalidator.table.GtfsEntity;

/**
* An annotation used to identify, configure, and document a validation notice. All notices should
* be annotated with this type.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface GtfsValidationNotice {
davidgamez marked this conversation as resolved.
Show resolved Hide resolved

/**
* The default severity level for the notice. The actual severity level may be configured to be
* different at validation time.
*/
SeverityLevel severity();

/**
* GTFS specification file references used in automatic documentation generation for the notice.
*/
FileRefs files() default @FileRefs({});

/**
* GTFS Best Practices file references used in automatic documentation generation for the notice.
*/
BestPracticesRefs bestPractices() default @BestPracticesRefs({});

/**
* Arbitrary documentation reference urls used in automatic documentation generation for the
* notice.
*/
UrlRef[] urls() default {};

/**
* Annotation used in notice documentation to specify a link to the specification documentation
* for a specific GTFS file, as identified by its table schema.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@interface BestPracticesRefs {
/** The set of GTFS table schemas corresponding to the GTFS file in question. */
Class<? extends GtfsEntity>[] value();
}

/**
* Annotation used in notice documentation to specify a link to the Best Practices documentation
* for a specific GTFS file, as identified by its table schema.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@interface FileRefs {
/** The set of GTFS table schemas corresponding to the GTFS file in question. */
Class<? extends GtfsEntity>[] value();

/** True if a particular notice applies to all files in the GTFS spec. */
boolean allFiles() default false;
}

/**
* Annotation used in notice documentation to specify a general reference URL for a notice. For
* links to specific GTFS file references and best-practices, use {@link FileRefs} or {@link
* BestPracticesRefs} instead.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@interface UrlRef {

/** The human-readable text used to display the url. */
String label();

/** The reference URL. */
String url();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.mobilitydata.gtfsvalidator.validator;

import static org.mobilitydata.gtfsvalidator.notice.SeverityLevel.ERROR;

import com.google.common.collect.Multimaps;
import java.time.LocalDate;
import java.util.ArrayList;
Expand All @@ -8,15 +10,18 @@
import java.util.List;
import java.util.Optional;
import javax.inject.Inject;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice.FileRefs;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice.UrlRef;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidator;
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer;
import org.mobilitydata.gtfsvalidator.notice.SeverityLevel;
import org.mobilitydata.gtfsvalidator.notice.ValidationNotice;
import org.mobilitydata.gtfsvalidator.table.GtfsCalendarDateTableContainer;
import org.mobilitydata.gtfsvalidator.table.GtfsCalendarTableContainer;
import org.mobilitydata.gtfsvalidator.table.GtfsStopTime;
import org.mobilitydata.gtfsvalidator.table.GtfsStopTimeTableContainer;
import org.mobilitydata.gtfsvalidator.table.GtfsTrip;
import org.mobilitydata.gtfsvalidator.table.GtfsTripSchema;
import org.mobilitydata.gtfsvalidator.table.GtfsTripTableContainer;
import org.mobilitydata.gtfsvalidator.type.GtfsDate;
import org.mobilitydata.gtfsvalidator.type.GtfsTime;
Expand Down Expand Up @@ -259,6 +264,13 @@ public LocalDate getIntersection() {
*
* <p>Severity: {@code SeverityLevel.ERROR}
*/
@GtfsValidationNotice(
severity = ERROR,
files = @FileRefs({GtfsTripSchema.class}),
urls =
@UrlRef(
label = "Original Python validator implementation",
url = "https://github.com/google/transitfeed"))
static class BlockTripsWithOverlappingStopTimesNotice extends ValidationNotice {

// The row number from `trips.txt` of the first faulty trip.
Expand Down Expand Up @@ -287,7 +299,7 @@ static class BlockTripsWithOverlappingStopTimesNotice extends ValidationNotice {

BlockTripsWithOverlappingStopTimesNotice(
GtfsTrip tripA, GtfsTrip tripB, GtfsDate intersection) {
super(SeverityLevel.ERROR);
super(ERROR);
this.csvRowNumberA = tripA.csvRowNumber();
this.tripIdA = tripA.tripId();
this.serviceIdA = tripA.serviceId();
Expand Down