From 87e54a46fbe4bc60cecf12c297de19c57b28dab5 Mon Sep 17 00:00:00 2001 From: Robin Beer Date: Tue, 10 Oct 2023 09:55:18 +0100 Subject: [PATCH] refactor(Upstream changes to export call): Updated to export proprietary files with comments --- pom.xml | 2 +- .../editor/controllers/api/SnapshotController.java | 13 +++++++++---- .../editor/jobs/ExportSnapshotToGTFSJob.java | 12 ++---------- .../controllers/api/FeedVersionController.java | 4 ++-- .../manager/jobs/ProcessSingleFeedJob.java | 3 ++- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index 0c3d529d1..8affc0ccb 100644 --- a/pom.xml +++ b/pom.xml @@ -268,7 +268,7 @@ com.github.conveyal gtfs-lib - a5f60417e38043d35148aa6873c93056e69e9c87 + 026599ba4907f4c42b24e883d154e63b0777dd31 diff --git a/src/main/java/com/conveyal/datatools/editor/controllers/api/SnapshotController.java b/src/main/java/com/conveyal/datatools/editor/controllers/api/SnapshotController.java index 6ed68bcc7..ebe45b692 100644 --- a/src/main/java/com/conveyal/datatools/editor/controllers/api/SnapshotController.java +++ b/src/main/java/com/conveyal/datatools/editor/controllers/api/SnapshotController.java @@ -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. */ @@ -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()); @@ -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."); } diff --git a/src/main/java/com/conveyal/datatools/editor/jobs/ExportSnapshotToGTFSJob.java b/src/main/java/com/conveyal/datatools/editor/jobs/ExportSnapshotToGTFSJob.java index 53c56b746..fc76890b5 100644 --- a/src/main/java/com/conveyal/datatools/editor/jobs/ExportSnapshotToGTFSJob.java +++ b/src/main/java/com/conveyal/datatools/editor/jobs/ExportSnapshotToGTFSJob.java @@ -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; @@ -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 diff --git a/src/main/java/com/conveyal/datatools/manager/controllers/api/FeedVersionController.java b/src/main/java/com/conveyal/datatools/manager/controllers/api/FeedVersionController.java index f4fe5c4d6..8f855efea 100644 --- a/src/main/java/com/conveyal/datatools/manager/controllers/api/FeedVersionController.java +++ b/src/main/java/com/conveyal/datatools/manager/controllers/api/FeedVersionController.java @@ -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; diff --git a/src/main/java/com/conveyal/datatools/manager/jobs/ProcessSingleFeedJob.java b/src/main/java/com/conveyal/datatools/manager/jobs/ProcessSingleFeedJob.java index 27585d946..c267fdd9a 100644 --- a/src/main/java/com/conveyal/datatools/manager/jobs/ProcessSingleFeedJob.java +++ b/src/main/java/com/conveyal/datatools/manager/jobs/ProcessSingleFeedJob.java @@ -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)); } }