Skip to content

Commit

Permalink
Merge filter report on message
Browse files Browse the repository at this point in the history
Signed-off-by: Ayoub LABIDI <[email protected]>
  • Loading branch information
ayolab committed Sep 16, 2024
2 parents 24787d8 + 8d5e031 commit bdf361b
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 1 deletion.
15 changes: 15 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<testcontainers.version>1.18.3</testcontainers.version>
<liquibase-hibernate-package>org.gridsuite.study.server</liquibase-hibernate-package>
<apache.httpclient.version>5.3</apache.httpclient.version>
<powsybl-network-store.version>1.16.0</powsybl-network-store.version>
</properties>

<build>
Expand Down Expand Up @@ -129,9 +130,23 @@
<groupId>com.powsybl</groupId>
<artifactId>powsybl-sensitivity-analysis-api</artifactId>
</dependency>
<!-- FIXME: to be removed at next powsybl-ws-dependencies upgrade -->
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-network-store-client</artifactId>
<version>${powsybl-network-store.version}</version>
</dependency>
<!-- FIXME: to be removed at next powsybl-ws-dependencies upgrade -->
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-network-store-model</artifactId>
<version>${powsybl-network-store.version}</version>
</dependency>
<!-- FIXME: to be removed at next powsybl-ws-dependencies upgrade -->
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-network-store-iidm-impl</artifactId>
<version>${powsybl-network-store.version}</version>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ private StudyConstants() {
public static final String QUERY_PARAM_REPORT_DEFAULT_NAME = "defaultName";
public static final String QUERY_PARAM_REPORT_SEVERITY_LEVEL = "severityLevels";
public static final String QUERY_PARAM_REPORT_NAME_FILTER = "reportNameFilter";
public static final String QUERY_PARAM_MESSAGE_FILTER = "message";
public static final String QUERY_PARAM_REPORT_NAME_MATCHING_TYPE = "reportNameMatchingType";
public static final String QUERY_PARAM_RECEIVER = "receiver";
public static final String QUERY_PARAM_REPORT_UUID = "reportUuid";
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/org/gridsuite/study/server/StudyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,29 @@ public ResponseEntity<Report> getSubReport(@Parameter(description = "Study uuid"
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getSubReport(reportId, severityLevels));
}

@GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/report/{reportId}/logs", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get node report logs")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The node report logs"), @ApiResponse(responseCode = "404", description = "The study/node is not found")})
public ResponseEntity<List<ReportLog>> getNodeReportLogs(@Parameter(description = "Study uuid") @PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "node id") @PathVariable("nodeUuid") UUID nodeUuid,
@Parameter(description = "reportId") @PathVariable("reportId") String reportId,
@Parameter(description = "the message filter") @RequestParam(name = "message", required = false) String messageFilter,
@Parameter(description = "Severity levels filter") @RequestParam(name = "severityLevels", required = false) Set<String> severityLevels) {
studyService.assertIsStudyAndNodeExist(studyUuid, nodeUuid);
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getReportLogs(reportId, messageFilter, severityLevels));
}

@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 node and all its parents nodes report logs"), @ApiResponse(responseCode = "404", description = "The study/node is not found")})
public ResponseEntity<List<ReportLog>> getParentNodesReportLogs(@Parameter(description = "Study uuid") @PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "node id") @PathVariable("nodeUuid") UUID nodeUuid,
@Parameter(description = "the message filter") @RequestParam(name = "message", required = false) String messageFilter,
@Parameter(description = "Severity levels filter") @RequestParam(name = "severityLevels", required = false) Set<String> severityLevels) {
studyService.assertIsStudyAndNodeExist(studyUuid, nodeUuid);
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getParentNodesCleanedReportLogs(nodeUuid, messageFilter, severityLevels));
}

@GetMapping(value = "/svg-component-libraries")
@Operation(summary = "Get a list of the available svg component libraries")
@ApiResponse(responseCode = "200", description = "The list of the available svg component libraries")
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/gridsuite/study/server/dto/ReportLog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.study.server.dto;

import org.gridsuite.study.server.StudyConstants;

import java.util.Set;
import java.util.UUID;

/**
* @author Abdelsalem Hedhili <abdelsalem.hedhili at rte-france.com>
*/
public record ReportLog(String message, Set<StudyConstants.Severity> severity, UUID parentId) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
package org.gridsuite.study.server.service;

import lombok.NonNull;

import org.apache.poi.util.StringUtil;
import org.gridsuite.study.server.RemoteServicesProperties;
import org.gridsuite.study.server.dto.Report;
import org.gridsuite.study.server.dto.ReportLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
Expand Down Expand Up @@ -78,6 +81,21 @@ public Report getSubReport(@NonNull UUID id, Set<String> severityLevels) {
}).getBody();
}

public List<ReportLog> getReportLogs(@NonNull UUID id, String messageFilter, Set<String> severityLevels) {
var uriBuilder = UriComponentsBuilder.fromPath("{id}/logs");
if (severityLevels != null && !severityLevels.isEmpty()) {
uriBuilder.queryParam(QUERY_PARAM_REPORT_SEVERITY_LEVEL, severityLevels);
}
if (!StringUtil.isBlank(messageFilter)) {
uriBuilder.queryParam(QUERY_PARAM_MESSAGE_FILTER, messageFilter);
}
var path = uriBuilder.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<List<ReportLog>>() {
}).getBody();
}

