Skip to content

Commit 11a2989

Browse files
committed
update by uuid. get project by uuid call change
1 parent 1c24a05 commit 11a2989

File tree

8 files changed

+104
-6
lines changed

8 files changed

+104
-6
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package com.redhat.labs.lodestar.model;
22

3+
import javax.json.bind.annotation.JsonbProperty;
4+
35
import lombok.Data;
46

57
@Data
68
public class Engagement {
79

810
private String uuid;
11+
12+
@JsonbProperty("project_id")
913
private long projectId;
1014

1115
}

src/main/java/com/redhat/labs/lodestar/resource/ArtifactResource.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import javax.ws.rs.GET;
1111
import javax.ws.rs.PUT;
1212
import javax.ws.rs.Path;
13+
import javax.ws.rs.PathParam;
1314
import javax.ws.rs.Produces;
1415
import javax.ws.rs.QueryParam;
1516
import javax.ws.rs.core.MediaType;
@@ -35,6 +36,7 @@ public class ArtifactResource {
3536
@Inject
3637
ArtifactService service;
3738

39+
//may need to remove this and only accept by engagement uuid
3840
@PUT
3941
@APIResponses(value = {
4042
@APIResponse(responseCode = "200", description = "The list of artifacts has been processed."),
@@ -48,6 +50,21 @@ public Response processArtifacts(@Valid List<Artifact> artifacts,
4850
return Response.ok().build();
4951

5052
}
53+
54+
@PUT
55+
@APIResponses(value = {
56+
@APIResponse(responseCode = "200", description = "The list of artifacts has been processed."),
57+
@APIResponse(responseCode = "400", description = "Invalid list of artifacts provided.") })
58+
@Operation(summary = "Artifacts have been processed and persisted for engagement.")
59+
@Path("/engagement/uuid/{engagementUuid}")
60+
public Response processEngagementArtifacts(List<Artifact> artifacts, @PathParam(value="engagementUuid") String engagementUuid,
61+
@QueryParam("authorEmail") Optional<String> authorEmail,
62+
@QueryParam("authorName") Optional<String> authorName) {
63+
64+
service.updateArtifacts(engagementUuid, artifacts, authorEmail, authorName);
65+
return Response.ok().build();
66+
67+
}
5168

5269
@GET
5370
@APIResponses(value = {

src/main/java/com/redhat/labs/lodestar/rest/client/EngagementApiRestClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import javax.ws.rs.Path;
77
import javax.ws.rs.PathParam;
88
import javax.ws.rs.Produces;
9+
import javax.ws.rs.QueryParam;
910

1011
import org.eclipse.microprofile.rest.client.annotation.RegisterProvider;
1112
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
@@ -19,7 +20,7 @@ public interface EngagementApiRestClient {
1920

2021
@GET
2122
@Path("/api/v1/engagements/projects/{uuid}")
22-
Engagement getEngagementProjectByUuid(@PathParam("uuid") String engagementUuid);
23+
Engagement getEngagementProjectByUuid(@PathParam("uuid") String engagementUuid, @QueryParam("mini") boolean mini);
2324

2425
@GET
2526
@Path("/api/v1/engagements/projects")

src/main/java/com/redhat/labs/lodestar/service/ArtifactService.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ public void process(List<Artifact> artifacts, Optional<String> authorEmail, Opti
151151
});
152152

153153
}
154+
155+
public void updateArtifacts(String engagementUuid, List<Artifact> artifacts, Optional<String> authorEmail, Optional<String> authorName) {
156+
157+
for(Artifact artifact : artifacts) {
158+
if(artifact.getEngagementUuid() == null) {
159+
artifact.setEngagementUuid(engagementUuid);
160+
}
161+
}
162+
163+
process(artifacts, authorEmail, authorName);
164+
}
154165

155166
/**
156167
* Returns a {@link List} of {@link Artifact}s matching the specified
@@ -217,6 +228,7 @@ public ArtifactCount countArtifacts(GetOptions options) {
217228
* @return
218229
*/
219230
Map<String, List<Artifact>> processArtifacts(List<Artifact> artifacts) {
231+
220232
return artifacts.stream().map(a -> {
221233
if (null == a.getUuid()) {
222234
a.setUuid(UUID.randomUUID().toString());
@@ -369,7 +381,7 @@ void updateArtifactsFile(String engagementUuid, List<Artifact> artifacts, Option
369381
Optional<String> authorName, Optional<String> commitMessage) {
370382

371383
// find project by engagement
372-
Engagement project = engagementRestClient.getEngagementProjectByUuid(engagementUuid);
384+
Engagement project = engagementRestClient.getEngagementProjectByUuid(engagementUuid, true);
373385

374386
// create json content
375387
String content = jsonb.toJson(artifacts);

src/test/java/com/redhat/labs/mock/ExternalApiWireMock.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ public Map<String, String> start() {
3131

3232
body = ResourceLoader.load("engagement-project-1.json");
3333

34-
stubFor(get(urlEqualTo("/api/v1/engagements/projects/1111"))
34+
stubFor(get(urlEqualTo("/api/v1/engagements/projects/1111?mini=true"))
3535
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(body)));
3636

3737
body = ResourceLoader.load("engagement-project-2.json");
3838

39-
stubFor(get(urlEqualTo("/api/v1/engagements/projects/2222"))
39+
stubFor(get(urlEqualTo("/api/v1/engagements/projects/2222?mini=true"))
4040
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(body)));
4141

4242
// stubFor(get(urlEqualTo("/api/v1/engagements/projects/2222"))
@@ -49,7 +49,12 @@ public Map<String, String> start() {
4949
stubFor(get(urlEqualTo("/api/v4/projects/1/repository/files/artifacts.json?ref=master"))
5050
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(body)));
5151

52-
stubFor(get(urlEqualTo("/api/v4/projects/2/repository/files/artifacts.json?ref=master"))
52+
body = ResourceLoader.load("project-91-artifacts-file.json");
53+
54+
stubFor(get(urlEqualTo("/api/v4/projects/91/repository/files/artifacts.json?ref=master"))
55+
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(body)));
56+
57+
stubFor(get(urlEqualTo("/api/v4/projects/92/repository/files/artifacts.json?ref=master"))
5358
.willReturn(aResponse().withStatus(404)));
5459

5560
// update existing artifacts.json

src/test/java/com/redhat/labs/resource/ArtifactResourceTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ void testCountArtifactsAll() {
5050
given().when().get("/api/artifacts/count").then().statusCode(200).body("count", equalTo(2));
5151

5252
}
53+
54+
@Test
55+
void testRefresh() {
56+
given().when().put("/api/artifacts/refresh").then().statusCode(202);
57+
58+
assertEquals(2, service.getArtifacts(new GetListOptions()).size());
59+
}
5360

5461
@Test
5562
void testCountArtifactsByEngagement() {
@@ -158,6 +165,41 @@ void testModifyArtifactsMissingEngagementUuid() {
158165
given().contentType(ContentType.JSON).body(requestBody).put("/api/artifacts").then().statusCode(400);
159166

160167
}
168+
169+
@Test
170+
void testModifyArtifactsByEngagementUuid() {
171+
172+
// get existing artifact
173+
GetListOptions options = new GetListOptions();
174+
options.setEngagementUuid("1111");
175+
List<Artifact> artifacts = service.getArtifacts(options);
176+
assertNotNull(artifacts);
177+
assertFalse(artifacts.isEmpty());
178+
Artifact modified = artifacts.get(0);
179+
modified.setDescription("UPDATED");
180+
181+
// new artifacts
182+
Artifact a1 = mockArtifact("1111");
183+
Artifact a2 = mockArtifact("2222");
184+
185+
String requestBody = jsonb.toJson(Arrays.asList(a1, a2, modified));
186+
187+
given().contentType(ContentType.JSON).body(requestBody).put("/api/artifacts/engagement/uuid/1111").then().statusCode(200);
188+
189+
JsonPath path = given().queryParam("engagementUuid", "1111").when().get("/api/artifacts").then().statusCode(200).extract().jsonPath();
190+
191+
assertEquals(2, path.getList(".").size());
192+
193+
String a0Type = path.getString("[0].type");
194+
String a0Desc = path.getString("[0].description");
195+
196+
String a1Type = path.getString("[1].type");
197+
String a1Desc = path.getString("[1].description");
198+
199+
boolean newTypeFound = "newType".equals(a0Type) || "newType".equals(a1Type);
200+
boolean descFound = "UPDATED".equals(a0Desc) || "UPDATED".equals(a1Desc);
201+
assertTrue(newTypeFound && descFound);
202+
}
161203

162204
@Test
163205
void testModifyArtifactsCreateUpdateDelete() {

src/test/resources/engagement-projects.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,17 @@
22
{
33
"uuid": "1111",
44
"project_id": "1"
5-
}
5+
},
6+
{
7+
"uuid": null,
8+
"project_id": "90"
9+
},
10+
{
11+
"uuid": "9191",
12+
"project_id": "91"
13+
},
14+
{
15+
"uuid": "9292",
16+
"project_id": "92"
17+
}
618
]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"content": null,
3+
"encoding": "base64",
4+
"file_path": "artifacts.json"
5+
}

0 commit comments

Comments
 (0)