From 0377cd65bcd7828e8bef7ea707c7800701111ad8 Mon Sep 17 00:00:00 2001 From: EtienneLt <32468651+EtienneLt@users.noreply.github.com> Date: Fri, 19 Jul 2024 15:53:31 +0200 Subject: [PATCH] refactor hvdc logs for creation and modification (#498) --------- Signed-off-by: Etienne LESOT --- .../server/modifications/BatteryCreation.java | 2 +- .../modifications/BatteryModification.java | 2 +- .../modifications/GeneratorCreation.java | 2 +- .../modifications/GeneratorModification.java | 2 +- .../server/modifications/LineCreation.java | 2 +- .../modifications/LineModification.java | 2 +- .../server/modifications/LoadCreation.java | 2 +- .../modifications/LoadModification.java | 2 +- .../server/modifications/PropertiesUtils.java | 68 ++++++++++++------- .../ShuntCompensatorCreation.java | 2 +- .../ShuntCompensatorModification.java | 2 +- .../modifications/SubstationCreation.java | 2 +- .../modifications/SubstationModification.java | 2 +- .../TwoWindingsTransformerCreation.java | 2 +- .../TwoWindingsTransformerModification.java | 2 +- .../modifications/VoltageLevelCreation.java | 2 +- .../VoltageLevelModification.java | 2 +- .../server/modifications/VscCreation.java | 2 +- .../server/modifications/VscModification.java | 2 +- 19 files changed, 61 insertions(+), 43 deletions(-) diff --git a/src/main/java/org/gridsuite/modification/server/modifications/BatteryCreation.java b/src/main/java/org/gridsuite/modification/server/modifications/BatteryCreation.java index bf5e41df5..fa07950bc 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/BatteryCreation.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/BatteryCreation.java @@ -69,7 +69,7 @@ public void apply(Network network, ReportNode subReportNode) { } // properties Battery battery = network.getBattery(modificationInfos.getEquipmentId()); - PropertiesUtils.applyProperties(battery, subReportNode, modificationInfos.getProperties()); + PropertiesUtils.applyProperties(battery, subReportNode, modificationInfos.getProperties(), "BatteryProperties"); } private void createBatteryInNodeBreaker(VoltageLevel voltageLevel, BatteryCreationInfos batteryCreationInfos, Network network, ReportNode subReportNode) { diff --git a/src/main/java/org/gridsuite/modification/server/modifications/BatteryModification.java b/src/main/java/org/gridsuite/modification/server/modifications/BatteryModification.java index 038fbf625..8ec26d100 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/BatteryModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/BatteryModification.java @@ -86,7 +86,7 @@ private void modifyBattery(Battery battery, BatteryModificationInfos modificatio modifyBatteryLimitsAttributes(modificationInfos, battery, subReportNode); modifyBatterySetpointsAttributes(modificationInfos, battery, subReportNode); ModificationUtils.getInstance().modifyInjectionConnection(modificationInfos, battery); - PropertiesUtils.applyProperties(battery, subReportNode, modificationInfos.getProperties()); + PropertiesUtils.applyProperties(battery, subReportNode, modificationInfos.getProperties(), "BatteryProperties"); } private void modifyBatterySetpointsAttributes(BatteryModificationInfos modificationInfos, diff --git a/src/main/java/org/gridsuite/modification/server/modifications/GeneratorCreation.java b/src/main/java/org/gridsuite/modification/server/modifications/GeneratorCreation.java index 3833535d8..d1e594440 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/GeneratorCreation.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/GeneratorCreation.java @@ -84,7 +84,7 @@ public void apply(Network network, ReportNode subReportNode) { } // apply the properties Generator generator = network.getGenerator(modificationInfos.getEquipmentId()); - PropertiesUtils.applyProperties(generator, subReportNode, modificationInfos.getProperties()); + PropertiesUtils.applyProperties(generator, subReportNode, modificationInfos.getProperties(), "GeneratorProperties"); } private void createGeneratorInNodeBreaker(VoltageLevel voltageLevel, GeneratorCreationInfos generatorCreationInfos, Network network, ReportNode subReportNode) { diff --git a/src/main/java/org/gridsuite/modification/server/modifications/GeneratorModification.java b/src/main/java/org/gridsuite/modification/server/modifications/GeneratorModification.java index ac1387db1..522332632 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/GeneratorModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/GeneratorModification.java @@ -103,7 +103,7 @@ private void modifyGenerator(Generator generator, GeneratorModificationInfos mod modifyGeneratorStartUpAttributes(modificationInfos, generator, subReportNode); ModificationUtils.getInstance().modifyInjectionConnection(modificationInfos, generator); - PropertiesUtils.applyProperties(generator, subReportNode, modificationInfos.getProperties()); + PropertiesUtils.applyProperties(generator, subReportNode, modificationInfos.getProperties(), "GeneratorProperties"); } private void modifyGeneratorShortCircuitAttributes(GeneratorModificationInfos modificationInfos, diff --git a/src/main/java/org/gridsuite/modification/server/modifications/LineCreation.java b/src/main/java/org/gridsuite/modification/server/modifications/LineCreation.java index 98921db67..8d1970668 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/LineCreation.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/LineCreation.java @@ -75,7 +75,7 @@ public void apply(Network network, ReportNode subReportNode) { ModificationUtils.getInstance().disconnectBranch(modificationInfos, network.getLine(modificationInfos.getEquipmentId()), subReportNode); // properties Line line = network.getLine(modificationInfos.getEquipmentId()); - PropertiesUtils.applyProperties(line, subReportNode, modificationInfos.getProperties()); + PropertiesUtils.applyProperties(line, subReportNode, modificationInfos.getProperties(), "LineProperties"); } private void addLine(Network network, VoltageLevel voltageLevel1, VoltageLevel voltageLevel2, LineCreationInfos lineCreationInfos, boolean withSwitch1, boolean withSwitch2, ReportNode subReportNode) { diff --git a/src/main/java/org/gridsuite/modification/server/modifications/LineModification.java b/src/main/java/org/gridsuite/modification/server/modifications/LineModification.java index 8a3cdf15c..5f58f7762 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/LineModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/LineModification.java @@ -45,7 +45,7 @@ public void apply(Network network, ReportNode subReportNode) { private void modifyLine(Line line, BranchModificationInfos lineModificationInfos, ReportNode subReportNode) { modifyBranch(line, lineModificationInfos, subReportNode, "lineModification", "Line with id=${id} modified :"); - PropertiesUtils.applyProperties(line, subReportNode, modificationInfos.getProperties()); + PropertiesUtils.applyProperties(line, subReportNode, modificationInfos.getProperties(), "LineProperties"); } @Override diff --git a/src/main/java/org/gridsuite/modification/server/modifications/LoadCreation.java b/src/main/java/org/gridsuite/modification/server/modifications/LoadCreation.java index 0ea633921..5afdcde99 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/LoadCreation.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/LoadCreation.java @@ -65,7 +65,7 @@ public void apply(Network network, ReportNode subReporter) { // properties Load load = network.getLoad(modificationInfos.getEquipmentId()); - PropertiesUtils.applyProperties(load, subReporter, modificationInfos.getProperties()); + PropertiesUtils.applyProperties(load, subReporter, modificationInfos.getProperties(), "LoadProperties"); } private void reportElementaryCreations(ReportNode subReportNode) { diff --git a/src/main/java/org/gridsuite/modification/server/modifications/LoadModification.java b/src/main/java/org/gridsuite/modification/server/modifications/LoadModification.java index 8d7b07673..36b8d7009 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/LoadModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/LoadModification.java @@ -55,7 +55,7 @@ private void modifyLoad(Load load, ReportNode subReportNode) { ModificationUtils.getInstance().applyElementaryModifications(load::setQ0, load::getQ0, modificationInfos.getQ0(), subReportNode, "Constant reactive power"); // properties - PropertiesUtils.applyProperties(load, subReportNode, modificationInfos.getProperties()); + PropertiesUtils.applyProperties(load, subReportNode, modificationInfos.getProperties(), "LoadProperties"); ModificationUtils.getInstance().modifyInjectionConnection(modificationInfos, load); } diff --git a/src/main/java/org/gridsuite/modification/server/modifications/PropertiesUtils.java b/src/main/java/org/gridsuite/modification/server/modifications/PropertiesUtils.java index 558fb3fc4..d37c1a2e4 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/PropertiesUtils.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/PropertiesUtils.java @@ -1,52 +1,70 @@ package org.gridsuite.modification.server.modifications; -import com.powsybl.commons.report.ReportNode; -import com.powsybl.commons.report.TypedValue; +import com.powsybl.commons.report.*; import com.powsybl.iidm.network.Identifiable; import org.gridsuite.modification.server.dto.FreePropertyInfos; import org.jetbrains.annotations.Nullable; -import java.util.List; -import java.util.Optional; +import java.util.*; public final class PropertiesUtils { + public static final String PROPERTIES = "Properties"; private PropertiesUtils() { // Should not be instantiated } - public static void applyProperties(Identifiable identifiable, ReportNode subReportNode, @Nullable List properties) { + public static void applyProperties(Identifiable identifiable, ReportNode subReportNode, @Nullable List properties, String propertiesLabelKey) { + List reportNodes = new ArrayList<>(); + ReportNode propertiesReporter = subReportNode.newReportNode().withMessageTemplate(PROPERTIES, PROPERTIES).add(); Optional.ofNullable(properties).ifPresent(props -> - props.forEach(prop -> PropertiesUtils.applyProperty(identifiable, prop, subReportNode))); + props.forEach(prop -> + Optional.ofNullable(PropertiesUtils.applyProperty(identifiable, prop)) + .ifPresent(reportNodes::add) + ) + ); + ModificationUtils.getInstance().reportModifications(propertiesReporter, reportNodes, + propertiesLabelKey, PROPERTIES, Map.of()); } - private static void applyProperty(Identifiable identifiable, FreePropertyInfos prop, ReportNode subReportNode) { + private static ReportNode applyProperty(Identifiable identifiable, FreePropertyInfos prop) { + ReportNodeBuilder builder = ReportNode.newRootReportNode(); if (prop.isDeletionMark()) { if (identifiable.removeProperty(prop.getName())) { - subReportNode.newReportNode() - .withMessageTemplate("propertyDeleted", " Property ${name} deleted") - .withUntypedValue("name", prop.getName()) - .withSeverity(TypedValue.INFO_SEVERITY) - .add(); + reportPropertyDeletion(builder, prop); + return builder.build(); } } else { String oldValue = identifiable.setProperty(prop.getName(), prop.getValue()); if (oldValue != null) { // update - subReportNode.newReportNode() - .withMessageTemplate("propertyChanged", " Property ${name} changed : ${from} -> ${to}") - .withUntypedValue("name", prop.getName()) - .withUntypedValue("from", oldValue) - .withUntypedValue("to", prop.getValue()) - .withSeverity(TypedValue.INFO_SEVERITY) - .add(); + reportPropertyModification(builder, prop); + return builder.build(); } else { // insert - subReportNode.newReportNode() - .withMessageTemplate("propertyAdded", " Property ${name} added with value ${value}") - .withUntypedValue("name", prop.getName()) - .withUntypedValue("value", prop.getValue()) - .withSeverity(TypedValue.INFO_SEVERITY) - .add(); + reportPropertyCreation(builder, prop); + return builder.build(); } } + return null; + } + + private static void reportPropertyCreation(ReportNodeAdderOrBuilder adderOrBuilder, FreePropertyInfos prop) { + adderOrBuilder.withMessageTemplate("propertyAdded", " Property ${name} added with value ${value}") + .withUntypedValue("name", prop.getName()) + .withUntypedValue("value", prop.getValue()) + .withSeverity(TypedValue.INFO_SEVERITY); + } + + private static void reportPropertyModification(ReportNodeAdderOrBuilder adderOrBuilder, FreePropertyInfos prop) { + adderOrBuilder.withMessageTemplate("propertyChanged", " Property ${name} changed : ${from} -> ${to}") + .withUntypedValue("name", prop.getName()) + .withUntypedValue("to", prop.getValue()) + .withUntypedValue("from", prop.getPreviousValue() == null ? "null" : prop.getPreviousValue()) + .withSeverity(TypedValue.INFO_SEVERITY); + } + + private static void reportPropertyDeletion(ReportNodeAdderOrBuilder adderOrBuilder, FreePropertyInfos prop) { + adderOrBuilder.withMessageTemplate("propertyDeleted", " Property ${name} deleted") + .withUntypedValue("name", prop.getName()) + .withSeverity(TypedValue.INFO_SEVERITY); } } diff --git a/src/main/java/org/gridsuite/modification/server/modifications/ShuntCompensatorCreation.java b/src/main/java/org/gridsuite/modification/server/modifications/ShuntCompensatorCreation.java index e7f59ed57..2d957edb7 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/ShuntCompensatorCreation.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/ShuntCompensatorCreation.java @@ -81,7 +81,7 @@ public void apply(Network network, ReportNode subReportNode) { ModificationUtils.getInstance().disconnectCreatedInjection(modificationInfos, network.getShuntCompensator(modificationInfos.getEquipmentId()), subReportNode); // properties ShuntCompensator shuntCompensator = network.getShuntCompensator(modificationInfos.getEquipmentId()); - PropertiesUtils.applyProperties(shuntCompensator, subReportNode, modificationInfos.getProperties()); + PropertiesUtils.applyProperties(shuntCompensator, subReportNode, modificationInfos.getProperties(), "ShuntCompensatorProperties"); } private ShuntCompensatorAdder createShuntAdderInNodeBreaker(VoltageLevel voltageLevel, ShuntCompensatorCreationInfos shuntCompensatorInfos) { diff --git a/src/main/java/org/gridsuite/modification/server/modifications/ShuntCompensatorModification.java b/src/main/java/org/gridsuite/modification/server/modifications/ShuntCompensatorModification.java index ea81593a8..1929751f7 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/ShuntCompensatorModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/ShuntCompensatorModification.java @@ -81,7 +81,7 @@ public void apply(Network network, ReportNode subReportNode) { } ModificationUtils.getInstance().modifyInjectionConnection(modificationInfos, shuntCompensator); - PropertiesUtils.applyProperties(shuntCompensator, subReportNode, modificationInfos.getProperties()); + PropertiesUtils.applyProperties(shuntCompensator, subReportNode, modificationInfos.getProperties(), "ShuntCompensatorProperties"); } diff --git a/src/main/java/org/gridsuite/modification/server/modifications/SubstationCreation.java b/src/main/java/org/gridsuite/modification/server/modifications/SubstationCreation.java index 4b8681ad7..2387ecb44 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/SubstationCreation.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/SubstationCreation.java @@ -38,6 +38,6 @@ public void apply(Network network, ReportNode subReportNode) { .reportElementaryCreation(subReportNode, modificationInfos.getCountry(), "Country"); } // properties - PropertiesUtils.applyProperties(substation, subReportNode, modificationInfos.getProperties()); + PropertiesUtils.applyProperties(substation, subReportNode, modificationInfos.getProperties(), "SubstationProperties"); } } diff --git a/src/main/java/org/gridsuite/modification/server/modifications/SubstationModification.java b/src/main/java/org/gridsuite/modification/server/modifications/SubstationModification.java index 8a07beb96..e38db3a7f 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/SubstationModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/SubstationModification.java @@ -49,6 +49,6 @@ public void apply(Network network, ReportNode subReportNode) { ModificationUtils.getInstance().applyElementaryModifications(station::setName, () -> station.getOptionalName().orElse("No value"), modificationInfos.getEquipmentName(), subReportNode, "Name"); ModificationUtils.getInstance().applyElementaryModifications(station::setCountry, station::getNullableCountry, modificationInfos.getCountry(), subReportNode, "Country"); // properties - PropertiesUtils.applyProperties(station, subReportNode, modificationInfos.getProperties()); + PropertiesUtils.applyProperties(station, subReportNode, modificationInfos.getProperties(), "SubstationProperties"); } } diff --git a/src/main/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerCreation.java b/src/main/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerCreation.java index 098840fb5..89c478cb2 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerCreation.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerCreation.java @@ -60,7 +60,7 @@ public void apply(Network network, ReportNode subReportNode) { ModificationUtils.getInstance().disconnectBranch(modificationInfos, network.getTwoWindingsTransformer(modificationInfos.getEquipmentId()), subReportNode); // properties - PropertiesUtils.applyProperties(twoWindingsTransformer, subReportNode, modificationInfos.getProperties()); + PropertiesUtils.applyProperties(twoWindingsTransformer, subReportNode, modificationInfos.getProperties(), "TwoWindingsTransformerProperties"); } private TwoWindingsTransformer create2WTInNodeBreaker(Network network, VoltageLevel voltageLevel1, VoltageLevel voltageLevel2, ReportNode subReportNode) { diff --git a/src/main/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModification.java b/src/main/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModification.java index 01fe58952..7b265106b 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModification.java @@ -50,7 +50,7 @@ public void apply(Network network, ReportNode subReportNode) { private void modifyTwoWindingsTransformer(TwoWindingsTransformer twoWindingsTransformer, BranchModificationInfos twoWindingsTransformerModificationInfos, ReportNode subReportNode, Network network) { modifyBranch(twoWindingsTransformer, twoWindingsTransformerModificationInfos, subReportNode, "twoWindingsTransformerModification", "TwoWindingsTransformer with id=${id} modified :"); addTapChangersToTwoWindingsTransformer(network, (TwoWindingsTransformerModificationInfos) modificationInfos, twoWindingsTransformer, subReportNode); - PropertiesUtils.applyProperties(twoWindingsTransformer, subReportNode, modificationInfos.getProperties()); + PropertiesUtils.applyProperties(twoWindingsTransformer, subReportNode, modificationInfos.getProperties(), "TwoWindingsTransformerProperties"); } @Override diff --git a/src/main/java/org/gridsuite/modification/server/modifications/VoltageLevelCreation.java b/src/main/java/org/gridsuite/modification/server/modifications/VoltageLevelCreation.java index ed78644f3..84993e890 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/VoltageLevelCreation.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/VoltageLevelCreation.java @@ -33,6 +33,6 @@ public void apply(Network network, ReportNode subReportNode) { ModificationUtils.getInstance().createVoltageLevel(modificationInfos, subReportNode, network); // properties VoltageLevel voltageLevel = network.getVoltageLevel(modificationInfos.getEquipmentId()); - PropertiesUtils.applyProperties(voltageLevel, subReportNode, modificationInfos.getProperties()); + PropertiesUtils.applyProperties(voltageLevel, subReportNode, modificationInfos.getProperties(), "VlProperties"); } } diff --git a/src/main/java/org/gridsuite/modification/server/modifications/VoltageLevelModification.java b/src/main/java/org/gridsuite/modification/server/modifications/VoltageLevelModification.java index 966300d42..7bbd83e8b 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/VoltageLevelModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/VoltageLevelModification.java @@ -89,7 +89,7 @@ public void apply(Network network, ReportNode subReportNode) { ModificationUtils.getInstance().applyElementaryModifications(voltageLevel::setHighVoltageLimit, voltageLevel::getHighVoltageLimit, modificationInfos.getHighVoltageLimit(), subReportNode, "High voltage limit"); modifyVoltageLevelShortCircuit(subReportNode, voltageLevel); - PropertiesUtils.applyProperties(voltageLevel, subReportNode, modificationInfos.getProperties()); + PropertiesUtils.applyProperties(voltageLevel, subReportNode, modificationInfos.getProperties(), "VlProperties"); } private void modifyVoltageLevelShortCircuit(ReportNode subReportNode, VoltageLevel voltageLevel) { diff --git a/src/main/java/org/gridsuite/modification/server/modifications/VscCreation.java b/src/main/java/org/gridsuite/modification/server/modifications/VscCreation.java index 8b70ecf73..ca5db7af8 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/VscCreation.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/VscCreation.java @@ -125,7 +125,7 @@ public void apply(Network network, ReportNode subReportNode) { .reportElementaryCreation(subReportNode, modificationInfos.getEquipmentName(), "Name"); } - PropertiesUtils.applyProperties(hvdcLine, subReportNode, modificationInfos.getProperties()); + PropertiesUtils.applyProperties(hvdcLine, subReportNode, modificationInfos.getProperties(), "VscProperties"); } private void reportHvdcLineInfos(ReportNode subReportNode) { diff --git a/src/main/java/org/gridsuite/modification/server/modifications/VscModification.java b/src/main/java/org/gridsuite/modification/server/modifications/VscModification.java index a4ce12f9c..45c8742a4 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/VscModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/VscModification.java @@ -97,7 +97,7 @@ private void modifyVsc(@NonNull Network network, @NonNull HvdcLine hvdcLine, Vsc modifyConverterStation(network, modificationInfos.getConverterStation1(), subReportNode); modifyConverterStation(network, modificationInfos.getConverterStation2(), subReportNode); - PropertiesUtils.applyProperties(hvdcLine, subReportNode, modificationInfos.getProperties()); + PropertiesUtils.applyProperties(hvdcLine, subReportNode, modificationInfos.getProperties(), "VscProperties"); } private static void operatorActivePowerLimit(HvdcLine hvdcLine, VscModificationInfos modificationInfos, ReportNode subReportNode) {