Skip to content

Commit 812eeac

Browse files
authored
feat: Initial entry for @GtfsValidationNotice annotation (#1361)
* Initial entry for @GtfsValidationNotice annotation, which will be used to configure and document validation notices in source code.
1 parent 2069c96 commit 812eeac

File tree

2 files changed

+94
-2
lines changed

2 files changed

+94
-2
lines changed

main/src/main/java/org/mobilitydata/gtfsvalidator/validator/BlockTripsWithOverlappingStopTimesValidator.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.mobilitydata.gtfsvalidator.validator;
22

3+
import static org.mobilitydata.gtfsvalidator.notice.SeverityLevel.ERROR;
4+
35
import com.google.common.collect.Multimaps;
46
import java.time.LocalDate;
57
import java.util.ArrayList;
@@ -8,15 +10,18 @@
810
import java.util.List;
911
import java.util.Optional;
1012
import javax.inject.Inject;
13+
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice;
14+
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice.FileRefs;
15+
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice.UrlRef;
1116
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidator;
1217
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer;
13-
import org.mobilitydata.gtfsvalidator.notice.SeverityLevel;
1418
import org.mobilitydata.gtfsvalidator.notice.ValidationNotice;
1519
import org.mobilitydata.gtfsvalidator.table.GtfsCalendarDateTableContainer;
1620
import org.mobilitydata.gtfsvalidator.table.GtfsCalendarTableContainer;
1721
import org.mobilitydata.gtfsvalidator.table.GtfsStopTime;
1822
import org.mobilitydata.gtfsvalidator.table.GtfsStopTimeTableContainer;
1923
import org.mobilitydata.gtfsvalidator.table.GtfsTrip;
24+
import org.mobilitydata.gtfsvalidator.table.GtfsTripSchema;
2025
import org.mobilitydata.gtfsvalidator.table.GtfsTripTableContainer;
2126
import org.mobilitydata.gtfsvalidator.type.GtfsDate;
2227
import org.mobilitydata.gtfsvalidator.type.GtfsTime;
@@ -259,6 +264,13 @@ public LocalDate getIntersection() {
259264
*
260265
* <p>Severity: {@code SeverityLevel.ERROR}
261266
*/
267+
@GtfsValidationNotice(
268+
severity = ERROR,
269+
files = @FileRefs({GtfsTripSchema.class}),
270+
urls =
271+
@UrlRef(
272+
label = "Original Python validator implementation",
273+
url = "https://github.com/google/transitfeed"))
262274
static class BlockTripsWithOverlappingStopTimesNotice extends ValidationNotice {
263275

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

288300
BlockTripsWithOverlappingStopTimesNotice(
289301
GtfsTrip tripA, GtfsTrip tripB, GtfsDate intersection) {
290-
super(SeverityLevel.ERROR);
302+
super(ERROR);
291303
this.csvRowNumberA = tripA.csvRowNumber();
292304
this.tripIdA = tripA.tripId();
293305
this.serviceIdA = tripA.serviceId();
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package org.mobilitydata.gtfsvalidator.annotation;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
import org.mobilitydata.gtfsvalidator.notice.SeverityLevel;
8+
import org.mobilitydata.gtfsvalidator.table.GtfsEntity;
9+
10+
/**
11+
* An annotation used to identify, configure, and document a validation notice. All notices should
12+
* be annotated with this type.
13+
*/
14+
@Retention(RetentionPolicy.RUNTIME)
15+
@Target(ElementType.TYPE)
16+
public @interface GtfsValidationNotice {
17+
18+
/**
19+
* The default severity level for the notice. The actual severity level may be configured to be
20+
* different at validation time.
21+
*/
22+
SeverityLevel severity();
23+
24+
/**
25+
* GTFS specification file references used in automatic documentation generation for the notice.
26+
*/
27+
FileRefs files() default @FileRefs({});
28+
29+
/**
30+
* GTFS Best Practices file references used in automatic documentation generation for the notice.
31+
*/
32+
BestPracticesRefs bestPractices() default @BestPracticesRefs({});
33+
34+
/**
35+
* Arbitrary documentation reference urls used in automatic documentation generation for the
36+
* notice.
37+
*/
38+
UrlRef[] urls() default {};
39+
40+
/**
41+
* Annotation used in notice documentation to specify a link to the specification documentation
42+
* for a specific GTFS file, as identified by its table schema.
43+
*/
44+
@Retention(RetentionPolicy.RUNTIME)
45+
@Target(ElementType.TYPE)
46+
@interface BestPracticesRefs {
47+
/** The set of GTFS table schemas corresponding to the GTFS file in question. */
48+
Class<? extends GtfsEntity>[] value();
49+
}
50+
51+
/**
52+
* Annotation used in notice documentation to specify a link to the Best Practices documentation
53+
* for a specific GTFS file, as identified by its table schema.
54+
*/
55+
@Retention(RetentionPolicy.RUNTIME)
56+
@Target(ElementType.TYPE)
57+
@interface FileRefs {
58+
/** The set of GTFS table schemas corresponding to the GTFS file in question. */
59+
Class<? extends GtfsEntity>[] value();
60+
61+
/** True if a particular notice applies to all files in the GTFS spec. */
62+
boolean allFiles() default false;
63+
}
64+
65+
/**
66+
* Annotation used in notice documentation to specify a general reference URL for a notice. For
67+
* links to specific GTFS file references and best-practices, use {@link FileRefs} or {@link
68+
* BestPracticesRefs} instead.
69+
*/
70+
@Retention(RetentionPolicy.RUNTIME)
71+
@Target(ElementType.TYPE)
72+
@interface UrlRef {
73+
74+
/** The human-readable text used to display the url. */
75+
String label();
76+
77+
/** The reference URL. */
78+
String url();
79+
}
80+
}

0 commit comments

Comments
 (0)