public void deleteReport(@NonNull UUID reportUuid) {
Objects.requireNonNull(reportUuid);
var uriBuilder = UriComponentsBuilder.fromPath("{reportUuid}")
Expand Down
25 changes: 25 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 @@ -68,6 +68,7 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.gridsuite.study.server.StudyException.Type.*;
import static org.gridsuite.study.server.dto.ComputationType.*;
Expand Down Expand Up @@ -803,6 +804,7 @@ public String getSecurityAnalysisParametersValues(UUID studyUuid) {
public void setSecurityAnalysisParametersValues(UUID studyUuid, String parameters, String userId) {
StudyEntity studyEntity = studyRepository.findById(studyUuid).orElseThrow(() -> new StudyException(STUDY_NOT_FOUND));
createOrUpdateSecurityAnalysisParameters(studyUuid, studyEntity, parameters);
notificationService.emitStudyChanged(studyUuid, null, NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS);
notificationService.emitElementUpdated(studyUuid, userId);
}

Expand Down Expand Up @@ -1644,6 +1646,29 @@ public List<Report> getNodeReport(UUID nodeUuid, String reportId, Set<String> se
return List.of(reportService.getReport(UUID.fromString(reportId), nodeUuid.toString(), severityLevels));
}

@Transactional(readOnly = true)
public List<ReportLog> getReportLogs(String reportId, String messageFilter, Set<String> severityLevels) {
return reportService.getReportLogs(UUID.fromString(reportId), messageFilter, severityLevels);
}

@Transactional(readOnly = true)
public List<ReportLog> getParentNodesReportLogs(UUID nodeUuid, String messageFilter, Set<String> severityLevels) {
// recursive function to retrieve all reports logs from a given node up to the Root node
AbstractNode nodeInfos = networkModificationTreeService.getNode(nodeUuid);
List<ReportLog> reportLogs = reportService.getReportLogs(nodeInfos.getReportUuid(), messageFilter, severityLevels);

Optional<UUID> parentUuid = networkModificationTreeService.getParentNodeUuid(nodeUuid);
if (parentUuid.isEmpty()) {
return reportLogs;
}
List<ReportLog> parentReporterMessages = self.getParentNodesReportLogs(parentUuid.get(), messageFilter, severityLevels);
return Stream.concat(parentReporterMessages.stream(), reportLogs.stream()).collect(Collectors.toList());
}

public List<ReportLog> getParentNodesCleanedReportLogs(UUID nodeUuid, String messageFilter, Set<String> severityLevels) {
return self.getParentNodesReportLogs(nodeUuid, messageFilter, severityLevels);
}

@Transactional(readOnly = true)
public List<Report> getParentNodesReport(UUID nodeUuid, boolean nodeOnlyReport, ReportType reportType, Set<String> severityLevels) {
AbstractNode nodeInfos = networkModificationTreeService.getNode(nodeUuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ public MockResponse dispatch(RecordedRequest request) {
return new MockResponse().setResponseCode(200)
.addHeader("Content-Type", MediaType.APPLICATION_JSON_UTF8)
.setBody("1");
} else if (path.matches("/v1/results/invalidate-status\\?resultUuid=.*")) {
return new MockResponse().setResponseCode(200)
.addHeader("Content-Type", "application/json; charset=utf-8");
} else if (path.matches("/v1/parameters/" + SECURITY_ANALYSIS_PARAMETERS_UUID)) {
if (method.equals("GET")) {
return new MockResponse().setResponseCode(200)
Expand Down Expand Up @@ -651,7 +654,7 @@ public void testSecurityAnalysisParameters() throws Exception {
status().isOk());
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/parameters/" + SECURITY_ANALYSIS_PARAMETERS_UUID)));
assertEquals(SECURITY_ANALYSIS_PARAMETERS_UUID, studyRepository.findById(studyNameUserIdUuid).orElseThrow().getSecurityAnalysisParametersUuid());

assertEquals(NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS, output.receive(TIMEOUT, studyUpdateDestination).getHeaders().get(NotificationService.HEADER_UPDATE_TYPE));
//get security analysis parameters but with an already registered securityAnalysisParametersUuid
mockMvc.perform(get("/v1/studies/{studyUuid}/security-analysis/parameters", studyNameUserIdUuid)).andExpectAll(
status().isOk(),
Expand All @@ -665,6 +668,7 @@ public void testSecurityAnalysisParameters() throws Exception {
.contentType(MediaType.APPLICATION_JSON)
.content(mnBodyJson)).andExpect(
status().isOk());
assertEquals(NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS, output.receive(TIMEOUT, studyUpdateDestination).getHeaders().get(NotificationService.HEADER_UPDATE_TYPE));
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/parameters/" + SECURITY_ANALYSIS_PARAMETERS_UUID)));
assertEquals(SECURITY_ANALYSIS_PARAMETERS_UUID, studyRepository.findById(studyNameUserIdUuid).orElseThrow().getSecurityAnalysisParametersUuid());
}
Expand All @@ -685,6 +689,7 @@ public void testCreateSecurityAnalysisParameters() throws Exception {
.andExpect(status().isOk());

assertEquals(SECURITY_ANALYSIS_PARAMETERS_UUID, studyRepository.findById(studyUuid).orElseThrow().getSecurityAnalysisParametersUuid());
assertEquals(NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS, output.receive(TIMEOUT, studyUpdateDestination).getHeaders().get(NotificationService.HEADER_UPDATE_TYPE));
Set<String> requests = TestUtils.getRequestsDone(1, server);
assertTrue(requests.stream().anyMatch(r -> r.matches("/v1/parameters")));
}
Expand Down
Loading

0 comments on commit bdf361b

Please sign in to comment.