Skip to content

Commit

Permalink
refactor(Upstream changes to export call): Updated to export propriet…
Browse files Browse the repository at this point in the history
…ary files with comments
  • Loading branch information
br648 committed Oct 10, 2023
1 parent 3ac3e7d commit 87e54a4
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
<groupId>com.github.conveyal</groupId>
<artifactId>gtfs-lib</artifactId>
<!-- Latest dev build on jitpack.io -->
<version>a5f60417e38043d35148aa6873c93056e69e9c87</version>
<version>026599ba4907f4c42b24e883d154e63b0777dd31</version>
<!-- Exclusions added in order to silence SLF4J warnings about multiple bindings:
http://www.slf4j.org/codes.html#multiple_bindings
-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ private static Snapshot getSnapshotFromRequest(Request req) {
return Persistence.snapshots.getById(id);
}

private static boolean getPublishProprietaryFiles(Request req) {
return Boolean.parseBoolean(
req.queryParamOrDefault("publishProprietaryFiles",Boolean.FALSE.toString())
);
}

/**
* HTTP endpoint that returns the list of snapshots for a given feed source.
*/
Expand All @@ -84,9 +90,7 @@ private static String createSnapshot (Request req, Response res) throws IOExcept
boolean publishNewVersion = Boolean.parseBoolean(
req.queryParamOrDefault("publishNewVersion", Boolean.FALSE.toString())
);
boolean publishProprietaryFiles = Boolean.parseBoolean(
req.queryParamOrDefault("publishProprietaryFiles", Boolean.FALSE.toString())
);
boolean publishProprietaryFiles = getPublishProprietaryFiles(req);
FeedSource feedSource = FeedVersionController.requestFeedSourceById(req, Actions.EDIT, "feedId");
// Take fields from request body for creating snapshot (i.e., feedId/feedSourceId, name, comment).
Snapshot snapshot = json.read(req.body());
Expand Down Expand Up @@ -176,9 +180,10 @@ private static String restoreSnapshot (Request req, Response res) {
private static String downloadSnapshotAsGTFS(Request req, Response res) {
Auth0UserProfile userProfile = req.attribute("user");
Snapshot snapshot = getSnapshotFromRequest(req);
boolean publishProprietaryFiles = getPublishProprietaryFiles(req);
// Create and kick off export job.
// FIXME: what if a snapshot is already written to S3?
ExportSnapshotToGTFSJob exportSnapshotToGTFSJob = new ExportSnapshotToGTFSJob(userProfile, snapshot);
ExportSnapshotToGTFSJob exportSnapshotToGTFSJob = new ExportSnapshotToGTFSJob(userProfile, snapshot, publishProprietaryFiles);
JobUtils.heavyExecutor.execute(exportSnapshotToGTFSJob);
return formatJobMessage(exportSnapshotToGTFSJob.jobId, "Exporting snapshot to GTFS.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ public class ExportSnapshotToGTFSJob extends MonitorableJob {
private File tempFile;
private final boolean publishProprietaryFiles;

public ExportSnapshotToGTFSJob(Auth0UserProfile owner, Snapshot snapshot, FeedVersion feedVersion) {
super(owner, "Exporting snapshot " + snapshot.name, JobType.EXPORT_SNAPSHOT_TO_GTFS);
this.snapshot = snapshot;
this.feedVersion = feedVersion;
this.publishProprietaryFiles = false; // DEFAULT. TODO: don't hide this here.
status.update("Starting database snapshot...", 10);
}

public ExportSnapshotToGTFSJob(Auth0UserProfile owner, Snapshot snapshot, FeedVersion feedVersion, boolean publishProprietaryFiles) {
super(owner, "Exporting snapshot " + snapshot.name, JobType.EXPORT_SNAPSHOT_TO_GTFS);
this.snapshot = snapshot;
Expand All @@ -46,8 +38,8 @@ public ExportSnapshotToGTFSJob(Auth0UserProfile owner, Snapshot snapshot, FeedVe
status.update("Starting database snapshot...", 10);
}

public ExportSnapshotToGTFSJob(Auth0UserProfile owner, Snapshot snapshot) {
this(owner, snapshot, null);
public ExportSnapshotToGTFSJob(Auth0UserProfile owner, Snapshot snapshot, boolean publishProprietaryFiles) {
this(owner, snapshot, null, publishProprietaryFiles);
}

@JsonProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ private static boolean createFeedVersionFromSnapshot (Request req, Response res)
if (snapshot == null) {
logMessageAndHalt(req, 400, "Must provide valid snapshot ID");
}
// TODO: Allow publishing with proprietary files from this endpoint?
// Publishing the proprietary files will preserve the pattern names in the newly published feed version.
CreateFeedVersionFromSnapshotJob createFromSnapshotJob =
new CreateFeedVersionFromSnapshotJob(feedSource, snapshot, userProfile, false);
new CreateFeedVersionFromSnapshotJob(feedSource, snapshot, userProfile, true);
JobUtils.heavyExecutor.execute(createFromSnapshotJob);

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ public void jobLogic() {
snapshot.feedTransformResult = dbTarget.feedTransformResult;
// If the user has selected to create a new version from the resulting snapshot, do so here.
if (rules.createNewVersion) {
addNextJob(new CreateFeedVersionFromSnapshotJob(feedSource, snapshot, owner, false));
// Publishing the proprietary files will preserve the pattern names in the newly created feed version.
addNextJob(new CreateFeedVersionFromSnapshotJob(feedSource, snapshot, owner, true));
}
}

Expand Down

0 comments on commit 87e54a4

Please sign in to comment.