From 81646fcc18a9c9ea36b2910b1f05169570c79987 Mon Sep 17 00:00:00 2001 From: Kevin McAnoy Date: Wed, 11 Aug 2021 10:48:46 -0700 Subject: [PATCH] add a retrieve by e uuid api --- .../lodestar/resource/EngagementResource.java | 13 ++++++++++++- .../lodestar/service/EngagementService.java | 10 ++++++++++ .../resource/EngagementResourceTest.java | 19 ++++++++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/redhat/labs/lodestar/resource/EngagementResource.java b/src/main/java/com/redhat/labs/lodestar/resource/EngagementResource.java index 221220d..6ee2a22 100644 --- a/src/main/java/com/redhat/labs/lodestar/resource/EngagementResource.java +++ b/src/main/java/com/redhat/labs/lodestar/resource/EngagementResource.java @@ -60,6 +60,17 @@ public Response createEngagement(Engagement engagement, @Context UriInfo uriInfo return Response.created(builder.build()).build(); } + + @GET + @Path("uuid/{uuid}") + public Response getEngagementByUuid(@PathParam("uuid") String uuid) { + Optional engagement = Optional.ofNullable(engagementService.getEnagementByUuid(uuid)); + + if(engagement.isPresent()) { + return Response.ok(engagement).build(); + } + return Response.noContent().status(404).entity(String.format("{ \"message\": \"Unable to find engagement for uuid %s in git-api\"}", uuid)).build(); + } @GET @Counted(name = "get-all-engagement", description = "Count of get all engagements") @@ -191,7 +202,7 @@ public Response getProjectByUuid(@PathParam("uuid") String uuid, @QueryParam("mi Optional p = engagementService.getProjectByUuid(uuid); if(p.isEmpty()) { - return Response.status(404).build(); + return Response.status(404).entity("{ \"message\": \"Unable to get project by uuid\" }").build(); } if(mini) { diff --git a/src/main/java/com/redhat/labs/lodestar/service/EngagementService.java b/src/main/java/com/redhat/labs/lodestar/service/EngagementService.java index 2528afe..7d51c9f 100644 --- a/src/main/java/com/redhat/labs/lodestar/service/EngagementService.java +++ b/src/main/java/com/redhat/labs/lodestar/service/EngagementService.java @@ -272,6 +272,16 @@ private List getEngagementsFromProject(List projects, Optio .collect(Collectors.toList()); } + + public Engagement getEnagementByUuid(String uuid) { + Engagement engagement = null; + Optional project = getProjectByUuid(uuid); + if(project.isPresent()) { + engagement = getEngagement(project.get(), false, false).orElse(null); + } + + return engagement; + } public Engagement getEngagement(String namespaceOrId, boolean includeStatus) { Engagement engagement = null; diff --git a/src/test/java/com/redhat/labs/lodestar/resource/EngagementResourceTest.java b/src/test/java/com/redhat/labs/lodestar/resource/EngagementResourceTest.java index 346bd00..60d953f 100644 --- a/src/test/java/com/redhat/labs/lodestar/resource/EngagementResourceTest.java +++ b/src/test/java/com/redhat/labs/lodestar/resource/EngagementResourceTest.java @@ -108,9 +108,26 @@ void testGetAllEngagementsSuccess() { + " }\n" + "]")); } + + @Test + void testGetEngagementByUuid() { + MockUtils.setFindProjectByEngagementId(gitLabService, 2, "abcd", Project.builder().id(1).build()); + MockUtils.setGetFileForEngagementJsonMock(gitLabService, 2, true); + + String engagementUuid = "k"; + + // Not found + given().pathParam("engagementUuid", engagementUuid).when().contentType(ContentType.JSON) + .get("/api/v1/engagements/uuid/{engagementUuid}").then().statusCode(404).body("message", is("Unable to find engagement for uuid k in git-api")); + + engagementUuid = "abcd"; + // Found + given().pathParam("engagementUuid", engagementUuid).when().contentType(ContentType.JSON) + .get("/api/v1/engagements/uuid/{engagementUuid}").then().statusCode(404); + } @Test - void tesetGetEngagementByNamespace() { + void testGetEngagementByNamespace() { // get projects by id Integer projectId = MockUtils.setGetProjectByPathMock(gitLabService, "top/dog/jello/tutti-frutti/iac", true,