diff --git a/legend-depot-core-data-services/src/main/java/org/finos/legend/depot/server/resources/dependencies/DependenciesResource.java b/legend-depot-core-data-services/src/main/java/org/finos/legend/depot/server/resources/dependencies/DependenciesResource.java index c2fc0b60a..f11d4582f 100644 --- a/legend-depot-core-data-services/src/main/java/org/finos/legend/depot/server/resources/dependencies/DependenciesResource.java +++ b/legend-depot-core-data-services/src/main/java/org/finos/legend/depot/server/resources/dependencies/DependenciesResource.java @@ -25,7 +25,6 @@ import org.finos.legend.depot.domain.VersionedData; import org.finos.legend.depot.domain.project.ProjectVersion; import org.finos.legend.depot.domain.project.Property; -import org.finos.legend.depot.domain.project.dependencies.ProjectDependencyReport; import org.finos.legend.depot.domain.project.dependencies.ProjectDependencyWithPlatformVersions; import org.finos.legend.depot.domain.version.VersionValidator; import org.finos.legend.depot.server.resources.projects.ProjectsResource; @@ -83,23 +82,23 @@ public Response getProjectDependencies(@PathParam("groupId") String groupId, @Path("/projects/analyzeDependencyTree") @ApiOperation(GET_PROJECT_DEPENDENCY_TREE) @Produces(MediaType.APPLICATION_JSON) - public ProjectDependencyReport analyzeDependencyTree(@ApiParam("projectDependencies") List projectDependencies) + public Response analyzeDependencyTree(@ApiParam("projectDependencies") List projectDependencies) { - return handle(GET_PROJECT_DEPENDENCY_TREE, GET_PROJECT_DEPENDENCY_TREE, () -> this.projectApi.getProjectDependencyReport(projectDependencies)); + return handleResponse(GET_PROJECT_DEPENDENCY_TREE, () -> this.projectApi.getProjectDependencyReport(projectDependencies)); } @GET @Path("/projects/{groupId}/{artifactId}/versions/{versionId}/dependantProjects") @ApiOperation(GET_DEPENDANT_PROJECTS) @Produces(MediaType.APPLICATION_JSON) - public List getDependantProjects(@PathParam("groupId") String groupId, - @PathParam("artifactId") String artifactId, - @PathParam("versionId") @ApiParam(value = VersionValidator.VALID_VERSION_ID_TXT) String versionId, - @QueryParam("latestOnly") @DefaultValue("false") + public Response getDependantProjects(@PathParam("groupId") String groupId, + @PathParam("artifactId") String artifactId, + @PathParam("versionId") @ApiParam(value = VersionValidator.VALID_VERSION_ID_TXT) String versionId, + @QueryParam("latestOnly") @DefaultValue("false") @ApiParam("Whether to only return the latest version of dependant projects") boolean latestOnly ) { - return handle(GET_DEPENDANT_PROJECTS, GET_DEPENDANT_PROJECTS + groupId + artifactId, () -> transform(this.projectApi.getDependantProjects(groupId, artifactId, versionId, latestOnly))); + return handleResponse(GET_DEPENDANT_PROJECTS, GET_DEPENDANT_PROJECTS + groupId + artifactId, () -> transform(this.projectApi.getDependantProjects(groupId, artifactId, versionId, latestOnly))); } diff --git a/legend-depot-core-data-services/src/main/java/org/finos/legend/depot/server/resources/projects/ProjectsResource.java b/legend-depot-core-data-services/src/main/java/org/finos/legend/depot/server/resources/projects/ProjectsResource.java index e9f0e2b77..60078a6bb 100644 --- a/legend-depot-core-data-services/src/main/java/org/finos/legend/depot/server/resources/projects/ProjectsResource.java +++ b/legend-depot-core-data-services/src/main/java/org/finos/legend/depot/server/resources/projects/ProjectsResource.java @@ -22,7 +22,6 @@ import io.swagger.annotations.ApiParam; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; -import org.finos.legend.depot.store.model.projects.StoreProjectData; import org.finos.legend.depot.services.api.projects.ProjectsService; import org.finos.legend.depot.core.services.tracing.resources.TracingResource; import org.finos.legend.depot.core.services.tracing.ResourceLoggingAndTracing; @@ -35,8 +34,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; -import java.util.List; -import java.util.Optional; +import javax.ws.rs.core.Response; @Path("") @Api("Projects") @@ -56,28 +54,28 @@ public ProjectsResource(ProjectsService projectApi) @Path("/project-configurations") @ApiOperation(ResourceLoggingAndTracing.GET_ALL_PROJECTS) @Produces(MediaType.APPLICATION_JSON) - public List getProjectsWithCoordinates() + public Response getProjectsWithCoordinates() { - return handle(ResourceLoggingAndTracing.GET_ALL_PROJECTS, () -> projectApi.getAllProjectCoordinates()); + return handleResponse(ResourceLoggingAndTracing.GET_ALL_PROJECTS, () -> projectApi.getAllProjectCoordinates()); } @GET @Path("/project-configurations/{groupId}/{artifactId}") @ApiOperation(ResourceLoggingAndTracing.GET_PROJECT_CONFIG_BY_GA) @Produces(MediaType.APPLICATION_JSON) - public Optional getProjectCoordinates(@PathParam("groupId")String groupId, @PathParam("artifactId") String artifactId) + public Response getProjectCoordinates(@PathParam("groupId")String groupId, @PathParam("artifactId") String artifactId) { - return handle(ResourceLoggingAndTracing.GET_PROJECT_CONFIG_BY_GA, () -> projectApi.findCoordinates(groupId, artifactId)); + return handleResponse(ResourceLoggingAndTracing.GET_PROJECT_CONFIG_BY_GA, () -> projectApi.findCoordinates(groupId, artifactId)); } @GET @Path("/projects/{groupId}/{artifactId}/versions") @ApiOperation(ResourceLoggingAndTracing.GET_VERSIONS) @Produces(MediaType.APPLICATION_JSON) - public List getVersions(@PathParam("groupId") String groupId, @PathParam("artifactId") String artifactId, - @QueryParam("snapshots") @ApiParam("wether to return snapshot versions too") @DefaultValue("false") boolean includeSnapshots) + public Response getVersions(@PathParam("groupId") String groupId, @PathParam("artifactId") String artifactId, + @QueryParam("snapshots") @ApiParam("wether to return snapshot versions too") @DefaultValue("false") boolean includeSnapshots) { - return handle(ResourceLoggingAndTracing.GET_VERSIONS, () -> projectApi.getVersions(groupId, artifactId,includeSnapshots)); + return handleResponse(ResourceLoggingAndTracing.GET_VERSIONS, () -> projectApi.getVersions(groupId, artifactId,includeSnapshots)); } @JsonIgnoreProperties(ignoreUnknown = true) diff --git a/legend-depot-core-data-services/src/main/java/org/finos/legend/depot/server/resources/versions/ProjectsVersionsResource.java b/legend-depot-core-data-services/src/main/java/org/finos/legend/depot/server/resources/versions/ProjectsVersionsResource.java index 836f10ab4..4e9bd1c73 100644 --- a/legend-depot-core-data-services/src/main/java/org/finos/legend/depot/server/resources/versions/ProjectsVersionsResource.java +++ b/legend-depot-core-data-services/src/main/java/org/finos/legend/depot/server/resources/versions/ProjectsVersionsResource.java @@ -36,12 +36,9 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Request; import javax.ws.rs.core.Response; import java.time.LocalDateTime; -import java.util.List; import java.util.Optional; import static org.finos.legend.depot.domain.DatesHandler.toTime; @@ -64,10 +61,10 @@ public ProjectsVersionsResource(ProjectsService projectVersionApi) @Path("/projects/versions/{updatedFrom}") @ApiOperation(ResourceLoggingAndTracing.GET_VERSIONS_BY_LASTUPDATE_DATE) @Produces(MediaType.APPLICATION_JSON) - public List findByUpdatedDate(@PathParam("updatedFrom") @ApiParam(value = "Updated From Date value in milliseconds (UTC) ") long updatedFrom, - @QueryParam("updatedTo") @ApiParam(value = "Updated To Date value in milliseconds (UTC) ") Long updatedTo) + public Response findByUpdatedDate(@PathParam("updatedFrom") @ApiParam(value = "Updated From Date value in milliseconds (UTC) ") long updatedFrom, + @QueryParam("updatedTo") @ApiParam(value = "Updated To Date value in milliseconds (UTC) ") Long updatedTo) { - return handle(ResourceLoggingAndTracing.GET_VERSIONS_BY_LASTUPDATE_DATE, + return handleResponse(ResourceLoggingAndTracing.GET_VERSIONS_BY_LASTUPDATE_DATE, () -> projectVersionApi.findByUpdatedDate(updatedFrom, updatedTo == null ? toTime(LocalDateTime.now()) : updatedTo)); } @@ -77,10 +74,9 @@ public List findByUpdatedDate(@PathParam("updatedFrom") @Produces(MediaType.APPLICATION_JSON) public Response getProjectVersion(@PathParam("groupId") String groupId, @PathParam("artifactId") String artifactId, - @PathParam("versionId") @ApiParam(value = VersionValidator.VALID_VERSION_ID_TXT) String versionId, - @Context Request request) + @PathParam("versionId") @ApiParam(value = VersionValidator.VALID_VERSION_ID_TXT) String versionId) { - return handle(ResourceLoggingAndTracing.GET_PROJECT_VERSION_BY_GAV, ResourceLoggingAndTracing.GET_PROJECT_VERSION_BY_GAV + groupId + artifactId + versionId, () -> + return handleResponse(ResourceLoggingAndTracing.GET_PROJECT_VERSION_BY_GAV, ResourceLoggingAndTracing.GET_PROJECT_VERSION_BY_GAV + groupId + artifactId + versionId, () -> { Optional projectVersion = projectVersionApi.find(groupId, artifactId, versionId); if (projectVersion.isPresent()) @@ -89,7 +85,7 @@ public Response getProjectVersion(@PathParam("groupId") String groupId, return Optional.of(new ProjectVersionDTO(pv.getGroupId(), pv.getArtifactId(), pv.getVersionId(), pv.getVersionData())); } return Optional.empty(); - }, request, () -> null); + }); } @JsonIgnoreProperties(ignoreUnknown = true) diff --git a/legend-depot-core-data-services/src/test/java/org/finos/legend/depot/server/resources/TestProjectsResource.java b/legend-depot-core-data-services/src/test/java/org/finos/legend/depot/server/resources/TestProjectsResource.java index 8d3b50eb4..0abac14f4 100644 --- a/legend-depot-core-data-services/src/test/java/org/finos/legend/depot/server/resources/TestProjectsResource.java +++ b/legend-depot-core-data-services/src/test/java/org/finos/legend/depot/server/resources/TestProjectsResource.java @@ -37,7 +37,7 @@ public class TestProjectsResource extends TestBaseServices @Test public void canQueryVersionsForProjectGA() { - List versionSet = projectsVersionsResource.getVersions("examples.metadata", "test", false); + List versionSet = (List) projectsVersionsResource.getVersions("examples.metadata", "test", false).getEntity(); Assert.assertNotNull(versionSet); Assert.assertEquals(2, versionSet.size()); } @@ -45,7 +45,7 @@ public void canQueryVersionsForProjectGA() @Test public void canQueryVersionsForProject() { - List versionSet = projectsVersionsResource.getVersions("examples.metadata", "test",false); + List versionSet = (List) projectsVersionsResource.getVersions("examples.metadata", "test",false).getEntity(); Assert.assertNotNull(versionSet); Assert.assertEquals(2, versionSet.size()); } diff --git a/legend-depot-core-data-services/src/test/java/org/finos/legend/depot/server/resources/TestProjectsVersionsResource.java b/legend-depot-core-data-services/src/test/java/org/finos/legend/depot/server/resources/TestProjectsVersionsResource.java index f1c83e3e6..16276d2a1 100644 --- a/legend-depot-core-data-services/src/test/java/org/finos/legend/depot/server/resources/TestProjectsVersionsResource.java +++ b/legend-depot-core-data-services/src/test/java/org/finos/legend/depot/server/resources/TestProjectsVersionsResource.java @@ -43,7 +43,7 @@ public class TestProjectsVersionsResource extends TestBaseServices @Test public void canQueryLatestProjectVersionData() { - Response responseOne = projectsVersionsResource.getProjectVersion("examples.metadata", "test","latest", null); + Response responseOne = projectsVersionsResource.getProjectVersion("examples.metadata", "test","latest"); Optional versionData = (Optional) responseOne.getEntity(); Assert.assertTrue(versionData.isPresent()); Assert.assertEquals(versionData.get().getGroupId(), "examples.metadata"); @@ -56,7 +56,7 @@ public void canQueryLatestProjectVersionData() Assert.assertEquals(manifestProperties.get("commit-author"), "test-author"); Assert.assertEquals(manifestProperties.get("commit-timestamp"), "2023-04-11T14:48:27+00:00"); - Response responseTwo = projectsVersionsResource.getProjectVersion("somethig.random", "test","latest", null); + Response responseTwo = projectsVersionsResource.getProjectVersion("somethig.random", "test","latest"); Optional versionData1 = (Optional) responseTwo.getEntity(); Assert.assertFalse(versionData1.isPresent()); } @@ -64,14 +64,14 @@ public void canQueryLatestProjectVersionData() @Test public void canQueryHeadProjectVersionData() { - Response responseOne = projectsVersionsResource.getProjectVersion("examples.metadata", "test","head", null); + Response responseOne = projectsVersionsResource.getProjectVersion("examples.metadata", "test","head"); Optional versionData = (Optional) responseOne.getEntity(); Assert.assertTrue(versionData.isPresent()); Assert.assertEquals(versionData.get().getGroupId(), "examples.metadata"); Assert.assertEquals(versionData.get().getArtifactId(), "test"); Assert.assertEquals(versionData.get().getVersionId(), BRANCH_SNAPSHOT("master")); - Response responseTwo = projectsVersionsResource.getProjectVersion("somethig.random", "test","head", null); + Response responseTwo = projectsVersionsResource.getProjectVersion("somethig.random", "test","head"); Optional versionData1 = (Optional) responseTwo.getEntity(); Assert.assertFalse(versionData1.isPresent()); } diff --git a/legend-depot-core-tracing/src/main/java/org/finos/legend/depot/core/services/tracing/resources/TracingResource.java b/legend-depot-core-tracing/src/main/java/org/finos/legend/depot/core/services/tracing/resources/TracingResource.java index e271beb93..7a18fe1ae 100644 --- a/legend-depot-core-tracing/src/main/java/org/finos/legend/depot/core/services/tracing/resources/TracingResource.java +++ b/legend-depot-core-tracing/src/main/java/org/finos/legend/depot/core/services/tracing/resources/TracingResource.java @@ -124,6 +124,16 @@ protected Response handle(String resourceAPIMetricName, String label, Suppli return responseBuilder.build(); } + protected Response handleResponse(String label, Supplier supplier) + { + return handleResponse(label, label, supplier); + } + + protected Response handleResponse(String resourceAPIMetricName,String label, Supplier supplier) + { + return handle(resourceAPIMetricName, label, supplier, null, () -> null); + } + protected T handle(String label, Supplier supplier) { return handle(label, label, supplier); diff --git a/legend-depot-entities-services/src/main/java/org/finos/legend/depot/server/resources/entities/EntitiesDependenciesResource.java b/legend-depot-entities-services/src/main/java/org/finos/legend/depot/server/resources/entities/EntitiesDependenciesResource.java index cb084f99a..baf5b28c2 100644 --- a/legend-depot-entities-services/src/main/java/org/finos/legend/depot/server/resources/entities/EntitiesDependenciesResource.java +++ b/legend-depot-entities-services/src/main/java/org/finos/legend/depot/server/resources/entities/EntitiesDependenciesResource.java @@ -18,7 +18,6 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.finos.legend.depot.domain.entity.ProjectVersionEntities; import org.finos.legend.depot.domain.project.ProjectVersion; import org.finos.legend.depot.domain.version.VersionValidator; import org.finos.legend.depot.services.api.entities.EntitiesService; @@ -76,12 +75,12 @@ public Response getEntitiesFromDependencies(@PathParam("groupId") String groupId @Path("/projects/dependencies") @ApiOperation(GET_VERSIONS_DEPENDENCY_ENTITIES) @Produces(MediaType.APPLICATION_JSON) - public List getAllEntitiesFromDependencies(@ApiParam("projectDependencies") List projectDependencies, + public Response getAllEntitiesFromDependencies(@ApiParam("projectDependencies") List projectDependencies, @QueryParam("transitive") @DefaultValue("false") @ApiParam("Whether to return transitive dependencies") boolean transitive, @QueryParam("includeOrigin") @DefaultValue("false") @ApiParam("Whether to return start of dependency tree") boolean includeOrigin) { - return handle(GET_VERSIONS_DEPENDENCY_ENTITIES, () -> this.entitiesService.getDependenciesEntities(projectDependencies, transitive, includeOrigin)); + return handleResponse(GET_VERSIONS_DEPENDENCY_ENTITIES, () -> this.entitiesService.getDependenciesEntities(projectDependencies, transitive, includeOrigin)); } } diff --git a/legend-depot-entities-services/src/main/java/org/finos/legend/depot/server/resources/entities/EntityClassifierResource.java b/legend-depot-entities-services/src/main/java/org/finos/legend/depot/server/resources/entities/EntityClassifierResource.java index 15cdbb980..eb92c23c6 100644 --- a/legend-depot-entities-services/src/main/java/org/finos/legend/depot/server/resources/entities/EntityClassifierResource.java +++ b/legend-depot-entities-services/src/main/java/org/finos/legend/depot/server/resources/entities/EntityClassifierResource.java @@ -18,7 +18,6 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.finos.legend.depot.domain.entity.DepotEntity; import org.finos.legend.depot.domain.version.Scope; import org.finos.legend.depot.services.api.entities.EntityClassifierService; import org.finos.legend.depot.core.services.tracing.resources.TracingResource; @@ -31,7 +30,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; -import java.util.List; +import javax.ws.rs.core.Response; import static org.finos.legend.depot.core.services.tracing.ResourceLoggingAndTracing.GET_ENTITIES_BY_CLASSIFIER_PATH; @@ -54,12 +53,12 @@ public EntityClassifierResource(EntityClassifierService graphService) // graph built in depot server. @ApiOperation(value = GET_ENTITIES_BY_CLASSIFIER_PATH, hidden = true) @Produces(MediaType.APPLICATION_JSON) - public List getEntities(@PathParam("classifierPath") @ApiParam("The classifier path of the entities") String classifierPath, - @QueryParam("search") @ApiParam("The search string that the entity path contains") String search, - @QueryParam("scope") @ApiParam("Whether to return entities for the latest released version or snapshot") @DefaultValue("RELEASES") Scope scope, - @QueryParam("limit") @ApiParam("Limit the number of entities returned") Integer limit, - @QueryParam("summary") @DefaultValue("false") @ApiParam("Whether to return the summary view of the ENTITIES or the full entity") boolean summary) + public Response getEntities(@PathParam("classifierPath") @ApiParam("The classifier path of the entities") String classifierPath, + @QueryParam("search") @ApiParam("The search string that the entity path contains") String search, + @QueryParam("scope") @ApiParam("Whether to return entities for the latest released version or snapshot") @DefaultValue("RELEASES") Scope scope, + @QueryParam("limit") @ApiParam("Limit the number of entities returned") Integer limit, + @QueryParam("summary") @DefaultValue("false") @ApiParam("Whether to return the summary view of the ENTITIES or the full entity") boolean summary) { - return handle(GET_ENTITIES_BY_CLASSIFIER_PATH, () -> this.graphService.getEntitiesByClassifierPath(classifierPath, search, limit, scope, summary)); + return handleResponse(GET_ENTITIES_BY_CLASSIFIER_PATH, () -> this.graphService.getEntitiesByClassifierPath(classifierPath, search, limit, scope, summary)); } }