Skip to content

Commit 3bd1910

Browse files
EstherDarkishBOUTIER CharlyTristan-WorkGH
authored
Upgrade to powsybl-dependencies v2025.0.0 (#136)
Signed-off-by: BOUTIER Charly <[email protected]> Signed-off-by: Tristan Chuine <[email protected]> Co-authored-by: BOUTIER Charly <[email protected]> Co-authored-by: Tristan Chuine <[email protected]>
1 parent 02755c2 commit 3bd1910

21 files changed

+509
-499
lines changed

src/main/java/org/gridsuite/shortcircuit/server/RestTemplateConfig.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,13 @@ private MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter(
4747
return converter;
4848
}
4949

50-
private static ObjectMapper createObjectMapper() {
50+
@Bean
51+
public static ObjectMapper objectMapper() {
5152
var objectMapper = Jackson2ObjectMapperBuilder.json().build();
5253
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
5354
objectMapper.registerModule(new ShortCircuitAnalysisJsonModule());
5455
objectMapper.registerModule(new ReportNodeJsonModule());
5556
objectMapper.setInjectableValues(new InjectableValues.Std().addValue(ReportNodeDeserializer.DICTIONARY_VALUE_ID, null));
5657
return objectMapper;
5758
}
58-
59-
@Bean
60-
public static ObjectMapper objectMapper() {
61-
return createObjectMapper();
62-
}
6359
}

src/main/java/org/gridsuite/shortcircuit/server/ShortCircuitController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public ResponseEntity<Void> invalidateStatus(@Parameter(description = "Result uu
142142
@Operation(summary = "Stop a short circuit analysis computation")
143143
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The short circuit analysis has been stopped")})
144144
public ResponseEntity<Void> stop(@Parameter(description = "Result UUID") @PathVariable("resultUuid") UUID resultUuid,
145-
@Parameter(description = "Result receiver") @RequestParam(name = "receiver", required = false) String receiver,
145+
@Parameter(description = "Result receiver") @RequestParam(name = "receiver") String receiver,
146146
@RequestHeader(HEADER_USER_ID) String userId) {
147147
shortCircuitService.stop(resultUuid, receiver, userId);
148148
return ResponseEntity.ok().build();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.gridsuite.shortcircuit.server.report;
2+
3+
import com.powsybl.commons.report.ReportNode;
4+
import lombok.NonNull;
5+
import org.gridsuite.shortcircuit.server.service.ShortCircuitRunContext;
6+
7+
public interface ReportMapper {
8+
/**
9+
* Look into the node and perform action on it if wanted.
10+
*
11+
* @param node the current node visited
12+
*/
13+
void transformNode(@NonNull final ReportNode node, @NonNull final ShortCircuitRunContext runContext);
14+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package org.gridsuite.shortcircuit.server.report;
2+
3+
import com.powsybl.commons.report.ReportNode;
4+
import com.powsybl.commons.report.ReportNodeImpl;
5+
import com.powsybl.commons.report.ReportNodeNoOp;
6+
import lombok.AllArgsConstructor;
7+
import lombok.NonNull;
8+
import lombok.extern.slf4j.Slf4j;
9+
import org.gridsuite.shortcircuit.server.service.ShortCircuitRunContext;
10+
import org.jetbrains.annotations.NotNull;
11+
import org.jetbrains.annotations.Nullable;
12+
import org.springframework.stereotype.Service;
13+
14+
import java.util.List;
15+
16+
@Service
17+
@Slf4j
18+
@AllArgsConstructor
19+
public class ReportMapperService {
20+
@NonNull private final List<ReportMapper> mappers;
21+
22+
/**
23+
* Do actions on a tree of {@link ReportMapper}s.
24+
*
25+
* @param rootReportNode The tree to transform.
26+
* @param runContext The run context used
27+
* @return The transformed tree (same instance).
28+
* @implNote We don't support a tree with a big depth because we use a recursive walker internally.
29+
* @apiNote Because {@link ReportNode} doesn't define setters, and known {@link ReportNodeImpl} & {@link ReportNodeNoOp} return
30+
* either {@code Collections.unmodifiable*()} or {@code Collections.empty*()}, no modification of {@code messageKey} and
31+
* deletion of node is supported.
32+
*/
33+
public ReportNode map(@Nullable final ReportNode rootReportNode, @NonNull final ShortCircuitRunContext runContext) {
34+
/* Quick check to be sure it's a tree build from AbstractWorkerService#run(...) */
35+
if (rootReportNode == null) {
36+
log.debug("No logs report, nothing to do.");
37+
} else if (!"ws.commons.rootReporterId".equals(rootReportNode.getMessageKey())) {
38+
log.debug("Unrecognized ReportNode: {}", rootReportNode);
39+
} else if (mappers.isEmpty()) {
40+
log.debug("No mapper to apply, nothing to do.");
41+
} else {
42+
log.info("ShortCircuitAnalysis root node: will modify it!");
43+
this.recursiveMap(rootReportNode, runContext);
44+
}
45+
return rootReportNode;
46+
}
47+
48+
//TODO redo the function in non-recursive one to avoid possibly StackOverflowError
49+
private void recursiveMap(@NotNull final ReportNode reportNode, @NotNull final ShortCircuitRunContext runContext) {
50+
for (final ReportMapper mapper : mappers) {
51+
mapper.transformNode(reportNode, runContext);
52+
}
53+
for (final ReportNode childNode : reportNode.getChildren()) {
54+
recursiveMap(childNode, runContext);
55+
}
56+
}
57+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
* SPDX-License-Identifier: MPL-2.0
7+
*/
8+
package org.gridsuite.shortcircuit.server.report;
9+
10+
import com.google.auto.service.AutoService;
11+
import com.powsybl.commons.report.ReportResourceBundle;
12+
13+
/**
14+
* @author Charly Boutier {@literal <charly.boutier at rte-france.com>}
15+
*/
16+
@AutoService(ReportResourceBundle.class)
17+
public final class ShortcircuitServerReportResourceBundle implements ReportResourceBundle {
18+
19+
public static final String BASE_NAME = "org.gridsuite.shortcircuit.server.reports";
20+
21+
public String getBaseName() {
22+
return BASE_NAME;
23+
}
24+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package org.gridsuite.shortcircuit.server.report.mappers;
2+
3+
import com.powsybl.commons.report.ReportConstants;
4+
import com.powsybl.commons.report.ReportNode;
5+
import com.powsybl.commons.report.TypedValue;
6+
import lombok.Data;
7+
import lombok.NonNull;
8+
import lombok.extern.slf4j.Slf4j;
9+
import org.gridsuite.shortcircuit.server.report.ShortcircuitServerReportResourceBundle;
10+
import org.gridsuite.shortcircuit.server.report.ReportMapper;
11+
import org.gridsuite.shortcircuit.server.service.ShortCircuitRunContext;
12+
import org.jetbrains.annotations.Nullable;
13+
import org.springframework.context.annotation.Bean;
14+
import org.springframework.context.annotation.Configuration;
15+
16+
/**
17+
* Pass some of the verbose ADN logs to {@link TypedValue#TRACE_SEVERITY TRACE} severity and insert a summarized log line.
18+
*
19+
* @see com.rte_france.powsybl.iidm.export.adn.ADNHelper
20+
* @see com.rte_france.powsybl.iidm.export.adn.BranchHelper
21+
*/
22+
@Slf4j
23+
@Data
24+
public class AdnTraceLevelAndSummarizeMapper implements ReportMapper {
25+
@NonNull public final String equipmentsLabel;
26+
@NonNull public final String parentMessageKey; //"Conversion of ..."
27+
@NonNull public final String toSummarizeMessageKey;
28+
@NonNull public final String summaryMessageKey;
29+
private long logsToSummarizeCount; // =0L
30+
private TypedValue logsToSummarizeSeverity = TypedValue.WARN_SEVERITY;
31+
32+
/** {@inheritDoc} */
33+
@Override
34+
public void transformNode(final @NonNull ReportNode node, @Nullable final ShortCircuitRunContext unused) {
35+
if (this.parentMessageKey.equals(node.getMessageKey())) {
36+
log.debug("ADN logs node for {} detected, will analyse them...", this.equipmentsLabel);
37+
for (final ReportNode child : node.getChildren()) {
38+
if (this.toSummarizeMessageKey.equals(child.getMessageKey())) {
39+
child.getValue(ReportConstants.SEVERITY_KEY).ifPresent(severity -> logsToSummarizeSeverity = severity);
40+
child.addSeverity(TypedValue.TRACE_SEVERITY);
41+
this.logsToSummarizeCount++;
42+
}
43+
}
44+
/* finalize computation of summaries */
45+
log.debug("Found {} lines in shortcircuit logs matching {}", this.logsToSummarizeCount, this.toSummarizeMessageKey);
46+
if (this.logsToSummarizeCount > 0L) {
47+
node.newReportNode()
48+
.withResourceBundles(ShortcircuitServerReportResourceBundle.BASE_NAME) //TODO what is this bug with tests?
49+
.withMessageTemplate(this.summaryMessageKey)
50+
.withTimestamp()
51+
.withSeverity(this.logsToSummarizeSeverity)
52+
.withUntypedValue("equipmentsLabel", this.equipmentsLabel)
53+
.withUntypedValue("nb", this.logsToSummarizeCount)
54+
.add();
55+
}
56+
}
57+
}
58+
59+
/**
60+
* Just initialize all the mappers
61+
*/
62+
@Configuration
63+
public static class AdnMapperBeans {
64+
65+
@Bean
66+
public AdnTraceLevelAndSummarizeMapper powsyblAdnGeneratorsMapper() {
67+
return new AdnTraceLevelAndSummarizeMapper("generators",
68+
"generatorConversion",
69+
"disconnectedTerminalGenerator",
70+
"shortcircuit.server.disconnectedTerminalEquipmentSummary");
71+
}
72+
73+
@Bean
74+
public AdnTraceLevelAndSummarizeMapper powsyblAdnBatteriesMapper() {
75+
return new AdnTraceLevelAndSummarizeMapper("batteries",
76+
"batteryConversion",
77+
"disconnectedTerminalGenerator",
78+
"shortcircuit.server.disconnectedTerminalEquipmentSummary");
79+
}
80+
81+
@Bean
82+
public AdnTraceLevelAndSummarizeMapper powsyblAdnTwoWindingsTransformersMapper() {
83+
// in branchConversion.twoWindingsTransformerConversion
84+
return new AdnTraceLevelAndSummarizeMapper("two windings transformers",
85+
"twoWindingsTransformerConversion",
86+
"addConstantRatio",
87+
"shortcircuit.server.addConstantRatioSummary");
88+
}
89+
90+
/* There is also possibly nodes:
91+
* branchConversion.threeWindingsTransformerConversion
92+
* branchConversion.lineConversion
93+
* branchConversion.tieLineConversion
94+
* danglinglinesConversion
95+
*/
96+
}
97+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.gridsuite.shortcircuit.server.report.mappers;
2+
3+
import com.powsybl.commons.report.ReportNode;
4+
import com.powsybl.commons.report.TypedValue;
5+
import lombok.NonNull;
6+
import org.apache.commons.lang3.StringUtils;
7+
import org.gridsuite.shortcircuit.server.report.ShortcircuitServerReportResourceBundle;
8+
import org.gridsuite.shortcircuit.server.report.ReportMapper;
9+
import org.gridsuite.shortcircuit.server.service.ShortCircuitRunContext;
10+
import org.springframework.stereotype.Component;
11+
12+
@Component
13+
public class VoltageLevelsWithWrongIpValuesMapper implements ReportMapper {
14+
/** {@inheritDoc} */
15+
@Override
16+
public void transformNode(@NonNull final ReportNode node, @NonNull final ShortCircuitRunContext runContext) {
17+
// only add a log line at the (true) root node
18+
if ("ws.commons.reportType".equals(node.getMessageKey())
19+
&& node.getValue("reportType").map(str -> ((String) str.getValue()).endsWith("ShortCircuitAnalysis")).orElse(Boolean.FALSE)
20+
&& !runContext.getVoltageLevelsWithWrongIsc().isEmpty()) {
21+
node.newReportNode()
22+
.withResourceBundles(ShortcircuitServerReportResourceBundle.BASE_NAME) //TODO what is this bug with tests?
23+
.withMessageTemplate("shortcircuit.server.VoltageLevelsWithWrongIscValues").add()
24+
.newReportNode()
25+
.withResourceBundles(ShortcircuitServerReportResourceBundle.BASE_NAME) //TODO what is this bug with tests?
26+
.withMessageTemplate("shortcircuit.server.VoltageLevelsWithWrongIscValuesSummarize")
27+
.withUntypedValue("voltageLevels", StringUtils.join(runContext.getVoltageLevelsWithWrongIsc(), ", "))
28+
.withSeverity(TypedValue.ERROR_SEVERITY)
29+
.withTimestamp()
30+
.add();
31+
}
32+
}
33+
}

src/main/java/org/gridsuite/shortcircuit/server/reports/AbstractReportMapper.java

Lines changed: 0 additions & 106 deletions
This file was deleted.

0 commit comments

Comments
 (0)