From 90119a60c9cdb798ad3987e70d05cc9bbdc16835 Mon Sep 17 00:00:00 2001 From: Olivier Perrin Date: Tue, 12 Nov 2024 16:00:23 +0100 Subject: [PATCH 1/4] Add OverloadManagementExtension extension SerDe test Signed-off-by: Olivier Perrin --- .../OverloadManagementSystemMockExt.java | 26 +++++++++++++ .../OverloadManagementSystemMockSerDe.java | 38 +++++++++++++++++++ .../OverloadManagementSystemSerDeTest.java | 4 +- .../overloadManagementSystemRoundTripRef.xml | 5 ++- .../xsd/overloadManagementSystemMock.xsd | 18 +++++++++ 5 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockExt.java create mode 100644 iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockSerDe.java create mode 100644 iidm/iidm-serde/src/test/resources/xsd/overloadManagementSystemMock.xsd diff --git a/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockExt.java b/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockExt.java new file mode 100644 index 00000000000..c46a109ec24 --- /dev/null +++ b/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockExt.java @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2024, 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/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.iidm.serde; + +import com.powsybl.commons.extensions.AbstractExtension; +import com.powsybl.iidm.network.OverloadManagementSystem; + +/** + * @author Olivier Perrin {@literal } + */ +public class OverloadManagementSystemMockExt extends AbstractExtension { + + public OverloadManagementSystemMockExt(OverloadManagementSystem overloadManagementSystem) { + super(overloadManagementSystem); + } + + @Override + public String getName() { + return "overloadManagementSystemMock"; + } +} diff --git a/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockSerDe.java b/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockSerDe.java new file mode 100644 index 00000000000..ee8d4a2f6bb --- /dev/null +++ b/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockSerDe.java @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2024, 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/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.iidm.serde; + +import com.google.auto.service.AutoService; +import com.powsybl.commons.extensions.AbstractExtensionSerDe; +import com.powsybl.commons.extensions.ExtensionSerDe; +import com.powsybl.commons.io.DeserializerContext; +import com.powsybl.commons.io.SerializerContext; +import com.powsybl.iidm.network.OverloadManagementSystem; + +/** + * @author Olivier Perrin {@literal } + */ +@AutoService(ExtensionSerDe.class) +public class OverloadManagementSystemMockSerDe extends AbstractExtensionSerDe { + + public OverloadManagementSystemMockSerDe() { + super("overloadManagementSystemMock", "network", OverloadManagementSystemMockExt.class, "overloadManagementSystemMock.xsd", + "http://www.powsybl.org/schema/iidm/ext/overloadmanagementsystem_mock/1_0", "omsmock"); + } + + @Override + public void write(OverloadManagementSystemMockExt omsFoo, SerializerContext context) { + // Nothing inside + } + + @Override + public OverloadManagementSystemMockExt read(OverloadManagementSystem overloadManagementSystem, DeserializerContext context) { + context.getReader().readEndNode(); + return new OverloadManagementSystemMockExt(overloadManagementSystem); + } +} diff --git a/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemSerDeTest.java b/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemSerDeTest.java index eef92de0751..cb88a92b3a4 100644 --- a/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemSerDeTest.java +++ b/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemSerDeTest.java @@ -187,7 +187,7 @@ private static Network createNetwork() { createThreeWindingsTransformer(s1, s1v400, s1v225, s1v90); // Create an overload management system with trippings on "2WT", "3WT" and "S1_400_LINE_2_BREAKER" - s1.newOverloadManagementSystem() + OverloadManagementSystem oms1 = s1.newOverloadManagementSystem() .setId("OMS1") .setName("1st OMS") .setEnabled(true) @@ -224,6 +224,8 @@ private static Network createNetwork() { .add() .add(); + oms1.addExtension(OverloadManagementSystemMockExt.class, new OverloadManagementSystemMockExt(oms1)); + // Create an overload management system monitoring "LINE_1" with a tripping on "LINE_2". // Note that this test is very important since the OMS uses identifiers of elements which are not // defined in the same substation, and furthermore which will be serialized AFTER the OMS (lines are serialized diff --git a/iidm/iidm-serde/src/test/resources/V1_13/overloadManagementSystemRoundTripRef.xml b/iidm/iidm-serde/src/test/resources/V1_13/overloadManagementSystemRoundTripRef.xml index f347392486a..a06ccdbcb68 100644 --- a/iidm/iidm-serde/src/test/resources/V1_13/overloadManagementSystemRoundTripRef.xml +++ b/iidm/iidm-serde/src/test/resources/V1_13/overloadManagementSystemRoundTripRef.xml @@ -1,5 +1,5 @@ - + @@ -55,4 +55,7 @@ + + + diff --git a/iidm/iidm-serde/src/test/resources/xsd/overloadManagementSystemMock.xsd b/iidm/iidm-serde/src/test/resources/xsd/overloadManagementSystemMock.xsd new file mode 100644 index 00000000000..6dd9cacf5ce --- /dev/null +++ b/iidm/iidm-serde/src/test/resources/xsd/overloadManagementSystemMock.xsd @@ -0,0 +1,18 @@ + + + + + + + From b8810ff659f71cd64268fa154e786fc52e6db1b5 Mon Sep 17 00:00:00 2001 From: Olivier Perrin Date: Wed, 13 Nov 2024 10:29:32 +0100 Subject: [PATCH 2/4] Improve unit test Signed-off-by: Olivier Perrin --- .../iidm/serde/OverloadManagementSystemMockExt.java | 8 +++++++- .../iidm/serde/OverloadManagementSystemMockSerDe.java | 11 +++++++---- .../iidm/serde/OverloadManagementSystemSerDeTest.java | 2 +- .../V1_13/overloadManagementSystemRoundTripRef.xml | 2 +- .../resources/xsd/overloadManagementSystemMock.xsd | 4 +++- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockExt.java b/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockExt.java index c46a109ec24..f605ca00960 100644 --- a/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockExt.java +++ b/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockExt.java @@ -14,9 +14,15 @@ * @author Olivier Perrin {@literal } */ public class OverloadManagementSystemMockExt extends AbstractExtension { + private final String foo; - public OverloadManagementSystemMockExt(OverloadManagementSystem overloadManagementSystem) { + public OverloadManagementSystemMockExt(OverloadManagementSystem overloadManagementSystem, String foo) { super(overloadManagementSystem); + this.foo = foo; + } + + public String getFoo() { + return foo; } @Override diff --git a/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockSerDe.java b/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockSerDe.java index ee8d4a2f6bb..9b71c263a54 100644 --- a/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockSerDe.java +++ b/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockSerDe.java @@ -21,18 +21,21 @@ public class OverloadManagementSystemMockSerDe extends AbstractExtensionSerDe { public OverloadManagementSystemMockSerDe() { - super("overloadManagementSystemMock", "network", OverloadManagementSystemMockExt.class, "overloadManagementSystemMock.xsd", + super("overloadManagementSystemMock", "network", OverloadManagementSystemMockExt.class, + "overloadManagementSystemMock.xsd", "http://www.powsybl.org/schema/iidm/ext/overloadmanagementsystem_mock/1_0", "omsmock"); } @Override public void write(OverloadManagementSystemMockExt omsFoo, SerializerContext context) { - // Nothing inside + context.getWriter().writeStringAttribute("foo", omsFoo.getFoo()); } @Override - public OverloadManagementSystemMockExt read(OverloadManagementSystem overloadManagementSystem, DeserializerContext context) { + public OverloadManagementSystemMockExt read(OverloadManagementSystem extendable, DeserializerContext context) { + String foo = context.getReader().readStringAttribute("foo"); context.getReader().readEndNode(); - return new OverloadManagementSystemMockExt(overloadManagementSystem); + return new OverloadManagementSystemMockExt(extendable, foo); } + } diff --git a/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemSerDeTest.java b/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemSerDeTest.java index cb88a92b3a4..63d02d4dbd4 100644 --- a/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemSerDeTest.java +++ b/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemSerDeTest.java @@ -224,7 +224,7 @@ private static Network createNetwork() { .add() .add(); - oms1.addExtension(OverloadManagementSystemMockExt.class, new OverloadManagementSystemMockExt(oms1)); + oms1.addExtension(OverloadManagementSystemMockExt.class, new OverloadManagementSystemMockExt(oms1, "bar")); // Create an overload management system monitoring "LINE_1" with a tripping on "LINE_2". // Note that this test is very important since the OMS uses identifiers of elements which are not diff --git a/iidm/iidm-serde/src/test/resources/V1_13/overloadManagementSystemRoundTripRef.xml b/iidm/iidm-serde/src/test/resources/V1_13/overloadManagementSystemRoundTripRef.xml index a06ccdbcb68..b49c0b9fe83 100644 --- a/iidm/iidm-serde/src/test/resources/V1_13/overloadManagementSystemRoundTripRef.xml +++ b/iidm/iidm-serde/src/test/resources/V1_13/overloadManagementSystemRoundTripRef.xml @@ -56,6 +56,6 @@ - + diff --git a/iidm/iidm-serde/src/test/resources/xsd/overloadManagementSystemMock.xsd b/iidm/iidm-serde/src/test/resources/xsd/overloadManagementSystemMock.xsd index 6dd9cacf5ce..a1a5ffbc854 100644 --- a/iidm/iidm-serde/src/test/resources/xsd/overloadManagementSystemMock.xsd +++ b/iidm/iidm-serde/src/test/resources/xsd/overloadManagementSystemMock.xsd @@ -13,6 +13,8 @@ targetNamespace="http://www.powsybl.org/schema/iidm/ext/overloadmanagementsystem_mock/1_0" elementFormDefault="qualified"> - + + + From bef8c58b3e5371f44d4e8681ef63ce34e474a894 Mon Sep 17 00:00:00 2001 From: Olivier Perrin Date: Wed, 13 Nov 2024 10:23:30 +0100 Subject: [PATCH 3/4] Introduce postponable creation extension SerDe Signed-off-by: Olivier Perrin --- .../PostponableCreationExtensionSerDe.java | 26 +++++++++ .../com/powsybl/iidm/serde/NetworkSerDe.java | 56 +++++++++++++------ .../OverloadManagementSystemMockSerDe.java | 18 ++++-- 3 files changed, 79 insertions(+), 21 deletions(-) create mode 100644 commons/src/main/java/com/powsybl/commons/extensions/PostponableCreationExtensionSerDe.java diff --git a/commons/src/main/java/com/powsybl/commons/extensions/PostponableCreationExtensionSerDe.java b/commons/src/main/java/com/powsybl/commons/extensions/PostponableCreationExtensionSerDe.java new file mode 100644 index 00000000000..1fb12feb67a --- /dev/null +++ b/commons/src/main/java/com/powsybl/commons/extensions/PostponableCreationExtensionSerDe.java @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2024, 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/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.commons.extensions; + +import com.powsybl.commons.io.DeserializerContext; + +import java.util.function.Function; + +/** + * @author Olivier Perrin {@literal } + */ +public interface PostponableCreationExtensionSerDe, E extends Extension> + extends ExtensionSerDe { + + @Override + default E read(T extendable, DeserializerContext context) { + return extensionCreator(context).apply(extendable); + } + + Function extensionCreator(DeserializerContext context); +} diff --git a/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/NetworkSerDe.java b/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/NetworkSerDe.java index 763b0caf03d..e93d722be90 100644 --- a/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/NetworkSerDe.java +++ b/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/NetworkSerDe.java @@ -17,9 +17,7 @@ import com.powsybl.commons.datasource.ReadOnlyDataSource; import com.powsybl.commons.exceptions.UncheckedSaxException; import com.powsybl.commons.exceptions.UncheckedXmlStreamException; -import com.powsybl.commons.extensions.Extension; -import com.powsybl.commons.extensions.ExtensionProviders; -import com.powsybl.commons.extensions.ExtensionSerDe; +import com.powsybl.commons.extensions.*; import com.powsybl.commons.io.TreeDataFormat; import com.powsybl.commons.io.TreeDataHeader; import com.powsybl.commons.io.TreeDataReader; @@ -54,6 +52,7 @@ import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.ForkJoinPool; +import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.zip.GZIPInputStream; @@ -640,7 +639,7 @@ private static void readNetworkElement(String elementName, Deque networ case TieLineSerDe.ROOT_ELEMENT_NAME -> TieLineSerDe.INSTANCE.read(networks.peek(), context); case HvdcLineSerDe.ROOT_ELEMENT_NAME -> HvdcLineSerDe.INSTANCE.read(networks.peek(), context); case VoltageAngleLimitSerDe.ROOT_ELEMENT_NAME -> VoltageAngleLimitSerDe.read(networks.peek(), context); - case EXTENSION_ROOT_ELEMENT_NAME -> findExtendableAndReadExtension(networks.getFirst(), context, extensionNamesImported, extensionNamesNotFound); + case EXTENSION_ROOT_ELEMENT_NAME -> readExtensionTag(networks.getFirst(), context, extensionNamesImported, extensionNamesNotFound); default -> throw new PowsyblException("Unknown element name '" + elementName + "' in 'network'"); } } @@ -679,13 +678,9 @@ private static void checkSupportedAndReadVoltageLevel(NetworkDeserializerContext VoltageLevelSerDe.INSTANCE.read(networks.peek(), context); } - private static void findExtendableAndReadExtension(Network network, NetworkDeserializerContext context, Set extensionNamesImported, Set extensionNamesNotFound) { - String id2 = context.getAnonymizer().deanonymizeString(context.getReader().readStringAttribute("id")); - Identifiable identifiable = network.getIdentifiable(id2); - if (identifiable == null) { - throw new PowsyblException("Identifiable " + id2 + " not found"); - } - readExtensions(identifiable, context, extensionNamesImported, extensionNamesNotFound); + private static void readExtensionTag(Network network, NetworkDeserializerContext context, Set extensionNamesImported, Set extensionNamesNotFound) { + String id = context.getAnonymizer().deanonymizeString(context.getReader().readStringAttribute("id")); + readExtensions(network, id, context, extensionNamesImported, extensionNamesNotFound); } private static Network initNetwork(NetworkFactory networkFactory, NetworkDeserializerContext context, TreeDataReader reader, Network rootNetwork) { @@ -811,19 +806,22 @@ public static Network validateAndRead(Path xmlFile) { return validateAndRead(xmlFile, new ImportOptions()); } - private static void readExtensions(Identifiable identifiable, NetworkDeserializerContext context, + private static void readExtensions(Network network, String id, NetworkDeserializerContext context, Set extensionNamesImported, Set extensionNamesNotFound) { - context.getReader().readChildNodes(extensionName -> { // extensions root elements are nested directly in 'extension' element, so there is no need // to check for an extension to exist if depth is greater than zero. Furthermore, in case of // missing extension serializer, we must not check for an extension in sub elements. if (context.getOptions().withExtension(extensionName)) { - ExtensionSerDe extensionXmlSerializer = EXTENSIONS_SUPPLIER.get().findProvider(extensionName); + ExtensionSerDe extensionXmlSerializer = EXTENSIONS_SUPPLIER.get().findProvider(extensionName); if (extensionXmlSerializer != null) { - Extension> extension = extensionXmlSerializer.read(identifiable, context); - identifiable.addExtension(extensionXmlSerializer.getExtensionClass(), extension); - extensionNamesImported.add(extensionName); + if (extensionXmlSerializer instanceof PostponableCreationExtensionSerDe, ? extends Extension > postponableCreationExtensionSerDe) { + Function, ?> extensionCreator = (Function, ?>) postponableCreationExtensionSerDe.extensionCreator(context); + context.getEndTasks().add(() -> createExtension(network, id, extensionCreator, extensionNamesImported, extensionName)); + } else { + Identifiable identifiable = getIdentifiable(network, id); + createExtension(identifiable, context, extensionNamesImported, extensionName, extensionXmlSerializer); + } } else { extensionNamesNotFound.add(extensionName); context.getReader().skipChildNodes(); @@ -834,6 +832,30 @@ private static void readExtensions(Identifiable identifiable, NetworkDeserialize }); } + private static Identifiable getIdentifiable(Network network, String id) { + Identifiable identifiable = network.getIdentifiable(id); + if (identifiable == null) { + throw new PowsyblException("Identifiable " + id + " not found"); + } + return identifiable; + } + + private static void createExtension(Network network, String id, + Function, ?> extensionCreator, + Set extensionNamesImported, String extensionName) { + Identifiable identifiable = getIdentifiable(network, id); + extensionCreator.apply(identifiable); + extensionNamesImported.add(extensionName); + } + + private static void createExtension(Identifiable identifiable, NetworkDeserializerContext context, + Set extensionNamesImported, String extensionName, + ExtensionSerDe extensionXmlSerializer) { + Extension> extension = extensionXmlSerializer.read(identifiable, context); + identifiable.addExtension(extensionXmlSerializer.getExtensionClass(), extension); + extensionNamesImported.add(extensionName); + } + public static byte[] gzip(Network network) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try (GZIPOutputStream gzos = new GZIPOutputStream(bos)) { diff --git a/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockSerDe.java b/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockSerDe.java index 9b71c263a54..facd8d24292 100644 --- a/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockSerDe.java +++ b/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockSerDe.java @@ -10,15 +10,19 @@ import com.google.auto.service.AutoService; import com.powsybl.commons.extensions.AbstractExtensionSerDe; import com.powsybl.commons.extensions.ExtensionSerDe; +import com.powsybl.commons.extensions.PostponableCreationExtensionSerDe; import com.powsybl.commons.io.DeserializerContext; import com.powsybl.commons.io.SerializerContext; import com.powsybl.iidm.network.OverloadManagementSystem; +import java.util.function.Function; + /** * @author Olivier Perrin {@literal } */ @AutoService(ExtensionSerDe.class) -public class OverloadManagementSystemMockSerDe extends AbstractExtensionSerDe { +public class OverloadManagementSystemMockSerDe extends AbstractExtensionSerDe + implements PostponableCreationExtensionSerDe { public OverloadManagementSystemMockSerDe() { super("overloadManagementSystemMock", "network", OverloadManagementSystemMockExt.class, @@ -32,10 +36,16 @@ public void write(OverloadManagementSystemMockExt omsFoo, SerializerContext cont } @Override - public OverloadManagementSystemMockExt read(OverloadManagementSystem extendable, DeserializerContext context) { + public Function extensionCreator(DeserializerContext context) { + // Read the elements String foo = context.getReader().readStringAttribute("foo"); context.getReader().readEndNode(); - return new OverloadManagementSystemMockExt(extendable, foo); - } + // Return the function creating the adder + return oms -> { + OverloadManagementSystemMockExt extension = new OverloadManagementSystemMockExt(oms, foo); + oms.addExtension(getExtensionClass(), extension); + return extension; + }; + } } From 42af5cdd4b4bbe685ad0a73239c5a9198fb017c5 Mon Sep 17 00:00:00 2001 From: Olivier Perrin Date: Wed, 13 Nov 2024 16:19:24 +0100 Subject: [PATCH 4/4] Support withAutomationSystems import/export options + fix unit tests Signed-off-by: Olivier Perrin --- .../powsybl/iidm/serde/NetworkDeserializerContext.java | 10 ++++++++++ .../main/java/com/powsybl/iidm/serde/NetworkSerDe.java | 9 +++++++-- .../iidm/serde/OverloadManagementSystemSerDe.java | 1 + .../iidm/serde/OverloadManagementSystemMockExt.java | 2 +- .../iidm/serde/OverloadManagementSystemMockSerDe.java | 2 +- .../V1_13/overloadManagementSystemRoundTripRef.xml | 2 +- .../resources/xsd/overloadManagementSystemMock.xsd | 2 +- 7 files changed, 22 insertions(+), 6 deletions(-) diff --git a/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/NetworkDeserializerContext.java b/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/NetworkDeserializerContext.java index c415acf8bba..f8639ba2872 100644 --- a/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/NetworkDeserializerContext.java +++ b/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/NetworkDeserializerContext.java @@ -34,6 +34,8 @@ public class NetworkDeserializerContext extends AbstractNetworkSerDeContext ignoredEquipments = new HashSet<>(); + public NetworkDeserializerContext(Anonymizer anonymizer, TreeDataReader reader) { this(anonymizer, reader, new ImportOptions(), CURRENT_IIDM_VERSION, Collections.emptyMap()); } @@ -80,4 +82,12 @@ public NetworkDeserializerContext setNetworkValidationLevel(ValidationLevel vali public ValidationLevel getNetworkValidationLevel() { return this.networkValidationLevel; } + + public void addIgnoredEquipment(String equipment) { + ignoredEquipments.add(equipment); + } + + public boolean isIgnoredEquipment(String equipment) { + return ignoredEquipments.contains(equipment); + } } diff --git a/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/NetworkSerDe.java b/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/NetworkSerDe.java index e93d722be90..eb1185cd73a 100644 --- a/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/NetworkSerDe.java +++ b/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/NetworkSerDe.java @@ -198,7 +198,7 @@ private static void writeVoltageAngleLimits(Network n, NetworkSerializerContext private static void writeExtensions(Network n, NetworkSerializerContext context) { context.getWriter().writeStartNodes(); for (Identifiable identifiable : IidmSerDeUtil.sorted(n.getIdentifiables(), context.getOptions())) { - if (!context.isExportedEquipment(identifiable) || !isElementWrittenInsideNetwork(identifiable, n, context)) { + if (ignoreEquipmentAtExport(identifiable, context) || !isElementWrittenInsideNetwork(identifiable, n, context)) { continue; } Collection>> extensions = identifiable.getExtensions().stream() @@ -217,6 +217,11 @@ private static void writeExtensions(Network n, NetworkSerializerContext context) context.getWriter().writeEndNodes(); } + private static boolean ignoreEquipmentAtExport(Identifiable identifiable, NetworkSerializerContext context) { + return !context.isExportedEquipment(identifiable) + || identifiable instanceof OverloadManagementSystem && !context.getOptions().isWithAutomationSystems(); + } + private static boolean canTheExtensionBeWritten(ExtensionSerDe extensionSerDe, IidmVersion version, ExportOptions options) { if (extensionSerDe == null) { return false; @@ -812,7 +817,7 @@ private static void readExtensions(Network network, String id, NetworkDeserializ // extensions root elements are nested directly in 'extension' element, so there is no need // to check for an extension to exist if depth is greater than zero. Furthermore, in case of // missing extension serializer, we must not check for an extension in sub elements. - if (context.getOptions().withExtension(extensionName)) { + if (context.getOptions().withExtension(extensionName) && !context.isIgnoredEquipment(id)) { ExtensionSerDe extensionXmlSerializer = EXTENSIONS_SUPPLIER.get().findProvider(extensionName); if (extensionXmlSerializer != null) { if (extensionXmlSerializer instanceof PostponableCreationExtensionSerDe, ? extends Extension > postponableCreationExtensionSerDe) { diff --git a/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/OverloadManagementSystemSerDe.java b/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/OverloadManagementSystemSerDe.java index 0b3310ac8ce..50d4c7a4ed1 100644 --- a/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/OverloadManagementSystemSerDe.java +++ b/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/OverloadManagementSystemSerDe.java @@ -193,5 +193,6 @@ public final void skip(Substation s, NetworkDeserializerContext context) { String id = readIdentifierAttributes(null, context); readRootElementAttributes(null, s, toApply, context); readSubElements(id, null, toApply, context); + context.addIgnoredEquipment(id); } } diff --git a/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockExt.java b/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockExt.java index f605ca00960..0cc6bc49098 100644 --- a/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockExt.java +++ b/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockExt.java @@ -27,6 +27,6 @@ public String getFoo() { @Override public String getName() { - return "overloadManagementSystemMock"; + return "omsMock"; } } diff --git a/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockSerDe.java b/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockSerDe.java index facd8d24292..f4db2556520 100644 --- a/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockSerDe.java +++ b/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/OverloadManagementSystemMockSerDe.java @@ -25,7 +25,7 @@ public class OverloadManagementSystemMockSerDe extends AbstractExtensionSerDe { public OverloadManagementSystemMockSerDe() { - super("overloadManagementSystemMock", "network", OverloadManagementSystemMockExt.class, + super("omsMock", "network", OverloadManagementSystemMockExt.class, "overloadManagementSystemMock.xsd", "http://www.powsybl.org/schema/iidm/ext/overloadmanagementsystem_mock/1_0", "omsmock"); } diff --git a/iidm/iidm-serde/src/test/resources/V1_13/overloadManagementSystemRoundTripRef.xml b/iidm/iidm-serde/src/test/resources/V1_13/overloadManagementSystemRoundTripRef.xml index b49c0b9fe83..624c0a338c2 100644 --- a/iidm/iidm-serde/src/test/resources/V1_13/overloadManagementSystemRoundTripRef.xml +++ b/iidm/iidm-serde/src/test/resources/V1_13/overloadManagementSystemRoundTripRef.xml @@ -56,6 +56,6 @@ - + diff --git a/iidm/iidm-serde/src/test/resources/xsd/overloadManagementSystemMock.xsd b/iidm/iidm-serde/src/test/resources/xsd/overloadManagementSystemMock.xsd index a1a5ffbc854..fde826b90c6 100644 --- a/iidm/iidm-serde/src/test/resources/xsd/overloadManagementSystemMock.xsd +++ b/iidm/iidm-serde/src/test/resources/xsd/overloadManagementSystemMock.xsd @@ -12,7 +12,7 @@ xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.powsybl.org/schema/iidm/ext/overloadmanagementsystem_mock/1_0" elementFormDefault="qualified"> - +