From 9a33abc7b30086ca0179335271abed6f66a9599e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Antonio=20Marqu=C3=A9s?= Date: Tue, 1 Mar 2022 12:31:54 +0100 Subject: [PATCH 1/6] Do not allow switches with the same node or bus at both ends MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Antonio Marqués --- .../network/impl/BusBreakerVoltageLevel.java | 3 + .../network/impl/NodeBreakerVoltageLevel.java | 3 + .../impl/tck/SwitchBusBreakerTest.java | 11 ++++ .../impl/tck/SwitchNodeBreakerTest.java | 11 ++++ .../tck/AbstractSwitchBusBreakerTest.java | 41 ++++++++++++++ .../tck/AbstractSwitchNodeBreakerTest.java | 55 +++++++++++++++++++ 6 files changed, 124 insertions(+) create mode 100644 iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/SwitchBusBreakerTest.java create mode 100644 iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/SwitchNodeBreakerTest.java create mode 100644 iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractSwitchBusBreakerTest.java create mode 100644 iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractSwitchNodeBreakerTest.java diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/BusBreakerVoltageLevel.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/BusBreakerVoltageLevel.java index 5af88f42c4b..5a5f9c38ada 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/BusBreakerVoltageLevel.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/BusBreakerVoltageLevel.java @@ -91,6 +91,9 @@ public Switch add() { if (busId2 == null) { throw new ValidationException(this, "second connection bus is not set"); } + if (busId1 == busId2) { + throw new ValidationException(this, "same bus at both ends"); + } SwitchImpl aSwitch = new SwitchImpl(BusBreakerVoltageLevel.this, id, getName(), isFictitious(), SwitchKind.BREAKER, open, true); addSwitch(aSwitch, busId1, busId2); diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NodeBreakerVoltageLevel.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NodeBreakerVoltageLevel.java index e0366bff634..5b0dc035d04 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NodeBreakerVoltageLevel.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NodeBreakerVoltageLevel.java @@ -151,6 +151,9 @@ public Switch add() { if (node2 == null) { throw new ValidationException(this, "second connection node is not set"); } + if (node1 == node2) { + throw new ValidationException(this, "same node at both ends"); + } if (kind == null) { throw new ValidationException(this, "kind is not set"); } diff --git a/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/SwitchBusBreakerTest.java b/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/SwitchBusBreakerTest.java new file mode 100644 index 00000000000..ea480bd1d38 --- /dev/null +++ b/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/SwitchBusBreakerTest.java @@ -0,0 +1,11 @@ +/** + * Copyright (c) 2022, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package com.powsybl.iidm.network.impl.tck; + +import com.powsybl.iidm.network.tck.AbstractSwitchBusBreakerTest; + +public class SwitchBusBreakerTest extends AbstractSwitchBusBreakerTest { } diff --git a/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/SwitchNodeBreakerTest.java b/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/SwitchNodeBreakerTest.java new file mode 100644 index 00000000000..0b81a0664f9 --- /dev/null +++ b/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/SwitchNodeBreakerTest.java @@ -0,0 +1,11 @@ +/** + * Copyright (c) 2022, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package com.powsybl.iidm.network.impl.tck; + +import com.powsybl.iidm.network.tck.AbstractSwitchNodeBreakerTest; + +public class SwitchNodeBreakerTest extends AbstractSwitchNodeBreakerTest { } diff --git a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractSwitchBusBreakerTest.java b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractSwitchBusBreakerTest.java new file mode 100644 index 00000000000..49867399e3d --- /dev/null +++ b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractSwitchBusBreakerTest.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) 2022, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package com.powsybl.iidm.network.tck; + +import com.powsybl.iidm.network.*; +import com.powsybl.iidm.network.test.BatteryNetworkFactory; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public abstract class AbstractSwitchBusBreakerTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + private Network network; + private VoltageLevel voltageLevel; + + @Before + public void initNetwork() { + network = BatteryNetworkFactory.create(); + voltageLevel = network.getVoltageLevel("VLGEN"); + } + + @Test + public void addSwitchWithSameBusAtBothEnds() { + thrown.expect(ValidationException.class); + thrown.expectMessage("Switch 'Sw1': same bus at both ends"); + Bus bus = voltageLevel.getBusBreakerView().getBus("NGEN"); + voltageLevel.getBusBreakerView().newSwitch() + .setId("Sw1") + .setBus1(bus.getId()) + .setBus2(bus.getId()) + .add(); + } +} diff --git a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractSwitchNodeBreakerTest.java b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractSwitchNodeBreakerTest.java new file mode 100644 index 00000000000..6c19146306d --- /dev/null +++ b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractSwitchNodeBreakerTest.java @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2022, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package com.powsybl.iidm.network.tck; + +import com.powsybl.iidm.network.*; +import com.powsybl.iidm.network.test.FictitiousSwitchFactory; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public abstract class AbstractSwitchNodeBreakerTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + private Network network; + private VoltageLevel voltageLevel; + + @Before + public void initNetwork() { + network = FictitiousSwitchFactory.create(); + voltageLevel = network.getVoltageLevel("C"); + } + + @Test + public void addSwitchWithSameNodeAtBothEnds() { + thrown.expect(ValidationException.class); + thrown.expectMessage("Switch 'Sw1': same node at both ends"); + int newNode = voltageLevel.getNodeBreakerView().getMaximumNodeIndex() + 1; + voltageLevel.getNodeBreakerView().newSwitch() + .setId("Sw1") + .setNode1(newNode) + .setNode2(newNode) + .setKind(SwitchKind.BREAKER) + .add(); + } + + @Test + public void addSwitchWithNullKind() { + thrown.expect(ValidationException.class); + thrown.expectMessage("Switch 'Sw1': kind is not set"); + int newNode1 = voltageLevel.getNodeBreakerView().getMaximumNodeIndex() + 1; + int newNode2 = newNode1 + 1; + voltageLevel.getNodeBreakerView().newSwitch() + .setId("Sw1") + .setNode1(newNode1) + .setNode2(newNode2) + .add(); + } +} From 7b2371c9b52842bc1149423f559eb6992bc6bba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Antonio=20Marqu=C3=A9s?= Date: Tue, 1 Mar 2022 14:44:41 +0100 Subject: [PATCH 2/6] Fix bugs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Antonio Marqués --- .../com/powsybl/iidm/network/impl/BusBreakerVoltageLevel.java | 2 +- .../com/powsybl/iidm/network/impl/NodeBreakerVoltageLevel.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/BusBreakerVoltageLevel.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/BusBreakerVoltageLevel.java index 5a5f9c38ada..dc7196c6cc0 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/BusBreakerVoltageLevel.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/BusBreakerVoltageLevel.java @@ -91,7 +91,7 @@ public Switch add() { if (busId2 == null) { throw new ValidationException(this, "second connection bus is not set"); } - if (busId1 == busId2) { + if (busId1 != null && busId1.equals(busId2)) { throw new ValidationException(this, "same bus at both ends"); } diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NodeBreakerVoltageLevel.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NodeBreakerVoltageLevel.java index 5b0dc035d04..8de6038556b 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NodeBreakerVoltageLevel.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NodeBreakerVoltageLevel.java @@ -151,7 +151,7 @@ public Switch add() { if (node2 == null) { throw new ValidationException(this, "second connection node is not set"); } - if (node1 == node2) { + if (node1 != null && node1.equals(node2)) { throw new ValidationException(this, "same node at both ends"); } if (kind == null) { From a9c5b31a1cecf356623aff0fefb5fd21aa8a8449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Antonio=20Marqu=C3=A9s?= Date: Tue, 1 Mar 2022 15:07:11 +0100 Subject: [PATCH 3/6] Fix code smells MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Antonio Marqués --- .../com/powsybl/iidm/network/impl/BusBreakerVoltageLevel.java | 2 +- .../com/powsybl/iidm/network/impl/NodeBreakerVoltageLevel.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/BusBreakerVoltageLevel.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/BusBreakerVoltageLevel.java index dc7196c6cc0..5c3ff6d3a2c 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/BusBreakerVoltageLevel.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/BusBreakerVoltageLevel.java @@ -91,7 +91,7 @@ public Switch add() { if (busId2 == null) { throw new ValidationException(this, "second connection bus is not set"); } - if (busId1 != null && busId1.equals(busId2)) { + if (busId1.equals(busId2)) { throw new ValidationException(this, "same bus at both ends"); } diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NodeBreakerVoltageLevel.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NodeBreakerVoltageLevel.java index 8de6038556b..3df6f6521fb 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NodeBreakerVoltageLevel.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NodeBreakerVoltageLevel.java @@ -151,7 +151,7 @@ public Switch add() { if (node2 == null) { throw new ValidationException(this, "second connection node is not set"); } - if (node1 != null && node1.equals(node2)) { + if (node1.equals(node2)) { throw new ValidationException(this, "same node at both ends"); } if (kind == null) { From 095f1207740349ee9ed690d1d063bc273a87321d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Antonio=20Marqu=C3=A9s?= Date: Wed, 9 Mar 2022 10:33:08 +0100 Subject: [PATCH 4/6] Handle compatibility with old XIIDM files by discarding switches with same node or bus. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Antonio Marqués --- .../iidm/xml/BusBreakerViewSwitchXml.java | 13 +++++- .../iidm/xml/NodeBreakerViewSwitchXml.java | 13 +++++- .../iidm/xml/AbstractXmlConverterTest.java | 7 ++++ .../java/com/powsybl/iidm/xml/SwitchTest.java | 40 +++++++++++++++++++ .../switchWithSameBusAtBothEnds.xiidm | 15 +++++++ .../switchWithSameNodeAtBothEnds.xiidm | 29 ++++++++++++++ 6 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 iidm/iidm-xml-converter/src/test/java/com/powsybl/iidm/xml/SwitchTest.java create mode 100644 iidm/iidm-xml-converter/src/test/resources/switches/switchWithSameBusAtBothEnds.xiidm create mode 100644 iidm/iidm-xml-converter/src/test/resources/switches/switchWithSameNodeAtBothEnds.xiidm diff --git a/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/BusBreakerViewSwitchXml.java b/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/BusBreakerViewSwitchXml.java index 180caaa36a6..37cedb8a13a 100644 --- a/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/BusBreakerViewSwitchXml.java +++ b/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/BusBreakerViewSwitchXml.java @@ -14,6 +14,9 @@ import javax.xml.stream.XMLStreamException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * @author Geoffroy Jamgotchian */ @@ -45,9 +48,17 @@ protected Switch readRootElementAttributes(VoltageLevel.BusBreakerView.SwitchAdd }); String bus1 = context.getAnonymizer().deanonymizeString(context.getReader().getAttributeValue(null, "bus1")); String bus2 = context.getAnonymizer().deanonymizeString(context.getReader().getAttributeValue(null, "bus2")); - return adder.setOpen(open) + // Discard switches with same bus at both ends + if (bus1 != null && bus1.equals(bus2)) { + LOGGER.info("Discard switch with same bus at both ends. Id: {}", context.getReader().getAttributeValue(null, "id")); + return null; + } else { + return adder.setOpen(open) .setBus1(bus1) .setBus2(bus2) .add(); + } } + + private static final Logger LOGGER = LoggerFactory.getLogger(BusBreakerViewSwitchXml.class); } diff --git a/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/NodeBreakerViewSwitchXml.java b/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/NodeBreakerViewSwitchXml.java index 776310d6a82..352e26e1871 100644 --- a/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/NodeBreakerViewSwitchXml.java +++ b/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/NodeBreakerViewSwitchXml.java @@ -14,6 +14,9 @@ import javax.xml.stream.XMLStreamException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * @author Geoffroy Jamgotchian */ @@ -45,11 +48,19 @@ protected Switch readRootElementAttributes(VoltageLevel.NodeBreakerView.SwitchAd }); int node1 = XmlUtil.readIntAttribute(context.getReader(), "node1"); int node2 = XmlUtil.readIntAttribute(context.getReader(), "node2"); - return adder.setKind(kind) + // Discard switches with same node at both ends + if (node1 == node2) { + LOGGER.info("Discard switch with same node at both ends. Id: {}", context.getReader().getAttributeValue(null, "id")); + return null; + } else { + return adder.setKind(kind) .setRetained(retained) .setOpen(open) .setNode1(node1) .setNode2(node2) .add(); + } } + + private static final Logger LOGGER = LoggerFactory.getLogger(NodeBreakerViewSwitchXml.class); } diff --git a/iidm/iidm-xml-converter/src/test/java/com/powsybl/iidm/xml/AbstractXmlConverterTest.java b/iidm/iidm-xml-converter/src/test/java/com/powsybl/iidm/xml/AbstractXmlConverterTest.java index 85d78af833f..101f2979baf 100644 --- a/iidm/iidm-xml-converter/src/test/java/com/powsybl/iidm/xml/AbstractXmlConverterTest.java +++ b/iidm/iidm-xml-converter/src/test/java/com/powsybl/iidm/xml/AbstractXmlConverterTest.java @@ -45,6 +45,13 @@ protected InputStream getVersionedNetworkAsStream(String fileName, IidmXmlVersio return getClass().getResourceAsStream(getVersionedNetworkPath(fileName, version)); } + /** + * Return an input stream of the test resource IIDM-XML file with a given file name. + */ + protected InputStream getNetworkAsStream(String fileName) { + return getClass().getResourceAsStream(fileName); + } + /** * Execute a round trip test on the test resource IIDM-XML file with a given file name for the given IIDM-XML versions. */ diff --git a/iidm/iidm-xml-converter/src/test/java/com/powsybl/iidm/xml/SwitchTest.java b/iidm/iidm-xml-converter/src/test/java/com/powsybl/iidm/xml/SwitchTest.java new file mode 100644 index 00000000000..763d2acb37b --- /dev/null +++ b/iidm/iidm-xml-converter/src/test/java/com/powsybl/iidm/xml/SwitchTest.java @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2022, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package com.powsybl.iidm.xml; + +import com.powsybl.iidm.network.Network; +import org.junit.Test; + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +/** + * @author Luma Zamarreño + * @author José Antonio Marqués + */ +public class SwitchTest extends AbstractXmlConverterTest { + + @Test + public void readAndDiscardSwitchWithSameNodeAtBothEnds() { + //Network n = NetworkXml.read(getVersionedNetworkAsStream("switchWithSameNodeAtBothEnds.xml", CURRENT_IIDM_XML_VERSION)); + Network n = NetworkXml.read(getNetworkAsStream("/switches/switchWithSameNodeAtBothEnds.xiidm")); + + // Check that the "looped-switch" has been discarded + assertEquals(2, n.getSwitchCount()); + assertNull(n.getSwitch("looped-switch")); + } + + @Test + public void readAndDiscardSwitchWithSameBusAtBothEnds() { + Network n = NetworkXml.read(getNetworkAsStream("/switches/switchWithSameBusAtBothEnds.xiidm")); + + // Check that the "looped-switch" has been discarded + assertEquals(0, n.getSwitchCount()); + assertNull(n.getSwitch("looped-switch")); + } +} diff --git a/iidm/iidm-xml-converter/src/test/resources/switches/switchWithSameBusAtBothEnds.xiidm b/iidm/iidm-xml-converter/src/test/resources/switches/switchWithSameBusAtBothEnds.xiidm new file mode 100644 index 00000000000..920a558622d --- /dev/null +++ b/iidm/iidm-xml-converter/src/test/resources/switches/switchWithSameBusAtBothEnds.xiidm @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/iidm/iidm-xml-converter/src/test/resources/switches/switchWithSameNodeAtBothEnds.xiidm b/iidm/iidm-xml-converter/src/test/resources/switches/switchWithSameNodeAtBothEnds.xiidm new file mode 100644 index 00000000000..f2ac4e5976a --- /dev/null +++ b/iidm/iidm-xml-converter/src/test/resources/switches/switchWithSameNodeAtBothEnds.xiidm @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 9a7c41ea79999a4d2c759e8ac36bb43e6e85ff2a Mon Sep 17 00:00:00 2001 From: VEDELAGO MIORA Date: Thu, 10 Mar 2022 10:48:22 +0100 Subject: [PATCH 5/6] Add condition to prevent NPE during reading + add valid condition to discard switches with same ends during writing (for example for calculated views) Signed-off-by: VEDELAGO MIORA --- .../powsybl/iidm/xml/AbstractIdentifiableXml.java | 11 ++++++++++- .../powsybl/iidm/xml/BusBreakerViewSwitchXml.java | 12 +++++++++++- .../powsybl/iidm/xml/NodeBreakerViewSwitchXml.java | 12 +++++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/AbstractIdentifiableXml.java b/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/AbstractIdentifiableXml.java index a91455f5568..6a0a5c4a9c5 100644 --- a/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/AbstractIdentifiableXml.java +++ b/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/AbstractIdentifiableXml.java @@ -30,12 +30,19 @@ protected boolean hasSubElements(T identifiable, NetworkXmlWriterContext context return hasSubElements(identifiable); } + protected boolean isValid(T identifiable, P parent) { + return true; + } + protected abstract void writeRootElementAttributes(T identifiable, P parent, NetworkXmlWriterContext context) throws XMLStreamException; protected void writeSubElements(T identifiable, P parent, NetworkXmlWriterContext context) throws XMLStreamException { } public final void write(T identifiable, P parent, NetworkXmlWriterContext context) throws XMLStreamException { + if (!isValid(identifiable, parent)) { + return; + } boolean isNotEmptyElement = hasSubElements(identifiable, context) || identifiable.hasProperty() || identifiable.hasAliases(); if (isNotEmptyElement) { context.getWriter().writeStartElement(context.getVersion().getNamespaceURI(context.isValid()), getRootElementName()); @@ -94,7 +101,9 @@ protected void readSubElements(T identifiable, NetworkXmlReaderContext context) protected void readElement(String id, A adder, NetworkXmlReaderContext context) throws XMLStreamException { T identifiable = readRootElementAttributes(adder, context); - readSubElements(identifiable, context); + if (identifiable != null) { + readSubElements(identifiable, context); + } } public final void read(P parent, NetworkXmlReaderContext context) throws XMLStreamException { diff --git a/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/BusBreakerViewSwitchXml.java b/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/BusBreakerViewSwitchXml.java index 37cedb8a13a..e56fa5b6562 100644 --- a/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/BusBreakerViewSwitchXml.java +++ b/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/BusBreakerViewSwitchXml.java @@ -24,6 +24,16 @@ public class BusBreakerViewSwitchXml extends AbstractSwitchXml Date: Thu, 10 Mar 2022 10:52:08 +0100 Subject: [PATCH 6/6] Change info to warn Signed-off-by: VEDELAGO MIORA --- .../main/java/com/powsybl/iidm/xml/BusBreakerViewSwitchXml.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/BusBreakerViewSwitchXml.java b/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/BusBreakerViewSwitchXml.java index e56fa5b6562..e99308ed932 100644 --- a/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/BusBreakerViewSwitchXml.java +++ b/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/BusBreakerViewSwitchXml.java @@ -60,7 +60,7 @@ protected Switch readRootElementAttributes(VoltageLevel.BusBreakerView.SwitchAdd String bus2 = context.getAnonymizer().deanonymizeString(context.getReader().getAttributeValue(null, "bus2")); // Discard switches with same bus at both ends if (bus1.equals(bus2)) { - LOGGER.info("Discard switch with same bus at both ends. Id: {}", context.getReader().getAttributeValue(null, "id")); + LOGGER.warn("Discard switch with same bus at both ends. Id: {}", context.getReader().getAttributeValue(null, "id")); return null; } else { return adder.setOpen(open)