diff --git a/commons/src/main/resources/com/powsybl/commons/reports.properties b/commons/src/main/resources/com/powsybl/commons/reports.properties index 22a4d7ab23c..1533bef29a9 100644 --- a/commons/src/main/resources/com/powsybl/commons/reports.properties +++ b/commons/src/main/resources/com/powsybl/commons/reports.properties @@ -136,6 +136,8 @@ core.iidm.modification.voltageLevelCreated = VoltageLevel ${voltageLevelId} crea 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 +core.iidm.modification.voltageLevelRemovingEquipmentsLeftWithQuadripoles = Voltage level ${vlId} still contains equipments including quadripoles, it is not removed +core.iidm.modification.voltageLevelRemovingEquipmentsLeftWithoutQuadripoles = Voltage level ${vlId} still contains equipments but no quadripoles, 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 4f57f14c227..ac435e308ae 100644 --- a/commons/src/main/resources/com/powsybl/commons/reports_fr.properties +++ b/commons/src/main/resources/com/powsybl/commons/reports_fr.properties @@ -136,6 +136,8 @@ 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. +core.iidm.modification.voltageLevelRemovingEquipmentsLeftWithQuadripoles = Le poste ${vlId} contient toujours des équipements dont des quadripoles, il n'est pas supprimé. +core.iidm.modification.voltageLevelRemovingEquipmentsLeftWithoutQuadripoles = Le poste ${vlId} contient toujours des équipements mais aucun quadripoles, 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 3ed9e11c8f0..0f6ad10894a 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 @@ -199,17 +199,26 @@ private static > voi } static void removeVoltageLevelAndSubstation(VoltageLevel voltageLevel, ReportNode reportNode) { - Optional substation = voltageLevel.getSubstation(); String vlId = voltageLevel.getId(); + boolean noMoreQuadripoles = 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); boolean noMoreEquipments = voltageLevel.getConnectableStream().noneMatch(c -> c.getType() != IdentifiableType.BUSBAR_SECTION); if (!noMoreEquipments) { - voltageLevelRemovingEquipmentsLeftReport(reportNode, vlId); - LOGGER.warn("Voltage level {} still contains equipments", vlId); + if (noMoreQuadripoles) { + voltageLevelRemovingEquipmentsLeftWithoutQuadripoleReport(reportNode, vlId); + LOGGER.warn("Voltage level {} still contains equipments but no quadripoles, it is not removed", vlId); + } else { + voltageLevelRemovingEquipmentsLeftWithQuadripoleReport(reportNode, vlId); + LOGGER.warn("Voltage level {} still contains equipments including quadripoles, it is not removed", vlId); + } + return; } + // substation must be gotten before removing the voltageLevel + Optional substation = voltageLevel.getSubstation(); voltageLevel.remove(); voltageLevelRemovedReport(reportNode, vlId); LOGGER.info("Voltage level {} removed", vlId); - substation.ifPresent(s -> { if (s.getVoltageLevelStream().count() == 0) { String substationId = s.getId(); 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..03ae8f8ae16 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 @@ -447,6 +447,22 @@ public static void voltageLevelRemovingEquipmentsLeftReport(ReportNode reportNod .add(); } + public static void voltageLevelRemovingEquipmentsLeftWithoutQuadripoleReport(ReportNode reportNode, String vlId) { + reportNode.newReportNode() + .withMessageTemplate("core.iidm.modification.voltageLevelRemovingEquipmentsLeftWithoutQuadripoles") + .withUntypedValue("vlId", vlId) + .withSeverity(TypedValue.WARN_SEVERITY) + .add(); + } + + public static void voltageLevelRemovingEquipmentsLeftWithQuadripoleReport(ReportNode reportNode, String vlId) { + reportNode.newReportNode() + .withMessageTemplate("core.iidm.modification.voltageLevelRemovingEquipmentsLeftWithQuadripoles") + .withUntypedValue("vlId", vlId) + .withSeverity(TypedValue.WARN_SEVERITY) + .add(); + } + // ERROR public static void notFoundBusOrBusbarSectionReport(ReportNode reportNode, String identifiableId) { reportNode.newReportNode() 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 4c07d2956f9..85d4721a5dc 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 @@ -9,8 +9,8 @@ import com.powsybl.commons.PowsyblException; import com.powsybl.commons.report.PowsyblCoreReportResourceBundle; -import com.powsybl.commons.test.PowsyblTestReportResourceBundle; import com.powsybl.commons.report.ReportNode; +import com.powsybl.commons.test.PowsyblTestReportResourceBundle; import com.powsybl.iidm.modification.AbstractNetworkModification; import com.powsybl.iidm.modification.NetworkModification; import com.powsybl.iidm.modification.NetworkModificationImpact; @@ -338,4 +338,35 @@ void testHasImpact() { .build(); assertEquals(NetworkModificationImpact.CANNOT_BE_APPLIED, modification.hasImpactOnNetwork(network)); } + + @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); + VoltageLevel vl = network.getVoltageLevel("CJ_VL"); + assertNotNull(vl); + + // add one element + vl.newLoad().setId("loadId").setP0(100).setQ0(50).setNode(4).add(); + + ReportNode reportNode = ReportNode.newRootReportNode() + .withResourceBundles(PowsyblTestReportResourceBundle.TEST_BASE_NAME, PowsyblCoreReportResourceBundle.BASE_NAME) + .withMessageTemplate("reportNodeTestRevertCreateLineOnLineKeepingTheVL") + .build(); + modification = new RevertCreateLineOnLineBuilder() + .withLineToBeMerged1Id("CJ_1") + .withLineToBeMerged2Id("CJ_2") + .withLineToBeDeletedId("testLine") + .withMergedLineId("CJ_NEW") + .build(); + modification.apply(network, true, reportNode); + vl = network.getVoltageLevel("CJ_VL"); + assertNotNull(vl); + Load load = network.getLoad("loadId"); + assertNotNull(load); + testReportNode(reportNode, "/reportNode/revert-create-line-on-line-keeping-vl.txt"); + } } diff --git a/iidm/iidm-modification/src/test/resources/i18n/reports.properties b/iidm/iidm-modification/src/test/resources/i18n/reports.properties index e5643781c29..a0f3a0d93af 100644 --- a/iidm/iidm-modification/src/test/resources/i18n/reports.properties +++ b/iidm/iidm-modification/src/test/resources/i18n/reports.properties @@ -7,6 +7,7 @@ ReportNodeTest = Testing reportNode reportNodeTestRevertCreateLineOnLine = Testing reportNode for reverting create line on line in node/breaker network reportNodeTestRevertCreateLineOnLineBB = Testing reportNode for reverting create line on line in bus/breaker network reportNodeTestRevertCreateLineOnLineNBBB = Testing reportNode for reverting create line on line with mixed topology network +reportNodeTestRevertCreateLineOnLineKeepingTheVL = Testing reportNode for reverting create line on line and not removing the voltage level reportPlannedDisconnectionComplete = Testing reportNode for connectable disconnection reportTest = Testing reportNode reportTestBbsInWrongVL = Testing reportNode with busbar section in wrong voltage level 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 new file mode 100644 index 00000000000..2fcca3a11f9 --- /dev/null +++ b/iidm/iidm-modification/src/test/resources/reportNode/revert-create-line-on-line-keeping-vl.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 quadripoles, it is not removed + Voltage level VLTEST removed