Skip to content

Commit f50ac99

Browse files
authored
Use i18n (#3349)
* Gather all network modification reports on ModificationReports class * Gather all network reports on NetworkReports class * Gather all time series reports on TimeseriesReports class * Create CGMES Model reports class * Gather Ucte reports in UcteReports class * Gather iidm deserialization reports in DeserializerReports * Gather dynamic simulation reports in DynamicSimulationReports class * Clean ReportNode key duplicates * Refactor some ModificationReports for ReportNode good practice to expose the report nodes keys * Populate resource bundle dictionary + use new local message template method for ReportNodes * Fix tests because ReportNode keys have changed (prefixes) * Replace deprecated use of withMessageTemplate in UCTE tests * Replace deprecated use of withMessageTemplate in CGMES tests * Replace deprecated use of withMessageTemplate in commons tests * Replace deprecated use of withMessageTemplate in iidm-api tests * Replace deprecated use of withMessageTemplate in iidm-modification tests * Replace deprecated use of withMessageTemplate in iidm-serde tests * Replace deprecated use of withMessageTemplate in shortcircuit-api tests * Replace deprecated use of withMessageTemplate in time-series tests * Replace deprecated use of withMessageTemplate in iidm-tck tests * Update documentation about the ReportNode internationalization * Fix checkstyle * Use mutualized constant to get bundle name * Replace "-" to "." in ReportNode translation keys * Add some ReportNode i18n use documentation * Remove use of deprecated withMessageTemplate due to last change with ReportNode timestamps * Sonar - Remove some duplicate blocks * Try to reduce the duplication * Fix code smell at some funny complexity cost Signed-off-by: CARON Alice <[email protected]>
1 parent 72d3983 commit f50ac99

File tree

111 files changed

+1686
-816
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+1686
-816
lines changed

cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/CgmesReports.java

+24-23
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
package com.powsybl.cgmes.conversion;
99

10+
import com.powsybl.commons.report.ReportBundleBaseName;
1011
import com.powsybl.commons.report.ReportNode;
1112
import com.powsybl.commons.report.TypedValue;
1213
import com.powsybl.iidm.network.Bus;
@@ -23,58 +24,58 @@ private CgmesReports() {
2324
// INFO
2425
public static ReportNode applyingPreprocessorsReport(ReportNode reportNode) {
2526
return reportNode.newReportNode()
26-
.withMessageTemplate("applyingPreprocessors", "Applying preprocessors.")
27+
.withLocaleMessageTemplate("core.cgmes.conversion.applyingPreprocessors", ReportBundleBaseName.BUNDLE_BASE_NAME)
2728
.withSeverity(TypedValue.INFO_SEVERITY)
2829
.add();
2930
}
3031

3132
public static void applyingProcessorReport(ReportNode reportNode, String processorName) {
3233
reportNode.newReportNode()
33-
.withMessageTemplate("applyingProcessor", "Applying processor: {processorName}.")
34+
.withLocaleMessageTemplate("core.cgmes.conversion.applyingProcessor", ReportBundleBaseName.BUNDLE_BASE_NAME)
3435
.withUntypedValue("processorName", processorName)
3536
.withSeverity(TypedValue.INFO_SEVERITY)
3637
.add();
3738
}
3839

3940
public static ReportNode buildingMappingsReport(ReportNode reportNode) {
4041
return reportNode.newReportNode()
41-
.withMessageTemplate("buildingMappings", "Building mappings.")
42+
.withLocaleMessageTemplate("core.cgmes.conversion.buildingMappings", ReportBundleBaseName.BUNDLE_BASE_NAME)
4243
.withSeverity(TypedValue.INFO_SEVERITY)
4344
.add();
4445
}
4546

4647
public static ReportNode convertingElementTypeReport(ReportNode reportNode, String elementType) {
4748
return reportNode.newReportNode()
48-
.withMessageTemplate("convertingElementType", "Converting ${elementType}.")
49+
.withLocaleMessageTemplate("core.cgmes.conversion.convertingElementType", ReportBundleBaseName.BUNDLE_BASE_NAME)
4950
.withUntypedValue("elementType", elementType)
5051
.withSeverity(TypedValue.INFO_SEVERITY)
5152
.add();
5253
}
5354

5455
public static ReportNode fixingDanglingLinesIssuesReport(ReportNode reportNode) {
5556
return reportNode.newReportNode()
56-
.withMessageTemplate("fixingDanglingLinesIssues", "Fixing issues with dangling lines.")
57+
.withLocaleMessageTemplate("core.cgmes.conversion.fixingDanglingLinesIssues", ReportBundleBaseName.BUNDLE_BASE_NAME)
5758
.withSeverity(TypedValue.INFO_SEVERITY)
5859
.add();
5960
}
6061

6162
public static ReportNode settingVoltagesAndAnglesReport(ReportNode reportNode) {
6263
return reportNode.newReportNode()
63-
.withMessageTemplate("settingVoltagesAndAngles", "Setting voltages and angles.")
64+
.withLocaleMessageTemplate("core.cgmes.conversion.settingVoltagesAndAngles", ReportBundleBaseName.BUNDLE_BASE_NAME)
6465
.withSeverity(TypedValue.INFO_SEVERITY)
6566
.add();
6667
}
6768

6869
public static ReportNode applyingPostprocessorsReport(ReportNode reportNode) {
6970
return reportNode.newReportNode()
70-
.withMessageTemplate("applyingPostprocessors", "Applying postprocessors.")
71+
.withLocaleMessageTemplate("core.cgmes.conversion.applyingPostprocessors", ReportBundleBaseName.BUNDLE_BASE_NAME)
7172
.withSeverity(TypedValue.INFO_SEVERITY)
7273
.add();
7374
}
7475

7576
public static void importedCgmesNetworkReport(ReportNode reportNode, String networkId) {
7677
reportNode.newReportNode()
77-
.withMessageTemplate("importedCgmesNetwork", "CGMES network ${networkId} is imported.")
78+
.withLocaleMessageTemplate("core.cgmes.conversion.importedCgmesNetwork", ReportBundleBaseName.BUNDLE_BASE_NAME)
7879
.withUntypedValue("networkId", networkId)
7980
.withSeverity(TypedValue.INFO_SEVERITY)
8081
.add();
@@ -83,7 +84,7 @@ public static void importedCgmesNetworkReport(ReportNode reportNode, String netw
8384
// WARN
8485
public static void badVoltageTargetValueRegulatingControlReport(ReportNode reportNode, String eqId, double targetValue) {
8586
reportNode.newReportNode()
86-
.withMessageTemplate("badVoltageTargetValueRegulatingControl", "Equipment ${equipmentId} has a regulating control with bad target value for voltage: ${targetValue}.")
87+
.withLocaleMessageTemplate("core.cgmes.conversion.badVoltageTargetValueRegulatingControl", ReportBundleBaseName.BUNDLE_BASE_NAME)
8788
.withUntypedValue("equipmentId", eqId)
8889
.withTypedValue("targetValue", targetValue, TypedValue.VOLTAGE)
8990
.withSeverity(TypedValue.WARN_SEVERITY)
@@ -92,7 +93,7 @@ public static void badVoltageTargetValueRegulatingControlReport(ReportNode repor
9293

9394
public static void badTargetDeadbandRegulatingControlReport(ReportNode reportNode, String eqId, double targetDeadband) {
9495
reportNode.newReportNode()
95-
.withMessageTemplate("badTargetDeadbandRegulatingControl", "Equipment ${equipmentId} has a regulating control with bad target deadband: ${targetDeadband}.")
96+
.withLocaleMessageTemplate("core.cgmes.conversion.badTargetDeadbandRegulatingControl", ReportBundleBaseName.BUNDLE_BASE_NAME)
9697
.withUntypedValue("equipmentId", eqId)
9798
.withTypedValue("targetDeadband", targetDeadband, TypedValue.VOLTAGE)
9899
.withSeverity(TypedValue.WARN_SEVERITY)
@@ -101,7 +102,7 @@ public static void badTargetDeadbandRegulatingControlReport(ReportNode reportNod
101102

102103
public static void invalidAngleVoltageBusReport(ReportNode reportNode, Bus bus, String nodeId, double v, double angle) {
103104
reportNode.newReportNode()
104-
.withMessageTemplate("invalidAngleVoltageBus", "Node ${nodeId} in substation ${substation}, voltageLevel ${voltageLevel}, bus ${bus} has invalid value for voltage and/or angle. Voltage magnitude is ${voltage}, angle is ${angle}.")
105+
.withLocaleMessageTemplate("core.cgmes.conversion.invalidAngleVoltageBus", ReportBundleBaseName.BUNDLE_BASE_NAME)
105106
.withUntypedValue("substation", bus.getVoltageLevel().getSubstation().map(Substation::getNameOrId).orElse("unknown"))
106107
.withUntypedValue("voltageLevel", bus.getVoltageLevel().getNameOrId())
107108
.withUntypedValue("bus", bus.getId())
@@ -114,7 +115,7 @@ public static void invalidAngleVoltageBusReport(ReportNode reportNode, Bus bus,
114115

115116
public static void invalidAngleVoltageNodeReport(ReportNode reportNode, String nodeId, double v, double angle) {
116117
reportNode.newReportNode()
117-
.withMessageTemplate("invalidAngleVoltageNode", "Node ${nodeId} has invalid value for voltage and/or angle. Voltage magnitude is ${voltage}, angle is ${angle}.")
118+
.withLocaleMessageTemplate("core.cgmes.conversion.invalidAngleVoltageNode", ReportBundleBaseName.BUNDLE_BASE_NAME)
118119
.withUntypedValue("nodeId", nodeId)
119120
.withTypedValue("voltage", v, TypedValue.VOLTAGE)
120121
.withTypedValue("angle", angle, TypedValue.ANGLE)
@@ -124,15 +125,15 @@ public static void invalidAngleVoltageNodeReport(ReportNode reportNode, String n
124125

125126
public static void removingUnattachedHvdcConverterStationReport(ReportNode reportNode, String converterId) {
126127
reportNode.newReportNode()
127-
.withMessageTemplate("removingUnattachedHvdcConverterStation", "HVDC Converter Station ${converterId} will be removed since it has no attached HVDC line.")
128+
.withLocaleMessageTemplate("core.cgmes.conversion.removingUnattachedHvdcConverterStation", ReportBundleBaseName.BUNDLE_BASE_NAME)
128129
.withUntypedValue("converterId", converterId)
129130
.withSeverity(TypedValue.WARN_SEVERITY)
130131
.add();
131132
}
132133

133134
public static void voltageLevelMappingReport(ReportNode reportNode, int voltageLevelMappingSize, String mapAsString) {
134135
reportNode.newReportNode()
135-
.withMessageTemplate("voltageLevelMapping", "Original ${voltageLevelMappingSize} VoltageLevel container(s) connected by switches have been merged in IIDM. Map of original VoltageLevel to IIDM: ${mapAsString}.")
136+
.withLocaleMessageTemplate("core.cgmes.conversion.voltageLevelMapping", ReportBundleBaseName.BUNDLE_BASE_NAME)
136137
.withUntypedValue("voltageLevelMappingSize", voltageLevelMappingSize)
137138
.withUntypedValue("mapAsString", mapAsString)
138139
.withSeverity(TypedValue.WARN_SEVERITY)
@@ -141,7 +142,7 @@ public static void voltageLevelMappingReport(ReportNode reportNode, int voltageL
141142

142143
public static void substationMappingReport(ReportNode reportNode, int substationMappingSize, String mapAsString) {
143144
reportNode.newReportNode()
144-
.withMessageTemplate("substationMapping", "Original ${substationMappingSize} Substation container(s) connected by transformers have been merged in IIDM. Map of original Substation to IIDM: ${mapAsString}.")
145+
.withLocaleMessageTemplate("core.cgmes.conversion.substationMapping", ReportBundleBaseName.BUNDLE_BASE_NAME)
145146
.withUntypedValue("substationMappingSize", substationMappingSize)
146147
.withUntypedValue("mapAsString", mapAsString)
147148
.withSeverity(TypedValue.WARN_SEVERITY)
@@ -150,7 +151,7 @@ public static void substationMappingReport(ReportNode reportNode, int substation
150151

151152
public static void nominalVoltageIsZeroReport(ReportNode reportNode, String voltageLevelId) {
152153
reportNode.newReportNode()
153-
.withMessageTemplate("nominalVoltageIsZero", "Ignoring VoltageLevel: ${voltageLevelId} for its nominal voltage is equal to 0.")
154+
.withLocaleMessageTemplate("core.cgmes.conversion.nominalVoltageIsZero", ReportBundleBaseName.BUNDLE_BASE_NAME)
154155
.withUntypedValue("voltageLevelId", voltageLevelId)
155156
.withSeverity(TypedValue.WARN_SEVERITY)
156157
.add();
@@ -159,23 +160,23 @@ public static void nominalVoltageIsZeroReport(ReportNode reportNode, String volt
159160
// ERROR
160161
public static void inconsistentProfilesTPRequiredReport(ReportNode reportNode, String networkId) {
161162
reportNode.newReportNode()
162-
.withMessageTemplate("inconsistentProfilesTPRequired", "Network contains node/breaker ${networkId} information. References to Topological Nodes in SSH/SV files will not be valid if TP is not exported.")
163+
.withLocaleMessageTemplate("core.cgmes.conversion.inconsistentProfilesTPRequired", ReportBundleBaseName.BUNDLE_BASE_NAME)
163164
.withUntypedValue("networkId", networkId)
164165
.withSeverity(TypedValue.ERROR_SEVERITY)
165166
.add();
166167
}
167168

168169
public static void danglingLineDisconnectedAtBoundaryHasBeenDisconnectedReport(ReportNode reportNode, String danglingLineId) {
169170
reportNode.newReportNode()
170-
.withMessageTemplate("danglingLineDisconnectedAtBoundaryHasBeenDisconnected", "DanglingLine ${danglingLineId} was connected at network side and disconnected at boundary side. It has been disconnected also at network side.")
171+
.withLocaleMessageTemplate("core.cgmes.conversion.danglingLineDisconnectedAtBoundaryHasBeenDisconnected", ReportBundleBaseName.BUNDLE_BASE_NAME)
171172
.withUntypedValue("danglingLineId", danglingLineId)
172173
.withSeverity(TypedValue.WARN_SEVERITY)
173174
.add();
174175
}
175176

176177
public static void multipleUnpairedDanglingLinesAtSameBoundaryReport(ReportNode reportNode, String danglingLineId, double p0, double q0, double p0Adjusted, double q0Adjusted) {
177178
reportNode.newReportNode()
178-
.withMessageTemplate("multipleUnpairedDanglingLinesAtSameBoundary", "Multiple unpaired DanglingLines were connected at the same boundary side. Adjusted original injection from (${p0}, ${q0}) to (${p0Adjusted}, ${q0Adjusted}) for dangling line ${danglingLineId}.")
179+
.withLocaleMessageTemplate("core.cgmes.conversion.multipleUnpairedDanglingLinesAtSameBoundary", ReportBundleBaseName.BUNDLE_BASE_NAME)
179180
.withUntypedValue("danglingLineId", danglingLineId)
180181
.withUntypedValue("p0", p0)
181182
.withUntypedValue("q0", q0)
@@ -187,7 +188,7 @@ public static void multipleUnpairedDanglingLinesAtSameBoundaryReport(ReportNode
187188

188189
public static void missingMandatoryAttributeReport(ReportNode reportNode, String attributeName, String objectClass, String objectId) {
189190
reportNode.newReportNode()
190-
.withMessageTemplate("missingMandatoryAttribute", "Could't retrieve mandatory attribute: ${attributeName} of ${objectClass}: ${objectId}.")
191+
.withLocaleMessageTemplate("core.cgmes.conversion.missingMandatoryAttribute", ReportBundleBaseName.BUNDLE_BASE_NAME)
191192
.withUntypedValue("attributeName", attributeName)
192193
.withUntypedValue("objectClass", objectClass)
193194
.withUntypedValue("objectId", objectId)
@@ -197,20 +198,20 @@ public static void missingMandatoryAttributeReport(ReportNode reportNode, String
197198

198199
public static ReportNode importingCgmesFileReport(ReportNode reportNode, String basename) {
199200
return reportNode.newReportNode()
200-
.withMessageTemplate("CGMESConversion", "Importing CGMES file(s) with basename '${basename}'")
201+
.withLocaleMessageTemplate("core.cgmes.conversion.CGMESConversion", ReportBundleBaseName.BUNDLE_BASE_NAME)
201202
.withUntypedValue("basename", basename)
202203
.add();
203204
}
204205

205206
public static ReportNode readingCgmesTriplestoreReport(ReportNode reportNode) {
206207
return reportNode.newReportNode()
207-
.withMessageTemplate("CGMESTriplestore", "Reading CGMES Triplestore")
208+
.withLocaleMessageTemplate("core.cgmes.conversion.CGMESTriplestore", ReportBundleBaseName.BUNDLE_BASE_NAME)
208209
.add();
209210
}
210211

211212
public static void exportedModelIdentifierReport(ReportNode reportNode, String description, String identifier, String networkId) {
212213
reportNode.newReportNode()
213-
.withMessageTemplate("ExportedCgmesId", "CGMES exported model identifier: ${cgmesId} for subset ${cgmesSubset} of network ${networkId}")
214+
.withLocaleMessageTemplate("core.cgmes.conversion.ExportedCgmesId", ReportBundleBaseName.BUNDLE_BASE_NAME)
214215
.withTypedValue("cgmesId", description, TypedValue.URN_UUID)
215216
.withTypedValue("cgmesSubset", identifier, TypedValue.CGMES_SUBSET)
216217
.withTypedValue("networkId", networkId, TypedValue.ID)

cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/CgmesReportsTest.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.powsybl.commons.datasource.ReadOnlyDataSource;
55
import com.powsybl.commons.datasource.ResourceDataSource;
66
import com.powsybl.commons.datasource.ResourceSet;
7+
import com.powsybl.commons.report.ReportBundleBaseName;
78
import com.powsybl.commons.report.ReportNode;
89
import org.junit.jupiter.api.Test;
910

@@ -12,7 +13,9 @@ class CgmesReportsTest {
1213

1314
@Test
1415
void importingCgmesFileReportTest() {
15-
ReportNode reportRoot = ReportNode.newRootReportNode().withMessageTemplate("test", "Test reports").build();
16+
ReportNode reportRoot = ReportNode.newRootReportNode()
17+
.withLocaleMessageTemplate("test", ReportBundleBaseName.BUNDLE_TEST_BASE_NAME)
18+
.build();
1619
ReadOnlyDataSource ds = new ResourceDataSource("CGMES import file(s)", new ResourceSet("/", "GeneratingUnitTypes.xml", "groundTest.xml"));
1720
ReportNode reportNode = CgmesReports.importingCgmesFileReport(reportRoot, ds.getBaseName());
1821
assertEquals("Importing CGMES file(s) with basename 'CGMES import file(s)'", reportNode.getMessage());

cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/FunctionalLogsTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.powsybl.cgmes.conformity.CgmesConformity1ModifiedCatalog;
1212
import com.powsybl.cgmes.conversion.CgmesImport;
1313
import com.powsybl.cgmes.model.GridModelReference;
14+
import com.powsybl.commons.report.ReportBundleBaseName;
1415
import com.powsybl.commons.report.ReportNode;
1516
import com.powsybl.iidm.network.Importers;
1617
import org.junit.jupiter.api.BeforeEach;
@@ -27,7 +28,6 @@
2728
* @author Luma Zamarreño {@literal <zamarrenolm at aia.es>}
2829
*/
2930
class FunctionalLogsTest {
30-
3131
private Properties importParams;
3232

3333
@BeforeEach
@@ -63,7 +63,7 @@ void testImportMiniGridNodeBreaker() throws IOException {
6363

6464
private ReportNode importReport(GridModelReference testCase) {
6565
ReportNode reportNode = ReportNode.newRootReportNode()
66-
.withMessageTemplate("testFunctionalLogs", "Test importing ${name}")
66+
.withLocaleMessageTemplate("testFunctionalLogs", ReportBundleBaseName.BUNDLE_TEST_BASE_NAME)
6767
.withUntypedValue("name", testCase.name())
6868
.build();
6969
Importers.importData("CGMES", testCase.dataSource(), importParams, reportNode);

cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/CommonGridModelExportTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.powsybl.commons.datasource.DirectoryDataSource;
1919
import com.powsybl.commons.datasource.MemDataSource;
2020
import com.powsybl.commons.datasource.ReadOnlyDataSource;
21+
import com.powsybl.commons.report.ReportBundleBaseName;
2122
import com.powsybl.commons.report.ReportNode;
2223
import com.powsybl.commons.test.AbstractSerDeTest;
2324
import com.powsybl.iidm.network.*;
@@ -57,7 +58,6 @@
5758
* @author Luma Zamarreño {@literal <zamarrenolm at aia.es>}
5859
*/
5960
class CommonGridModelExportTest extends AbstractSerDeTest {
60-
6161
private static final Pattern REGEX_SCENARIO_TIME = Pattern.compile("Model.scenarioTime>(.*?)<");
6262
private static final Pattern REGEX_DESCRIPTION = Pattern.compile("Model.description>(.*?)<");
6363
private static final Pattern REGEX_VERSION = Pattern.compile("Model.version>(.*?)<");
@@ -449,7 +449,7 @@ void testFaraoUseCase() {
449449
// Export using a reporter to gather the exported model identifiers
450450
ReportNode report = ReportNode
451451
.newRootReportNode()
452-
.withMessageTemplate("rootKey", "")
452+
.withLocaleMessageTemplate("rootKey", ReportBundleBaseName.BUNDLE_TEST_BASE_NAME)
453453
.build();
454454

455455
MemDataSource memDataSource = new MemDataSource();
@@ -494,7 +494,7 @@ void testFaraoUseCase() {
494494
// Obtain exported model identifiers from reporter
495495
Set<String> exportedModelIdsFromReporter = new HashSet<>();
496496
for (ReportNode n : report.getChildren()) {
497-
if ("ExportedCgmesId".equals(n.getMessageKey())) {
497+
if ("core.cgmes.conversion.ExportedCgmesId".equals(n.getMessageKey())) {
498498
cgmesId = n.getValue("cgmesId").orElseThrow().toString();
499499
exportedModelIdsFromReporter.add(cgmesId);
500500
String subset = n.getValue("cgmesSubset").orElseThrow().toString();

0 commit comments

Comments
 (0)