Skip to content

Commit bc6418c

Browse files
feat(AutoPublishJob): Add and hook auto publish job.
1 parent b281dea commit bc6418c

File tree

4 files changed

+83
-22
lines changed

4 files changed

+83
-22
lines changed

src/main/java/com/conveyal/datatools/manager/jobs/AutoPublishJob.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public void jobLogic() {
9999
// If validation successful, just execute the feed updating process.
100100
// FIXME: move method to another class.
101101
FeedVersionController.publishToExternalResource(latestFeedVersion);
102+
LOG.info("Auto-published feed source {} to external resource.", feedSource.id);
102103
} catch (Exception e) {
103104
status.fail(
104105
String.format("Could not auto-publish feed source %s!", feedSource.name),

src/main/java/com/conveyal/datatools/manager/jobs/ProcessSingleFeedJob.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,16 @@ public void jobLogic() {
150150
) {
151151
addNextJob(new AutoDeployJob(feedSource.retrieveProject(), owner));
152152
}
153+
154+
// If auto-publish job is enabled (MTC extension required),
155+
// create an auto-publish job for feeds that are fetched automatically.
156+
if (
157+
DataManager.isExtensionEnabled("mtc") &&
158+
feedSource.autoPublish &&
159+
feedVersion.retrievalMethod == FeedRetrievalMethod.FETCHED_AUTOMATICALLY
160+
) {
161+
addNextJob(new AutoPublishJob(feedSource, owner));
162+
}
153163
}
154164

155165
/**

src/main/java/com/conveyal/datatools/manager/models/FeedVersion.java

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,34 @@ private boolean hasFeedVersionExpired() {
407407
* @return whether high severity error types have been flagged.
408408
*/
409409
private boolean hasHighSeverityErrorTypes() {
410-
Set<String> highSeverityErrorTypes = Stream.of(NewGTFSErrorType.values())
411-
.filter(type -> type.priority == Priority.HIGH)
412-
.map(NewGTFSErrorType::toString)
413-
.collect(Collectors.toSet());
410+
return hasSpecificErrorTypes(Stream.of(NewGTFSErrorType.values())
411+
.filter(type -> type.priority == Priority.HIGH));
412+
}
413+
414+
/**
415+
* Checks for issues that block feed publishing, consistent with UI.
416+
*/
417+
public boolean hasBlockingIssuesForPublishing() {
418+
if (this.validationResult.fatalException != null) return true;
419+
420+
return hasSpecificErrorTypes(Stream.of(
421+
NewGTFSErrorType.ILLEGAL_FIELD_VALUE,
422+
NewGTFSErrorType.MISSING_COLUMN,
423+
NewGTFSErrorType.REFERENTIAL_INTEGRITY,
424+
NewGTFSErrorType.SERVICE_WITHOUT_DAYS_OF_WEEK,
425+
NewGTFSErrorType.TABLE_MISSING_COLUMN_HEADERS,
426+
NewGTFSErrorType.TABLE_IN_SUBDIRECTORY,
427+
NewGTFSErrorType.WRONG_NUMBER_OF_FIELDS
428+
));
429+
}
430+
431+
/**
432+
* Determines whether this feed has specific error types.
433+
*/
434+
private boolean hasSpecificErrorTypes(Stream<NewGTFSErrorType> errorTypes) {
435+
Set<String> highSeverityErrorTypes = errorTypes
436+
.map(NewGTFSErrorType::toString)
437+
.collect(Collectors.toSet());
414438
try (Connection connection = GTFS_DATA_SOURCE.getConnection()) {
415439
String sql = String.format("select distinct error_type from %s.errors", namespace);
416440
PreparedStatement preparedStatement = connection.prepareStatement(sql);
@@ -427,23 +451,8 @@ private boolean hasHighSeverityErrorTypes() {
427451
// is invalid for one reason or another.
428452
return true;
429453
}
430-
return false;
431-
}
432-
433-
/**
434-
* Checks for issues that block feed publishing, consistent with UI.
435-
*/
436-
public boolean hasBlockingIssuesForPublishing() {
437-
return this.validationResult.fatalException != null;
438-
/*
439-
if () return true;
440-
const errorCounts = version.validationResult.error_counts
441-
return errorCounts &&
442-
!!(errorCounts.find(ec => BLOCKING_ERROR_TYPES.indexOf(ec.type) !== -1))
443-
}
444454

445-
446-
*/
455+
return false;
447456
}
448457

449458
@JsonView(JsonViews.UserInterface.class)

src/test/java/com/conveyal/datatools/manager/models/FeedVersionTest.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,27 @@
33
import com.conveyal.datatools.DatatoolsTest;
44
import com.conveyal.datatools.UnitTest;
55
import com.conveyal.datatools.manager.persistence.Persistence;
6+
import com.conveyal.gtfs.error.NewGTFSError;
7+
import com.conveyal.gtfs.error.NewGTFSErrorType;
8+
import com.conveyal.gtfs.error.SQLErrorStorage;
9+
import com.conveyal.gtfs.util.InvalidNamespaceException;
610
import com.conveyal.gtfs.validator.ValidationResult;
711
import org.junit.jupiter.api.AfterAll;
812
import org.junit.jupiter.api.BeforeAll;
913
import org.junit.jupiter.api.Test;
14+
import org.junit.jupiter.params.ParameterizedTest;
15+
import org.junit.jupiter.params.provider.Arguments;
16+
import org.junit.jupiter.params.provider.EnumSource;
17+
import org.junit.jupiter.params.provider.MethodSource;
18+
import org.junit.jupiter.params.provider.ValueSource;
1019

20+
import java.sql.Connection;
21+
import java.sql.SQLException;
1122
import java.util.Date;
23+
import java.util.stream.Stream;
1224

25+
import static com.conveyal.datatools.TestUtils.createFeedVersionFromGtfsZip;
26+
import static com.conveyal.datatools.manager.DataManager.GTFS_DATA_SOURCE;
1327
import static org.hamcrest.MatcherAssert.assertThat;
1428
import static org.hamcrest.Matchers.equalTo;
1529
import static org.hamcrest.Matchers.not;
@@ -55,14 +69,41 @@ void canCreateUniqueFeedVersionIDs() {
5569
}
5670

5771
/**
58-
* Detect feeds with blocking issues for publishing.
72+
* Detect feeds with fatal exceptions (a blocking issue for publishing).
5973
*/
6074
@Test
61-
void canDetectBlockingIssuesForPublishing() {
75+
void canDetectBlockingFatalExceptionsForPublishing() {
6276
FeedVersion feedVersion1 = new FeedVersion(feedSource);
6377
feedVersion1.validationResult = new ValidationResult();
6478
feedVersion1.validationResult.fatalException = "A fatal exception occurred";
6579

6680
assertThat(feedVersion1.hasBlockingIssuesForPublishing(), equalTo(true));
6781
}
82+
83+
/**
84+
* Detect feeds with blocking error types that prevents publishing, per
85+
* https://github.com/ibi-group/datatools-ui/blob/dev/lib/manager/util/version.js#L79.
86+
*/
87+
@ParameterizedTest
88+
@EnumSource(value = NewGTFSErrorType.class, names = {
89+
"ILLEGAL_FIELD_VALUE",
90+
"MISSING_COLUMN",
91+
"REFERENTIAL_INTEGRITY",
92+
"SERVICE_WITHOUT_DAYS_OF_WEEK",
93+
"TABLE_MISSING_COLUMN_HEADERS",
94+
"TABLE_IN_SUBDIRECTORY",
95+
"WRONG_NUMBER_OF_FIELDS"
96+
})
97+
void canDetectBlockingErrorTypesForPublishing(NewGTFSErrorType errorType) throws InvalidNamespaceException, SQLException {
98+
FeedVersion feedVersion1 = createFeedVersionFromGtfsZip(feedSource, "bart_old_lite.zip");
99+
100+
// Add blocking error types to feed version
101+
try (Connection connection = GTFS_DATA_SOURCE.getConnection()) {
102+
SQLErrorStorage errorStorage = new SQLErrorStorage(connection, feedVersion1.namespace + ".", false);
103+
errorStorage.storeError(NewGTFSError.forFeed(errorType, null));
104+
errorStorage.commitAndClose();
105+
}
106+
107+
assertThat(feedVersion1.hasBlockingIssuesForPublishing(), equalTo(true));
108+
}
68109
}

0 commit comments

Comments
 (0)