Skip to content

Commit

Permalink
return responses for depot server resources (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
gs-gunjan authored Dec 1, 2023
1 parent ce91f96 commit 6772643
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ProjectVersion> projectDependencies)
public Response analyzeDependencyTree(@ApiParam("projectDependencies") List<ProjectVersion> 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<ProjectVersionPlatformDependency> 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)));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")
Expand All @@ -56,28 +54,28 @@ public ProjectsResource(ProjectsService projectApi)
@Path("/project-configurations")
@ApiOperation(ResourceLoggingAndTracing.GET_ALL_PROJECTS)
@Produces(MediaType.APPLICATION_JSON)
public List<StoreProjectData> 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<StoreProjectData> 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<String> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<StoreProjectVersionData> 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));
}

Expand All @@ -77,10 +74,9 @@ public List<StoreProjectVersionData> 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<StoreProjectVersionData> projectVersion = projectVersionApi.find(groupId, artifactId, versionId);
if (projectVersion.isPresent())
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public class TestProjectsResource extends TestBaseServices
@Test
public void canQueryVersionsForProjectGA()
{
List<String> versionSet = projectsVersionsResource.getVersions("examples.metadata", "test", false);
List<String> versionSet = (List<String>) projectsVersionsResource.getVersions("examples.metadata", "test", false).getEntity();
Assert.assertNotNull(versionSet);
Assert.assertEquals(2, versionSet.size());
}

@Test
public void canQueryVersionsForProject()
{
List<String> versionSet = projectsVersionsResource.getVersions("examples.metadata", "test",false);
List<String> versionSet = (List<String>) projectsVersionsResource.getVersions("examples.metadata", "test",false).getEntity();
Assert.assertNotNull(versionSet);
Assert.assertEquals(2, versionSet.size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProjectsVersionsResource.ProjectVersionDTO> versionData = (Optional<ProjectsVersionsResource.ProjectVersionDTO>) responseOne.getEntity();
Assert.assertTrue(versionData.isPresent());
Assert.assertEquals(versionData.get().getGroupId(), "examples.metadata");
Expand All @@ -56,22 +56,22 @@ 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<ProjectsVersionsResource.ProjectVersionDTO> versionData1 = (Optional<ProjectsVersionsResource.ProjectVersionDTO>) responseTwo.getEntity();
Assert.assertFalse(versionData1.isPresent());
}

@Test
public void canQueryHeadProjectVersionData()
{
Response responseOne = projectsVersionsResource.getProjectVersion("examples.metadata", "test","head", null);
Response responseOne = projectsVersionsResource.getProjectVersion("examples.metadata", "test","head");
Optional<ProjectsVersionsResource.ProjectVersionDTO> versionData = (Optional<ProjectsVersionsResource.ProjectVersionDTO>) 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<ProjectsVersionsResource.ProjectVersionDTO> versionData1 = (Optional<ProjectsVersionsResource.ProjectVersionDTO>) responseTwo.getEntity();
Assert.assertFalse(versionData1.isPresent());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ protected <T> Response handle(String resourceAPIMetricName, String label, Suppli
return responseBuilder.build();
}

protected <T> Response handleResponse(String label, Supplier<T> supplier)
{
return handleResponse(label, label, supplier);
}

protected <T> Response handleResponse(String resourceAPIMetricName,String label, Supplier<T> supplier)
{
return handle(resourceAPIMetricName, label, supplier, null, () -> null);
}

protected <T> T handle(String label, Supplier<T> supplier)
{
return handle(label, label, supplier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ProjectVersionEntities> getAllEntitiesFromDependencies(@ApiParam("projectDependencies") List<ProjectVersion> projectDependencies,
public Response getAllEntitiesFromDependencies(@ApiParam("projectDependencies") List<ProjectVersion> 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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<DepotEntity> 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));
}
}

0 comments on commit 6772643

Please sign in to comment.