From c081ba27da1512184aacf3e2c08f871e51dceb6e Mon Sep 17 00:00:00 2001 From: Luma Date: Fri, 13 Dec 2024 19:42:40 +0100 Subject: [PATCH] remove legacy extension, adapt unit tests Signed-off-by: Luma --- .../conversion/export/EquipmentExport.java | 40 ++--- ...gmesConformity1ModifiedConversionTest.java | 3 +- .../test/export/EquipmentExportTest.java | 34 ++-- .../cgmes/extensions/CgmesControlArea.java | 48 ------ .../extensions/CgmesControlAreaAdder.java | 30 ---- .../extensions/CgmesControlAreaAdderImpl.java | 67 -------- .../extensions/CgmesControlAreaImpl.java | 94 ----------- .../cgmes/extensions/CgmesControlAreas.java | 41 ----- .../extensions/CgmesControlAreasAdder.java | 22 --- .../CgmesControlAreasAdderImpl.java | 27 ---- .../CgmesControlAreasAdderImplProvider.java | 40 ----- .../extensions/CgmesControlAreasImpl.java | 54 ------- .../extensions/CgmesControlAreasSerDe.java | 147 ------------------ .../extensions/CgmesControlAreaTest.java | 66 -------- .../CgmesControlAreasSerDeTest.java | 55 ------- 15 files changed, 25 insertions(+), 743 deletions(-) delete mode 100644 cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlArea.java delete mode 100644 cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreaAdder.java delete mode 100644 cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreaAdderImpl.java delete mode 100644 cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreaImpl.java delete mode 100644 cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreas.java delete mode 100644 cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreasAdder.java delete mode 100644 cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreasAdderImpl.java delete mode 100644 cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreasAdderImplProvider.java delete mode 100644 cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreasImpl.java delete mode 100644 cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreasSerDe.java delete mode 100644 cgmes/cgmes-extensions/src/test/java/com/powsybl/cgmes/extensions/CgmesControlAreaTest.java delete mode 100644 cgmes/cgmes-extensions/src/test/java/com/powsybl/cgmes/extensions/CgmesControlAreasSerDeTest.java diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/EquipmentExport.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/EquipmentExport.java index c6076243b1e..952738b301a 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/EquipmentExport.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/EquipmentExport.java @@ -1385,29 +1385,29 @@ private static void writeAcdcConverterDCTerminal(String id, String conductingEqu private static void writeControlAreas(String energyAreaId, Network network, String cimNamespace, String euNamespace, XMLStreamWriter writer, CgmesExportContext context) throws XMLStreamException { for (Area area : network.getAreas()) { if (area.getAreaType().equals("ControlAreaTypeKind.Interchange")) { - writeControlArea(area, energyAreaId, cimNamespace, euNamespace, writer, context, network); + writeControlArea(area, energyAreaId, cimNamespace, euNamespace, writer, context); } } } private static void writeControlArea(Area controlArea, String energyAreaId, String cimNamespace, String euNamespace, - XMLStreamWriter writer, CgmesExportContext context, Network network) throws XMLStreamException { + XMLStreamWriter writer, CgmesExportContext context) throws XMLStreamException { // Original control area identifiers may not respect mRID rules, so we pass it through naming strategy // to obtain always valid mRID identifiers String controlAreaCgmesId = context.getNamingStrategy().getCgmesId(controlArea.getId()); String energyIdentCodeEic = controlArea.getAliasFromType(CgmesNames.ENERGY_IDENT_CODE_EIC).orElse(""); ControlAreaEq.write(controlAreaCgmesId, controlArea.getNameOrId(), energyIdentCodeEic, energyAreaId, cimNamespace, euNamespace, writer, context); for (AreaBoundary areaBoundary : controlArea.getAreaBoundaries()) { - TieFlow.from(areaBoundary, context, network).ifPresent(tieFlow -> + TieFlow.from(areaBoundary, context).ifPresent(tieFlow -> TieFlowEq.write(tieFlow.id(), controlAreaCgmesId, tieFlow.terminalId(), cimNamespace, writer, context) ); } } private record TieFlow(String id, String terminalId) { - static Optional from(AreaBoundary areaBoundary, CgmesExportContext context, Network network) { + static Optional from(AreaBoundary areaBoundary, CgmesExportContext context) { return areaBoundary.getTerminal().map(terminal -> from(terminal, context)) - .orElse(areaBoundary.getBoundary().flatMap(boundary -> from(boundary, context, network))); + .orElse(areaBoundary.getBoundary().flatMap(boundary -> from(boundary, context))); } static Optional from(Terminal terminal, CgmesExportContext context) { @@ -1416,8 +1416,8 @@ static Optional from(Terminal terminal, CgmesExportContext context) { CgmesExportUtil.getTerminalId(terminal, context))); } - static Optional from(Boundary boundary, CgmesExportContext context, Network network) { - String terminalId = getTieFlowBoundaryTerminal(boundary, context, network); + static Optional from(Boundary boundary, CgmesExportContext context) { + String terminalId = getTieFlowBoundaryTerminal(boundary, context); if (terminalId != null) { return Optional.of(new TieFlow( context.getNamingStrategy().getCgmesId(ref(terminalId), TIE_FLOW), @@ -1428,34 +1428,14 @@ static Optional from(Boundary boundary, CgmesExportContext context, Net } } - private static String getTieFlowBoundaryTerminal(Boundary boundary, CgmesExportContext context, Network network) { + private static String getTieFlowBoundaryTerminal(Boundary boundary, CgmesExportContext context) { DanglingLine dl = boundary.getDanglingLine(); - if (network.isBoundaryElement(dl)) { - return context.getNamingStrategy().getCgmesIdFromAlias(dl, Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + TERMINAL_BOUNDARY); - } else { - // This means the boundary corresponds to a TieLine. - // Because the network should not be a merging view, - // the only way to have a TieLine in the model is that - // the original data for the network contained both halves of the TieLine. - // That is, the initial CGMES data contains the two ACLSs at each side of one boundary point. - - // Currently, we are exporting TieLines in the EQ as a single ACLS, - // We are not exporting the individual halves of the tie line as separate equipment. - // So we do not have terminals for the boundary points. - - // This error should be fixed exporting the two halves of the TieLine to the EQ, - // with their corresponding terminals. - // Also, the boundary node should not be exported but referenced, - // as it should be defined in the boundary, not in the instance EQ file. - - LOG.error("Unsupported tie flow at TieLine boundary {}", dl.getId()); - return null; - } + return context.getNamingStrategy().getCgmesIdFromAlias(dl, Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + TERMINAL_BOUNDARY); } private static void writeTerminals(Network network, Map mapTerminal2Id, Map mapNodeKey2NodeId, String cimNamespace, XMLStreamWriter writer, CgmesExportContext context) throws XMLStreamException { - for (Connectable c : network.getConnectables()) { // TODO write boundary terminals for tie lines from CGMES + for (Connectable c : network.getConnectables()) { if (context.isExportedEquipment(c)) { for (Terminal t : c.getTerminals()) { writeTerminal(t, mapTerminal2Id, mapNodeKey2NodeId, cimNamespace, writer, context); diff --git a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/conformity/modified/CgmesConformity1ModifiedConversionTest.java b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/conformity/modified/CgmesConformity1ModifiedConversionTest.java index 4a2e0ee2eb3..7848b322cf0 100644 --- a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/conformity/modified/CgmesConformity1ModifiedConversionTest.java +++ b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/conformity/modified/CgmesConformity1ModifiedConversionTest.java @@ -15,7 +15,6 @@ import com.powsybl.cgmes.conversion.CgmesModelExtension; import com.powsybl.cgmes.conversion.Conversion; import com.powsybl.cgmes.conversion.test.ConversionUtil; -import com.powsybl.cgmes.extensions.CgmesControlAreas; import com.powsybl.cgmes.extensions.CgmesMetadataModels; import com.powsybl.cgmes.model.*; import com.powsybl.commons.PowsyblException; @@ -862,7 +861,7 @@ void miniNodeBreakerMissingSubstationRegion() { @Test void smallBusBranchTieFlowWithoutControlArea() { Network network = new CgmesImport().importData(CgmesConformity1ModifiedCatalog.smallBusBranchTieFlowsWithoutControlArea().dataSource(), NetworkFactory.findDefault(), importParams); - assertNull(network.getExtension(CgmesControlAreas.class)); + assertEquals(0, network.getAreaCount()); } @Test diff --git a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/EquipmentExportTest.java b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/EquipmentExportTest.java index 5c0aa6e11c8..68bba576810 100644 --- a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/EquipmentExportTest.java +++ b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/EquipmentExportTest.java @@ -160,29 +160,22 @@ void microGridBaseCaseAssembledSwitchAtBoundary() throws XMLStreamException, IOE ReadOnlyDataSource dataSource = CgmesConformity1ModifiedCatalog.microGridBaseCaseAssembledSwitchAtBoundary().dataSource(); Network network = new CgmesImport().importData(dataSource, NetworkFactory.findDefault(), importParams); - network.newExtension(CgmesControlAreasAdder.class).add(); - CgmesControlAreas cgmesControlAreas = network.getExtension(CgmesControlAreas.class); - CgmesControlArea cgmesControlArea = cgmesControlAreas.newCgmesControlArea() + // Define a tie flow at the boundary of a dangling line + TieLine tieLine = network.getTieLine("78736387-5f60-4832-b3fe-d50daf81b0a6 + 7f43f508-2496-4b64-9146-0a40406cbe49"); + Area area = network.newArea() .setId("controlAreaId") .setName("controlAreaName") - .setEnergyIdentificationCodeEic("energyIdentCodeEic") - .setNetInterchange(Double.NaN) + .setAreaType("ControlAreaTypeKind.Interchange") + .setInterchangeTarget(Double.NaN) + .addAreaBoundary(tieLine.getDanglingLine2().getBoundary(), true) .add(); - TieLine tieLine = network.getTieLine("78736387-5f60-4832-b3fe-d50daf81b0a6 + 7f43f508-2496-4b64-9146-0a40406cbe49"); - cgmesControlArea.add(tieLine.getDanglingLine2().getBoundary()); + area.addAlias("energyIdentCodeEic", CgmesNames.ENERGY_IDENT_CODE_EIC); - // TODO(Luma) updated expected result after halves of tie lines are exported as equipment - // instead of an error logged and the tie flow ignored, - // the reimported network control area should contain one tie flow - Network actual = exportImportNodeBreaker(network, dataSource); + // The reimported network control area should contain one tie flow + Network actual = exportImportBusBranch(network, dataSource); Area actualControlArea = actual.getArea("controlAreaId"); - boolean tieFlowsAtTieLinesAreSupported = false; - if (tieFlowsAtTieLinesAreSupported) { - assertEquals(1, actualControlArea.getAreaBoundaryStream().count()); - assertEquals("7f43f508-2496-4b64-9146-0a40406cbe49", actualControlArea.getAreaBoundaries().iterator().next().getBoundary().get().getDanglingLine().getId()); - } else { - assertNull(actualControlArea); - } + assertEquals(1, actualControlArea.getAreaBoundaryStream().count()); + assertEquals("7f43f508-2496-4b64-9146-0a40406cbe49", actualControlArea.getAreaBoundaries().iterator().next().getBoundary().get().getDanglingLine().getId()); } @Test @@ -593,7 +586,7 @@ void microGridCgmesExportPreservingOriginalClassesOfLoads() throws IOException, // Remove the default control area created in expected network during export expected.getAreaStream().map(Area::getId).toList().forEach(a -> expected.getArea(a).remove()); - // Avoid comparing targetP and targetQ (reimport does not consider the SSH file); + // Avoid comparing targetP and targetQ, as reimport does not consider the SSH file expected.getGenerators().forEach(expectedGenerator -> { Generator actualGenerator = actual.getGenerator(expectedGenerator.getId()); actualGenerator.setTargetP(expectedGenerator.getTargetP()); @@ -671,7 +664,7 @@ void miniGridCgmesExportPreservingOriginalClassesOfGenerators() throws IOExcepti assertEquals(generatorsCreatedFromOriginalClassCount(expected, "ExternalNetworkInjection"), generatorsCreatedFromOriginalClassCount(actual, "ExternalNetworkInjection")); assertEquals(generatorsCreatedFromOriginalClassCount(expected, "EquivalentInjection"), generatorsCreatedFromOriginalClassCount(actual, "EquivalentInjection")); - // Avoid comparing targetP and targetQ (reimport does not consider the SSH file); + // Avoid comparing targetP and targetQ, as reimport does not consider the SSH file expected.getGenerators().forEach(expectedGenerator -> { Generator actualGenerator = actual.getGenerator(expectedGenerator.getId()); actualGenerator.setTargetP(expectedGenerator.getTargetP()); @@ -1664,6 +1657,7 @@ private Path exportToCgmesEQ(Network network) throws IOException, XMLStreamExcep private Path exportToCgmesEQ(Network network, boolean transformersWithHighestVoltageAtEnd1) throws IOException, XMLStreamException { // Export CGMES EQ file + tmpDir = Path.of("/Users/zamarrenolm/Downloads"); Path exportedEq = tmpDir.resolve("exportedEq.xml"); try (OutputStream os = new BufferedOutputStream(Files.newOutputStream(exportedEq))) { XMLStreamWriter writer = XmlUtil.initializeWriter(true, " ", os); diff --git a/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlArea.java b/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlArea.java deleted file mode 100644 index c0bf843e29c..00000000000 --- a/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlArea.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright (c) 2021, 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.cgmes.extensions; - -import com.powsybl.commons.PowsyblException; -import com.powsybl.iidm.network.Boundary; -import com.powsybl.iidm.network.Terminal; - -import java.util.Set; - -/** - * @author Miora Ralambotiana {@literal } - */ -public interface CgmesControlArea { - - String getId(); - - String getName(); - - String getEnergyIdentificationCodeEIC(); - - double getNetInterchange(); - - void add(Terminal terminal); - - void add(Boundary boundary); - - Set getTerminals(); - - Set getBoundaries(); - - default void setNetInterchange(double netInterchange) { - throw new PowsyblException("Unsupported method"); - } - - default double getPTolerance() { - throw new PowsyblException("Unsupported method"); - } - - default void setPTolerance(double pTolerance) { - throw new PowsyblException("Unsupported method"); - } -} diff --git a/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreaAdder.java b/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreaAdder.java deleted file mode 100644 index 224cbd2b023..00000000000 --- a/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreaAdder.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (c) 2021, 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.cgmes.extensions; - -import com.powsybl.commons.PowsyblException; - -/** - * @author Miora Ralambotiana {@literal } - */ -public interface CgmesControlAreaAdder { - - CgmesControlAreaAdder setId(String id); - - CgmesControlAreaAdder setName(String name); - - CgmesControlAreaAdder setEnergyIdentificationCodeEic(String energyIdentificationCodeEic); - - CgmesControlAreaAdder setNetInterchange(double netInterchange); - - default CgmesControlAreaAdder setPTolerance(double pTolerance) { - throw new PowsyblException("Unsupported method"); - } - - CgmesControlArea add(); -} diff --git a/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreaAdderImpl.java b/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreaAdderImpl.java deleted file mode 100644 index 6156b8b97e9..00000000000 --- a/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreaAdderImpl.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Copyright (c) 2021, 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.cgmes.extensions; - -import com.powsybl.commons.PowsyblException; - -import java.util.Objects; - -/** - * @author Miora Ralambotiana {@literal } - */ -class CgmesControlAreaAdderImpl implements CgmesControlAreaAdder { - - private final CgmesControlAreasImpl mapping; - private String id; - private String name; - private String energyIdentificationCodeEic; - private double netInterchange = Double.NaN; - private double pTolerance = Double.NaN; - - CgmesControlAreaAdderImpl(CgmesControlAreasImpl mapping) { - this.mapping = Objects.requireNonNull(mapping); - } - - @Override - public CgmesControlAreaAdder setId(String id) { - this.id = id; - return this; - } - - @Override - public CgmesControlAreaAdder setName(String name) { - this.name = name; - return this; - } - - @Override - public CgmesControlAreaAdder setEnergyIdentificationCodeEic(String energyIdentificationCodeEic) { - this.energyIdentificationCodeEic = energyIdentificationCodeEic; - return this; - } - - @Override - public CgmesControlAreaAdder setNetInterchange(double netInterchange) { - this.netInterchange = netInterchange; - return this; - } - - @Override - public CgmesControlAreaAdder setPTolerance(double pTolerance) { - this.pTolerance = pTolerance; - return this; - } - - @Override - public CgmesControlAreaImpl add() { - if (id == null) { - throw new PowsyblException("Undefined ID for CGMES control area"); - } - return new CgmesControlAreaImpl(id, name, energyIdentificationCodeEic, netInterchange, pTolerance, mapping); - } -} diff --git a/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreaImpl.java b/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreaImpl.java deleted file mode 100644 index 427bae1c5a9..00000000000 --- a/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreaImpl.java +++ /dev/null @@ -1,94 +0,0 @@ -/** - * Copyright (c) 2021, 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.cgmes.extensions; - -import com.powsybl.iidm.network.Boundary; -import com.powsybl.iidm.network.Terminal; - -import java.util.*; - -/** - * @author Marcos de Miguel {@literal } - */ -class CgmesControlAreaImpl implements CgmesControlArea { - private final String id; - private final String name; - private final String energyIdentificationCodeEic; - private final Set terminals = new LinkedHashSet<>(); - private final Set boundaries = new LinkedHashSet<>(); - private double netInterchange; - private double pTolerance; - - CgmesControlAreaImpl(String id, String name, String energyIdentificationCodeEic, double netInterchange, double pTolerance, CgmesControlAreasImpl mapping) { - this.id = Objects.requireNonNull(id); - this.name = name; - this.energyIdentificationCodeEic = energyIdentificationCodeEic; - this.netInterchange = netInterchange; - this.pTolerance = pTolerance; - attach(mapping); - } - - private void attach(CgmesControlAreasImpl mapping) { - mapping.putCgmesControlArea(this); - } - - @Override - public String getId() { - return id; - } - - @Override - public String getName() { - return name; - } - - @Override - public String getEnergyIdentificationCodeEIC() { - return energyIdentificationCodeEic; - } - - @Override - public Set getTerminals() { - return Collections.unmodifiableSet(terminals); - } - - @Override - public Set getBoundaries() { - return Collections.unmodifiableSet(boundaries); - } - - @Override - public double getNetInterchange() { - return netInterchange; - } - - @Override - public void add(Terminal terminal) { - terminals.add(terminal); - } - - @Override - public void add(Boundary boundary) { - boundaries.add(boundary); - } - - @Override - public void setNetInterchange(double netInterchange) { - this.netInterchange = netInterchange; - } - - @Override - public double getPTolerance() { - return pTolerance; - } - - @Override - public void setPTolerance(double pTolerance) { - this.pTolerance = pTolerance; - } -} diff --git a/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreas.java b/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreas.java deleted file mode 100644 index b3095e31bfc..00000000000 --- a/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreas.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright (c) 2021, 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.cgmes.extensions; - -import java.util.Collection; - -import com.powsybl.commons.extensions.Extension; -import com.powsybl.iidm.network.Network; - -/** - * @author Marcos de Miguel {@literal } - */ -public interface CgmesControlAreas extends Extension { - - String NAME = "cgmesControlAreas"; - - CgmesControlAreaAdder newCgmesControlArea(); - - Collection getCgmesControlAreas(); - - CgmesControlArea getCgmesControlArea(String controlAreaId); - - boolean containsCgmesControlAreaId(String controlAreaId); - - default void cleanIfEmpty() { - if (getCgmesControlAreas().isEmpty()) { - getExtendable().removeExtension(CgmesControlAreas.class); - } - } - - @Override - default String getName() { - return NAME; - } - -} diff --git a/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreasAdder.java b/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreasAdder.java deleted file mode 100644 index 151f69b8c14..00000000000 --- a/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreasAdder.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Copyright (c) 2021, 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.cgmes.extensions; - -import com.powsybl.commons.extensions.ExtensionAdder; -import com.powsybl.iidm.network.Network; - -/** - * @author Marcos de Miguel {@literal } - */ -public interface CgmesControlAreasAdder extends ExtensionAdder { - - @Override - default Class getExtensionClass() { - return CgmesControlAreas.class; - } -} diff --git a/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreasAdderImpl.java b/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreasAdderImpl.java deleted file mode 100644 index efdfdb67704..00000000000 --- a/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreasAdderImpl.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) 2021, 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.cgmes.extensions; - -import com.powsybl.commons.extensions.AbstractExtensionAdder; -import com.powsybl.iidm.network.Network; - -/** - * @author Marcos de Miguel {@literal } - */ -class CgmesControlAreasAdderImpl extends AbstractExtensionAdder implements CgmesControlAreasAdder { - - CgmesControlAreasAdderImpl(Network extendable) { - super(extendable); - } - - @Override - protected CgmesControlAreas createExtension(Network extendable) { - return new CgmesControlAreasImpl(extendable); - } - -} diff --git a/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreasAdderImplProvider.java b/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreasAdderImplProvider.java deleted file mode 100644 index e5ef577432e..00000000000 --- a/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreasAdderImplProvider.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (c) 2021, 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.cgmes.extensions; - -import com.google.auto.service.AutoService; -import com.powsybl.commons.extensions.ExtensionAdderProvider; -import com.powsybl.iidm.network.Network; - -/** - * @author Marcos de Miguel {@literal } - */ -@AutoService(ExtensionAdderProvider.class) -public class CgmesControlAreasAdderImplProvider implements ExtensionAdderProvider { - - @Override - public String getImplementationName() { - return "Default"; - } - - @Override - public String getExtensionName() { - return CgmesControlAreas.NAME; - } - - @Override - public Class getAdderClass() { - return CgmesControlAreasAdderImpl.class; - } - - @Override - public CgmesControlAreasAdderImpl newAdder(Network extendable) { - return new CgmesControlAreasAdderImpl(extendable); - } - -} diff --git a/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreasImpl.java b/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreasImpl.java deleted file mode 100644 index 0074ec25ab8..00000000000 --- a/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreasImpl.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright (c) 2021, 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.cgmes.extensions; - -import java.util.*; - -import com.powsybl.commons.PowsyblException; -import com.powsybl.commons.extensions.AbstractExtension; -import com.powsybl.iidm.network.Network; - -/** - * @author Marcos de Miguel {@literal } - */ -class CgmesControlAreasImpl extends AbstractExtension implements CgmesControlAreas { - - private final Map cgmesControlAreas = new HashMap<>(); - - CgmesControlAreasImpl(Network network) { - super(network); - } - - @Override - public CgmesControlAreaAdder newCgmesControlArea() { - return new CgmesControlAreaAdderImpl(this); - } - - @Override - public Collection getCgmesControlAreas() { - return Collections.unmodifiableCollection(cgmesControlAreas.values()); - } - - @Override - public CgmesControlArea getCgmesControlArea(String controlAreaId) { - return cgmesControlAreas.get(controlAreaId); - } - - @Override - public boolean containsCgmesControlAreaId(String controlAreaId) { - return cgmesControlAreas.containsKey(controlAreaId); - } - - void putCgmesControlArea(CgmesControlAreaImpl cgmesControlArea) { - Objects.requireNonNull(cgmesControlArea); - if (cgmesControlAreas.containsKey(cgmesControlArea.getId())) { - throw new PowsyblException(String.format("CGMES control area %s has already been added", cgmesControlArea.getId())); - } - cgmesControlAreas.put(cgmesControlArea.getId(), cgmesControlArea); - } -} diff --git a/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreasSerDe.java b/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreasSerDe.java deleted file mode 100644 index d88fd421fc9..00000000000 --- a/cgmes/cgmes-extensions/src/main/java/com/powsybl/cgmes/extensions/CgmesControlAreasSerDe.java +++ /dev/null @@ -1,147 +0,0 @@ -/** - * Copyright (c) 2021, 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.cgmes.extensions; - -import com.google.auto.service.AutoService; -import com.powsybl.commons.PowsyblException; -import com.powsybl.commons.extensions.AbstractExtensionSerDe; -import com.powsybl.commons.extensions.ExtensionSerDe; -import com.powsybl.commons.io.TreeDataReader; -import com.powsybl.commons.io.TreeDataWriter; -import com.powsybl.commons.io.DeserializerContext; -import com.powsybl.commons.io.SerializerContext; -import com.powsybl.iidm.network.*; -import com.powsybl.iidm.serde.NetworkDeserializerContext; -import com.powsybl.iidm.serde.NetworkSerializerContext; -import com.powsybl.iidm.serde.TerminalRefSerDe; - -import java.util.Map; - -/** - * @author Marcos de Miguel {@literal } - */ -@AutoService(ExtensionSerDe.class) -public class CgmesControlAreasSerDe extends AbstractExtensionSerDe { - - private static final String CONTROL_AREA_ROOT_ELEMENT = "controlArea"; - private static final String CONTROL_AREA_ARRAY_ELEMENT = "controlAreas"; - public static final String TERMINAL_ROOT_ELEMENT = "terminal"; - public static final String TERMINAL_ARRAY_ELEMENT = "terminals"; - public static final String BOUNDARY_ROOT_ELEMENT = "boundary"; - public static final String BOUNDARY_ARRAY_ELEMENT = "boundaries"; - - public CgmesControlAreasSerDe() { - super("cgmesControlAreas", "network", CgmesControlAreas.class, "cgmesControlAreas.xsd", - "http://www.powsybl.org/schema/iidm/ext/cgmes_control_areas/1_0", "cca"); - } - - @Override - public Map getArrayNameToSingleNameMap() { - return Map.of(CONTROL_AREA_ARRAY_ELEMENT, CONTROL_AREA_ROOT_ELEMENT, - TERMINAL_ARRAY_ELEMENT, TERMINAL_ROOT_ELEMENT, - BOUNDARY_ARRAY_ELEMENT, BOUNDARY_ROOT_ELEMENT); - } - - @Override - public boolean isSerializable(CgmesControlAreas extension) { - return !extension.getCgmesControlAreas().isEmpty(); - } - - @Override - public void write(CgmesControlAreas extension, SerializerContext context) { - NetworkSerializerContext networkContext = (NetworkSerializerContext) context; - TreeDataWriter writer = networkContext.getWriter(); - writer.writeStartNodes(); - for (CgmesControlArea controlArea : extension.getCgmesControlAreas()) { - writer.writeStartNode(getNamespaceUri(), CONTROL_AREA_ROOT_ELEMENT); - writer.writeStringAttribute("id", controlArea.getId()); - writer.writeStringAttribute("name", controlArea.getName()); - writer.writeStringAttribute("energyIdentificationCodeEic", controlArea.getEnergyIdentificationCodeEIC()); - writer.writeDoubleAttribute("netInterchange", controlArea.getNetInterchange()); - writer.writeDoubleAttribute("pTolerance", controlArea.getPTolerance()); - - writer.writeStartNodes(); - for (Terminal terminal : controlArea.getTerminals()) { - TerminalRefSerDe.writeTerminalRef(terminal, networkContext, getNamespaceUri(), TERMINAL_ROOT_ELEMENT); - } - writer.writeEndNodes(); - - writer.writeStartNodes(); - for (Boundary boundary : controlArea.getBoundaries()) { - if (boundary.getDanglingLine() != null) { // TODO: delete this later, only for compatibility - writer.writeStartNode(getNamespaceUri(), BOUNDARY_ROOT_ELEMENT); - writer.writeStringAttribute("id", networkContext.getAnonymizer().anonymizeString(boundary.getDanglingLine().getId())); - - // TODO use TieLine Id and DanglingLine Id for reference instead of TieLine Id and Side - writer.writeEnumAttribute("side", getSide(boundary)); - writer.writeEndNode(); - } - } - writer.writeEndNodes(); - - writer.writeEndNode(); - } - writer.writeEndNodes(); - } - - private static TwoSides getSide(Boundary boundary) { - // a TieLine with two dangingLines inside - return boundary.getDanglingLine().getTieLine().map(tl -> { - if (tl.getDanglingLine1() == boundary.getDanglingLine()) { - return TwoSides.ONE; - } - return TwoSides.TWO; - }).orElse(null); - } - - @Override - public CgmesControlAreas read(Network extendable, DeserializerContext context) { - NetworkDeserializerContext networkContext = (NetworkDeserializerContext) context; - TreeDataReader reader = networkContext.getReader(); - extendable.newExtension(CgmesControlAreasAdder.class).add(); - CgmesControlAreas mapping = extendable.getExtension(CgmesControlAreas.class); - reader.readChildNodes(elementName -> { - if (elementName.equals(CONTROL_AREA_ROOT_ELEMENT)) { - CgmesControlArea cgmesControlArea = mapping.newCgmesControlArea() - .setId(reader.readStringAttribute("id")) - .setName(reader.readStringAttribute("name")) - .setEnergyIdentificationCodeEic(reader.readStringAttribute("energyIdentificationCodeEic")) - .setNetInterchange(reader.readDoubleAttribute("netInterchange")) - .setPTolerance(reader.readDoubleAttribute("pTolerance")) - .add(); - readBoundariesAndTerminals(networkContext, cgmesControlArea, extendable); - } else { - throw new PowsyblException("Unknown element name '" + elementName + "' in 'cgmesControlArea'"); - } - }); - return extendable.getExtension(CgmesControlAreas.class); - } - - private void readBoundariesAndTerminals(NetworkDeserializerContext networkContext, CgmesControlArea cgmesControlArea, Network network) { - TreeDataReader reader = networkContext.getReader(); - reader.readChildNodes(elementName -> { - switch (elementName) { - case BOUNDARY_ROOT_ELEMENT -> { - String id = networkContext.getAnonymizer().deanonymizeString(reader.readStringAttribute("id")); - TwoSides side = reader.readEnumAttribute("side", TwoSides.class); - Identifiable identifiable = network.getIdentifiable(id); - if (identifiable instanceof DanglingLine dl) { - cgmesControlArea.add(dl.getBoundary()); - } else if (identifiable instanceof TieLine tl) { - cgmesControlArea.add(tl.getDanglingLine(side).getBoundary()); - } else { - throw new PowsyblException("Unexpected Identifiable instance: " + identifiable.getClass()); - } - reader.readEndNode(); - } - case TERMINAL_ROOT_ELEMENT -> cgmesControlArea.add(TerminalRefSerDe.readTerminal(networkContext, network)); - default -> throw new PowsyblException("Unknown element name '" + elementName + "' in 'controlArea'"); - } - }); - } -} diff --git a/cgmes/cgmes-extensions/src/test/java/com/powsybl/cgmes/extensions/CgmesControlAreaTest.java b/cgmes/cgmes-extensions/src/test/java/com/powsybl/cgmes/extensions/CgmesControlAreaTest.java deleted file mode 100644 index 81ac08d7ed2..00000000000 --- a/cgmes/cgmes-extensions/src/test/java/com/powsybl/cgmes/extensions/CgmesControlAreaTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Copyright (c) 2021, 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.cgmes.extensions; - -import com.powsybl.commons.PowsyblException; -import com.powsybl.iidm.network.Network; -import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.assertEquals; - -/** - * @author Marcos de Miguel {@literal } - */ -class CgmesControlAreaTest { - - @Test - void test() { - Network network = EurostagTutorialExample1Factory.create(); - network.newExtension(CgmesControlAreasAdder.class).add(); - CgmesControlAreas extension = network.getExtension(CgmesControlAreas.class); - extension.newCgmesControlArea() - .setId("cgmesControlAreaId") - .setName("cgmesControlAreaName") - .setEnergyIdentificationCodeEic("energyIdentCodeEic") - .setNetInterchange(100.0) - .add() - .add(network.getLine("NHV1_NHV2_1").getTerminal1()); - - assertNotNull(extension); - assertTrue(extension.containsCgmesControlAreaId("cgmesControlAreaId")); - CgmesControlArea controlArea = extension.getCgmesControlArea("cgmesControlAreaId"); - assertNotNull(controlArea); - assertEquals("cgmesControlAreaId", controlArea.getId()); - assertEquals("cgmesControlAreaName", controlArea.getName()); - assertEquals("energyIdentCodeEic", controlArea.getEnergyIdentificationCodeEIC()); - assertEquals(100.0, controlArea.getNetInterchange(), 0.0); - assertEquals(1, controlArea.getTerminals().size()); - controlArea.getTerminals().forEach(t -> assertSame(network.getLine("NHV1_NHV2_1").getTerminal1(), t)); - } - - @Test - void invalid() { - Network network = EurostagTutorialExample1Factory.create(); - network.newExtension(CgmesControlAreasAdder.class).add(); - - try { - network.getExtension(CgmesControlAreas.class) - .newCgmesControlArea() - .setName("cgmesControlAreaName") - .setEnergyIdentificationCodeEic("energyIdentCodeEic") - .setNetInterchange(100.0) - .add() - .add(network.getLine("NHV1_NHV2_1").getTerminal1()); - fail(); - } catch (PowsyblException e) { - assertEquals("Undefined ID for CGMES control area", e.getMessage()); - } - } -} diff --git a/cgmes/cgmes-extensions/src/test/java/com/powsybl/cgmes/extensions/CgmesControlAreasSerDeTest.java b/cgmes/cgmes-extensions/src/test/java/com/powsybl/cgmes/extensions/CgmesControlAreasSerDeTest.java deleted file mode 100644 index fac05f9a391..00000000000 --- a/cgmes/cgmes-extensions/src/test/java/com/powsybl/cgmes/extensions/CgmesControlAreasSerDeTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright (c) 2021, 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.cgmes.extensions; - -import com.powsybl.iidm.network.Network; -import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; -import org.junit.jupiter.api.Test; - -import java.io.IOException; -import java.time.ZonedDateTime; - -/** - * @author Marcos de Miguel {@literal } - */ -class CgmesControlAreasSerDeTest extends AbstractCgmesExtensionTest { - - @Test - void test() throws IOException { - Network network = EurostagTutorialExample1Factory.create(); - network.setCaseDate(ZonedDateTime.parse("2021-02-02T09:27:39.856+01:00")); - network.getVoltageLevel("VLGEN") - .getBusBreakerView() - .newBus() - .setId("NDL") - .add(); - network.getVoltageLevel("VLGEN") - .newDanglingLine() - .setP0(0.0) - .setQ0(0.0) - .setR(1.0) - .setX(1.0) - .setB(0.0) - .setG(0.0) - .setId("DL") - .setConnectableBus("NDL") - .setBus("NDL") - .add(); - network.newExtension(CgmesControlAreasAdder.class).add(); - network.getExtension(CgmesControlAreas.class).newCgmesControlArea() - .setId("cgmesControlAreaId") - .setName("cgmesControlAreaName") - .setEnergyIdentificationCodeEic("energyIdentCodeEic") - .setNetInterchange(100.0) - .add() - .add(network.getLine("NHV1_NHV2_1").getTerminal1()); - network.getExtension(CgmesControlAreas.class).getCgmesControlArea("cgmesControlAreaId").add(network.getDanglingLine("DL").getBoundary()); - - allFormatsRoundTripTest(network, "/eurostag_cgmes_control_area.xml"); - } -}