Skip to content

Commit 939b7bc

Browse files
authored
Upgrade to powsybl.dependencies 2024.1.0 (#561)
Signed-off-by: Ayoub LABIDI <[email protected]>
1 parent 9ff053d commit 939b7bc

File tree

10 files changed

+145
-113
lines changed

10 files changed

+145
-113
lines changed

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</developers>
4343

4444
<properties>
45-
<powsybl-ws-dependencies.version>2.9.0</powsybl-ws-dependencies.version>
45+
<gridsuite-dependencies.version>29</gridsuite-dependencies.version>
4646
<log4j2-mock-version>0.0.2</log4j2-mock-version>
4747
<testcontainers.version>1.18.3</testcontainers.version>
4848
<liquibase-hibernate-package>org.gridsuite.study.server</liquibase-hibernate-package>
@@ -85,9 +85,9 @@
8585

8686
<!-- imports -->
8787
<dependency>
88-
<groupId>com.powsybl</groupId>
89-
<artifactId>powsybl-ws-dependencies</artifactId>
90-
<version>${powsybl-ws-dependencies.version}</version>
88+
<groupId>org.gridsuite</groupId>
89+
<artifactId>gridsuite-dependencies</artifactId>
90+
<version>${gridsuite-dependencies.version}</version>
9191
<type>pom</type>
9292
<scope>import</scope>
9393
</dependency>

src/main/java/org/gridsuite/study/server/StudyController.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
package org.gridsuite.study.server;
88

99
import com.fasterxml.jackson.databind.JsonNode;
10-
import com.powsybl.commons.reporter.ReporterModel;
10+
import com.powsybl.commons.report.ReportNode;
1111
import com.powsybl.timeseries.DoubleTimeSeries;
1212
import io.swagger.v3.oas.annotations.Operation;
1313
import io.swagger.v3.oas.annotations.Parameter;
@@ -1030,7 +1030,7 @@ public ResponseEntity<Void> stopSecurityAnalysis(@Parameter(description = "Study
10301030
@GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/parent-nodes-report", produces = MediaType.APPLICATION_JSON_VALUE)
10311031
@Operation(summary = "Get node report with its parent nodes")
10321032
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The node report"), @ApiResponse(responseCode = "404", description = "The study/node is not found")})
1033-
public ResponseEntity<List<ReporterModel>> getParentNodesReport(@Parameter(description = "Study uuid") @PathVariable("studyUuid") UUID studyUuid,
1033+
public ResponseEntity<List<ReportNode>> getParentNodesReport(@Parameter(description = "Study uuid") @PathVariable("studyUuid") UUID studyUuid,
10341034
@Parameter(description = "Node uuid") @PathVariable("nodeUuid") UUID nodeUuid,
10351035
@Parameter(description = "Node only report") @RequestParam(value = "nodeOnlyReport", required = false, defaultValue = "true") boolean nodeOnlyReport,
10361036
@Parameter(description = "The report Type") @RequestParam(name = "reportType") StudyService.ReportType reportType,
@@ -1042,7 +1042,7 @@ public ResponseEntity<List<ReporterModel>> getParentNodesReport(@Parameter(descr
10421042
@GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/report", produces = MediaType.APPLICATION_JSON_VALUE)
10431043
@Operation(summary = "Get node report")
10441044
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The node report"), @ApiResponse(responseCode = "404", description = "The study/node is not found")})
1045-
public ResponseEntity<List<ReporterModel>> getNodeReport(@Parameter(description = "Study uuid") @PathVariable("studyUuid") UUID studyUuid,
1045+
public ResponseEntity<List<ReportNode>> getNodeReport(@Parameter(description = "Study uuid") @PathVariable("studyUuid") UUID studyUuid,
10461046
@Parameter(description = "Node uuid") @PathVariable("nodeUuid") UUID nodeUuid,
10471047
@Parameter(description = "The report Id") @RequestParam(name = "reportId", required = false) String reportId,
10481048
@Parameter(description = "The report Type") @RequestParam(name = "reportType") StudyService.ReportType reportType,
@@ -1054,7 +1054,7 @@ public ResponseEntity<List<ReporterModel>> getNodeReport(@Parameter(description
10541054
@GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/subreport", produces = MediaType.APPLICATION_JSON_VALUE)
10551055
@Operation(summary = "Get node sub-report")
10561056
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The node subreport"), @ApiResponse(responseCode = "404", description = "The study/node is not found")})
1057-
public ResponseEntity<ReporterModel> getSubReport(@Parameter(description = "Study uuid") @PathVariable("studyUuid") UUID studyUuid,
1057+
public ResponseEntity<ReportNode> getSubReport(@Parameter(description = "Study uuid") @PathVariable("studyUuid") UUID studyUuid,
10581058
@Parameter(description = "Node uuid") @PathVariable("nodeUuid") UUID nodeUuid,
10591059
@Parameter(description = "The report Id") @RequestParam(name = "reportId") String reportId,
10601060
@Parameter(description = "Severity levels") @RequestParam(name = "severityLevels", required = false) Set<String> severityLevels) {

src/main/java/org/gridsuite/study/server/service/ReportService.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
import com.fasterxml.jackson.databind.InjectableValues;
1010
import com.fasterxml.jackson.databind.ObjectMapper;
11-
import com.powsybl.commons.reporter.ReporterModel;
12-
import com.powsybl.commons.reporter.ReporterModelDeserializer;
13-
import com.powsybl.commons.reporter.ReporterModelJsonModule;
11+
import com.powsybl.commons.report.ReportNode;
12+
import com.powsybl.commons.report.ReportNodeDeserializer;
13+
import com.powsybl.commons.report.ReportNodeJsonModule;
1414
import lombok.NonNull;
1515
import org.apache.poi.util.StringUtil;
1616
import org.gridsuite.study.server.RemoteServicesProperties;
@@ -31,6 +31,7 @@
3131
import java.util.UUID;
3232

3333
import static org.gridsuite.study.server.StudyConstants.*;
34+
import static org.gridsuite.study.server.utils.StudyUtils.insertReportNode;
3435

3536
/**
3637
* @author Slimane amar <slimane.amar at rte-france.com
@@ -49,10 +50,10 @@ public ReportService(ObjectMapper objectMapper,
4950
RemoteServicesProperties remoteServicesProperties,
5051
RestTemplate restTemplate) {
5152
this.reportServerBaseUri = remoteServicesProperties.getServiceUri("report-server");
52-
ReporterModelJsonModule reporterModelJsonModule = new ReporterModelJsonModule();
53+
ReportNodeJsonModule reporterModelJsonModule = new ReportNodeJsonModule();
5354
reporterModelJsonModule.setSerializers(null); // FIXME: remove when dicos will be used on the front side
5455
objectMapper.registerModule(reporterModelJsonModule);
55-
objectMapper.setInjectableValues(new InjectableValues.Std().addValue(ReporterModelDeserializer.DICTIONARY_VALUE_ID, null)); //FIXME : remove with powsyble core
56+
objectMapper.setInjectableValues(new InjectableValues.Std().addValue(ReportNodeDeserializer.DICTIONARY_VALUE_ID, null)); //FIXME : remove with powsyble core
5657
this.restTemplate = restTemplate;
5758
}
5859

@@ -68,7 +69,7 @@ private String getSubReportsServerURI() {
6869
return this.reportServerBaseUri + DELIMITER + REPORT_API_VERSION + DELIMITER + "subreports" + DELIMITER;
6970
}
7071

71-
public ReporterModel getReport(@NonNull UUID id, @NonNull String defaultName, String reportNameFilter, StudyService.ReportNameMatchingType reportNameMatchingType, Set<String> severityLevels) {
72+
public ReportNode getReport(@NonNull UUID id, @NonNull String defaultName, String reportNameFilter, StudyService.ReportNameMatchingType reportNameMatchingType, Set<String> severityLevels) {
7273
var uriBuilder = UriComponentsBuilder.fromPath("{id}")
7374
.queryParam(QUERY_PARAM_REPORT_DEFAULT_NAME, defaultName)
7475
.queryParam(QUERY_PARAM_REPORT_WITH_ELEMENTS, true)
@@ -80,22 +81,24 @@ public ReporterModel getReport(@NonNull UUID id, @NonNull String defaultName, St
8081
return reportServerCall(id, this.getReportsServerURI(), uriBuilder);
8182
}
8283

83-
public ReporterModel getSubReport(@NonNull UUID id, Set<String> severityLevels) {
84+
public ReportNode getSubReport(@NonNull UUID id, Set<String> severityLevels) {
8485
var uriBuilder = UriComponentsBuilder.fromPath("{id}")
8586
.queryParam(QUERY_PARAM_REPORT_SEVERITY_LEVEL, severityLevels);
8687
return reportServerCall(id, this.getSubReportsServerURI(), uriBuilder);
8788
}
8889

89-
private ReporterModel reportServerCall(UUID id, String serverUri, UriComponentsBuilder uriBuilder) {
90+
private ReportNode reportServerCall(UUID id, String serverUri, UriComponentsBuilder uriBuilder) {
9091
var path = uriBuilder.buildAndExpand(id).toUriString();
9192
HttpHeaders headers = new HttpHeaders();
9293
headers.setContentType(MediaType.APPLICATION_JSON);
93-
List<ReporterModel> reporters = restTemplate.exchange(serverUri + path, HttpMethod.GET, new HttpEntity<>(headers), new ParameterizedTypeReference<List<ReporterModel>>() {
94+
List<ReportNode> reporters = restTemplate.exchange(serverUri + path, HttpMethod.GET, new HttpEntity<>(headers), new ParameterizedTypeReference<List<ReportNode>>() {
9495
}).getBody();
9596
// TODO : Remove this hack when fix to avoid key collision in hades2 will be done
96-
ReporterModel reporter = new ReporterModel(id.toString(), id.toString());
97+
ReportNode reporter = ReportNode.newRootReportNode()
98+
.withMessageTemplate(id.toString(), id.toString())
99+
.build();
97100
if (reporters != null) {
98-
reporters.forEach(reporter::addSubReporter);
101+
reporters.forEach(reportNode -> insertReportNode(reporter, reportNode));
99102
}
100103
return reporter;
101104
}

src/main/java/org/gridsuite/study/server/service/StudyService.java

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99
import com.fasterxml.jackson.core.JsonProcessingException;
1010
import com.fasterxml.jackson.databind.ObjectMapper;
11-
import com.powsybl.commons.reporter.ReporterModel;
12-
import com.powsybl.commons.reporter.TypedValue;
11+
import com.powsybl.commons.report.*;
1312
import com.powsybl.iidm.network.Network;
1413
import com.powsybl.loadflow.LoadFlowParameters;
1514
import com.powsybl.network.store.model.VariantInfos;
@@ -76,6 +75,7 @@
7675
import static org.gridsuite.study.server.dto.InfoTypeParameters.QUERY_PARAM_OPERATION;
7776
import static org.gridsuite.study.server.service.NetworkModificationTreeService.ROOT_NODE_NAME;
7877
import static org.gridsuite.study.server.utils.StudyUtils.handleHttpError;
78+
import static org.gridsuite.study.server.utils.StudyUtils.insertReportNode;
7979

8080
/**
8181
* @author Abdelsalem Hedhili <abdelsalem.hedhili at rte-france.com>
@@ -1590,12 +1590,12 @@ private void checkStudyContainsNode(UUID studyUuid, UUID nodeUuid) {
15901590
}
15911591

15921592
@Transactional(readOnly = true)
1593-
public ReporterModel getSubReport(String subReportId, Set<String> severityLevels) {
1593+
public ReportNode getSubReport(String subReportId, Set<String> severityLevels) {
15941594
return reportService.getSubReport(UUID.fromString(subReportId), severityLevels);
15951595
}
15961596

15971597
@Transactional(readOnly = true)
1598-
public List<ReporterModel> getNodeReport(UUID nodeUuid, String reportId, ReportType reportType, Set<String> severityLevels) {
1598+
public List<ReportNode> getNodeReport(UUID nodeUuid, String reportId, ReportType reportType, Set<String> severityLevels) {
15991599
return getSubReporters(nodeUuid, UUID.fromString(reportId), nodeUuid + "@" + reportType.reportKey, ReportNameMatchingType.EXACT_MATCHING, severityLevels);
16001600
}
16011601

@@ -1614,45 +1614,46 @@ private Pair<String, ReportNameMatchingType> getFiltersParamaters(UUID nodeUuid,
16141614
}
16151615

16161616
@Transactional(readOnly = true)
1617-
public List<ReporterModel> getParentNodesReport(UUID nodeUuid, boolean nodeOnlyReport, ReportType reportType, Set<String> severityLevels) {
1617+
public List<ReportNode> getParentNodesReport(UUID nodeUuid, boolean nodeOnlyReport, ReportType reportType, Set<String> severityLevels) {
16181618
Pair<String, ReportNameMatchingType> filtersParameters = getFiltersParamaters(nodeUuid, nodeOnlyReport, reportType);
16191619
AbstractNode nodeInfos = networkModificationTreeService.getNode(nodeUuid);
1620-
List<ReporterModel> subReporters = getSubReporters(nodeUuid, nodeInfos.getReportUuid(), filtersParameters.getFirst(), filtersParameters.getSecond(), severityLevels);
1620+
List<ReportNode> subReporters = getSubReporters(nodeUuid, nodeInfos.getReportUuid(), filtersParameters.getFirst(), filtersParameters.getSecond(), severityLevels);
16211621
if (subReporters.isEmpty()) {
16221622
return subReporters;
16231623
} else if (nodeOnlyReport) {
16241624
return List.of(subReporters.get(subReporters.size() - 1));
16251625
} else {
1626-
if (subReporters.get(0).getTaskKey().equals(ROOT_NODE_NAME)) {
1626+
if (subReporters.get(0).getMessageKey().equals(ROOT_NODE_NAME)) {
16271627
return subReporters;
16281628
}
1629-
Optional<UUID> parentUuid = networkModificationTreeService.getParentNodeUuid(UUID.fromString(subReporters.get(0).getTaskKey()));
1629+
Optional<UUID> parentUuid = networkModificationTreeService.getParentNodeUuid(UUID.fromString(subReporters.get(0).getMessageKey()));
16301630
if (parentUuid.isEmpty()) {
16311631
return subReporters;
16321632
}
1633-
List<ReporterModel> parentReporters = self.getParentNodesReport(parentUuid.get(), false, reportType, severityLevels);
1633+
List<ReportNode> parentReporters = self.getParentNodesReport(parentUuid.get(), false, reportType, severityLevels);
16341634
return Stream.concat(parentReporters.stream(), subReporters.stream()).collect(Collectors.toList());
16351635
}
16361636
}
16371637

1638-
private List<ReporterModel> getSubReporters(UUID nodeUuid, UUID reportUuid, String reportNameFilter, ReportNameMatchingType reportNameMatchingType, Set<String> severityLevels) {
1639-
ReporterModel reporter = reportService.getReport(reportUuid, nodeUuid.toString(), reportNameFilter, reportNameMatchingType, severityLevels);
1640-
Map<String, List<ReporterModel>> subReportersByNode = new LinkedHashMap<>();
1641-
reporter.getSubReporters().forEach(subReporter -> subReportersByNode.putIfAbsent(getNodeIdFromReportKey(subReporter), new ArrayList<>()));
1642-
reporter.getSubReporters().forEach(subReporter ->
1643-
subReportersByNode.get(getNodeIdFromReportKey(subReporter)).addAll(subReporter.getSubReporters())
1644-
);
1638+
private List<ReportNode> getSubReporters(UUID nodeUuid, UUID reportUuid, String reportNameFilter,
1639+
ReportNameMatchingType reportNameMatchingType, Set<String> severityLevels) {
1640+
ReportNode reporter = reportService.getReport(reportUuid, nodeUuid.toString(), reportNameFilter,
1641+
reportNameMatchingType, severityLevels);
1642+
Map<String, List<ReportNode>> subReportersByNode = new LinkedHashMap<>();
1643+
reporter.getChildren().forEach(
1644+
subReporter -> subReportersByNode.putIfAbsent(getNodeIdFromReportKey(subReporter), new ArrayList<>()));
1645+
reporter.getChildren().forEach(subReporter -> subReportersByNode.get(getNodeIdFromReportKey(subReporter))
1646+
.addAll(subReporter.getChildren()));
16451647
return subReportersByNode.keySet().stream().map(nodeId -> {
1646-
// For a node report, pass the reportId to the Front as taskValues, to allow direct access
1647-
Map<String, TypedValue> taskValues = Map.of("id", new TypedValue(reportUuid.toString(), "ID"));
1648-
ReporterModel newSubReporter = new ReporterModel(nodeId, nodeId, taskValues);
1649-
subReportersByNode.get(nodeId).forEach(newSubReporter::addSubReporter);
1648+
ReportNode newSubReporter = ReportNode.newRootReportNode().withMessageTemplate(nodeId, nodeId)
1649+
.withUntypedValue("id", reportUuid.toString()).build();
1650+
subReportersByNode.get(nodeId).forEach(child -> insertReportNode(newSubReporter, child));
16501651
return newSubReporter;
16511652
}).collect(Collectors.toList());
16521653
}
16531654

1654-
private String getNodeIdFromReportKey(ReporterModel reporter) {
1655-
return Arrays.stream(reporter.getTaskKey().split("@")).findFirst().orElseThrow();
1655+
private String getNodeIdFromReportKey(ReportNode reporter) {
1656+
return Arrays.stream(reporter.getMessageKey().split("@")).findFirst().orElseThrow();
16561657
}
16571658

16581659
private void updateNode(UUID studyUuid, UUID nodeUuid, Optional<NetworkModificationResult> networkModificationResult) {

src/main/java/org/gridsuite/study/server/utils/StudyUtils.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
import com.fasterxml.jackson.core.JsonProcessingException;
1111
import com.fasterxml.jackson.databind.JsonNode;
1212
import com.fasterxml.jackson.databind.ObjectMapper;
13+
import com.powsybl.commons.report.ReportNode;
14+
import com.powsybl.commons.report.ReportNodeAdder;
15+
import com.powsybl.commons.report.TypedValue;
16+
17+
import java.util.Map;
18+
1319
import org.gridsuite.study.server.StudyException;
1420
import org.slf4j.Logger;
1521
import org.slf4j.LoggerFactory;
@@ -59,4 +65,15 @@ public static void addPageableToQueryParams(UriComponentsBuilder builder, Pageab
5965
builder.queryParam("sort", order.getProperty() + "," + order.getDirection());
6066
}
6167
}
68+
69+
public static void insertReportNode(ReportNode parent, ReportNode child) {
70+
ReportNodeAdder adder = parent.newReportNode().withMessageTemplate(child.getMessageKey(), child.getMessageTemplate());
71+
for (Map.Entry<String, TypedValue> valueEntry : child.getValues().entrySet()) {
72+
adder.withUntypedValue(valueEntry.getKey(), valueEntry.getValue().toString());
73+
}
74+
ReportNode insertedChild = adder.add();
75+
if (child.getChildren() != null) {
76+
child.getChildren().forEach(grandChild -> insertReportNode(insertedChild, grandChild));
77+
}
78+
}
6279
}

src/test/java/org/gridsuite/study/server/NetworkModificationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import com.powsybl.commons.datasource.ResourceDataSource;
1717
import com.powsybl.commons.datasource.ResourceSet;
1818
import com.powsybl.commons.exceptions.UncheckedInterruptedException;
19-
import com.powsybl.commons.reporter.ReporterModel;
19+
import com.powsybl.commons.report.ReportNode;
2020
import com.powsybl.iidm.network.IdentifiableType;
2121
import com.powsybl.iidm.network.Network;
2222
import com.powsybl.iidm.network.VariantManagerConstants;
@@ -128,7 +128,7 @@ public class NetworkModificationTest {
128128

129129
private static final String MODIFICATION_UUID = "796719f5-bd31-48be-be46-ef7b96951e32";
130130

131-
private static final ReporterModel REPORT_TEST = new ReporterModel("test", "test");
131+
private static final ReportNode REPORT_TEST = ReportNode.newRootReportNode().withMessageTemplate("test", "test").build();
132132

133133
private static final String TEST_FILE = "testCase.xiidm";
134134

0 commit comments

Comments
 (0)