From a29b811a1346ee9ae7f38e51a655dc8317a567f1 Mon Sep 17 00:00:00 2001
From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com>
Date: Fri, 10 Feb 2023 16:11:42 -0500
Subject: [PATCH 1/5] chore(deps): Upgrade sparkjava to 2.9.4.
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 144cc41c2..fdf561578 100644
--- a/pom.xml
+++ b/pom.xml
@@ -218,7 +218,7 @@
com.sparkjava
spark-core
- 2.7.2
+ 2.9.4
From dd14d9718b6bf1f8713aa3b9c0032e3c07e35586 Mon Sep 17 00:00:00 2001
From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com>
Date: Thu, 6 Apr 2023 17:00:36 -0400
Subject: [PATCH 2/5] fix(FeedVersion): Remove parent publishedVersionId if
needed when deleting FeedVersion.
---
.../datatools/manager/models/FeedVersion.java | 14 +++++-
.../manager/models/FeedVersionTest.java | 46 +++++++++++++++++--
2 files changed, 55 insertions(+), 5 deletions(-)
diff --git a/src/main/java/com/conveyal/datatools/manager/models/FeedVersion.java b/src/main/java/com/conveyal/datatools/manager/models/FeedVersion.java
index b3615939f..41a8a192e 100644
--- a/src/main/java/com/conveyal/datatools/manager/models/FeedVersion.java
+++ b/src/main/java/com/conveyal/datatools/manager/models/FeedVersion.java
@@ -489,6 +489,8 @@ public void delete() {
fs.lastFetched = null;
Persistence.feedSources.replace(fs.id, fs);
}
+ ensurePublishedVersionIdIsUnset(fs);
+
feedStore.deleteFeed(id);
// Delete feed version tables in GTFS database
GTFS.delete(this.namespace, DataManager.GTFS_DATA_SOURCE);
@@ -499,7 +501,7 @@ public void delete() {
Persistence.deployments.getMongoCollection().updateMany(eq("projectId", this.parentFeedSource().projectId),
pull("feedVersionIds", this.id));
Persistence.feedVersions.removeById(this.id);
- this.parentFeedSource().renumberFeedVersions();
+ fs.renumberFeedVersions();
// recalculate feed expiration notifications in case the latest version has changed
Scheduler.scheduleExpirationNotifications(fs);
@@ -510,6 +512,16 @@ public void delete() {
}
}
+ /**
+ * If this feed version is referenced in the parent feed source by publishedVersionId,
+ * ensure that the field is set to null.
+ */
+ private void ensurePublishedVersionIdIsUnset(FeedSource fs) {
+ if (this.namespace != null && this.namespace.equals(fs.publishedVersionId)) {
+ Persistence.feedSources.updateField(fs.id, "publishedVersionId", null);
+ }
+ }
+
/**
* Assign characteristics from a new GTFS file to the feed version. This should generally be called directly after
* constructing the feed version (assuming the GTFS file is available). Characteristics set from file include:
diff --git a/src/test/java/com/conveyal/datatools/manager/models/FeedVersionTest.java b/src/test/java/com/conveyal/datatools/manager/models/FeedVersionTest.java
index 11889e000..7c0344f32 100644
--- a/src/test/java/com/conveyal/datatools/manager/models/FeedVersionTest.java
+++ b/src/test/java/com/conveyal/datatools/manager/models/FeedVersionTest.java
@@ -12,18 +12,15 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.EnumSource;
-import org.junit.jupiter.params.provider.MethodSource;
-import org.junit.jupiter.params.provider.ValueSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;
-import java.util.stream.Stream;
import static com.conveyal.datatools.TestUtils.createFeedVersionFromGtfsZip;
import static com.conveyal.datatools.manager.DataManager.GTFS_DATA_SOURCE;
+import static com.mongodb.client.model.Filters.eq;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
@@ -106,4 +103,45 @@ void canDetectBlockingErrorTypesForPublishing(NewGTFSErrorType errorType) throws
assertThat(feedVersion1.hasBlockingIssuesForPublishing(), equalTo(true));
}
+
+ /**
+ * {@link FeedSource::publishedVersionId} should be unset if it references a feed version being deleted.
+ */
+ @Test
+ void shouldDeletePublishedVersionIdWhenDeletingVersion() {
+ final String NAMESPACE = "published_namespace";
+
+ FeedSource storedFeedSource = Persistence.feedSources.getOneFiltered(eq("projectId", project.id));
+ String feedSourceId = storedFeedSource.id;
+
+ // Create a feed version linked to the feed source.
+ FeedVersion feedVersion1 = new FeedVersion(feedSource);
+ feedVersion1.namespace = NAMESPACE;
+ feedVersion1.feedSourceId = feedSourceId;
+ Persistence.feedVersions.create(feedVersion1);
+
+ // Other a feed version linked to the feed source.
+ FeedVersion feedVersion2 = new FeedVersion(feedSource);
+ feedVersion2.namespace = "other_namespace";
+ feedVersion2.feedSourceId = feedSourceId;
+ Persistence.feedVersions.create(feedVersion2);
+
+ // Set publishedVersionId of FeedSource as the namespace of the feed version, per FeedVersionController logic.
+ Persistence.feedSources.updateField(feedSourceId, "publishedVersionId", NAMESPACE);
+
+ // publishedVersionId should be set at this point.
+ assertThat(getPubVersionId(feedSourceId), equalTo(NAMESPACE));
+
+ // Deleting feedVersion2 should not touch publishedVersionId.
+ feedVersion2.delete();
+ assertThat(getPubVersionId(feedSourceId), equalTo(NAMESPACE));
+
+ // Deleting feedVersion1 should unset publishedVersionId.
+ feedVersion1.delete();
+ assertThat(getPubVersionId(feedSourceId), equalTo(null));
+ }
+
+ String getPubVersionId(String feedSourceId) {
+ return Persistence.feedSources.getById(feedSourceId).publishedVersionId;
+ }
}
From bec4fa2b7e66cd721327c64b18c46d24a4a5742c Mon Sep 17 00:00:00 2001
From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com>
Date: Fri, 21 Apr 2023 11:50:57 -0400
Subject: [PATCH 3/5] refactor(FeedVersionTest): Fix comment typo.
---
.../com/conveyal/datatools/manager/models/FeedVersionTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/test/java/com/conveyal/datatools/manager/models/FeedVersionTest.java b/src/test/java/com/conveyal/datatools/manager/models/FeedVersionTest.java
index 7c0344f32..a5b3e7b5f 100644
--- a/src/test/java/com/conveyal/datatools/manager/models/FeedVersionTest.java
+++ b/src/test/java/com/conveyal/datatools/manager/models/FeedVersionTest.java
@@ -120,7 +120,7 @@ void shouldDeletePublishedVersionIdWhenDeletingVersion() {
feedVersion1.feedSourceId = feedSourceId;
Persistence.feedVersions.create(feedVersion1);
- // Other a feed version linked to the feed source.
+ // Other feed version linked to the feed source, without effect to the published version.
FeedVersion feedVersion2 = new FeedVersion(feedSource);
feedVersion2.namespace = "other_namespace";
feedVersion2.feedSourceId = feedSourceId;
From 4100775f478eccec35f90dd4a41d225f345b2c3f Mon Sep 17 00:00:00 2001
From: "philip.cline"
Date: Tue, 25 Apr 2023 09:11:50 -0400
Subject: [PATCH 4/5] chore(gtfs lib): bump GTFS lib version
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 38229dc08..f9b95a751 100644
--- a/pom.xml
+++ b/pom.xml
@@ -262,7 +262,7 @@
com.github.conveyal
gtfs-lib
- ca419a8149
+ bdb76ee
From 70a01b7d282db11a7a337475a580a5d70475d895 Mon Sep 17 00:00:00 2001
From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com>
Date: Tue, 25 Apr 2023 10:01:29 -0400
Subject: [PATCH 5/5] test(FeedVersionTest): Add comments and cleanup code for
feed versions with fake namespaces.
---
.../datatools/manager/models/FeedVersionTest.java | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/src/test/java/com/conveyal/datatools/manager/models/FeedVersionTest.java b/src/test/java/com/conveyal/datatools/manager/models/FeedVersionTest.java
index a5b3e7b5f..9bbca2755 100644
--- a/src/test/java/com/conveyal/datatools/manager/models/FeedVersionTest.java
+++ b/src/test/java/com/conveyal/datatools/manager/models/FeedVersionTest.java
@@ -24,6 +24,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.notNullValue;
public class FeedVersionTest extends UnitTest {
private static Project project;
@@ -139,6 +140,14 @@ void shouldDeletePublishedVersionIdWhenDeletingVersion() {
// Deleting feedVersion1 should unset publishedVersionId.
feedVersion1.delete();
assertThat(getPubVersionId(feedSourceId), equalTo(null));
+
+ // The delete statements above will not remove the feed versions from Mongo.
+ // This is because of expected caught exceptions about deleting the non-existent namespaces in this test.
+ assertThat(Persistence.feedVersions.getById(feedVersion1.id), notNullValue());
+ assertThat(Persistence.feedVersions.getById(feedVersion2.id), notNullValue());
+ // Delete the feed versions manually as a result.
+ Persistence.feedVersions.removeById(feedVersion1.id);
+ Persistence.feedVersions.removeById(feedVersion2.id);
}
String getPubVersionId(String feedSourceId) {