Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add endpoints to retreive aggregated severities #663

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/main/java/org/gridsuite/study/server/StudyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,25 @@ public ResponseEntity<List<ReportLog>> getNodeReportLogs(@Parameter(description
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getReportLogs(reportId, messageFilter, severityLevels));
}

@GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/report/{reportId}/aggregated-severities", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get node report severities")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The node report severities"), @ApiResponse(responseCode = "404", description = "The study/node is not found")})
public ResponseEntity<Set<String>> getNodeReportAggregatedSeverities(@Parameter(description = "Study uuid") @PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "node id") @PathVariable("nodeUuid") UUID nodeUuid,
@Parameter(description = "reportId") @PathVariable("reportId") UUID reportId) {
studyService.assertIsStudyAndNodeExist(studyUuid, nodeUuid);
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getNodeReportAggregatedSeverities(reportId));
}

@GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/report/aggregated-severities", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get the report severities of the given node and all its parents")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The report severities of the node and all its parent"), @ApiResponse(responseCode = "404", description = "The study/node is not found")})
public ResponseEntity<Set<String>> getParentNodesAggregatedReportSeverities(@Parameter(description = "Study uuid") @PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "node id") @PathVariable("nodeUuid") UUID nodeUuid) {
studyService.assertIsStudyAndNodeExist(studyUuid, nodeUuid);
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getParentNodesAggregatedReportSeverities(nodeUuid, studyService.getStudyFirstRootNetworkUuid(studyUuid)));
}

@GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/report/logs", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get the report logs of the given node and all its parents")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The report logs of the node and all its parent"), @ApiResponse(responseCode = "404", description = "The study/node is not found")})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,12 @@ public UUID duplicateReport(@NonNull UUID id) {
return UUID.randomUUID();
}
}

public Set<String> getReportAggregatedSeverities(@NonNull UUID id) {
var path = UriComponentsBuilder.fromPath("{id}/aggregated-severities").buildAndExpand(id).toUriString();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
return restTemplate.exchange(this.getReportsServerURI() + path, HttpMethod.GET, new HttpEntity<>(headers), new ParameterizedTypeReference<Set<String>>() {
}).getBody();
}
}
16 changes: 16 additions & 0 deletions src/main/java/org/gridsuite/study/server/service/StudyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -1785,6 +1785,22 @@ public List<ReportLog> getReportLogs(String reportId, String messageFilter, Set<
return reportService.getReportLogs(UUID.fromString(reportId), messageFilter, severityLevels);
}

public Set<String> getNodeReportAggregatedSeverities(UUID reportId) {
return reportService.getReportAggregatedSeverities(reportId);
}

public Set<String> getParentNodesAggregatedReportSeverities(UUID nodeUuid, UUID rootNetworkUuid) {
List<UUID> nodeIds = nodesTree(nodeUuid);
Set<String> severities = new HashSet<>();
Map<UUID, UUID> modificationReportsMap = networkModificationTreeService.getModificationReports(nodeUuid, rootNetworkUuid);

for (UUID nodeId : nodeIds) {
UUID reportId = modificationReportsMap.getOrDefault(nodeId, networkModificationTreeService.getReportUuid(nodeId, rootNetworkUuid));
severities.addAll(reportService.getReportAggregatedSeverities(reportId));
}
return severities;
}

@Transactional(readOnly = true)
public List<ReportLog> getParentNodesReportLogs(UUID nodeUuid, UUID rootNetworkUuid, String messageFilter, Set<String> severityLevels) {
List<UUID> nodeIds = nodesTree(nodeUuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Stream;

Expand Down Expand Up @@ -128,6 +129,12 @@ public MockResponse dispatch(RecordedRequest request) {
return new MockResponse(HttpStatus.OK.value(), Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), mapper.writeValueAsString(getNodeReport(UUID.fromString(reportId), reportId)));
} else if (path.matches("/v1/reports/" + NOT_FOUND_REPORT_UUID + "/duplicate")) {
return new MockResponse(HttpStatus.NOT_FOUND.value());
} else if (path.matches("/v1/reports/" + MODIFICATION_CHILD_NODE1_REPORT_UUID + "/aggregated-severities")) {
return new MockResponse(HttpStatus.OK.value(), Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), mapper.writeValueAsString(Set.of("INFO")));
} else if (path.matches("/v1/reports/" + ROOT_NODE_REPORT_UUID + "/aggregated-severities")) {
return new MockResponse(HttpStatus.OK.value(), Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), mapper.writeValueAsString(Set.of("WARN")));
} else if (path.matches("/v1/reports/.*/aggregated-severities")) {
return new MockResponse(HttpStatus.OK.value(), Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), mapper.writeValueAsString(Set.of("UNKNOWN")));
} else {
LOGGER.error("Unhandled method+path: {} {}", request.getMethod(), request.getPath());
return new MockResponse.Builder().code(HttpStatus.I_AM_A_TEAPOT.value()).body("Unhandled method+path: " + request.getMethod() + " " + request.getPath()).build();
Expand Down Expand Up @@ -236,6 +243,14 @@ void testMultipleReport(final MockWebServer server) throws Exception {
checkReports(child1Reports, List.of(child1ExpectedReport));
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/reports/.*")));

// get only Child1 aggregated severities
mvcResult = mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/report/{reportId}/aggregated-severities", rootNode.getStudyId(), child1.getId(), MODIFICATION_CHILD_NODE1_REPORT_UUID))
.andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON))
.andReturn();
Set<String> child1AggregatedSeverities = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { });
assertEquals(Set.of("INFO"), child1AggregatedSeverities);
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/reports/.*/aggregated-severities")));

// get Child2 report + parents
mvcResult = mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/parent-nodes-report?nodeOnlyReport=false&reportType=NETWORK_MODIFICATION", rootNode.getStudyId(), child2.getId()))
.andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON))
Expand All @@ -249,6 +264,13 @@ void testMultipleReport(final MockWebServer server) throws Exception {
checkReports(child2AndParentsReports, childrenAndParentsExpectedReports);
assertTrue(TestUtils.getRequestsDone(childrenAndParentsExpectedReports.size(), server).stream().anyMatch(r -> r.matches("/v1/reports/.*")));

mvcResult = mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/report/aggregated-severities", rootNode.getStudyId(), node.getId()))
.andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON))
.andReturn();
Set<String> child2AggregatedSeverities = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { });
assertEquals(Set.of("WARN", "UNKNOWN"), child2AggregatedSeverities);
assertTrue(TestUtils.getRequestsDone(2, server).stream().anyMatch(r -> r.matches("/v1/reports/.*/aggregated-severities")));

// get Child1 report + parents
mvcResult = mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/parent-nodes-report?nodeOnlyReport=false&reportType=NETWORK_MODIFICATION", rootNode.getStudyId(), child1.getId()))
.andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON))
Expand Down
Loading