diff --git a/legend-depot-artifacts-services/src/main/java/org/finos/legend/depot/services/artifacts/refresh/ProjectVersionRefreshHandler.java b/legend-depot-artifacts-services/src/main/java/org/finos/legend/depot/services/artifacts/refresh/ProjectVersionRefreshHandler.java index 73730695b..49c01fb2d 100644 --- a/legend-depot-artifacts-services/src/main/java/org/finos/legend/depot/services/artifacts/refresh/ProjectVersionRefreshHandler.java +++ b/legend-depot-artifacts-services/src/main/java/org/finos/legend/depot/services/artifacts/refresh/ProjectVersionRefreshHandler.java @@ -43,7 +43,6 @@ import org.finos.legend.depot.services.api.artifacts.handlers.ProjectArtifactsHandler; import org.finos.legend.depot.core.services.tracing.TracerFactory; import org.finos.legend.depot.core.services.metrics.PrometheusMetricsFactory; -import org.finos.legend.sdlc.domain.model.version.VersionId; import org.slf4j.Logger; import javax.inject.Inject; @@ -308,28 +307,10 @@ private void updateProjectVersionData(StoreProjectData project, String versionId private void updateProjectData(StoreProjectData projectData, String versionId) { - if (!VersionValidator.isSnapshotVersion(versionId)) + if (projectData.evaluateLatestVersionAndUpdate(versionId)) { - String latestVersion = calculateLatestVersion(projectData.getLatestVersion(), versionId); - if (!latestVersion.equals(projectData.getLatestVersion())) - { - projectData.setLatestVersion(latestVersion); - projects.createOrUpdate(projectData); - } - } - } - - private String calculateLatestVersion(String projectLatestVersion, String versionId) - { - if (projectLatestVersion == null) - { - return versionId; - } - else if (VersionId.parseVersionId(versionId).compareTo(VersionId.parseVersionId(projectLatestVersion)) > 1) - { - return versionId; + projects.createOrUpdate(projectData); } - return projectLatestVersion; } private String queueWorkToRefreshProjectVersion(StoreProjectData projectData, String versionId, boolean fullUpdate, boolean transitive, String parentEvent) diff --git a/legend-depot-core-data-api/src/main/java/org/finos/legend/depot/store/model/projects/StoreProjectData.java b/legend-depot-core-data-api/src/main/java/org/finos/legend/depot/store/model/projects/StoreProjectData.java index ea8f5b2cd..aab9f4a49 100644 --- a/legend-depot-core-data-api/src/main/java/org/finos/legend/depot/store/model/projects/StoreProjectData.java +++ b/legend-depot-core-data-api/src/main/java/org/finos/legend/depot/store/model/projects/StoreProjectData.java @@ -22,6 +22,8 @@ import org.apache.commons.lang.builder.HashCodeBuilder; import org.finos.legend.depot.store.model.HasIdentifier; import org.finos.legend.depot.domain.CoordinateData; +import org.finos.legend.sdlc.domain.model.version.VersionId; +import org.finos.legend.depot.domain.version.VersionValidator; @JsonIgnoreProperties(ignoreUnknown = true) public class StoreProjectData extends CoordinateData implements HasIdentifier @@ -78,6 +80,17 @@ public void setLatestVersion(String latestVersion) this.latestVersion = latestVersion; } + public boolean evaluateLatestVersionAndUpdate(String candidateVersion) + { + if (!VersionValidator.isSnapshotVersion(candidateVersion) && + (this.getLatestVersion() == null || VersionId.parseVersionId(candidateVersion).compareTo(VersionId.parseVersionId(this.getLatestVersion())) == 1)) + { + this.setLatestVersion(candidateVersion); + return true; + } + return false; + } + @Override @JsonIgnore public String getId() diff --git a/legend-depot-core-data-api/src/test/java/org/finos/legend/depot/domain/project/TestProjectValidator.java b/legend-depot-core-data-api/src/test/java/org/finos/legend/depot/domain/project/TestProjectUtilities.java similarity index 63% rename from legend-depot-core-data-api/src/test/java/org/finos/legend/depot/domain/project/TestProjectValidator.java rename to legend-depot-core-data-api/src/test/java/org/finos/legend/depot/domain/project/TestProjectUtilities.java index f8dabde5c..fb6acc5a8 100644 --- a/legend-depot-core-data-api/src/test/java/org/finos/legend/depot/domain/project/TestProjectValidator.java +++ b/legend-depot-core-data-api/src/test/java/org/finos/legend/depot/domain/project/TestProjectUtilities.java @@ -16,10 +16,11 @@ package org.finos.legend.depot.domain.project; import org.finos.legend.depot.domain.CoordinateValidator; +import org.finos.legend.depot.store.model.projects.StoreProjectData; import org.junit.Assert; import org.junit.Test; -public class TestProjectValidator +public class TestProjectUtilities { @Test @@ -41,4 +42,23 @@ public void validArtifactId() Assert.assertFalse(CoordinateValidator.isValidArtifactId("")); Assert.assertFalse(CoordinateValidator.isValidArtifactId("singleWordNoDots")); } + + @Test + public void testEvaluateLatestVersionAndUpdate() + { + StoreProjectData projectData = new StoreProjectData("PROD-1", "examples.test", "metadata", null, "2.1.0"); + + Assert.assertTrue(projectData.evaluateLatestVersionAndUpdate("3.0.0")); + Assert.assertEquals(projectData.getLatestVersion(), "3.0.0"); + + projectData.setLatestVersion("2.1.0"); + Assert.assertFalse(projectData.evaluateLatestVersionAndUpdate("2.1.0")); + Assert.assertFalse(projectData.evaluateLatestVersionAndUpdate("2.0.1")); + + projectData = new StoreProjectData("PROD-1", "examples.test", "metadata", null, null); + Assert.assertTrue(projectData.evaluateLatestVersionAndUpdate("3.0.0")); + Assert.assertEquals(projectData.getLatestVersion(), "3.0.0"); + + Assert.assertFalse(projectData.evaluateLatestVersionAndUpdate("master-SNAPSHOT")); + } }