Skip to content

Commit

Permalink
fix: add support for externally defined newGTFSErrorType
Browse files Browse the repository at this point in the history
  • Loading branch information
miles-grant-ibigroup committed Jul 25, 2023
1 parent b0b94e4 commit 0bca927
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/main/java/com/conveyal/gtfs/error/NewGTFSError.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class NewGTFSError {
public Class<? extends Entity> entityType;

/** The kind of error encountered. */
public final NewGTFSErrorType errorType;
public final NewGTFSErrorInterface errorType;

/** Key-value pairs providing additional information about this error. */
public Map<String, String> errorInfo = new HashMap<>();
Expand Down Expand Up @@ -70,29 +70,29 @@ public NewGTFSError addInfo (String key, String value) {
* @param entityType should be supplied for a table, may be null if the error affects a whole feed.
* @param errorType must always be supplied.
*/
private NewGTFSError (Class<? extends Entity> entityType, NewGTFSErrorType errorType) {
private NewGTFSError (Class<? extends Entity> entityType, NewGTFSErrorInterface errorType) {
this.entityType = entityType;
this.errorType = errorType;
}

// Factory Builder for cases where an entity has not yet been constructed, but we know the line number.
public static NewGTFSError forLine (Table table, int lineNumber, NewGTFSErrorType errorType, String badValue) {
public static NewGTFSError forLine (Table table, int lineNumber, NewGTFSErrorInterface errorType, String badValue) {
NewGTFSError error = new NewGTFSError(table.getEntityClass(), errorType);
error.lineNumber = lineNumber;
error.badValue = badValue;
return error;
}

// Factory Builder for cases where an entity has not yet been constructed, but we know the line number.
public static NewGTFSError forLine(LineContext lineContext, NewGTFSErrorType errorType, String badValue) {
public static NewGTFSError forLine(LineContext lineContext, NewGTFSErrorInterface errorType, String badValue) {
NewGTFSError error = new NewGTFSError(lineContext.table.getEntityClass(), errorType);
error.lineNumber = lineContext.lineNumber;
error.badValue = badValue;
return error;
}

// Factory Builder for cases where the entity has already been decoded and an error is discovered during validation
public static NewGTFSError forEntity(Entity entity, NewGTFSErrorType errorType) {
public static NewGTFSError forEntity(Entity entity, NewGTFSErrorInterface errorType) {
NewGTFSError error = new NewGTFSError(entity.getClass(), errorType);
error.lineNumber = entity.id;
error.entityId = entity.getId();
Expand All @@ -101,12 +101,12 @@ public static NewGTFSError forEntity(Entity entity, NewGTFSErrorType errorType)
}

// Factory Builder
public static NewGTFSError forTable (Table table, NewGTFSErrorType errorType) {
public static NewGTFSError forTable (Table table, NewGTFSErrorInterface errorType) {
return new NewGTFSError(table.getEntityClass(), errorType);
}

// Factory Builder for feed-wide error
public static NewGTFSError forFeed (NewGTFSErrorType errorType, String badValue) {
public static NewGTFSError forFeed (NewGTFSErrorInterface errorType, String badValue) {
return new NewGTFSError(null, errorType).setBadValue(badValue);
}

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/conveyal/gtfs/error/NewGTFSErrorInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.conveyal.gtfs.error;

import com.conveyal.gtfs.validator.model.Priority;

/**
* Interface the enum implements, allowing for externally defined error types
*/
public interface NewGTFSErrorInterface {
Priority priority = null;
String englishMessage = null;

String name();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* This enum defines the GTFS error types that can be encountered when validating GTFS table data. Each error type has a
* severity level and related error message.
*/
public enum NewGTFSErrorType {
public enum NewGTFSErrorType implements NewGTFSErrorInterface {
// Standard errors.
AGENCY_ID_REQUIRED_FOR_MULTI_AGENCY_FEEDS(Priority.HIGH, "For GTFS feeds with more than one agency, agency_id is required."),
BOOLEAN_FORMAT(Priority.MEDIUM, "A GTFS boolean field must contain the value 1 or 0."),
Expand Down

0 comments on commit 0bca927

Please sign in to comment.