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

fix: add support for externally defined newGTFSErrorType #390

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 4 additions & 3 deletions src/main/java/com/conveyal/gtfs/validator/Validator.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.conveyal.gtfs.validator;

import com.conveyal.gtfs.error.NewGTFSError;
import com.conveyal.gtfs.error.NewGTFSErrorInterface;
import com.conveyal.gtfs.error.NewGTFSErrorType;
import com.conveyal.gtfs.error.SQLErrorStorage;
import com.conveyal.gtfs.loader.Feed;
Expand Down Expand Up @@ -33,7 +34,7 @@ public Validator(Feed feed, SQLErrorStorage errorStorage) {
/**
* Store an error that affects a single line of a single table. Wraps the underlying error factory method.
*/
public void registerError(Entity entity, NewGTFSErrorType errorType) {
public void registerError(Entity entity, NewGTFSErrorInterface errorType) {
errorStorage.storeError(NewGTFSError.forEntity(entity, errorType));
}

Expand All @@ -49,7 +50,7 @@ public void storeErrors(Set<NewGTFSError> errors) {
* collection of errors need to be temporarily held before storing in batch (e.g., waiting to store travel time zero
* errors before it is determined that the entire feed uses travel times rounded to the minute).
*/
NewGTFSError createUnregisteredError (Entity entity, NewGTFSErrorType errorType) {
NewGTFSError createUnregisteredError (Entity entity, NewGTFSErrorInterface errorType) {
return NewGTFSError.forEntity(entity, errorType);
}

Expand All @@ -65,7 +66,7 @@ NewGTFSError createUnregisteredError (Entity entity, NewGTFSErrorType errorType)
* Store an error that affects a single line of a single table.
* Add a bad value to it.
*/
public void registerError(Entity entity, NewGTFSErrorType errorType, Object badValue) {
public void registerError(Entity entity, NewGTFSErrorInterface errorType, Object badValue) {
errorStorage.storeError(NewGTFSError.forEntity(entity, errorType).setBadValue(badValue.toString()));
}

Expand Down
Loading