From 6b85068d96072522f05879c1bfad93552d41e433 Mon Sep 17 00:00:00 2001 From: Etienne LESOT Date: Wed, 27 May 2026 10:59:07 +0200 Subject: [PATCH] refactor logs when deleting vl on revert modification Signed-off-by: Etienne LESOT --- .../com/powsybl/commons/reports.properties | 3 +- .../com/powsybl/commons/reports_fr.properties | 3 +- .../topology/TopologyModificationUtils.java | 9 +++- .../util/ModificationReports.java | 12 ++++- .../topology/RevertCreateLineOnLineTest.java | 49 ++++++++++++++----- ...-line-on-line-keeping-vl-with-branches.txt | 7 +++ .../revert-create-line-on-line-keeping-vl.txt | 2 +- 7 files changed, 66 insertions(+), 19 deletions(-) create mode 100644 iidm/iidm-modification/src/test/resources/reportNode/revert-create-line-on-line-keeping-vl-with-branches.txt diff --git a/commons/src/main/resources/com/powsybl/commons/reports.properties b/commons/src/main/resources/com/powsybl/commons/reports.properties index b68234885bb..928c39a32ef 100644 --- a/commons/src/main/resources/com/powsybl/commons/reports.properties +++ b/commons/src/main/resources/com/powsybl/commons/reports.properties @@ -135,7 +135,8 @@ core.iidm.modification.voltageConnectedOnLine = Voltage level ${voltageLevelId} core.iidm.modification.voltageLevelCreated = VoltageLevel ${voltageLevelId} created core.iidm.modification.voltageLevelNotFound = Voltage level ${voltageLevelId} is not found core.iidm.modification.voltageLevelRemoved = Voltage level ${vlId} removed -core.iidm.modification.voltageLevelRemovingEquipmentsLeft = Voltage level ${vlId} still contains equipments and it is not removed. +core.iidm.modification.voltageLevelNotRemovedWithRemainingBranches = Voltage level ${vlId} still contains equipments including branches, it is not removed. +core.iidm.modification.voltageLevelNotRemovedWithNoBranch = Voltage level ${vlId} still contains equipments but no branch, it is not removed. core.iidm.modification.wrongSwitchKind = Switch kinds must be DISCONNECTOR or BREAKER core.iidm.modification.noBusbarSection = No busbar section provided. core.iidm.modification.wrongNetwork = All busbar sections must be in the network passed to the method. diff --git a/commons/src/main/resources/com/powsybl/commons/reports_fr.properties b/commons/src/main/resources/com/powsybl/commons/reports_fr.properties index 10c0aff9dfd..4e99d64032a 100644 --- a/commons/src/main/resources/com/powsybl/commons/reports_fr.properties +++ b/commons/src/main/resources/com/powsybl/commons/reports_fr.properties @@ -135,7 +135,8 @@ core.iidm.modification.voltageConnectedOnLine = Le poste ${voltageLevelId} conne core.iidm.modification.voltageLevelCreated = Poste ${voltageLevelId} créé. core.iidm.modification.voltageLevelNotFound = Poste ${voltageLevelId} introuvable. core.iidm.modification.voltageLevelRemoved = Le poste ${vlId} a été supprimé. -core.iidm.modification.voltageLevelRemovingEquipmentsLeft = Le poste ${vlId} contient toujours des équipements, il n'est donc pas supprimé. +core.iidm.modification.voltageLevelNotRemovedWithRemainingBranches = Le poste ${vlId} contient toujours des équipements dont des quadripôles, il n'est pas supprimé. +core.iidm.modification.voltageLevelNotRemovedWithNoBranch =Le poste ${vlId} contient toujours des équipements mais aucun quadripôles, il n'est pas supprimé. core.iidm.modification.wrongSwitchKind = Les organes de coupures doivent être de type DISCONNECTOR ou BREAKER. core.iidm.modification.noBusbarSection = Aucune section de jeu de barres donnée core.iidm.modification.wrongNetwork = Toutes les sections de jeu de barres doivent être dans le réseau passé en entrée. diff --git a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/TopologyModificationUtils.java b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/TopologyModificationUtils.java index 2e46363ce02..72ed4ca91d4 100644 --- a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/TopologyModificationUtils.java +++ b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/TopologyModificationUtils.java @@ -202,7 +202,14 @@ static void removeVoltageLevelAndSubstation(VoltageLevel voltageLevel, ReportNod String vlId = voltageLevel.getId(); boolean noMoreEquipments = voltageLevel.getConnectableStream().noneMatch(c -> c.getType() != IdentifiableType.BUSBAR_SECTION); if (!noMoreEquipments) { - voltageLevelRemovingEquipmentsLeftReport(reportNode, vlId); + boolean noMoreBranch = voltageLevel.getConnectableStream().noneMatch(c -> c.getType() == IdentifiableType.LINE + || c.getType() == IdentifiableType.TWO_WINDINGS_TRANSFORMER || c.getType() == IdentifiableType.THREE_WINDINGS_TRANSFORMER || + c.getType() == IdentifiableType.HVDC_CONVERTER_STATION); + if (noMoreBranch) { + voltageLevelNotRemovedWithNoBranch(reportNode, vlId); + } else { + voltageLevelNotRemovedWithRemainingBranches(reportNode, vlId); + } LOGGER.warn("Voltage level {} still contains equipments and it is not removed.", vlId); return; } diff --git a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/util/ModificationReports.java b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/util/ModificationReports.java index 2e3ee587b61..3412e5b52ed 100644 --- a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/util/ModificationReports.java +++ b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/util/ModificationReports.java @@ -439,9 +439,17 @@ public static void noConnectablePositionExtension(ReportNode reportNode, Voltage .add(); } - public static void voltageLevelRemovingEquipmentsLeftReport(ReportNode reportNode, String vlId) { + public static void voltageLevelNotRemovedWithRemainingBranches(ReportNode reportNode, String vlId) { reportNode.newReportNode() - .withMessageTemplate("core.iidm.modification.voltageLevelRemovingEquipmentsLeft") + .withMessageTemplate("core.iidm.modification.voltageLevelNotRemovedWithRemainingBranches") + .withUntypedValue("vlId", vlId) + .withSeverity(TypedValue.WARN_SEVERITY) + .add(); + } + + public static void voltageLevelNotRemovedWithNoBranch(ReportNode reportNode, String vlId) { + reportNode.newReportNode() + .withMessageTemplate("core.iidm.modification.voltageLevelNotRemovedWithNoBranch") .withUntypedValue("vlId", vlId) .withSeverity(TypedValue.WARN_SEVERITY) .add(); diff --git a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/RevertCreateLineOnLineTest.java b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/RevertCreateLineOnLineTest.java index 0cd3ab456af..09e917fc344 100644 --- a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/RevertCreateLineOnLineTest.java +++ b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/RevertCreateLineOnLineTest.java @@ -29,11 +29,7 @@ class RevertCreateLineOnLineTest extends AbstractModificationTest { @Test void revertCreateLineOnLineNbTest() throws IOException { - Network network = createNbNetworkWithBusbarSection(); - Line line = network.getLine("CJ"); - LineAdder adder = createLineAdder(line, network); - NetworkModification modification = new CreateLineOnLineBuilder().withBusbarSectionOrBusId(BBS).withLine(line).withLineAdder(adder).build(); - modification.apply(network); + Network network = createNetworkWithLineOnLine(); VoltageLevel vl = network.newVoltageLevel().setId("VL3").setNominalV(380).setTopologyKind(TopologyKind.NODE_BREAKER).add(); vl.getNodeBreakerView().newBusbarSection().setId("bbs3").setNode(0).add(); @@ -167,7 +163,7 @@ void revertCreateLineOnLineNbTest() throws IOException { .withResourceBundles(PowsyblTestReportResourceBundle.TEST_BASE_NAME, PowsyblCoreReportResourceBundle.BASE_NAME) .withMessageTemplate("reportNodeTestRevertCreateLineOnLine") .build(); - modification = new RevertCreateLineOnLineBuilder() + NetworkModification modification = new RevertCreateLineOnLineBuilder() .withLineToBeMerged1Id("CJ_1") .withLineToBeMerged2Id("CJ_2") .withLineToBeDeletedId("testLine") @@ -341,17 +337,12 @@ void testHasImpact() { @Test void testDoesNotDeleteVoltageLevel() throws IOException { - Network network = createNbNetworkWithBusbarSection(); - Line line = network.getLine("CJ"); - LineAdder adder = createLineAdder(line, network); - NetworkModification modification = new CreateLineOnLineBuilder().withBusbarSectionOrBusId(BBS).withLine(line).withLineAdder(adder).build(); - modification.apply(network); + Network network = createNetworkWithLineOnLine(); VoltageLevel vlTest = network.getVoltageLevel(VLTEST); assertNotNull(vlTest.getNodeBreakerView().getSwitch("CJ_BREAKER")); assertNotNull(vlTest.getNodeBreakerView().getSwitch("CJ_DISCONNECTOR_2_0")); VoltageLevel vl = network.getVoltageLevel("CJ_VL"); assertNotNull(vl); - // add one element vl.newLoad().setId("loadId").setP0(100).setQ0(50).setNode(4).add(); @@ -359,7 +350,7 @@ void testDoesNotDeleteVoltageLevel() throws IOException { .withResourceBundles(PowsyblTestReportResourceBundle.TEST_BASE_NAME, PowsyblCoreReportResourceBundle.BASE_NAME) .withMessageTemplate("reportNodeTestRevertCreateLineOnLineKeepingTheVL") .build(); - modification = new RevertCreateLineOnLineBuilder() + NetworkModification modification = new RevertCreateLineOnLineBuilder() .withLineToBeMerged1Id("CJ_1") .withLineToBeMerged2Id("CJ_2") .withLineToBeDeletedId("testLine") @@ -375,4 +366,36 @@ void testDoesNotDeleteVoltageLevel() throws IOException { assertNull(vlTest.getNodeBreakerView().getSwitch("CJ_DISCONNECTOR_2_0")); testReportNode(reportNode, "/reportNode/revert-create-line-on-line-keeping-vl.txt"); } + + @Test + void testDoesNotDeleteVoltageLevelWithBranches() throws IOException { + Network network = createNetworkWithLineOnLine(); + VoltageLevel vl = network.getVoltageLevel("CJ_VL"); + assertNotNull(vl); + // add one element + network.newLine().setId("line").setR(1).setX(1).setVoltageLevel1("CJ_VL").setVoltageLevel2(VLTEST).setNode1(4).setNode2(5).add(); + ReportNode reportNode = ReportNode.newRootReportNode() + .withResourceBundles(PowsyblTestReportResourceBundle.TEST_BASE_NAME, PowsyblCoreReportResourceBundle.BASE_NAME) + .withMessageTemplate("reportNodeTestRevertCreateLineOnLineKeepingTheVL") + .build(); + NetworkModification modification = new RevertCreateLineOnLineBuilder() + .withLineToBeMerged1Id("CJ_1") + .withLineToBeMerged2Id("CJ_2") + .withLineToBeDeletedId("testLine") + .withMergedLineId("CJ_NEW") + .build(); + modification.apply(network, true, reportNode); + Line line = network.getLine("line"); + assertNotNull(line); + testReportNode(reportNode, "/reportNode/revert-create-line-on-line-keeping-vl-with-branches.txt"); + } + + private Network createNetworkWithLineOnLine() { + Network network = createNbNetworkWithBusbarSection(); + Line line = network.getLine("CJ"); + LineAdder adder = createLineAdder(line, network); + NetworkModification modification = new CreateLineOnLineBuilder().withBusbarSectionOrBusId(BBS).withLine(line).withLineAdder(adder).build(); + modification.apply(network); + return network; + } } diff --git a/iidm/iidm-modification/src/test/resources/reportNode/revert-create-line-on-line-keeping-vl-with-branches.txt b/iidm/iidm-modification/src/test/resources/reportNode/revert-create-line-on-line-keeping-vl-with-branches.txt new file mode 100644 index 00000000000..adbe3b4f392 --- /dev/null +++ b/iidm/iidm-modification/src/test/resources/reportNode/revert-create-line-on-line-keeping-vl-with-branches.txt @@ -0,0 +1,7 @@ ++ Testing reportNode for reverting create line on line and not removing the voltage level + Line CJ_1 removed + Line CJ_2 removed + Line testLine removed + Line CJ_NEW created + Voltage level CJ_VL still contains equipments including branches, it is not removed. + Voltage level VLTEST still contains equipments including branches, it is not removed. diff --git a/iidm/iidm-modification/src/test/resources/reportNode/revert-create-line-on-line-keeping-vl.txt b/iidm/iidm-modification/src/test/resources/reportNode/revert-create-line-on-line-keeping-vl.txt index 02770f2b70a..3d3f2968578 100644 --- a/iidm/iidm-modification/src/test/resources/reportNode/revert-create-line-on-line-keeping-vl.txt +++ b/iidm/iidm-modification/src/test/resources/reportNode/revert-create-line-on-line-keeping-vl.txt @@ -3,5 +3,5 @@ Line CJ_2 removed Line testLine removed Line CJ_NEW created - Voltage level CJ_VL still contains equipments and it is not removed. + Voltage level CJ_VL still contains equipments but no branch, it is not removed. Voltage level VLTEST removed