From 5c64670e60da8d15c7fbcdb41f1c929e2f669fc6 Mon Sep 17 00:00:00 2001 From: Yannan <73408381+YannanGao-gs@users.noreply.github.com> Date: Thu, 26 Sep 2024 10:15:08 -0400 Subject: [PATCH] enable etag on latest version by resolving latest --- .../depot/server/resources/entities/EntitiesResource.java | 8 ++++++-- .../depot/services/entities/EntitiesServiceImpl.java | 4 ++-- .../depot/server/resources/TestEntitiesResource.java | 8 +++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/legend-depot-entities-services/src/main/java/org/finos/legend/depot/server/resources/entities/EntitiesResource.java b/legend-depot-entities-services/src/main/java/org/finos/legend/depot/server/resources/entities/EntitiesResource.java index c715c6e33..73e03df50 100644 --- a/legend-depot-entities-services/src/main/java/org/finos/legend/depot/server/resources/entities/EntitiesResource.java +++ b/legend-depot-entities-services/src/main/java/org/finos/legend/depot/server/resources/entities/EntitiesResource.java @@ -22,6 +22,7 @@ import org.finos.legend.depot.services.api.entities.EntitiesService; import org.finos.legend.depot.core.services.tracing.resources.TracingResource; import org.finos.legend.depot.services.api.EtagBuilder; +import org.finos.legend.depot.services.api.projects.ProjectsService; import javax.inject.Inject; import javax.ws.rs.DefaultValue; @@ -45,11 +46,13 @@ public class EntitiesResource extends TracingResource { private final EntitiesService entitiesService; + private final ProjectsService projectsService; @Inject - public EntitiesResource(EntitiesService entitiesService) + public EntitiesResource(EntitiesService entitiesService, ProjectsService projectsService) { this.entitiesService = entitiesService; + this.projectsService = projectsService; } @GET @@ -61,7 +64,8 @@ public Response getEntities(@PathParam("groupId") String groupId, @PathParam("versionId") @ApiParam(value = VersionValidator.VALID_VERSION_ID_TXT) String versionId, @Context Request request) { - return handle(GET_VERSION_ENTITIES, () -> this.entitiesService.getEntities(groupId, artifactId, versionId), request, () -> EtagBuilder.create().withGAV(groupId, artifactId, versionId).build()); + String resolvedVersionId = this.projectsService.resolveAliasesAndCheckVersionExists(groupId, artifactId, versionId); + return handle(GET_VERSION_ENTITIES, () -> this.entitiesService.getEntities(groupId, artifactId, resolvedVersionId), request, () -> EtagBuilder.create().withGAV(groupId, artifactId, resolvedVersionId).build()); } @GET diff --git a/legend-depot-entities-services/src/main/java/org/finos/legend/depot/services/entities/EntitiesServiceImpl.java b/legend-depot-entities-services/src/main/java/org/finos/legend/depot/services/entities/EntitiesServiceImpl.java index ca8ad7760..526e0818d 100644 --- a/legend-depot-entities-services/src/main/java/org/finos/legend/depot/services/entities/EntitiesServiceImpl.java +++ b/legend-depot-entities-services/src/main/java/org/finos/legend/depot/services/entities/EntitiesServiceImpl.java @@ -57,8 +57,8 @@ public EntitiesServiceImpl(Entities entities, ProjectsService projects) @Override public List getEntities(String groupId, String artifactId, String versionId) { - String version = this.projects.resolveAliasesAndCheckVersionExists(groupId, artifactId, versionId); - return entities.getAllEntities(groupId, artifactId, version); + String resolvedVersionId = this.projects.resolveAliasesAndCheckVersionExists(groupId, artifactId, versionId); + return entities.getAllEntities(groupId, artifactId, resolvedVersionId); } @Override diff --git a/legend-depot-entities-services/src/test/java/org/finos/legend/depot/server/resources/TestEntitiesResource.java b/legend-depot-entities-services/src/test/java/org/finos/legend/depot/server/resources/TestEntitiesResource.java index 088ae6616..1fc5f7b22 100644 --- a/legend-depot-entities-services/src/test/java/org/finos/legend/depot/server/resources/TestEntitiesResource.java +++ b/legend-depot-entities-services/src/test/java/org/finos/legend/depot/server/resources/TestEntitiesResource.java @@ -17,6 +17,7 @@ import org.finos.legend.depot.domain.project.ProjectVersion; import org.finos.legend.depot.services.api.metrics.query.QueryMetricsService; +import org.finos.legend.depot.services.api.projects.ProjectsService; import org.finos.legend.depot.services.metrics.query.InMemoryQueryMetricsRegistry; import org.finos.legend.depot.services.metrics.query.QueryMetricsServiceImpl; import org.finos.legend.depot.store.model.projects.StoreProjectData; @@ -60,8 +61,9 @@ public class TestEntitiesResource extends TestBaseServices private final Queue queue = mock(Queue.class); private UpdateEntities entitiesStore = new EntitiesMongo(mongoProvider); private EntitiesMongoTestUtils entityUtils = new EntitiesMongoTestUtils(mongoProvider); - private final EntitiesService entitiesService = new EntitiesServiceImpl(entitiesStore,new ProjectsServiceImpl(projectsVersions, projects, metricsRegistry, queue, new ProjectsConfiguration("master"))); - private EntitiesResource entitiesResource = new EntitiesResource(entitiesService); + private ProjectsService projectsService = new ProjectsServiceImpl(projectsVersions, projects, metricsRegistry, queue, new ProjectsConfiguration("master")); + private final EntitiesService entitiesService = new EntitiesServiceImpl(entitiesStore,projectsService); + private EntitiesResource entitiesResource = new EntitiesResource(entitiesService, projectsService); private QueryMetricsMongo metricsStore = new QueryMetricsMongo(mongoProvider); private QueryMetricsService metricsHandler = new QueryMetricsServiceImpl(metricsStore); @@ -135,7 +137,7 @@ public void canGetMetrics() throws InterruptedException metricsHandler.persist(metricsRegistry); Assert.assertNotNull(metricsStore.get("examples.metadata", "test", "2.3.0").get(0).getLastQueryTime()); - Assert.assertEquals(2, metricsStore.getAllStoredEntities().size()); + Assert.assertEquals(3, metricsStore.getAllStoredEntities().size()); } @Test