From b8476d79a6576d6185389848eee511e3d71871a2 Mon Sep 17 00:00:00 2001 From: Geoffroy Jamgotchian Date: Thu, 3 Nov 2022 15:54:11 +0100 Subject: [PATCH] Remove iidm-converter-api (merged with iidm-api) (#2350) Signed-off-by: Geoffroy Jamgotchian --- .../simulator/loadflow/CaseExporter.java | 7 +- .../simulator/tools/ActionSimulatorTool.java | 15 +- .../simulator/loadflow/CaseExporterTest.java | 4 +- .../tools/ActionSimulatorToolTest.java | 4 +- ampl-converter/pom.xml | 2 +- .../powsybl/ampl/converter/AmplExporter.java | 2 +- cgmes/cgmes-conversion/pom.xml | 5 - .../powsybl/cgmes/conversion/CgmesExport.java | 2 +- .../powsybl/cgmes/conversion/CgmesImport.java | 2 +- .../conversion/test/FunctionalLogsTest.java | 2 +- .../test/SourceForIidmIdentifiersTest.java | 2 +- .../cim14/Cim14SmallCasesConversionTest.java | 2 +- .../Cgmes3ModifiedConversionTest.java | 2 +- ...gmesConformity1ModifiedConversionTest.java | 2 +- .../test/export/CgmesExportTest.java | 24 +- .../test/export/CgmesMappingTest.java | 6 +- .../test/export/EquipmentExportTest.java | 6 +- .../export/ExportProfilesConsistencyTest.java | 7 +- .../test/export/ExportToCimVersionTest.java | 5 +- .../test/export/StateVariablesExportTest.java | 4 +- .../SteadyStateHypothesisExportTest.java | 5 +- .../export/TopologyExportCornerCasesTest.java | 3 +- .../test/export/TopologyExportTest.java | 7 +- cgmes/cgmes-shortcircuit/pom.xml | 5 + distribution-core/pom.xml | 6 - .../dynamic-simulation-tool/pom.xml | 2 +- .../tool/DynamicSimulationTool.java | 7 +- ieee-cdf/ieee-cdf-converter/pom.xml | 2 +- .../ieeecdf/converter/IeeeCdfImporter.java | 2 +- .../converter/IeeeCdfImporterTest.java | 2 +- iidm/iidm-api/pom.xml | 30 ++ .../com/powsybl/iidm/network}/Exporter.java | 5 +- .../iidm/network}/ExporterPluginInfo.java | 2 +- .../com/powsybl/iidm/network/Exporters.java | 45 ++ .../iidm/network}/ExportersLoader.java | 2 +- .../iidm/network}/ExportersLoaderList.java | 2 +- .../iidm/network}/ExportersServiceLoader.java | 2 +- .../powsybl/iidm/network}/ImportConfig.java | 2 +- .../iidm/network}/ImportPostProcessor.java | 3 +- .../ImportPostProcessorPluginInfo.java | 2 +- .../com/powsybl/iidm/network}/Importer.java | 4 +- .../iidm/network}/ImporterPluginInfo.java | 2 +- .../com/powsybl/iidm/network/Importers.java | 194 ++++++++ .../iidm/network}/ImportersLoader.java | 2 +- .../iidm/network}/ImportersLoaderList.java | 2 +- .../iidm/network}/ImportersServiceLoader.java | 2 +- .../com/powsybl/iidm/network/Network.java | 342 ++++++++++++++ .../iidm/network}/tools/ConversionTool.java | 29 +- .../network}/tools/ConversionToolUtils.java | 2 +- .../iidm/network}/AbstractConvertersTest.java | 2 +- .../powsybl/iidm/network}/ExportersTest.java | 28 +- .../network}/ImportPostProcessorMock.java | 3 +- .../powsybl/iidm/network}/ImportersTest.java | 45 +- .../iidm/network/NetworkFactoryMock.java | 37 ++ .../network}/PostProcessorReporterTest.java | 8 +- .../powsybl/iidm/network}/TestExporter.java | 3 +- .../network}/TestImportPostProcessor.java | 4 +- .../powsybl/iidm/network}/TestImporter.java | 7 +- .../network}/tools/ConversionToolTest.java | 11 +- .../iidm/network}/tools/ExporterMock.java | 4 +- .../tools/ExporterMockWithReporter.java | 4 +- .../iidm/network}/tools/ImporterMock.java | 4 +- .../resources/export-parameters.properties | 0 .../src/test/resources/exportReporterTest.txt | 0 .../src/test/resources/import-parameters.xml | 0 .../resources/postProcessorReporterTest.json | 0 iidm/iidm-converter-api/pom.xml | 123 ----- .../com/powsybl/iidm/export/Exporters.java | 121 ----- .../com/powsybl/iidm/import_/Importers.java | 447 ------------------ .../topology/CreateBranchFeederBaysTest.java | 12 +- .../topology/CreateCouplingDeviceTest.java | 11 +- .../topology/CreateFeederBayTest.java | 19 +- .../TopologyModificationUtilsTest.java | 14 +- iidm/iidm-scripting/pom.xml | 5 - ...etworkLoadSaveGroovyScriptExtension.groovy | 16 +- .../scripting/GroovyScriptPostProcessor.java | 2 +- .../scripting/JavaScriptPostProcessor.java | 2 +- ...workLoadSaveGroovyScriptExtensionTest.java | 6 +- iidm/iidm-xml-converter/pom.xml | 5 - .../com/powsybl/iidm/xml/XMLExporter.java | 2 +- .../com/powsybl/iidm/xml/XMLImporter.java | 2 +- .../powsybl/iidm/xml/SkipExtensionTest.java | 3 +- .../com/powsybl/iidm/xml/XMLExporterTest.java | 11 +- iidm/pom.xml | 1 - loadflow/loadflow-api/pom.xml | 5 - .../loadflow/tools/RunLoadFlowTool.java | 14 +- ...oadFlowResultsCompletionPostProcessor.java | 2 +- .../loadflow/validation/ValidationTool.java | 9 +- matpower/matpower-converter/pom.xml | 2 +- .../matpower/converter/MatpowerExporter.java | 2 +- .../matpower/converter/MatpowerImporter.java | 2 +- .../converter/MatpowerExporterTest.java | 3 +- .../converter/MatpowerImporterTest.java | 2 +- pom.xml | 5 - powerfactory/powerfactory-converter/pom.xml | 4 - .../converter/PowerFactoryImporter.java | 2 +- psse/psse-converter/pom.xml | 2 +- .../powsybl/psse/converter/PsseExporter.java | 2 +- .../powsybl/psse/converter/PsseImporter.java | 2 +- .../psse/converter/PsseImporterTest.java | 2 +- .../security-analysis-api/pom.xml | 5 - .../security/tools/SecurityAnalysisTool.java | 13 +- .../powsybl/security/NetworkImporterMock.java | 2 +- .../tools/SecurityAnalysisToolTest.java | 2 +- .../security-analysis-default/pom.xml | 5 - .../sensitivity/SensitivityAnalysisTool.java | 9 +- .../tools/ShortCircuitAnalysisTool.java | 3 +- ucte/ucte-converter/pom.xml | 2 +- .../powsybl/ucte/converter/UcteExporter.java | 2 +- .../powsybl/ucte/converter/UcteImporter.java | 2 +- .../converter/UcteImporterReporterTest.java | 4 +- 111 files changed, 882 insertions(+), 1009 deletions(-) rename iidm/{iidm-converter-api/src/main/java/com/powsybl/iidm/export => iidm-api/src/main/java/com/powsybl/iidm/network}/Exporter.java (95%) rename iidm/{iidm-converter-api/src/main/java/com/powsybl/iidm/export => iidm-api/src/main/java/com/powsybl/iidm/network}/ExporterPluginInfo.java (95%) create mode 100644 iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Exporters.java rename iidm/{iidm-converter-api/src/main/java/com/powsybl/iidm/export => iidm-api/src/main/java/com/powsybl/iidm/network}/ExportersLoader.java (92%) rename iidm/{iidm-converter-api/src/main/java/com/powsybl/iidm/export => iidm-api/src/main/java/com/powsybl/iidm/network}/ExportersLoaderList.java (96%) rename iidm/{iidm-converter-api/src/main/java/com/powsybl/iidm/export => iidm-api/src/main/java/com/powsybl/iidm/network}/ExportersServiceLoader.java (95%) rename iidm/{iidm-converter-api/src/main/java/com/powsybl/iidm/import_ => iidm-api/src/main/java/com/powsybl/iidm/network}/ImportConfig.java (98%) rename iidm/{iidm-converter-api/src/main/java/com/powsybl/iidm/import_ => iidm-api/src/main/java/com/powsybl/iidm/network}/ImportPostProcessor.java (92%) rename iidm/{iidm-converter-api/src/main/java/com/powsybl/iidm/import_ => iidm-api/src/main/java/com/powsybl/iidm/network}/ImportPostProcessorPluginInfo.java (96%) rename iidm/{iidm-converter-api/src/main/java/com/powsybl/iidm/import_ => iidm-api/src/main/java/com/powsybl/iidm/network}/Importer.java (99%) rename iidm/{iidm-converter-api/src/main/java/com/powsybl/iidm/import_ => iidm-api/src/main/java/com/powsybl/iidm/network}/ImporterPluginInfo.java (95%) create mode 100644 iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Importers.java rename iidm/{iidm-converter-api/src/main/java/com/powsybl/iidm/import_ => iidm-api/src/main/java/com/powsybl/iidm/network}/ImportersLoader.java (94%) rename iidm/{iidm-converter-api/src/main/java/com/powsybl/iidm/import_ => iidm-api/src/main/java/com/powsybl/iidm/network}/ImportersLoaderList.java (97%) rename iidm/{iidm-converter-api/src/main/java/com/powsybl/iidm/import_ => iidm-api/src/main/java/com/powsybl/iidm/network}/ImportersServiceLoader.java (96%) rename iidm/{iidm-converter-api/src/main/java/com/powsybl/iidm => iidm-api/src/main/java/com/powsybl/iidm/network}/tools/ConversionTool.java (77%) rename iidm/{iidm-converter-api/src/main/java/com/powsybl/iidm => iidm-api/src/main/java/com/powsybl/iidm/network}/tools/ConversionToolUtils.java (98%) rename iidm/{iidm-converter-api/src/test/java/com/powsybl/iidm => iidm-api/src/test/java/com/powsybl/iidm/network}/AbstractConvertersTest.java (97%) rename iidm/{iidm-converter-api/src/test/java/com/powsybl/iidm/export => iidm-api/src/test/java/com/powsybl/iidm/network}/ExportersTest.java (82%) rename iidm/{iidm-converter-api/src/test/java/com/powsybl/iidm/import_ => iidm-api/src/test/java/com/powsybl/iidm/network}/ImportPostProcessorMock.java (93%) rename iidm/{iidm-converter-api/src/test/java/com/powsybl/iidm/import_ => iidm-api/src/test/java/com/powsybl/iidm/network}/ImportersTest.java (80%) create mode 100644 iidm/iidm-api/src/test/java/com/powsybl/iidm/network/NetworkFactoryMock.java rename iidm/{iidm-converter-api/src/test/java/com/powsybl/iidm/import_ => iidm-api/src/test/java/com/powsybl/iidm/network}/PostProcessorReporterTest.java (87%) rename iidm/{iidm-converter-api/src/test/java/com/powsybl/iidm/export => iidm-api/src/test/java/com/powsybl/iidm/network}/TestExporter.java (93%) rename iidm/{iidm-converter-api/src/test/java/com/powsybl/iidm/import_ => iidm-api/src/test/java/com/powsybl/iidm/network}/TestImportPostProcessor.java (85%) rename iidm/{iidm-converter-api/src/test/java/com/powsybl/iidm/import_ => iidm-api/src/test/java/com/powsybl/iidm/network}/TestImporter.java (84%) rename iidm/{iidm-converter-api/src/test/java/com/powsybl/iidm => iidm-api/src/test/java/com/powsybl/iidm/network}/tools/ConversionToolTest.java (90%) rename iidm/{iidm-converter-api/src/test/java/com/powsybl/iidm => iidm-api/src/test/java/com/powsybl/iidm/network}/tools/ExporterMock.java (93%) rename iidm/{iidm-converter-api/src/test/java/com/powsybl/iidm => iidm-api/src/test/java/com/powsybl/iidm/network}/tools/ExporterMockWithReporter.java (93%) rename iidm/{iidm-converter-api/src/test/java/com/powsybl/iidm => iidm-api/src/test/java/com/powsybl/iidm/network}/tools/ImporterMock.java (95%) rename iidm/{iidm-converter-api => iidm-api}/src/test/resources/export-parameters.properties (100%) rename iidm/{iidm-converter-api => iidm-api}/src/test/resources/exportReporterTest.txt (100%) rename iidm/{iidm-converter-api => iidm-api}/src/test/resources/import-parameters.xml (100%) rename iidm/{iidm-converter-api => iidm-api}/src/test/resources/postProcessorReporterTest.json (100%) delete mode 100644 iidm/iidm-converter-api/pom.xml delete mode 100644 iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/export/Exporters.java delete mode 100644 iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/Importers.java diff --git a/action/action-simulator/src/main/java/com/powsybl/action/simulator/loadflow/CaseExporter.java b/action/action-simulator/src/main/java/com/powsybl/action/simulator/loadflow/CaseExporter.java index ca0f929e64f..f1b71e88eb8 100644 --- a/action/action-simulator/src/main/java/com/powsybl/action/simulator/loadflow/CaseExporter.java +++ b/action/action-simulator/src/main/java/com/powsybl/action/simulator/loadflow/CaseExporter.java @@ -10,9 +10,8 @@ import com.powsybl.commons.datasource.DataSource; import com.powsybl.commons.datasource.DataSourceUtil; import com.powsybl.contingency.Contingency; -import com.powsybl.iidm.export.Exporters; -import com.powsybl.iidm.export.ExportersLoader; -import com.powsybl.iidm.export.ExportersServiceLoader; +import com.powsybl.iidm.network.ExportersLoader; +import com.powsybl.iidm.network.ExportersServiceLoader; import com.powsybl.security.LimitViolation; import java.nio.file.Path; @@ -68,7 +67,7 @@ public void loadFlowConverged(RunningContext runningContext, List ${project.groupId} - powsybl-iidm-converter-api + powsybl-iidm-api ${project.version} diff --git a/ampl-converter/src/main/java/com/powsybl/ampl/converter/AmplExporter.java b/ampl-converter/src/main/java/com/powsybl/ampl/converter/AmplExporter.java index 4ee1ae8329e..1cdb702d925 100644 --- a/ampl-converter/src/main/java/com/powsybl/ampl/converter/AmplExporter.java +++ b/ampl-converter/src/main/java/com/powsybl/ampl/converter/AmplExporter.java @@ -10,7 +10,7 @@ import com.google.auto.service.AutoService; import com.powsybl.commons.config.PlatformConfig; import com.powsybl.commons.datasource.DataSource; -import com.powsybl.iidm.export.Exporter; +import com.powsybl.iidm.network.Exporter; import com.powsybl.iidm.network.Network; import com.powsybl.commons.parameters.Parameter; import com.powsybl.commons.parameters.ParameterDefaultValueConfig; diff --git a/cgmes/cgmes-conversion/pom.xml b/cgmes/cgmes-conversion/pom.xml index 21b3c16d7e6..6155410eb6e 100644 --- a/cgmes/cgmes-conversion/pom.xml +++ b/cgmes/cgmes-conversion/pom.xml @@ -62,11 +62,6 @@ powsybl-iidm-api ${project.version} - - ${project.groupId} - powsybl-iidm-converter-api - ${project.version} - ${project.groupId} powsybl-iidm-xml-converter diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/CgmesExport.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/CgmesExport.java index f35732b5a9f..dec4610b445 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/CgmesExport.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/CgmesExport.java @@ -20,7 +20,7 @@ import com.powsybl.commons.reporter.Reporter; import com.powsybl.commons.reporter.TypedValue; import com.powsybl.commons.xml.XmlUtil; -import com.powsybl.iidm.export.Exporter; +import com.powsybl.iidm.network.Exporter; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.TopologyKind; import com.powsybl.iidm.network.VoltageLevel; diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/CgmesImport.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/CgmesImport.java index 4daa316d024..f1c2232be45 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/CgmesImport.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/CgmesImport.java @@ -22,7 +22,7 @@ import com.powsybl.commons.parameters.ParameterScope; import com.powsybl.commons.parameters.ParameterType; import com.powsybl.commons.util.ServiceLoaderCache; -import com.powsybl.iidm.import_.Importer; +import com.powsybl.iidm.network.Importer; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.NetworkFactory; import com.powsybl.triplestore.api.TripleStoreFactory; diff --git a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/FunctionalLogsTest.java b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/FunctionalLogsTest.java index 493d7227d3e..cdfdadcdeae 100644 --- a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/FunctionalLogsTest.java +++ b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/FunctionalLogsTest.java @@ -12,7 +12,7 @@ import com.powsybl.cgmes.model.test.TestGridModel; import com.powsybl.commons.reporter.ReporterModel; import com.powsybl.commons.reporter.TypedValue; -import com.powsybl.iidm.import_.Importers; +import com.powsybl.iidm.network.Importers; import org.junit.Test; import java.io.IOException; diff --git a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/SourceForIidmIdentifiersTest.java b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/SourceForIidmIdentifiersTest.java index c064bf896bc..f8ef51b813d 100644 --- a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/SourceForIidmIdentifiersTest.java +++ b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/SourceForIidmIdentifiersTest.java @@ -9,7 +9,7 @@ import com.powsybl.cgmes.conformity.CgmesConformity1Catalog; import com.powsybl.cgmes.conversion.CgmesImport; -import com.powsybl.iidm.import_.Importers; +import com.powsybl.iidm.network.Importers; import com.powsybl.iidm.network.Network; import com.powsybl.triplestore.api.TripleStore; import com.powsybl.triplestore.api.TripleStoreFactory; diff --git a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/cim14/Cim14SmallCasesConversionTest.java b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/cim14/Cim14SmallCasesConversionTest.java index 1b4a85614e1..3786e7b2243 100644 --- a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/cim14/Cim14SmallCasesConversionTest.java +++ b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/cim14/Cim14SmallCasesConversionTest.java @@ -12,7 +12,7 @@ import com.powsybl.cgmes.conversion.test.network.compare.ComparisonConfig; import com.powsybl.cgmes.model.CgmesModel; import com.powsybl.cgmes.model.test.cim14.Cim14SmallCasesCatalog; -import com.powsybl.iidm.import_.Importers; +import com.powsybl.iidm.network.Importers; import com.powsybl.iidm.network.Network; import com.powsybl.triplestore.api.TripleStoreFactory; import org.junit.BeforeClass; diff --git a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/conformity/modified/Cgmes3ModifiedConversionTest.java b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/conformity/modified/Cgmes3ModifiedConversionTest.java index 51ddda8d3c5..744e6d5c76a 100644 --- a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/conformity/modified/Cgmes3ModifiedConversionTest.java +++ b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/conformity/modified/Cgmes3ModifiedConversionTest.java @@ -11,7 +11,7 @@ import com.powsybl.cgmes.conformity.Cgmes3Catalog; import com.powsybl.cgmes.conformity.Cgmes3ModifiedCatalog; import com.powsybl.cgmes.conversion.CgmesModelExtension; -import com.powsybl.iidm.import_.Importers; +import com.powsybl.iidm.network.Importers; import com.powsybl.iidm.network.Network; import org.junit.After; import org.junit.Before; 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 4fd53dc4555..969b14a115f 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 @@ -23,7 +23,7 @@ import com.powsybl.commons.PowsyblException; import com.powsybl.commons.config.InMemoryPlatformConfig; import com.powsybl.commons.datasource.ReadOnlyDataSource; -import com.powsybl.iidm.import_.Importers; +import com.powsybl.iidm.network.Importers; import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.GeneratorEntsoeCategory; import com.powsybl.iidm.network.extensions.LoadDetail; diff --git a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/CgmesExportTest.java b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/CgmesExportTest.java index d854b441c79..ba2939f62ae 100644 --- a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/CgmesExportTest.java +++ b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/CgmesExportTest.java @@ -20,8 +20,6 @@ import com.powsybl.cgmes.model.test.cim14.Cim14SmallCasesCatalog; import com.powsybl.commons.datasource.GenericReadOnlyDataSource; import com.powsybl.commons.datasource.ReadOnlyDataSource; -import com.powsybl.iidm.export.Exporters; -import com.powsybl.iidm.import_.Importers; import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.test.FictitiousSwitchFactory; import com.powsybl.iidm.network.util.Networks; @@ -91,8 +89,8 @@ public void testFromIidm() throws IOException { try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) { Path tmpDir = Files.createDirectory(fs.getPath("/cgmes")); - Exporters.export("CGMES", network, null, tmpDir.resolve("tmp")); - Network n2 = Importers.loadNetwork(new GenericReadOnlyDataSource(tmpDir, "tmp")); + network.write("CGMES", null, tmpDir.resolve("tmp")); + Network n2 = Network.read(new GenericReadOnlyDataSource(tmpDir, "tmp")); VoltageLevel c = n2.getVoltageLevel("C"); assertNull(Networks.getEquivalentTerminal(c, c.getNodeBreakerView().getNode2("TEST_SW"))); assertNull(n2.getVscConverterStation("C2").getTerminal().getBusView().getBus()); @@ -108,7 +106,7 @@ public void testSynchronousMachinesWithSameGeneratingUnit() throws IOException { try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) { Path tmpDir = Files.createDirectory(fs.getPath(exportFolder)); // Export to CGMES and add boundary EQ for reimport - Exporters.export("CGMES", n, null, tmpDir.resolve(baseName)); + n.write("CGMES", null, tmpDir.resolve(baseName)); String eqbd = ds.listNames(".*EQ_BD.*").stream().findFirst().orElse(null); if (eqbd != null) { try (InputStream is = ds.newInputStream(eqbd)) { @@ -116,7 +114,7 @@ public void testSynchronousMachinesWithSameGeneratingUnit() throws IOException { } } - Network n2 = Importers.loadNetwork(new GenericReadOnlyDataSource(tmpDir, baseName), null); + Network n2 = Network.read(new GenericReadOnlyDataSource(tmpDir, baseName), null); Generator g1 = n2.getGenerator("3a3b27be-b18b-4385-b557-6735d733baf0"); Generator g2 = n2.getGenerator("550ebe0d-f2b2-48c1-991f-cebea43a21aa"); String gu1 = g1.getProperty(Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + "GeneratingUnit"); @@ -139,14 +137,14 @@ public void testPhaseTapChangerFixedTapNotExported() throws IOException, XMLStre // With original regulating mode the regulating control should be written in the EQ output String baseNameWithRc = baseName + "-with-rc"; - Exporters.export("CGMES", n, null, tmpDir.resolve(baseNameWithRc)); + n.write("CGMES", null, tmpDir.resolve(baseNameWithRc)); assertTrue(cgmesFileContainsRegulatingControl(regulatingControlId, tmpDir, baseNameWithRc, "EQ")); assertTrue(cgmesFileContainsRegulatingControl(regulatingControlId, tmpDir, baseNameWithRc, "SSH")); transformer.getPhaseTapChanger().setRegulating(false); transformer.getPhaseTapChanger().setRegulationMode(PhaseTapChanger.RegulationMode.FIXED_TAP); String baseNameNoRc = baseName + "-no-rc"; - Exporters.export("CGMES", n, null, tmpDir.resolve(baseNameNoRc)); + n.write("CGMES", null, tmpDir.resolve(baseNameNoRc)); assertFalse(cgmesFileContainsRegulatingControl(regulatingControlId, tmpDir, baseNameNoRc, "EQ")); assertFalse(cgmesFileContainsRegulatingControl(regulatingControlId, tmpDir, baseNameNoRc, "SSH")); } @@ -216,14 +214,14 @@ private static void testPhaseTapChangerType(ReadOnlyDataSource ds, String transf Properties paramsOnlySsh = new Properties(); paramsOnlySsh.put(CgmesExport.PROFILES, List.of("SSH")); paramsOnlySsh.put(CgmesExport.CIM_VERSION, "" + cimVersion); - Exporters.export("CGMES", network, paramsOnlySsh, tmpDir.resolve(baseName)); + network.write("CGMES", paramsOnlySsh, tmpDir.resolve(baseName)); String typeOnlySsh = CgmesExportUtil.cgmesTapChangerType(transformer, phaseTapChangerId).orElseThrow(RuntimeException::new); assertEquals(typeOriginal, typeOnlySsh); // If we export EQ and SSH (or all instance fiels), type of tap changer should be changed to tabular Properties paramsEqAndSsh = new Properties(); paramsEqAndSsh.put(CgmesExport.CIM_VERSION, "" + cimVersion); - Exporters.export("CGMES", network, paramsEqAndSsh, tmpDir.resolve(baseName)); + network.write("CGMES", paramsEqAndSsh, tmpDir.resolve(baseName)); String typeEqAndSsh = CgmesExportUtil.cgmesTapChangerType(transformer, phaseTapChangerId).orElseThrow(RuntimeException::new); assertEquals(CgmesNames.PHASE_TAP_CHANGER_TABULAR, typeEqAndSsh); } @@ -259,7 +257,7 @@ public void testDoNotExportFictitiousSwitchesCreatedForDisconnectedTerminals() t assertFalse(cgmes.terminal(disconnectedTerminalId).connected()); // Verify that the fictitious switch is created again when we re-import the exported CGMES data - Network networkReimported = Importers.loadNetwork(exportedCgmes, null); + Network networkReimported = Network.read(exportedCgmes, null); Switch fictitiousSwitchReimported = networkReimported.getSwitch(fictitiousSwitchId); assertNotNull(fictitiousSwitchReimported); assertTrue(fictitiousSwitchReimported.isFictitious()); @@ -275,14 +273,14 @@ public void testDoNotExportFictitiousSwitchesCreatedForDisconnectedTerminals() t assertTrue(cgmes1.isNodeBreaker()); assertFalse(cgmes1.switches().stream().anyMatch(sw -> sw.getId("Switch").equals(fictitiousSwitchId))); assertTrue(cgmes1.terminal(disconnectedTerminalId).connected()); - Network networkReimported1 = Importers.loadNetwork(exportedCgmes1, null); + Network networkReimported1 = Network.read(exportedCgmes1, null); Switch fictitiousSwitchReimported1 = networkReimported1.getSwitch(fictitiousSwitchId); assertNull(fictitiousSwitchReimported1); } } private static ReadOnlyDataSource exportAndAddBoundaries(Network network, Path tmpDir, String baseName, ReadOnlyDataSource originalDataSource) throws IOException { - Exporters.export("CGMES", network, null, tmpDir.resolve(baseName)); + network.write("CGMES", null, tmpDir.resolve(baseName)); String eqbd = originalDataSource.listNames(".*EQ_BD.*").stream().findFirst().orElse(null); if (eqbd != null) { try (InputStream is = originalDataSource.newInputStream(eqbd)) { diff --git a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/CgmesMappingTest.java b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/CgmesMappingTest.java index 7c4dc17b94e..0fa4231e650 100644 --- a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/CgmesMappingTest.java +++ b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/CgmesMappingTest.java @@ -13,8 +13,6 @@ import com.powsybl.cgmes.model.CgmesNames; import com.powsybl.commons.AbstractConverterTest; import com.powsybl.commons.datasource.*; -import com.powsybl.iidm.export.Exporters; -import com.powsybl.iidm.import_.Importers; import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.SlackTerminal; import com.powsybl.iidm.xml.NetworkXml; @@ -83,7 +81,7 @@ public void testExportUsingCgmesNamingStrategy(String namingStrategy, Network ne exportParams.put(CgmesExport.NAMING_STRATEGY, namingStrategy); String outputFolder = "exportedCgmes" + baseName; DataSource exportedCgmes = tmpDataSource(outputFolder, baseName); - Exporters.export("CGMES", network, exportParams, exportedCgmes); + network.write("CGMES", exportParams, exportedCgmes); if (originalDataSource != null) { copyBoundary(outputFolder, baseName, originalDataSource); } @@ -123,7 +121,7 @@ public void testExportUsingCgmesNamingStrategy(String namingStrategy, Network ne Properties reExportParams = exportParams; String reOutputFolder = "reExportedCgmes" + baseName; DataSource reExportedCgmes = tmpDataSource(reOutputFolder, baseName); - Exporters.export("CGMES", networkActual, reExportParams, reExportedCgmes); + networkActual.write("CGMES", reExportParams, reExportedCgmes); if (originalDataSource != null) { copyBoundary(reOutputFolder, baseName, originalDataSource); } 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 c63f5491803..24ff77d9ab4 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 @@ -23,8 +23,6 @@ import com.powsybl.commons.datasource.ResourceSet; import com.powsybl.commons.xml.XmlUtil; import com.powsybl.computation.local.LocalComputationManager; -import com.powsybl.iidm.import_.ImportConfig; -import com.powsybl.iidm.import_.Importers; import com.powsybl.iidm.network.*; import com.powsybl.iidm.xml.ExportOptions; import com.powsybl.iidm.xml.NetworkXml; @@ -452,7 +450,7 @@ private Network exportImport(Network expected, ReadOnlyDataSource dataSource, bo // There is no need to create the IIDM-CGMES mappings // We are reading only an EQ, we won't have TP data in the input // And to compare the expected and actual networks we are dropping all IIDM-CGMES mapping context information - return Importers.loadNetwork(repackaged, LocalComputationManager.getDefault(), ImportConfig.load(), null); + return Network.read(repackaged, LocalComputationManager.getDefault(), ImportConfig.load(), null); } private Path exportToCgmesEQ(Network network) throws IOException, XMLStreamException { @@ -496,7 +494,7 @@ private void compareNetworksEQdata(Network expected, Network actual) throws IOEx ExportXmlCompare::numericDifferenceEvaluator, ExportXmlCompare::ignoringNonEQ)); - compareTemporaryLimits(Importers.loadNetwork(tmpDir.resolve("expected.xml")), Importers.loadNetwork(tmpDir.resolve("actual.xml"))); + compareTemporaryLimits(Network.read(tmpDir.resolve("expected.xml")), Network.read(tmpDir.resolve("actual.xml"))); } private void compareTemporaryLimits(Network expected, Network actual) { diff --git a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/ExportProfilesConsistencyTest.java b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/ExportProfilesConsistencyTest.java index 5042eb57d8c..32e5e7ad0fc 100644 --- a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/ExportProfilesConsistencyTest.java +++ b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/ExportProfilesConsistencyTest.java @@ -15,9 +15,8 @@ import com.powsybl.commons.reporter.Report; import com.powsybl.commons.reporter.Reporter; import com.powsybl.commons.reporter.ReporterModel; -import com.powsybl.iidm.export.Exporters; -import com.powsybl.iidm.export.ExportersServiceLoader; -import com.powsybl.iidm.import_.Importers; +import com.powsybl.iidm.network.ExportersServiceLoader; +import com.powsybl.iidm.network.Importers; import com.powsybl.iidm.network.Network; import org.junit.Test; @@ -60,6 +59,6 @@ private Network importNetwork(ReadOnlyDataSource dataSource) { private void exportProfiles(List profiles, Network network, Reporter reporter) { Properties params = new Properties(); params.put(CgmesExport.PROFILES, profiles); - Exporters.export(new ExportersServiceLoader(), "CGMES", network, params, tmpDir.resolve("exported"), reporter); + network.write(new ExportersServiceLoader(), "CGMES", params, tmpDir.resolve("exported"), reporter); } } diff --git a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/ExportToCimVersionTest.java b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/ExportToCimVersionTest.java index c8220987733..5bda8194b6a 100644 --- a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/ExportToCimVersionTest.java +++ b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/ExportToCimVersionTest.java @@ -16,7 +16,6 @@ import com.powsybl.commons.datasource.MemDataSource; import com.powsybl.commons.datasource.ReadOnlyDataSource; import com.powsybl.commons.datasource.ZipFileDataSource; -import com.powsybl.iidm.import_.Importers; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.NetworkFactory; import com.powsybl.iidm.network.test.NetworkTest1Factory; @@ -76,7 +75,7 @@ public void testExportIEEE14ToCim100CheckIsNodeBreaker() { params.put(CgmesExport.CIM_VERSION, "100"); ZipFileDataSource zip = new ZipFileDataSource(tmpDir.resolve("."), cimZipFilename); new CgmesExport().export(network, params, zip); - Network network100 = Importers.loadNetwork(tmpDir.resolve(cimZipFilename + ".zip")); + Network network100 = Network.read(tmpDir.resolve(cimZipFilename + ".zip")); CgmesModel cgmesModel100 = network100.getExtension(CgmesModelExtension.class).getCgmesModel(); assertTrue(cgmesModel100.isNodeBreaker()); } @@ -94,7 +93,7 @@ private void testExportToCim(Network network, String name, int cimVersion) { new CgmesExport().export(network, params, zip); // Reimport and verify contents of Network - Network networkCimVersion = Importers.loadNetwork(tmpDir.resolve(cimZipFilename + ".zip")); + Network networkCimVersion = Network.read(tmpDir.resolve(cimZipFilename + ".zip")); CimCharacteristics cim = networkCimVersion.getExtension(CimCharacteristics.class); assertEquals(cimVersion, cim.getCimVersion()); diff --git a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/StateVariablesExportTest.java b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/StateVariablesExportTest.java index b38dc17b564..6f168ef1937 100644 --- a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/StateVariablesExportTest.java +++ b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/StateVariablesExportTest.java @@ -18,8 +18,6 @@ import com.powsybl.commons.datasource.ReadOnlyDataSource; import com.powsybl.commons.xml.XmlUtil; import com.powsybl.computation.DefaultComputationManagerConfig; -import com.powsybl.iidm.import_.ImportConfig; -import com.powsybl.iidm.import_.Importers; import com.powsybl.iidm.network.*; import com.powsybl.iidm.xml.ExportOptions; import com.powsybl.iidm.xml.NetworkXml; @@ -256,7 +254,7 @@ private void test(ReadOnlyDataSource dataSource, boolean exportTp, int svVersion r.zip(repackaged); // Import with new SV - Network actual = Importers.loadNetwork(repackaged, + Network actual = Network.read(repackaged, DefaultComputationManagerConfig.load().createShortTimeExecutionComputationManager(), ImportConfig.load(), properties); // Export original and with new SV diff --git a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/SteadyStateHypothesisExportTest.java b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/SteadyStateHypothesisExportTest.java index 0fcfe3fbcec..8fbc599fb38 100644 --- a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/SteadyStateHypothesisExportTest.java +++ b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/SteadyStateHypothesisExportTest.java @@ -16,8 +16,7 @@ import com.powsybl.commons.datasource.ReadOnlyDataSource; import com.powsybl.commons.xml.XmlUtil; import com.powsybl.computation.DefaultComputationManagerConfig; -import com.powsybl.iidm.import_.ImportConfig; -import com.powsybl.iidm.import_.Importers; +import com.powsybl.iidm.network.ImportConfig; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.NetworkFactory; import com.powsybl.iidm.xml.NetworkXml; @@ -134,7 +133,7 @@ private void test(ReadOnlyDataSource dataSource, int version, DifferenceEvaluato r.zip(repackaged); // Import with new SSH - Network actual = Importers.loadNetwork(repackaged, + Network actual = Network.read(repackaged, DefaultComputationManagerConfig.load().createShortTimeExecutionComputationManager(), ImportConfig.load(), properties); // Remove ControlAreas extension diff --git a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/TopologyExportCornerCasesTest.java b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/TopologyExportCornerCasesTest.java index 7a88bcc3302..a81d88b8e78 100644 --- a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/TopologyExportCornerCasesTest.java +++ b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/TopologyExportCornerCasesTest.java @@ -3,7 +3,6 @@ import com.powsybl.cgmes.conversion.CgmesExport; import com.powsybl.commons.AbstractConverterTest; import com.powsybl.commons.datasource.ZipFileDataSource; -import com.powsybl.iidm.import_.Importers; import com.powsybl.iidm.network.*; import org.junit.Ignore; import org.junit.Test; @@ -79,7 +78,7 @@ private void test(Network network, params.put(CgmesExport.CIM_VERSION, "100"); ZipFileDataSource zip = new ZipFileDataSource(tmpDir.resolve("."), name); new CgmesExport().export(network, params, zip); - Network networkFromCgmes = Importers.loadNetwork(tmpDir.resolve(name + ".zip")); + Network networkFromCgmes = Network.read(tmpDir.resolve(name + ".zip")); if (checkAllTerminalsConnected) { checkAllTerminalsConnected(network, name + "_from_CGMES"); } diff --git a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/TopologyExportTest.java b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/TopologyExportTest.java index 376821dee6b..22b94489243 100644 --- a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/TopologyExportTest.java +++ b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/TopologyExportTest.java @@ -14,11 +14,10 @@ import com.powsybl.commons.datasource.ReadOnlyDataSource; import com.powsybl.commons.xml.XmlUtil; import com.powsybl.computation.DefaultComputationManagerConfig; -import com.powsybl.iidm.xml.ExportOptions; -import com.powsybl.iidm.import_.ImportConfig; -import com.powsybl.iidm.import_.Importers; +import com.powsybl.iidm.network.ImportConfig; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.NetworkFactory; +import com.powsybl.iidm.xml.ExportOptions; import com.powsybl.iidm.xml.NetworkXml; import org.junit.Test; @@ -87,7 +86,7 @@ private void test(ReadOnlyDataSource dataSource, boolean importSsh) throws IOExc r.zip(repackaged); // Import with new TP - Network actual = Importers.loadNetwork(repackaged, + Network actual = Network.read(repackaged, DefaultComputationManagerConfig.load().createShortTimeExecutionComputationManager(), ImportConfig.load(), properties); prepareNetworkForComparison(expected); diff --git a/cgmes/cgmes-shortcircuit/pom.xml b/cgmes/cgmes-shortcircuit/pom.xml index 6b7ded17d4d..dbfecfb5658 100644 --- a/cgmes/cgmes-shortcircuit/pom.xml +++ b/cgmes/cgmes-shortcircuit/pom.xml @@ -54,6 +54,11 @@ + + org.slf4j + slf4j-simple + test + ${project.groupId} powsybl-cgmes-conformity diff --git a/distribution-core/pom.xml b/distribution-core/pom.xml index bfcdd54f56f..212b4bd8cea 100644 --- a/distribution-core/pom.xml +++ b/distribution-core/pom.xml @@ -223,12 +223,6 @@ ${project.version} - - ${project.groupId} - powsybl-iidm-converter-api - ${project.version} - - ${project.groupId} powsybl-iidm-extensions diff --git a/dynamic-simulation/dynamic-simulation-tool/pom.xml b/dynamic-simulation/dynamic-simulation-tool/pom.xml index 76c76467e4c..f8e08b2bdba 100644 --- a/dynamic-simulation/dynamic-simulation-tool/pom.xml +++ b/dynamic-simulation/dynamic-simulation-tool/pom.xml @@ -55,7 +55,7 @@ ${project.groupId} - powsybl-iidm-converter-api + powsybl-iidm-api ${project.version} diff --git a/dynamic-simulation/dynamic-simulation-tool/src/main/java/com/powsybl/dynamicsimulation/tool/DynamicSimulationTool.java b/dynamic-simulation/dynamic-simulation-tool/src/main/java/com/powsybl/dynamicsimulation/tool/DynamicSimulationTool.java index 04f73976c8e..294495ff610 100644 --- a/dynamic-simulation/dynamic-simulation-tool/src/main/java/com/powsybl/dynamicsimulation/tool/DynamicSimulationTool.java +++ b/dynamic-simulation/dynamic-simulation-tool/src/main/java/com/powsybl/dynamicsimulation/tool/DynamicSimulationTool.java @@ -24,11 +24,10 @@ import com.powsybl.dynamicsimulation.groovy.GroovyDynamicModelsSupplier; import com.powsybl.dynamicsimulation.json.DynamicSimulationResultSerializer; import com.powsybl.dynamicsimulation.json.JsonDynamicSimulationParameters; -import com.powsybl.iidm.import_.ImportConfig; -import com.powsybl.iidm.import_.Importers; +import com.powsybl.iidm.network.ImportConfig; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.VariantManagerConstants; -import com.powsybl.iidm.tools.ConversionToolUtils; +import com.powsybl.iidm.network.tools.ConversionToolUtils; import com.powsybl.tools.Command; import com.powsybl.tools.Tool; import com.powsybl.tools.ToolRunningContext; @@ -136,7 +135,7 @@ public void run(CommandLine line, ToolRunningContext context) throws Exception { context.getOutputStream().println("Loading network '" + caseFile + "'"); Properties inputParams = ConversionToolUtils.readProperties(line, ConversionToolUtils.OptionType.IMPORT, context); - Network network = Importers.loadNetwork(caseFile, context.getShortTimeExecutionComputationManager(), ImportConfig.load(), inputParams); + Network network = Network.read(caseFile, context.getShortTimeExecutionComputationManager(), ImportConfig.load(), inputParams); if (network == null) { throw new PowsyblException("Case '" + caseFile + "' not found"); } diff --git a/ieee-cdf/ieee-cdf-converter/pom.xml b/ieee-cdf/ieee-cdf-converter/pom.xml index 2b81078830e..f304de5d733 100644 --- a/ieee-cdf/ieee-cdf-converter/pom.xml +++ b/ieee-cdf/ieee-cdf-converter/pom.xml @@ -45,7 +45,7 @@ ${project.groupId} - powsybl-iidm-converter-api + powsybl-iidm-api ${project.version} diff --git a/ieee-cdf/ieee-cdf-converter/src/main/java/com/powsybl/ieeecdf/converter/IeeeCdfImporter.java b/ieee-cdf/ieee-cdf-converter/src/main/java/com/powsybl/ieeecdf/converter/IeeeCdfImporter.java index 2acb2cd9efa..2c5111b600d 100644 --- a/ieee-cdf/ieee-cdf-converter/src/main/java/com/powsybl/ieeecdf/converter/IeeeCdfImporter.java +++ b/ieee-cdf/ieee-cdf-converter/src/main/java/com/powsybl/ieeecdf/converter/IeeeCdfImporter.java @@ -12,7 +12,7 @@ import com.powsybl.commons.datasource.DataSource; import com.powsybl.commons.datasource.ReadOnlyDataSource; import com.powsybl.ieeecdf.model.*; -import com.powsybl.iidm.import_.Importer; +import com.powsybl.iidm.network.Importer; import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.SlackTerminal; import com.powsybl.iidm.network.util.ContainersMapping; diff --git a/ieee-cdf/ieee-cdf-converter/src/test/java/com/powsybl/ieeecdf/converter/IeeeCdfImporterTest.java b/ieee-cdf/ieee-cdf-converter/src/test/java/com/powsybl/ieeecdf/converter/IeeeCdfImporterTest.java index 82ad8b496be..92455328bfc 100644 --- a/ieee-cdf/ieee-cdf-converter/src/test/java/com/powsybl/ieeecdf/converter/IeeeCdfImporterTest.java +++ b/ieee-cdf/ieee-cdf-converter/src/test/java/com/powsybl/ieeecdf/converter/IeeeCdfImporterTest.java @@ -21,7 +21,7 @@ import com.powsybl.commons.datasource.FileDataSource; import com.powsybl.commons.datasource.ResourceDataSource; import com.powsybl.commons.datasource.ResourceSet; -import com.powsybl.iidm.import_.Importer; +import com.powsybl.iidm.network.Importer; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.xml.NetworkXml; import com.powsybl.loadflow.LoadFlowParameters; diff --git a/iidm/iidm-api/pom.xml b/iidm/iidm-api/pom.xml index 8e4538ff92c..fda6bece129 100644 --- a/iidm/iidm-api/pom.xml +++ b/iidm/iidm-api/pom.xml @@ -68,13 +68,28 @@ powsybl-commons ${project.version} + + ${project.groupId} + powsybl-computation-local + ${project.version} + ${project.groupId} powsybl-math ${project.version} + + ${project.groupId} + powsybl-tools + ${project.version} + + + com.google.jimfs + jimfs + test + junit junit @@ -90,6 +105,21 @@ slf4j-simple test + + + ${project.groupId} + powsybl-commons + ${project.version} + test-jar + test + + + ${project.groupId} + powsybl-tools + ${project.version} + test-jar + test + diff --git a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/export/Exporter.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Exporter.java similarity index 95% rename from iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/export/Exporter.java rename to iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Exporter.java index bff2ae847f7..9bf7b1c8f0a 100644 --- a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/export/Exporter.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Exporter.java @@ -4,11 +4,10 @@ * 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.export; +package com.powsybl.iidm.network; import com.powsybl.commons.datasource.DataSource; import com.powsybl.commons.reporter.Reporter; -import com.powsybl.iidm.network.Network; import com.powsybl.commons.parameters.Parameter; import java.util.*; @@ -19,7 +18,7 @@ * *

Exporter lookup is based on the ServiceLoader * architecture so do not forget to create a - * META-INF/services/com.powsybl.iidm.export.Exporter file + * META-INF/services/com.powsybl.iidm.network.Exporter file * with the fully qualified name of your Exporter implementation. * * @see java.util.ServiceLoader diff --git a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/export/ExporterPluginInfo.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ExporterPluginInfo.java similarity index 95% rename from iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/export/ExporterPluginInfo.java rename to iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ExporterPluginInfo.java index fe3fba76ee1..966ccdda068 100644 --- a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/export/ExporterPluginInfo.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ExporterPluginInfo.java @@ -4,7 +4,7 @@ * 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.export; +package com.powsybl.iidm.network; import com.google.auto.service.AutoService; import com.powsybl.commons.plugins.PluginInfo; diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Exporters.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Exporters.java new file mode 100644 index 00000000000..7ba0325b8cf --- /dev/null +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Exporters.java @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2016, All partners of the iTesla project (http://www.itesla-project.eu/consortium) + * 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; + +import com.powsybl.commons.datasource.DataSource; +import com.powsybl.commons.datasource.DataSourceObserver; +import com.powsybl.commons.datasource.DataSourceUtil; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Objects; + +/** + * A utility class to work with IIDM exporters. + * + * @author Geoffroy Jamgotchian + */ +public final class Exporters { + + private Exporters() { + } + + public static DataSource createDataSource(Path directory, String fileNameOrBaseName, DataSourceObserver observer) { + return DataSourceUtil.createDataSource(directory, fileNameOrBaseName, observer); + } + + public static DataSource createDataSource(Path file, DataSourceObserver observer) { + Objects.requireNonNull(file); + if (Files.exists(file) && !Files.isRegularFile(file)) { + throw new UncheckedIOException(new IOException("File " + file + " already exists and is not a regular file")); + } + Path absFile = file.toAbsolutePath(); + return createDataSource(absFile.getParent(), absFile.getFileName().toString(), observer); + } + + public static DataSource createDataSource(Path file) { + return createDataSource(file, null); + } +} diff --git a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/export/ExportersLoader.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ExportersLoader.java similarity index 92% rename from iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/export/ExportersLoader.java rename to iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ExportersLoader.java index e6ac4bb2a3c..5425c595bea 100644 --- a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/export/ExportersLoader.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ExportersLoader.java @@ -4,7 +4,7 @@ * 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.export; +package com.powsybl.iidm.network; import java.util.List; diff --git a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/export/ExportersLoaderList.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ExportersLoaderList.java similarity index 96% rename from iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/export/ExportersLoaderList.java rename to iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ExportersLoaderList.java index 109ec942231..79300637b17 100644 --- a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/export/ExportersLoaderList.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ExportersLoaderList.java @@ -4,7 +4,7 @@ * 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.export; +package com.powsybl.iidm.network; import java.util.Arrays; import java.util.List; diff --git a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/export/ExportersServiceLoader.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ExportersServiceLoader.java similarity index 95% rename from iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/export/ExportersServiceLoader.java rename to iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ExportersServiceLoader.java index 7ac8eb2f239..c76e0b38809 100644 --- a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/export/ExportersServiceLoader.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ExportersServiceLoader.java @@ -4,7 +4,7 @@ * 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.export; +package com.powsybl.iidm.network; import com.powsybl.commons.util.ServiceLoaderCache; diff --git a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/ImportConfig.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ImportConfig.java similarity index 98% rename from iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/ImportConfig.java rename to iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ImportConfig.java index c2ca4e5ea11..0af9d222305 100644 --- a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/ImportConfig.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ImportConfig.java @@ -4,7 +4,7 @@ * 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.import_; +package com.powsybl.iidm.network; import com.google.common.base.Suppliers; import com.powsybl.commons.config.PlatformConfig; diff --git a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/ImportPostProcessor.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ImportPostProcessor.java similarity index 92% rename from iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/ImportPostProcessor.java rename to iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ImportPostProcessor.java index 7c11b1e0a28..b1c3a23ef9c 100644 --- a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/ImportPostProcessor.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ImportPostProcessor.java @@ -4,11 +4,10 @@ * 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.import_; +package com.powsybl.iidm.network; import com.powsybl.commons.reporter.Reporter; import com.powsybl.computation.ComputationManager; -import com.powsybl.iidm.network.Network; /** * diff --git a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/ImportPostProcessorPluginInfo.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ImportPostProcessorPluginInfo.java similarity index 96% rename from iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/ImportPostProcessorPluginInfo.java rename to iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ImportPostProcessorPluginInfo.java index 2d3087ea729..e12a9e8fff1 100644 --- a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/ImportPostProcessorPluginInfo.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ImportPostProcessorPluginInfo.java @@ -4,7 +4,7 @@ * 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.import_; +package com.powsybl.iidm.network; import com.google.auto.service.AutoService; import com.powsybl.commons.plugins.PluginInfo; diff --git a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/Importer.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Importer.java similarity index 99% rename from iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/Importer.java rename to iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Importer.java index e2cc407a7d1..43060128bc9 100644 --- a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/Importer.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Importer.java @@ -4,7 +4,7 @@ * 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.import_; +package com.powsybl.iidm.network; import com.powsybl.commons.PowsyblException; import com.powsybl.commons.datasource.DataSource; @@ -12,8 +12,6 @@ import com.powsybl.commons.reporter.Reporter; import com.powsybl.computation.ComputationManager; import com.powsybl.computation.local.LocalComputationManager; -import com.powsybl.iidm.network.Network; -import com.powsybl.iidm.network.NetworkFactory; import com.powsybl.commons.parameters.Parameter; import javax.annotation.Nullable; diff --git a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/ImporterPluginInfo.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ImporterPluginInfo.java similarity index 95% rename from iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/ImporterPluginInfo.java rename to iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ImporterPluginInfo.java index 91e3e68721e..f91db8c86db 100644 --- a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/ImporterPluginInfo.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ImporterPluginInfo.java @@ -4,7 +4,7 @@ * 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.import_; +package com.powsybl.iidm.network; import com.google.auto.service.AutoService; import com.powsybl.commons.plugins.PluginInfo; diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Importers.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Importers.java new file mode 100644 index 00000000000..1641f885682 --- /dev/null +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Importers.java @@ -0,0 +1,194 @@ +/** + * Copyright (c) 2016, All partners of the iTesla project (http://www.itesla-project.eu/consortium) + * 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; + +import com.powsybl.commons.PowsyblException; +import com.powsybl.commons.datasource.*; +import com.powsybl.commons.reporter.Reporter; +import com.powsybl.computation.ComputationManager; +import com.powsybl.computation.local.LocalComputationManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.*; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * A utility class to work with IIDM importers. + * + * @author Geoffroy Jamgotchian + */ +public final class Importers { + + private static final Logger LOGGER = LoggerFactory.getLogger(Importers.class); + + static final String UNSUPPORTED_FILE_FORMAT_OR_INVALID_FILE = "Unsupported file format or invalid file."; + + private Importers() { + } + + /** + * A convenient method to create a model from data in a given format. + * + * @param format the import format + * @param dataSource data source + * @param parameters some properties to configure the import + * @param computationManager computation manager to use for default post processors + * @param config the import configuration + * @param reporter the reporter used for functional logs + * @return the model + */ + public static Network importData(ImportersLoader loader, String format, ReadOnlyDataSource dataSource, Properties parameters, ComputationManager computationManager, ImportConfig config, Reporter reporter) { + Importer importer = Importer.find(loader, format, computationManager, config); + if (importer == null) { + throw new PowsyblException("Import format " + format + " not supported"); + } + return importer.importData(dataSource, NetworkFactory.findDefault(), parameters, reporter); + } + + public static Network importData(ImportersLoader loader, String format, ReadOnlyDataSource dataSource, Properties parameters, ComputationManager computationManager, ImportConfig config) { + return importData(loader, format, dataSource, parameters, computationManager, config, Reporter.NO_OP); + } + + public static Network importData(String format, ReadOnlyDataSource dataSource, Properties parameters, ComputationManager computationManager, Reporter reporter) { + return importData(new ImportersServiceLoader(), format, dataSource, parameters, computationManager, ImportConfig.CACHE.get(), reporter); + } + + public static Network importData(String format, ReadOnlyDataSource dataSource, Properties parameters, ComputationManager computationManager) { + return importData(new ImportersServiceLoader(), format, dataSource, parameters, computationManager, ImportConfig.CACHE.get(), Reporter.NO_OP); + } + + public static Network importData(String format, ReadOnlyDataSource dataSource, Properties parameters, Reporter reporter) { + return importData(new ImportersServiceLoader(), format, dataSource, parameters, LocalComputationManager.getDefault(), ImportConfig.CACHE.get(), reporter); + } + + public static Network importData(String format, ReadOnlyDataSource dataSource, Properties parameters) { + return importData(format, dataSource, parameters, LocalComputationManager.getDefault()); + } + + /** + * A convenient method to create a model from data in a given format. + * + * @param format the import format + * @param directory the directory where input files are + * @param baseName a base name for all input files + * @param parameters some properties to configure the import + * @return the model + */ + public static Network importData(String format, String directory, String baseName, Properties parameters) { + return importData(format, new FileDataSource(Paths.get(directory), baseName), parameters); + } + + private static void doImport(ReadOnlyDataSource dataSource, Importer importer, Properties parameters, Consumer consumer, Consumer listener, NetworkFactory networkFactory, Reporter reporter) { + Objects.requireNonNull(consumer); + try { + if (listener != null) { + listener.accept(dataSource); + } + Network network = importer.importData(dataSource, networkFactory, parameters, reporter); + consumer.accept(network); + } catch (Exception e) { + LOGGER.error(e.toString(), e); + } + } + + private static void addDataSource(Path dir, Path file, Importer importer, List dataSources) { + Objects.requireNonNull(importer); + String caseBaseName = DataSourceUtil.getBaseName(file); + ReadOnlyDataSource ds = new GenericReadOnlyDataSource(dir, caseBaseName); + if (importer.exists(ds)) { + dataSources.add(ds); + } + } + + private static void importAll(Path parent, Importer importer, List dataSources) throws IOException { + if (Files.isDirectory(parent)) { + try (Stream stream = Files.list(parent)) { + stream.sorted().forEach(child -> { + if (Files.isDirectory(child)) { + try { + importAll(child, importer, dataSources); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } else { + addDataSource(parent, child, importer, dataSources); + } + }); + } + } else { + if (parent.getParent() != null) { + addDataSource(parent.getParent(), parent, importer, dataSources); + } + } + } + + public static void importAll(Path dir, Importer importer, boolean parallel, Properties parameters, Consumer consumer, Consumer listener, Reporter reporter) throws IOException, InterruptedException, ExecutionException { + importAll(dir, importer, parallel, parameters, consumer, listener, NetworkFactory.findDefault(), reporter); + } + + public static void importAll(Path dir, Importer importer, boolean parallel, Properties parameters, Consumer consumer, Consumer listener, NetworkFactory networkFactory, Reporter reporter) throws IOException, InterruptedException, ExecutionException { + List dataSources = new ArrayList<>(); + importAll(dir, importer, dataSources); + if (parallel) { + ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); + try { + List> futures = dataSources.stream() + .map(ds -> { + Reporter child = createSubReporter(reporter, ds); + return executor.submit(() -> doImport(ds, importer, parameters, consumer, listener, networkFactory, child)); + }) + .collect(Collectors.toList()); + for (Future future : futures) { + future.get(); + } + } finally { + executor.shutdownNow(); + } + } else { + for (ReadOnlyDataSource dataSource : dataSources) { + doImport(dataSource, importer, parameters, consumer, listener, networkFactory, createSubReporter(reporter, dataSource)); + } + } + } + + private static Reporter createSubReporter(Reporter reporter, ReadOnlyDataSource ds) { + return reporter.createSubReporter("importDataSource", "Import data source ${dataSource}", "dataSource", ds.getBaseName()); + } + + public static void importAll(Path dir, Importer importer, boolean parallel, Consumer consumer, Consumer listener) throws IOException, InterruptedException, ExecutionException { + importAll(dir, importer, parallel, null, consumer, listener, Reporter.NO_OP); + } + + public static void importAll(Path dir, Importer importer, boolean parallel, Consumer consumer) throws IOException, InterruptedException, ExecutionException { + importAll(dir, importer, parallel, consumer, null); + } + + public static DataSource createDataSource(Path file) { + Objects.requireNonNull(file); + if (!Files.isRegularFile(file)) { + throw new PowsyblException("File " + file + " does not exist or is not a regular file"); + } + Path absFile = file.toAbsolutePath(); + return createDataSource(absFile.getParent(), absFile.getFileName().toString()); + } + + public static DataSource createDataSource(Path directory, String fileNameOrBaseName) { + return DataSourceUtil.createDataSource(directory, fileNameOrBaseName, null); + } +} diff --git a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/ImportersLoader.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ImportersLoader.java similarity index 94% rename from iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/ImportersLoader.java rename to iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ImportersLoader.java index 4939d978552..d469c46790b 100644 --- a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/ImportersLoader.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ImportersLoader.java @@ -4,7 +4,7 @@ * 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.import_; +package com.powsybl.iidm.network; import java.util.List; diff --git a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/ImportersLoaderList.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ImportersLoaderList.java similarity index 97% rename from iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/ImportersLoaderList.java rename to iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ImportersLoaderList.java index 1320f0d96de..d540c65bc66 100644 --- a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/ImportersLoaderList.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ImportersLoaderList.java @@ -4,7 +4,7 @@ * 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.import_; +package com.powsybl.iidm.network; import java.util.Arrays; import java.util.Collections; diff --git a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/ImportersServiceLoader.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ImportersServiceLoader.java similarity index 96% rename from iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/ImportersServiceLoader.java rename to iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ImportersServiceLoader.java index 80e1dde5fe2..04f7de54ebd 100644 --- a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/ImportersServiceLoader.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/ImportersServiceLoader.java @@ -4,7 +4,7 @@ * 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.import_; +package com.powsybl.iidm.network; import com.powsybl.commons.util.ServiceLoaderCache; diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Network.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Network.java index dd01655bd58..51f844cab9e 100644 --- a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Network.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Network.java @@ -7,11 +7,22 @@ package com.powsybl.iidm.network; import com.powsybl.commons.PowsyblException; +import com.powsybl.commons.datasource.*; import com.powsybl.commons.reporter.Reporter; +import com.powsybl.computation.ComputationManager; +import com.powsybl.computation.local.LocalComputationManager; import org.joda.time.DateTime; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Collection; +import java.util.Properties; import java.util.Set; +import java.util.concurrent.ExecutionException; +import java.util.function.Consumer; import java.util.stream.Stream; /** @@ -88,6 +99,271 @@ */ public interface Network extends Container { + /** + * Read a network from the specified file, trying to guess its format. + * + * @param file The file to be loaded. + * @param computationManager A computation manager which may be used by import post-processors + * @param config The import config, in particular definition of post processors + * @param parameters Import-specific parameters + * @param networkFactory Network factory + * @param loader Provides the list of available importers and post-processors + * @param reporter The reporter used for functional logs + * @return The loaded network + */ + static Network read(Path file, ComputationManager computationManager, ImportConfig config, Properties parameters, NetworkFactory networkFactory, + ImportersLoader loader, Reporter reporter) { + ReadOnlyDataSource dataSource = Importers.createDataSource(file); + Importer importer = Importer.find(dataSource, loader, computationManager, config); + if (importer != null) { + return importer.importData(dataSource, networkFactory, parameters, reporter); + } + throw new PowsyblException(Importers.UNSUPPORTED_FILE_FORMAT_OR_INVALID_FILE); + } + + static Network read(Path file, ComputationManager computationManager, ImportConfig config, Properties parameters, + ImportersLoader loader, Reporter reporter) { + return read(file, computationManager, config, parameters, NetworkFactory.findDefault(), loader, reporter); + } + + /** + * Read a network from the specified file, trying to guess its format. + * + * @param file The file to be loaded. + * @param computationManager A computation manager which may be used by import post-processors + * @param config The import config, in particular definition of post processors + * @param parameters Import-specific parameters + * @param loader Provides the list of available importers and post-processors + * @return The loaded network + */ + static Network read(Path file, ComputationManager computationManager, ImportConfig config, Properties parameters, ImportersLoader loader) { + return read(file, computationManager, config, parameters, loader, Reporter.NO_OP); + } + + /** + * Read a network from the specified file, trying to guess its format, + * and using importers and post processors defined as services. + * + * @param file The file to be loaded. + * @param computationManager A computation manager which may be used by import post-processors + * @param config The import config, in particular definition of post processors + * @param parameters Import-specific parameters + * @return The loaded network + */ + static Network read(Path file, ComputationManager computationManager, ImportConfig config, Properties parameters) { + return read(file, computationManager, config, parameters, new ImportersServiceLoader()); + } + + /** + * Read a network from the specified file, trying to guess its format, + * and using importers and post processors defined as services. + * Import will be performed using import configuration defined in default platform config, + * and with no importer-specific parameters. + * Post processors will use the default {@link LocalComputationManager}, as defined in + * default platform config. + * + * @param file The file to be loaded. + * @return The loaded network + */ + static Network read(Path file) { + return read(file, LocalComputationManager.getDefault(), ImportConfig.CACHE.get(), null); + } + + /** + * Loads a network from the specified file path, see {@link #read(Path)}. + * + * @param file The file to be loaded. + * @return The loaded network + */ + static Network read(String file) { + return read(Paths.get(file)); + } + + /** + * Read a network from a raw input stream, trying to guess the format from the specified filename. + * Please note that the input stream must be from a simple file, not a zipped one. + * + * @param filename The name of the file to be imported. + * @param data The raw data from which the network should be loaded + * @param computationManager A computation manager which may be used by import post-processors + * @param config The import config, in particular definition of post processors + * @param parameters Import-specific parameters + * @param networkFactory Network factory + * @param loader Provides the list of available importers and post-processors + * @param reporter The reporter used for functional logs + * @return The loaded network + */ + static Network read(String filename, InputStream data, ComputationManager computationManager, ImportConfig config, Properties parameters, NetworkFactory networkFactory, ImportersLoader loader, Reporter reporter) { + ReadOnlyMemDataSource dataSource = new ReadOnlyMemDataSource(DataSourceUtil.getBaseName(filename)); + dataSource.putData(filename, data); + Importer importer = Importer.find(dataSource, loader, computationManager, config); + if (importer != null) { + return importer.importData(dataSource, networkFactory, parameters, reporter); + } + throw new PowsyblException(Importers.UNSUPPORTED_FILE_FORMAT_OR_INVALID_FILE); + } + + /** + * Read a network from a raw input stream, trying to guess the format from the specified filename. + * Please note that the input stream must be from a simple file, not a zipped one. + * + * @param filename The name of the file to be imported. + * @param data The raw data from which the network should be loaded + * @param computationManager A computation manager which may be used by import post-processors + * @param config The import config, in particular definition of post processors + * @param parameters Import-specific parameters + * @param loader Provides the list of available importers and post-processors + * @param reporter The reporter used for functional logs + * @return The loaded network + */ + static Network read(String filename, InputStream data, ComputationManager computationManager, ImportConfig config, Properties parameters, ImportersLoader loader, Reporter reporter) { + return read(filename, data, computationManager, config, parameters, NetworkFactory.findDefault(), loader, reporter); + } + + /** + * Read a network from a raw input stream, trying to guess the format from the specified filename. + * Please note that the input stream must be from a simple file, not a zipped one. + * + * @param filename The name of the file to be imported. + * @param data The raw data from which the network should be loaded + * @param computationManager A computation manager which may be used by import post-processors + * @param config The import config, in particular definition of post processors + * @param parameters Import-specific parameters + * @param loader Provides the list of available importers and post-processors + * @return The loaded network + */ + static Network read(String filename, InputStream data, ComputationManager computationManager, ImportConfig config, Properties parameters, ImportersLoader loader) { + return read(filename, data, computationManager, config, parameters, loader, Reporter.NO_OP); + } + + /** + * Read a network from a raw input stream, trying to guess the format from the specified filename, + * and using importers and post processors defined as services. + * Please note that the input stream must be from a simple file, not a zipped one. + * + * @param filename The name of the file to be imported. + * @param data The raw data from which the network should be loaded + * @param computationManager A computation manager which may be used by import post-processors + * @param config The import config, in particular definition of post processors + * @param parameters Import-specific parameters + * @return The loaded network + */ + static Network read(String filename, InputStream data, ComputationManager computationManager, ImportConfig config, Properties parameters) { + return read(filename, data, computationManager, config, parameters, new ImportersServiceLoader()); + } + + /** + * Read a network from a raw input stream, trying to guess the format from the specified filename, + * and using importers and post processors defined as services. + * Import will be performed using import configuration defined in default platform config, + * and with no importer-specific parameters. + * Please note that the input stream must be from a simple file, not a zipped one. + * + * @param filename The name of the file to be imported. + * @param data The raw data from which the network should be loaded + * @param computationManager A computation manager which may be used by import post-processors + * @return The loaded network + */ + static Network read(String filename, InputStream data, ComputationManager computationManager) { + return read(filename, data, computationManager, ImportConfig.CACHE.get(), null); + } + + /** + * Read a network from a raw input stream, trying to guess the format from the specified filename, + * and using importers and post processors defined as services. + * Import will be performed using import configuration defined in default platform config, + * and with no importer-specific parameters. + * Post processors will use the default {@link LocalComputationManager}, as defined in + * default platform config. + * Please note that the input stream must be from a simple file, not a zipped one. + * + * @param filename The name of the file to be imported. + * @param data The raw data from which the network should be loaded + * @return The loaded network + */ + static Network read(String filename, InputStream data) { + return read(filename, data, LocalComputationManager.getDefault()); + } + + /** + * Read a network from a raw input stream, trying to guess the format from the specified filename, + * and using importers and post processors defined as services. + * Import will be performed using import configuration defined in default platform config, + * and with no importer-specific parameters. + * Post processors will use the default {@link LocalComputationManager}, as defined in + * default platform config. + * Please note that the input stream must be from a simple file, not a zipped one. + * + * @param filename The name of the file to be imported. + * @param data The raw data from which the network should be loaded + * @param reporter The reporter used for functional logs + * @return The loaded network + */ + static Network read(String filename, InputStream data, Reporter reporter) { + return read(filename, data, LocalComputationManager.getDefault(), ImportConfig.CACHE.get(), null, new ImportersServiceLoader(), reporter); + } + + static Network read(ReadOnlyDataSource dataSource) { + return read(dataSource, null); + } + + static Network read(ReadOnlyDataSource dataSource, Properties properties) { + return read(dataSource, properties, Reporter.NO_OP); + } + + static Network read(ReadOnlyDataSource dataSource, Properties properties, Reporter reporter) { + Importer importer = Importer.find(dataSource); + if (importer != null) { + return importer.importData(dataSource, NetworkFactory.findDefault(), properties, reporter); + } + throw new PowsyblException(Importers.UNSUPPORTED_FILE_FORMAT_OR_INVALID_FILE); + } + + static void readAll(Path dir, boolean parallel, ImportersLoader loader, ComputationManager computationManager, ImportConfig config, Properties parameters, Consumer consumer, Consumer listener, NetworkFactory networkFactory, Reporter reporter) throws IOException, InterruptedException, ExecutionException { + if (!Files.isDirectory(dir)) { + throw new PowsyblException("Directory " + dir + " does not exist or is not a regular directory"); + } + for (Importer importer : Importer.list(loader, computationManager, config)) { + Importers.importAll(dir, importer, parallel, parameters, consumer, listener, networkFactory, reporter); + } + } + + static void readAll(Path dir, boolean parallel, ImportersLoader loader, ComputationManager computationManager, ImportConfig config, Properties parameters, Consumer consumer, Consumer listener, Reporter reporter) throws IOException, InterruptedException, ExecutionException { + readAll(dir, parallel, loader, computationManager, config, parameters, consumer, listener, NetworkFactory.findDefault(), reporter); + } + + static void readAll(Path dir, boolean parallel, ImportersLoader loader, ComputationManager computationManager, ImportConfig config, Properties parameters, Consumer consumer, Consumer listener) throws IOException, InterruptedException, ExecutionException { + readAll(dir, parallel, loader, computationManager, config, parameters, consumer, listener, Reporter.NO_OP); + } + + static void readAll(Path dir, boolean parallel, ImportersLoader loader, ComputationManager computationManager, ImportConfig config, Consumer consumer, Consumer listener) throws IOException, InterruptedException, ExecutionException { + readAll(dir, parallel, loader, computationManager, config, null, consumer, listener); + } + + static void readAll(Path dir, boolean parallel, ComputationManager computationManager, ImportConfig config, Properties parameters, Consumer consumer, Consumer listener) throws IOException, InterruptedException, ExecutionException { + readAll(dir, parallel, new ImportersServiceLoader(), computationManager, config, parameters, consumer, listener); + } + + static void readAll(Path dir, boolean parallel, ComputationManager computationManager, ImportConfig config, Consumer consumer, Consumer listener) throws IOException, InterruptedException, ExecutionException { + readAll(dir, parallel, new ImportersServiceLoader(), computationManager, config, consumer, listener); + } + + static void readAll(Path dir, boolean parallel, ComputationManager computationManager, ImportConfig config, Consumer consumer) throws IOException, InterruptedException, ExecutionException { + readAll(dir, parallel, computationManager, config, consumer, null); + } + + static void readAll(Path dir, boolean parallel, Consumer consumer) throws IOException, InterruptedException, ExecutionException { + readAll(dir, parallel, LocalComputationManager.getDefault(), ImportConfig.CACHE.get(), consumer); + } + + static void readAll(Path dir, boolean parallel, Consumer consumer, Consumer listener) throws IOException, InterruptedException, ExecutionException { + readAll(dir, parallel, LocalComputationManager.getDefault(), ImportConfig.CACHE.get(), consumer, listener); + } + + static void readAll(Path dir, Consumer consumer) throws IOException, InterruptedException, ExecutionException { + readAll(dir, false, LocalComputationManager.getDefault(), ImportConfig.CACHE.get(), consumer); + } + /** * A global bus/breaker view of the network. *

@@ -954,4 +1230,70 @@ default > Stream getIdentifiableStream(Identifiable throw new PowsyblException("can get a stream of " + identifiableType + " from a network."); } } + + /** + * Write the network to a given format. + * + * @param format the export format + * @param parameters some properties to configure the export + * @param dataSource data source + * @param reporter the reporter used for functional logs + */ + default void write(ExportersLoader loader, String format, Properties parameters, DataSource dataSource, Reporter reporter) { + Exporter exporter = Exporter.find(loader, format); + if (exporter == null) { + throw new PowsyblException("Export format " + format + " not supported"); + } + exporter.export(this, parameters, dataSource, reporter); + } + + default void write(ExportersLoader loader, String format, Properties parameters, DataSource dataSource) { + write(loader, format, parameters, dataSource, Reporter.NO_OP); + } + + default void write(String format, Properties parameters, DataSource dataSource) { + write(new ExportersServiceLoader(), format, parameters, dataSource); + } + + /** + * Write the network to a given format. + * + * @param format the export format + * @param parameters some properties to configure the export + * @param file the network file + * @param reporter the reporter used for functional logs + */ + default void write(ExportersLoader loader, String format, Properties parameters, Path file, Reporter reporter) { + DataSource dataSource = Exporters.createDataSource(file); + write(loader, format, parameters, dataSource, reporter); + } + + default void write(ExportersLoader loader, String format, Properties parameters, Path file) { + write(loader, format, parameters, file, Reporter.NO_OP); + } + + default void write(String format, Properties parameters, Path file) { + write(new ExportersServiceLoader(), format, parameters, file); + } + + /** + * Write the network to a given format. + * + * @param format the export format + * @param parameters some properties to configure the export + * @param directory the output directory where files are generated + * @param baseName a base name for all generated files + * @param reporter the reporter used for functional logs + */ + default void write(ExportersLoader loader, String format, Properties parameters, String directory, String baseName, Reporter reporter) { + write(loader, format, parameters, new FileDataSource(Paths.get(directory), baseName), reporter); + } + + default void write(ExportersLoader loader, String format, Properties parameters, String directory, String basename) { + write(loader, format, parameters, directory, basename, Reporter.NO_OP); + } + + default void write(String format, Properties parameters, String directory, String baseName) { + write(new ExportersServiceLoader(), format, parameters, directory, baseName); + } } diff --git a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/tools/ConversionTool.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/tools/ConversionTool.java similarity index 77% rename from iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/tools/ConversionTool.java rename to iidm/iidm-api/src/main/java/com/powsybl/iidm/network/tools/ConversionTool.java index 98d1060f2dc..0067bf7ab8e 100644 --- a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/tools/ConversionTool.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/tools/ConversionTool.java @@ -4,17 +4,14 @@ * 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.tools; +package com.powsybl.iidm.network.tools; import com.google.auto.service.AutoService; import com.powsybl.commons.PowsyblException; import com.powsybl.commons.datasource.DataSource; import com.powsybl.commons.datasource.DefaultDataSourceObserver; -import com.powsybl.iidm.export.Exporter; -import com.powsybl.iidm.export.Exporters; -import com.powsybl.iidm.import_.ImportConfig; -import com.powsybl.iidm.import_.Importers; -import com.powsybl.iidm.network.Network; +import com.powsybl.commons.reporter.Reporter; +import com.powsybl.iidm.network.*; import com.powsybl.tools.Command; import com.powsybl.tools.Tool; import com.powsybl.tools.ToolRunningContext; @@ -24,8 +21,6 @@ import java.util.Properties; -import static com.powsybl.iidm.tools.ConversionToolUtils.*; - /** * * @author Geoffroy Jamgotchian @@ -42,6 +37,10 @@ protected ImportConfig createImportConfig() { return ImportConfig.load(); } + protected NetworkFactory createNetworkFactory() { + return NetworkFactory.findDefault(); + } + @Override public Command getCommand() { return new Command() { @@ -82,10 +81,10 @@ public Options getOptions() { .argName("OUTPUT_FILE") .required() .build()); - options.addOption(createImportParametersFileOption()); - options.addOption(createImportParameterOption()); - options.addOption(createExportParametersFileOption()); - options.addOption(createExportParameterOption()); + options.addOption(ConversionToolUtils.createImportParametersFileOption()); + options.addOption(ConversionToolUtils.createImportParameterOption()); + options.addOption(ConversionToolUtils.createExportParametersFileOption()); + options.addOption(ConversionToolUtils.createExportParameterOption()); return options; } @@ -107,10 +106,10 @@ public void run(CommandLine line, ToolRunningContext context) throws Exception { throw new PowsyblException("Target format " + outputFormat + " not supported"); } - Properties inputParams = readProperties(line, ConversionToolUtils.OptionType.IMPORT, context); - Network network = Importers.loadNetwork(context.getFileSystem().getPath(inputFile), context.getShortTimeExecutionComputationManager(), createImportConfig(), inputParams); + Properties inputParams = ConversionToolUtils.readProperties(line, ConversionToolUtils.OptionType.IMPORT, context); + Network network = Network.read(context.getFileSystem().getPath(inputFile), context.getShortTimeExecutionComputationManager(), createImportConfig(), inputParams, createNetworkFactory(), new ImportersServiceLoader(), Reporter.NO_OP); - Properties outputParams = readProperties(line, ConversionToolUtils.OptionType.EXPORT, context); + Properties outputParams = ConversionToolUtils.readProperties(line, ConversionToolUtils.OptionType.EXPORT, context); DataSource ds2 = Exporters.createDataSource(context.getFileSystem().getPath(outputFile), new DefaultDataSourceObserver() { @Override public void opened(String streamName) { diff --git a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/tools/ConversionToolUtils.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/tools/ConversionToolUtils.java similarity index 98% rename from iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/tools/ConversionToolUtils.java rename to iidm/iidm-api/src/main/java/com/powsybl/iidm/network/tools/ConversionToolUtils.java index 4fa761dcaa2..d17c0c1ee89 100644 --- a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/tools/ConversionToolUtils.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/tools/ConversionToolUtils.java @@ -4,7 +4,7 @@ * 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.tools; +package com.powsybl.iidm.network.tools; import com.powsybl.tools.ToolRunningContext; import org.apache.commons.cli.CommandLine; diff --git a/iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/AbstractConvertersTest.java b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/AbstractConvertersTest.java similarity index 97% rename from iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/AbstractConvertersTest.java rename to iidm/iidm-api/src/test/java/com/powsybl/iidm/network/AbstractConvertersTest.java index 7525a535c4b..45102bc5fae 100644 --- a/iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/AbstractConvertersTest.java +++ b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/AbstractConvertersTest.java @@ -4,7 +4,7 @@ * 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; +package com.powsybl.iidm.network; import com.google.common.jimfs.Configuration; import com.google.common.jimfs.Jimfs; diff --git a/iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/export/ExportersTest.java b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/ExportersTest.java similarity index 82% rename from iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/export/ExportersTest.java rename to iidm/iidm-api/src/test/java/com/powsybl/iidm/network/ExportersTest.java index 25d68c0279f..5dccc5efb57 100644 --- a/iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/export/ExportersTest.java +++ b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/ExportersTest.java @@ -4,7 +4,7 @@ * 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.export; +package com.powsybl.iidm.network; import com.google.common.io.ByteStreams; import com.powsybl.commons.PowsyblException; @@ -12,9 +12,9 @@ import com.powsybl.commons.datasource.DataSource; import com.powsybl.commons.reporter.Report; import com.powsybl.commons.reporter.ReporterModel; -import com.powsybl.iidm.AbstractConvertersTest; -import com.powsybl.iidm.tools.ExporterMockWithReporter; +import com.powsybl.iidm.network.tools.ExporterMockWithReporter; import org.junit.Test; +import org.mockito.Mockito; import java.io.IOException; import java.io.InputStream; @@ -83,29 +83,37 @@ public void createDataSource3() throws IOException { public void failExport() { expected.expect(PowsyblException.class); expected.expectMessage("Export format " + UNSUPPORTED_FORMAT + " not supported"); - Exporters.export(loader, UNSUPPORTED_FORMAT, null, null, Exporters.createDataSource(path)); + Network network = Mockito.spy(Network.class); + network.write(loader, UNSUPPORTED_FORMAT, null, Exporters.createDataSource(path)); } @Test public void export1() throws IOException { DataSource dataSource = Exporters.createDataSource(path); - Exporters.export(loader, TEST_FORMAT, null, null, dataSource); - assertEquals(Byte.BYTES, dataSource.newInputStream(null, EXTENSION).read()); + Network network = Mockito.spy(Network.class); + network.write(loader, TEST_FORMAT, null, dataSource); + try (var is = dataSource.newInputStream(null, EXTENSION)) { + assertEquals(1, is.read()); + } } @Test public void export2() throws IOException { - Exporters.export(loader, TEST_FORMAT, null, null, path); + Network network = Mockito.spy(Network.class); + network.write(loader, TEST_FORMAT, null, path); DataSource dataSource = Exporters.createDataSource(path); - assertEquals(Byte.BYTES, dataSource.newInputStream(null, EXTENSION).read()); + try (var is = dataSource.newInputStream(null, EXTENSION)) { + assertEquals(1, is.read()); + } } @Test public void export3() throws IOException { Path dir = Files.createTempDirectory("tmp-export"); - Exporters.export(loader, TEST_FORMAT, null, null, dir.toString(), "tmp"); + Network network = Mockito.spy(Network.class); + network.write(loader, TEST_FORMAT, null, dir.toString(), "tmp"); try (InputStream is = Files.newInputStream(dir.resolve("tmp.tst"))) { - assertEquals(Byte.BYTES, is.read()); + assertEquals(1, is.read()); } } diff --git a/iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/import_/ImportPostProcessorMock.java b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/ImportPostProcessorMock.java similarity index 93% rename from iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/import_/ImportPostProcessorMock.java rename to iidm/iidm-api/src/test/java/com/powsybl/iidm/network/ImportPostProcessorMock.java index 38cf19e9643..761f92398ad 100644 --- a/iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/import_/ImportPostProcessorMock.java +++ b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/ImportPostProcessorMock.java @@ -4,12 +4,11 @@ * 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.import_; +package com.powsybl.iidm.network; import com.powsybl.commons.reporter.Report; import com.powsybl.commons.reporter.Reporter; import com.powsybl.computation.ComputationManager; -import com.powsybl.iidm.network.Network; import org.joda.time.DateTime; /** diff --git a/iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/import_/ImportersTest.java b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/ImportersTest.java similarity index 80% rename from iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/import_/ImportersTest.java rename to iidm/iidm-api/src/test/java/com/powsybl/iidm/network/ImportersTest.java index 2aff5698a0c..6a6efba7017 100644 --- a/iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/import_/ImportersTest.java +++ b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/ImportersTest.java @@ -4,18 +4,14 @@ * 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.import_; +package com.powsybl.iidm.network; import com.powsybl.commons.PowsyblException; import com.powsybl.commons.TestUtil; import com.powsybl.commons.datasource.DataSource; -import com.powsybl.commons.datasource.ReadOnlyDataSource; +import com.powsybl.commons.reporter.Reporter; import com.powsybl.commons.reporter.ReporterModel; import com.powsybl.computation.ComputationManager; -import com.powsybl.iidm.AbstractConvertersTest; -import com.powsybl.iidm.network.LoadType; -import com.powsybl.iidm.network.Network; -import com.powsybl.iidm.network.NetworkFactory; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -85,7 +81,7 @@ public void getImporter() { public void getImporterWithImportConfig() { Importer importer = Importer.find(loader, TEST_FORMAT, computationManager, importConfigWithPostProcessor); assertNotNull(importer); - Network network = importer.importData(null, NetworkFactory.findDefault(), null); + Network network = importer.importData(null, new NetworkFactoryMock(), null); assertNotNull(network); assertEquals(LoadType.FICTITIOUS, network.getLoad("LOAD").getLoadType()); } @@ -95,7 +91,7 @@ public void getImporterWithImportConfigAndReporter() { Importer importer = Importer.find(loader, TEST_FORMAT, computationManager, importConfigWithPostProcessor); ReporterModel reporter = new ReporterModel("testFunctionalLog", "testFunctionalLogs"); assertNotNull(importer); - Network network = importer.importData(null, NetworkFactory.findDefault(), null, reporter); + Network network = importer.importData(null, new NetworkFactoryMock(), null, reporter); assertNotNull(network); assertEquals(LoadType.FICTITIOUS, network.getLoad("LOAD").getLoadType()); @@ -127,12 +123,12 @@ public void getPostProcessorNames() { @Test public void addAndRemovePostProcessor() { Importer importer1 = Importer.addPostProcessors(loader, testImporter, computationManager, "test"); - Network network1 = importer1.importData(null, NetworkFactory.findDefault(), null); + Network network1 = importer1.importData(null, new NetworkFactoryMock(), null); assertNotNull(network1); assertEquals(LoadType.FICTITIOUS, network1.getLoad("LOAD").getLoadType()); Importer importer2 = Importer.removePostProcessors(importer1); - Network network2 = importer2.importData(null, NetworkFactory.findDefault(), null); + Network network2 = importer2.importData(null, new NetworkFactoryMock(), null); assertNotNull(network2); assertEquals(LoadType.UNDEFINED, network2.getLoad("LOAD").getLoadType()); } @@ -140,18 +136,11 @@ public void addAndRemovePostProcessor() { @Test public void setPostProcessor() { Importer importer = Importer.setPostProcessors(loader, testImporter, computationManager, "test"); - Network network = importer.importData(null, NetworkFactory.findDefault(), null); + Network network = importer.importData(null, new NetworkFactoryMock(), null); assertNotNull(network); assertEquals(LoadType.FICTITIOUS, network.getLoad("LOAD").getLoadType()); } - @Test - public void importData() throws IOException { - Network network = Importers.loadNetwork((ReadOnlyDataSource) null); - assertNotNull(network); - assertNotNull(network.getLoad("LOAD")); - } - @Test public void importBadData() { expected.expect(PowsyblException.class); @@ -162,7 +151,7 @@ public void importBadData() { @Test public void importAll() throws InterruptedException, ExecutionException, IOException { List isLoadPresent = new ArrayList<>(); - Importers.importAll(fileSystem.getPath(WORK_DIR), testImporter, false, n -> isLoadPresent.add(n.getLoad("LOAD") != null)); + Importers.importAll(fileSystem.getPath(WORK_DIR), testImporter, false, null, n -> isLoadPresent.add(n.getLoad("LOAD") != null), null, new NetworkFactoryMock(), Reporter.NO_OP); assertEquals(2, isLoadPresent.size()); isLoadPresent.forEach(Assert::assertTrue); } @@ -170,7 +159,7 @@ public void importAll() throws InterruptedException, ExecutionException, IOExcep @Test public void importAllParallel() throws InterruptedException, ExecutionException, IOException { List isLoadPresent = Collections.synchronizedList(new ArrayList<>()); - Importers.importAll(fileSystem.getPath(WORK_DIR), testImporter, true, n -> isLoadPresent.add(n.getLoad("LOAD") != null)); + Importers.importAll(fileSystem.getPath(WORK_DIR), testImporter, true, null, n -> isLoadPresent.add(n.getLoad("LOAD") != null), null, new NetworkFactoryMock(), Reporter.NO_OP); assertEquals(2, isLoadPresent.size()); isLoadPresent.forEach(Assert::assertTrue); } @@ -202,7 +191,7 @@ public void findNullImporter() { @Test public void loadNetwork1() { - Network network = Importers.loadNetwork(path, computationManager, importConfigMock, null, loader); + Network network = Network.read(path, computationManager, importConfigMock, null, new NetworkFactoryMock(), loader, Reporter.NO_OP); assertNotNull(network); assertNotNull(network.getLoad("LOAD")); } @@ -211,27 +200,29 @@ public void loadNetwork1() { public void loadNullNetwork1() { expected.expect(PowsyblException.class); expected.expectMessage("Unsupported file format or invalid file."); - Importers.loadNetwork(badPath, computationManager, importConfigMock, null, loader); + Network.read(badPath, computationManager, importConfigMock, null, new NetworkFactoryMock(), loader, Reporter.NO_OP); } @Test public void loadNetwork2() throws IOException { - Network network = Importers.loadNetwork(FOO_TST, Importers.createDataSource(path).newInputStream(null, EXTENSION), computationManager, importConfigMock, null, loader); - assertNotNull(network); - assertNotNull(network.getLoad("LOAD")); + try (var is = Importers.createDataSource(path).newInputStream(null, EXTENSION)) { + Network network = Network.read(FOO_TST, is, computationManager, importConfigMock, null, new NetworkFactoryMock(), loader, Reporter.NO_OP); + assertNotNull(network); + assertNotNull(network.getLoad("LOAD")); + } } @Test public void loadNullNetwork2() throws IOException { expected.expect(PowsyblException.class); expected.expectMessage("Unsupported file format or invalid file."); - Importers.loadNetwork("baz.txt", Importers.createDataSource(badPath).newInputStream(null, "txt"), computationManager, importConfigMock, null, loader); + Network.read("baz.txt", Importers.createDataSource(badPath).newInputStream(null, "txt"), computationManager, importConfigMock, null, new NetworkFactoryMock(), loader, Reporter.NO_OP); } @Test public void loadNetworks() throws InterruptedException, ExecutionException, IOException { List isLoadPresent = new ArrayList<>(); - Importers.loadNetworks(fileSystem.getPath(WORK_DIR), false, loader, computationManager, importConfigMock, n -> isLoadPresent.add(n.getLoad("LOAD") != null), null); + Network.readAll(fileSystem.getPath(WORK_DIR), false, loader, computationManager, importConfigMock, null, n -> isLoadPresent.add(n.getLoad("LOAD") != null), null, new NetworkFactoryMock(), Reporter.NO_OP); assertEquals(2, isLoadPresent.size()); isLoadPresent.forEach(Assert::assertTrue); } diff --git a/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/NetworkFactoryMock.java b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/NetworkFactoryMock.java new file mode 100644 index 00000000000..601ff47a8c5 --- /dev/null +++ b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/NetworkFactoryMock.java @@ -0,0 +1,37 @@ +/** + * 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; + +import org.joda.time.DateTime; +import org.mockito.Mockito; + +/** + * + * @author Geoffroy Jamgotchian + */ +public class NetworkFactoryMock implements NetworkFactory { + + @Override + public Network createNetwork(String id, String sourceFormat) { + Network network = Mockito.mock(Network.class); + Mockito.when(network.getCaseDate()) + .thenReturn(new DateTime(2021, 12, 20, 0, 0, 0)); + Load load = Mockito.mock(Load.class); + Mockito.when(network.getLoad(Mockito.anyString())) + .thenReturn(load); + LoadType[] loadType = new LoadType[1]; + loadType[0] = LoadType.UNDEFINED; + Mockito.doAnswer(invocationOnMock -> { + loadType[0] = (LoadType) invocationOnMock.getArguments()[0]; + return load; + }).when(load).setLoadType(Mockito.any(LoadType.class)); + Mockito.when(load.getLoadType()) + .thenAnswer(invocationOnMock -> loadType[0]); + + return network; + } +} diff --git a/iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/import_/PostProcessorReporterTest.java b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/PostProcessorReporterTest.java similarity index 87% rename from iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/import_/PostProcessorReporterTest.java rename to iidm/iidm-api/src/test/java/com/powsybl/iidm/network/PostProcessorReporterTest.java index b695dbcc05c..7f77f21d9c8 100644 --- a/iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/import_/PostProcessorReporterTest.java +++ b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/PostProcessorReporterTest.java @@ -4,7 +4,7 @@ * 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.import_; +package com.powsybl.iidm.network; import com.powsybl.commons.AbstractConverterTest; import com.powsybl.commons.reporter.Report; @@ -12,8 +12,6 @@ import com.powsybl.commons.reporter.ReporterModelDeserializer; import com.powsybl.commons.reporter.ReporterModelSerializer; import com.powsybl.computation.ComputationManager; -import com.powsybl.iidm.network.Network; -import com.powsybl.iidm.network.NetworkFactory; import org.joda.time.DateTime; import org.junit.Test; import org.mockito.Mockito; @@ -38,7 +36,7 @@ public class PostProcessorReporterTest extends AbstractConverterTest { public void postProcessorWithReporter() throws IOException { ReporterModel reporter = new ReporterModel("testPostProcessor", "Test importer post processor"); - Network network1 = importer1.importData(null, NetworkFactory.findDefault(), null, reporter); + Network network1 = importer1.importData(null, new NetworkFactoryMock(), null, reporter); assertNotNull(network1); Optional report = reporter.getReports().stream().findFirst(); @@ -49,7 +47,7 @@ public void postProcessorWithReporter() throws IOException { @Test public void postProcessorWithoutReporter() throws Exception { - Network network1 = importer1.importData(null, NetworkFactory.findDefault(), null); + Network network1 = importer1.importData(null, new NetworkFactoryMock(), null); importPostProcessorMock.process(network1, computationManager); assertNotNull(network1); assertEquals(new DateTime(2021, 12, 20, 0, 0, 0), network1.getCaseDate()); diff --git a/iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/export/TestExporter.java b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/TestExporter.java similarity index 93% rename from iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/export/TestExporter.java rename to iidm/iidm-api/src/test/java/com/powsybl/iidm/network/TestExporter.java index af26df8d363..794c9ad4fbe 100644 --- a/iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/export/TestExporter.java +++ b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/TestExporter.java @@ -4,11 +4,10 @@ * 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.export; +package com.powsybl.iidm.network; import com.google.auto.service.AutoService; import com.powsybl.commons.datasource.DataSource; -import com.powsybl.iidm.network.Network; import java.io.IOException; import java.io.OutputStream; diff --git a/iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/import_/TestImportPostProcessor.java b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/TestImportPostProcessor.java similarity index 85% rename from iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/import_/TestImportPostProcessor.java rename to iidm/iidm-api/src/test/java/com/powsybl/iidm/network/TestImportPostProcessor.java index 07fe80523d1..35d30c6f131 100644 --- a/iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/import_/TestImportPostProcessor.java +++ b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/TestImportPostProcessor.java @@ -4,11 +4,9 @@ * 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.import_; +package com.powsybl.iidm.network; import com.powsybl.computation.ComputationManager; -import com.powsybl.iidm.network.LoadType; -import com.powsybl.iidm.network.Network; /** * @author Miora Ralambotiana diff --git a/iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/import_/TestImporter.java b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/TestImporter.java similarity index 84% rename from iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/import_/TestImporter.java rename to iidm/iidm-api/src/test/java/com/powsybl/iidm/network/TestImporter.java index eeca7a07f41..8b029047c25 100644 --- a/iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/import_/TestImporter.java +++ b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/TestImporter.java @@ -4,14 +4,11 @@ * 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.import_; +package com.powsybl.iidm.network; import com.google.auto.service.AutoService; import com.powsybl.commons.datasource.ReadOnlyDataSource; import com.powsybl.commons.reporter.Reporter; -import com.powsybl.iidm.network.Network; -import com.powsybl.iidm.network.NetworkFactory; -import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; import java.io.IOException; import java.io.UncheckedIOException; @@ -47,6 +44,6 @@ public Network importData(ReadOnlyDataSource dataSource, NetworkFactory networkF if (reporter != null) { reporter.report("test", "Import model ${model}", "model", "eurostagTutorialExample1"); } - return EurostagTutorialExample1Factory.create(); + return networkFactory.createNetwork("mock", "test"); } } diff --git a/iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/tools/ConversionToolTest.java b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/tools/ConversionToolTest.java similarity index 90% rename from iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/tools/ConversionToolTest.java rename to iidm/iidm-api/src/test/java/com/powsybl/iidm/network/tools/ConversionToolTest.java index 01d1ce01798..48e028422c8 100644 --- a/iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/tools/ConversionToolTest.java +++ b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/tools/ConversionToolTest.java @@ -4,15 +4,17 @@ * 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.tools; +package com.powsybl.iidm.network.tools; import com.powsybl.commons.config.InMemoryPlatformConfig; import com.powsybl.commons.config.MapModuleConfig; import com.powsybl.commons.config.PlatformConfig; +import com.powsybl.iidm.network.ImportConfig; +import com.powsybl.iidm.network.NetworkFactory; +import com.powsybl.iidm.network.NetworkFactoryMock; import com.powsybl.tools.AbstractToolTest; import com.powsybl.tools.CommandLineTools; import com.powsybl.tools.Tool; -import com.powsybl.iidm.import_.ImportConfig; import org.junit.Before; import org.junit.Test; @@ -34,6 +36,11 @@ private ConversionTool createConversionTool() { protected ImportConfig createImportConfig() { return ImportConfig.load(platformConfig); } + + @Override + protected NetworkFactory createNetworkFactory() { + return new NetworkFactoryMock(); + } }; } diff --git a/iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/tools/ExporterMock.java b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/tools/ExporterMock.java similarity index 93% rename from iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/tools/ExporterMock.java rename to iidm/iidm-api/src/test/java/com/powsybl/iidm/network/tools/ExporterMock.java index 4fade698bd1..10b00c03147 100644 --- a/iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/tools/ExporterMock.java +++ b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/tools/ExporterMock.java @@ -4,11 +4,11 @@ * 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.tools; +package com.powsybl.iidm.network.tools; import com.google.auto.service.AutoService; import com.powsybl.commons.datasource.DataSource; -import com.powsybl.iidm.export.Exporter; +import com.powsybl.iidm.network.Exporter; import com.powsybl.iidm.network.Network; import java.util.Properties; diff --git a/iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/tools/ExporterMockWithReporter.java b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/tools/ExporterMockWithReporter.java similarity index 93% rename from iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/tools/ExporterMockWithReporter.java rename to iidm/iidm-api/src/test/java/com/powsybl/iidm/network/tools/ExporterMockWithReporter.java index 3de8e31e48c..0331b41ea55 100644 --- a/iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/tools/ExporterMockWithReporter.java +++ b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/tools/ExporterMockWithReporter.java @@ -4,13 +4,13 @@ * 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.tools; +package com.powsybl.iidm.network.tools; import com.google.auto.service.AutoService; import com.powsybl.commons.datasource.DataSource; import com.powsybl.commons.reporter.Report; import com.powsybl.commons.reporter.Reporter; -import com.powsybl.iidm.export.Exporter; +import com.powsybl.iidm.network.Exporter; import com.powsybl.iidm.network.Network; import java.util.Properties; diff --git a/iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/tools/ImporterMock.java b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/tools/ImporterMock.java similarity index 95% rename from iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/tools/ImporterMock.java rename to iidm/iidm-api/src/test/java/com/powsybl/iidm/network/tools/ImporterMock.java index 45c9f3cc3b8..87bacebe09b 100644 --- a/iidm/iidm-converter-api/src/test/java/com/powsybl/iidm/tools/ImporterMock.java +++ b/iidm/iidm-api/src/test/java/com/powsybl/iidm/network/tools/ImporterMock.java @@ -4,12 +4,12 @@ * 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.tools; +package com.powsybl.iidm.network.tools; import com.google.auto.service.AutoService; import com.powsybl.commons.datasource.DataSource; import com.powsybl.commons.datasource.ReadOnlyDataSource; -import com.powsybl.iidm.import_.Importer; +import com.powsybl.iidm.network.Importer; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.NetworkFactory; import com.powsybl.commons.parameters.Parameter; diff --git a/iidm/iidm-converter-api/src/test/resources/export-parameters.properties b/iidm/iidm-api/src/test/resources/export-parameters.properties similarity index 100% rename from iidm/iidm-converter-api/src/test/resources/export-parameters.properties rename to iidm/iidm-api/src/test/resources/export-parameters.properties diff --git a/iidm/iidm-converter-api/src/test/resources/exportReporterTest.txt b/iidm/iidm-api/src/test/resources/exportReporterTest.txt similarity index 100% rename from iidm/iidm-converter-api/src/test/resources/exportReporterTest.txt rename to iidm/iidm-api/src/test/resources/exportReporterTest.txt diff --git a/iidm/iidm-converter-api/src/test/resources/import-parameters.xml b/iidm/iidm-api/src/test/resources/import-parameters.xml similarity index 100% rename from iidm/iidm-converter-api/src/test/resources/import-parameters.xml rename to iidm/iidm-api/src/test/resources/import-parameters.xml diff --git a/iidm/iidm-converter-api/src/test/resources/postProcessorReporterTest.json b/iidm/iidm-api/src/test/resources/postProcessorReporterTest.json similarity index 100% rename from iidm/iidm-converter-api/src/test/resources/postProcessorReporterTest.json rename to iidm/iidm-api/src/test/resources/postProcessorReporterTest.json diff --git a/iidm/iidm-converter-api/pom.xml b/iidm/iidm-converter-api/pom.xml deleted file mode 100644 index 1dc41a66c07..00000000000 --- a/iidm/iidm-converter-api/pom.xml +++ /dev/null @@ -1,123 +0,0 @@ - - - - 4.0.0 - - - com.powsybl - powsybl-iidm - 4.11.0-SNAPSHOT - - - powsybl-iidm-converter-api - IIDM converter API - An API to import and export IIDM networks - - - - - org.apache.maven.plugins - maven-jar-plugin - - - - com.powsybl.iidm.converter.api - - - - - - - - - - - com.google.auto.service - auto-service - - - org.slf4j - slf4j-api - - - ${project.groupId} - powsybl-computation - ${project.version} - - - ${project.groupId} - powsybl-computation-local - ${project.version} - - - ${project.groupId} - powsybl-iidm-api - ${project.version} - - - - - com.google.jimfs - jimfs - test - - - junit - junit - test - - - org.mockito - mockito-core - test - - - org.slf4j - slf4j-simple - test - - - ${project.groupId} - powsybl-config-test - ${project.version} - test - - - ${project.groupId} - powsybl-iidm-impl - ${project.version} - test - - - ${project.groupId} - powsybl-iidm-test - ${project.version} - test - - - ${project.groupId} - powsybl-tools - ${project.version} - test-jar - test - - - ${project.groupId} - powsybl-commons - ${project.version} - test - test-jar - - - - - diff --git a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/export/Exporters.java b/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/export/Exporters.java deleted file mode 100644 index a73298a9b63..00000000000 --- a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/export/Exporters.java +++ /dev/null @@ -1,121 +0,0 @@ -/** - * Copyright (c) 2016, All partners of the iTesla project (http://www.itesla-project.eu/consortium) - * 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.export; - -import com.powsybl.commons.PowsyblException; -import com.powsybl.commons.datasource.DataSource; -import com.powsybl.commons.datasource.DataSourceObserver; -import com.powsybl.commons.datasource.DataSourceUtil; -import com.powsybl.commons.datasource.FileDataSource; -import com.powsybl.commons.reporter.Reporter; -import com.powsybl.iidm.network.Network; - -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Objects; -import java.util.Properties; - -/** - * A utility class to work with IIDM exporters. - * - * @author Geoffroy Jamgotchian - */ -public final class Exporters { - - private Exporters() { - } - - public static DataSource createDataSource(Path directory, String fileNameOrBaseName, DataSourceObserver observer) { - return DataSourceUtil.createDataSource(directory, fileNameOrBaseName, observer); - } - - public static DataSource createDataSource(Path file, DataSourceObserver observer) { - Objects.requireNonNull(file); - if (Files.exists(file) && !Files.isRegularFile(file)) { - throw new UncheckedIOException(new IOException("File " + file + " already exists and is not a regular file")); - } - Path absFile = file.toAbsolutePath(); - return createDataSource(absFile.getParent(), absFile.getFileName().toString(), observer); - } - - public static DataSource createDataSource(Path file) { - return createDataSource(file, null); - } - - /** - * A convenient method to export a model to a given format. - * - * @param format the export format - * @param network the model - * @param parameters some properties to configure the export - * @param dataSource data source - * @param reporter the reporter used for functional logs - */ - public static void export(ExportersLoader loader, String format, Network network, Properties parameters, DataSource dataSource, Reporter reporter) { - Exporter exporter = Exporter.find(loader, format); - if (exporter == null) { - throw new PowsyblException("Export format " + format + " not supported"); - } - exporter.export(network, parameters, dataSource, reporter); - } - - public static void export(ExportersLoader loader, String format, Network network, Properties parameters, DataSource dataSource) { - export(loader, format, network, parameters, dataSource, Reporter.NO_OP); - } - - public static void export(String format, Network network, Properties parameters, DataSource dataSource) { - export(new ExportersServiceLoader(), format, network, parameters, dataSource); - } - - /** - * A convenient method to export a model to a given format. - * - * @param format the export format - * @param network the model - * @param parameters some properties to configure the export - * @param file the network file - * @param reporter the reporter used for functional logs - */ - public static void export(ExportersLoader loader, String format, Network network, Properties parameters, Path file, Reporter reporter) { - DataSource dataSource = createDataSource(file); - export(loader, format, network, parameters, dataSource, reporter); - } - - public static void export(ExportersLoader loader, String format, Network network, Properties parameters, Path file) { - export(loader, format, network, parameters, file, Reporter.NO_OP); - } - - public static void export(String format, Network network, Properties parameters, Path file) { - export(new ExportersServiceLoader(), format, network, parameters, file); - } - - /** - * A convenient method to export a model to a given format. - * - * @param format the export format - * @param network the model - * @param parameters some properties to configure the export - * @param directory the output directory where files are generated - * @param baseName a base name for all generated files - * @param reporter the reporter used for functional logs - */ - public static void export(ExportersLoader loader, String format, Network network, Properties parameters, String directory, String baseName, Reporter reporter) { - export(loader, format, network, parameters, new FileDataSource(Paths.get(directory), baseName), reporter); - } - - public static void export(ExportersLoader loader, String format, Network network, Properties parameters, String directory, String basename) { - export(loader, format, network, parameters, directory, basename, Reporter.NO_OP); - } - - public static void export(String format, Network network, Properties parameters, String directory, String baseName) { - export(new ExportersServiceLoader(), format, network, parameters, directory, baseName); - } - -} diff --git a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/Importers.java b/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/Importers.java deleted file mode 100644 index 49aabb2a9ca..00000000000 --- a/iidm/iidm-converter-api/src/main/java/com/powsybl/iidm/import_/Importers.java +++ /dev/null @@ -1,447 +0,0 @@ -/** - * Copyright (c) 2016, All partners of the iTesla project (http://www.itesla-project.eu/consortium) - * 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.import_; - -import com.powsybl.commons.PowsyblException; -import com.powsybl.commons.datasource.*; -import com.powsybl.commons.reporter.Reporter; -import com.powsybl.computation.ComputationManager; -import com.powsybl.computation.local.LocalComputationManager; -import com.powsybl.iidm.network.Network; -import com.powsybl.iidm.network.NetworkFactory; -import com.powsybl.commons.parameters.Parameter; -import com.powsybl.commons.parameters.ParameterDefaultValueConfig; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.io.InputStream; -import java.io.UncheckedIOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.*; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -/** - * A utility class to work with IIDM importers. - * - * @author Geoffroy Jamgotchian - */ -public final class Importers { - - private static final Logger LOGGER = LoggerFactory.getLogger(Importers.class); - - private static final String UNSUPPORTED_FILE_FORMAT_OR_INVALID_FILE = "Unsupported file format or invalid file."; - - private Importers() { - } - - /** - * A convenient method to create a model from data in a given format. - * - * @param format the import format - * @param dataSource data source - * @param parameters some properties to configure the import - * @param computationManager computation manager to use for default post processors - * @param config the import configuration - * @param reporter the reporter used for functional logs - * @return the model - */ - public static Network importData(ImportersLoader loader, String format, ReadOnlyDataSource dataSource, Properties parameters, ComputationManager computationManager, ImportConfig config, Reporter reporter) { - Importer importer = Importer.find(loader, format, computationManager, config); - if (importer == null) { - throw new PowsyblException("Import format " + format + " not supported"); - } - return importer.importData(dataSource, NetworkFactory.findDefault(), parameters, reporter); - } - - public static Network importData(ImportersLoader loader, String format, ReadOnlyDataSource dataSource, Properties parameters, ComputationManager computationManager, ImportConfig config) { - return importData(loader, format, dataSource, parameters, computationManager, config, Reporter.NO_OP); - } - - public static Network importData(String format, ReadOnlyDataSource dataSource, Properties parameters, ComputationManager computationManager, Reporter reporter) { - return importData(new ImportersServiceLoader(), format, dataSource, parameters, computationManager, ImportConfig.CACHE.get(), reporter); - } - - public static Network importData(String format, ReadOnlyDataSource dataSource, Properties parameters, ComputationManager computationManager) { - return importData(new ImportersServiceLoader(), format, dataSource, parameters, computationManager, ImportConfig.CACHE.get(), Reporter.NO_OP); - } - - public static Network importData(String format, ReadOnlyDataSource dataSource, Properties parameters, Reporter reporter) { - return importData(new ImportersServiceLoader(), format, dataSource, parameters, LocalComputationManager.getDefault(), ImportConfig.CACHE.get(), reporter); - } - - public static Network importData(String format, ReadOnlyDataSource dataSource, Properties parameters) { - return importData(format, dataSource, parameters, LocalComputationManager.getDefault()); - } - - /** - * A convenient method to create a model from data in a given format. - * - * @param format the import format - * @param directory the directory where input files are - * @param baseName a base name for all input files - * @param parameters some properties to configure the import - * @return the model - */ - public static Network importData(String format, String directory, String baseName, Properties parameters) { - return importData(format, new FileDataSource(Paths.get(directory), baseName), parameters); - } - - private static void doImport(ReadOnlyDataSource dataSource, Importer importer, Properties parameters, Consumer consumer, Consumer listener, Reporter reporter) { - Objects.requireNonNull(consumer); - try { - if (listener != null) { - listener.accept(dataSource); - } - Network network = importer.importData(dataSource, NetworkFactory.findDefault(), parameters, reporter); - consumer.accept(network); - } catch (Exception e) { - LOGGER.error(e.toString(), e); - } - } - - private static void addDataSource(Path dir, Path file, Importer importer, List dataSources) { - Objects.requireNonNull(importer); - String caseBaseName = DataSourceUtil.getBaseName(file); - ReadOnlyDataSource ds = new GenericReadOnlyDataSource(dir, caseBaseName); - if (importer.exists(ds)) { - dataSources.add(ds); - } - } - - private static void importAll(Path parent, Importer importer, List dataSources) throws IOException { - if (Files.isDirectory(parent)) { - try (Stream stream = Files.list(parent)) { - stream.sorted().forEach(child -> { - if (Files.isDirectory(child)) { - try { - importAll(child, importer, dataSources); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - } else { - addDataSource(parent, child, importer, dataSources); - } - }); - } - } else { - if (parent.getParent() != null) { - addDataSource(parent.getParent(), parent, importer, dataSources); - } - } - } - - public static void importAll(Path dir, Importer importer, boolean parallel, Properties parameters, Consumer consumer, Consumer listener, Reporter reporter) throws IOException, InterruptedException, ExecutionException { - List dataSources = new ArrayList<>(); - importAll(dir, importer, dataSources); - if (parallel) { - ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); - try { - List> futures = dataSources.stream() - .map(ds -> { - Reporter child = createSubReporter(reporter, ds); - return executor.submit(() -> doImport(ds, importer, parameters, consumer, listener, child)); - }) - .collect(Collectors.toList()); - for (Future future : futures) { - future.get(); - } - } finally { - executor.shutdownNow(); - } - } else { - for (ReadOnlyDataSource dataSource : dataSources) { - doImport(dataSource, importer, parameters, consumer, listener, createSubReporter(reporter, dataSource)); - } - } - } - - private static Reporter createSubReporter(Reporter reporter, ReadOnlyDataSource ds) { - return reporter.createSubReporter("importDataSource", "Import data source ${dataSource}", "dataSource", ds.getBaseName()); - } - - public static void importAll(Path dir, Importer importer, boolean parallel, Consumer consumer, Consumer listener) throws IOException, InterruptedException, ExecutionException { - importAll(dir, importer, parallel, null, consumer, listener, Reporter.NO_OP); - } - - public static void importAll(Path dir, Importer importer, boolean parallel, Consumer consumer) throws IOException, InterruptedException, ExecutionException { - importAll(dir, importer, parallel, consumer, null); - } - - /** - * @deprecated Use {@link Parameter#read(String, Properties, Parameter)} instead - */ - @Deprecated - public static Object readParameter(String format, Properties parameters, Parameter configuredParameter) { - return Parameter.read(format, parameters, configuredParameter); - } - - /** - * @deprecated Use {@link Parameter#read(String, Properties, Parameter, ParameterDefaultValueConfig)} instead - */ - @Deprecated - public static Object readParameter(String format, Properties parameters, Parameter configuredParameter, ParameterDefaultValueConfig defaultValueConfig) { - return Parameter.read(format, parameters, configuredParameter, defaultValueConfig); - } - - public static DataSource createDataSource(Path file) { - Objects.requireNonNull(file); - if (!Files.isRegularFile(file)) { - throw new PowsyblException("File " + file + " does not exist or is not a regular file"); - } - Path absFile = file.toAbsolutePath(); - return createDataSource(absFile.getParent(), absFile.getFileName().toString()); - } - - public static DataSource createDataSource(Path directory, String fileNameOrBaseName) { - return DataSourceUtil.createDataSource(directory, fileNameOrBaseName, null); - } - - /** - * Loads a network from the specified file, trying to guess its format. - * - * @param file The file to be loaded. - * @param computationManager A computation manager which may be used by import post-processors - * @param config The import config, in particular definition of post processors - * @param parameters Import-specific parameters - * @param loader Provides the list of available importers and post-processors - * @param reporter The reporter used for functional logs - * @return The loaded network - */ - public static Network loadNetwork(Path file, ComputationManager computationManager, ImportConfig config, Properties parameters, ImportersLoader loader, Reporter reporter) { - ReadOnlyDataSource dataSource = createDataSource(file); - Importer importer = Importer.find(dataSource, loader, computationManager, config); - if (importer != null) { - return importer.importData(dataSource, NetworkFactory.findDefault(), parameters, reporter); - } - throw new PowsyblException(UNSUPPORTED_FILE_FORMAT_OR_INVALID_FILE); - } - - /** - * Loads a network from the specified file, trying to guess its format. - * - * @param file The file to be loaded. - * @param computationManager A computation manager which may be used by import post-processors - * @param config The import config, in particular definition of post processors - * @param parameters Import-specific parameters - * @param loader Provides the list of available importers and post-processors - * @return The loaded network - */ - public static Network loadNetwork(Path file, ComputationManager computationManager, ImportConfig config, Properties parameters, ImportersLoader loader) { - return loadNetwork(file, computationManager, config, parameters, loader, Reporter.NO_OP); - } - - /** - * Loads a network from the specified file, trying to guess its format, - * and using importers and post processors defined as services. - * - * @param file The file to be loaded. - * @param computationManager A computation manager which may be used by import post-processors - * @param config The import config, in particular definition of post processors - * @param parameters Import-specific parameters - * @return The loaded network - */ - public static Network loadNetwork(Path file, ComputationManager computationManager, ImportConfig config, Properties parameters) { - return loadNetwork(file, computationManager, config, parameters, new ImportersServiceLoader()); - } - - /** - * Loads a network from the specified file, trying to guess its format, - * and using importers and post processors defined as services. - * Import will be performed using import configuration defined in default platform config, - * and with no importer-specific parameters. - * Post processors will use the default {@link LocalComputationManager}, as defined in - * default platform config. - * - * @param file The file to be loaded. - * @return The loaded network - */ - public static Network loadNetwork(Path file) { - return loadNetwork(file, LocalComputationManager.getDefault(), ImportConfig.CACHE.get(), null); - } - - /** - * Loads a network from the specified file path, see {@link #loadNetwork(Path)}. - * - * @param file The file to be loaded. - * @return The loaded network - */ - public static Network loadNetwork(String file) { - return loadNetwork(Paths.get(file)); - } - - /** - * Loads a network from a raw input stream, trying to guess the format from the specified filename. - * Please note that the input stream must be from a simple file, not a zipped one. - * - * @param filename The name of the file to be imported. - * @param data The raw data from which the network should be loaded - * @param computationManager A computation manager which may be used by import post-processors - * @param config The import config, in particular definition of post processors - * @param parameters Import-specific parameters - * @param loader Provides the list of available importers and post-processors - * @param reporter The reporter used for functional logs - * @return The loaded network - */ - public static Network loadNetwork(String filename, InputStream data, ComputationManager computationManager, ImportConfig config, Properties parameters, ImportersLoader loader, Reporter reporter) { - ReadOnlyMemDataSource dataSource = new ReadOnlyMemDataSource(DataSourceUtil.getBaseName(filename)); - dataSource.putData(filename, data); - Importer importer = Importer.find(dataSource, loader, computationManager, config); - if (importer != null) { - return importer.importData(dataSource, NetworkFactory.findDefault(), parameters, reporter); - } - throw new PowsyblException(UNSUPPORTED_FILE_FORMAT_OR_INVALID_FILE); - } - - /** - * Loads a network from a raw input stream, trying to guess the format from the specified filename. - * Please note that the input stream must be from a simple file, not a zipped one. - * - * @param filename The name of the file to be imported. - * @param data The raw data from which the network should be loaded - * @param computationManager A computation manager which may be used by import post-processors - * @param config The import config, in particular definition of post processors - * @param parameters Import-specific parameters - * @param loader Provides the list of available importers and post-processors - * @return The loaded network - */ - public static Network loadNetwork(String filename, InputStream data, ComputationManager computationManager, ImportConfig config, Properties parameters, ImportersLoader loader) { - return loadNetwork(filename, data, computationManager, config, parameters, loader, Reporter.NO_OP); - } - - /** - * Loads a network from a raw input stream, trying to guess the format from the specified filename, - * and using importers and post processors defined as services. - * Please note that the input stream must be from a simple file, not a zipped one. - * - * @param filename The name of the file to be imported. - * @param data The raw data from which the network should be loaded - * @param computationManager A computation manager which may be used by import post-processors - * @param config The import config, in particular definition of post processors - * @param parameters Import-specific parameters - * @return The loaded network - */ - public static Network loadNetwork(String filename, InputStream data, ComputationManager computationManager, ImportConfig config, Properties parameters) { - return loadNetwork(filename, data, computationManager, config, parameters, new ImportersServiceLoader()); - } - - /** - * Loads a network from a raw input stream, trying to guess the format from the specified filename, - * and using importers and post processors defined as services. - * Import will be performed using import configuration defined in default platform config, - * and with no importer-specific parameters. - * Please note that the input stream must be from a simple file, not a zipped one. - * - * @param filename The name of the file to be imported. - * @param data The raw data from which the network should be loaded - * @param computationManager A computation manager which may be used by import post-processors - * @return The loaded network - */ - public static Network loadNetwork(String filename, InputStream data, ComputationManager computationManager) { - return loadNetwork(filename, data, computationManager, ImportConfig.CACHE.get(), null); - } - - /** - * Loads a network from a raw input stream, trying to guess the format from the specified filename, - * and using importers and post processors defined as services. - * Import will be performed using import configuration defined in default platform config, - * and with no importer-specific parameters. - * Post processors will use the default {@link LocalComputationManager}, as defined in - * default platform config. - * Please note that the input stream must be from a simple file, not a zipped one. - * - * @param filename The name of the file to be imported. - * @param data The raw data from which the network should be loaded - * @return The loaded network - */ - public static Network loadNetwork(String filename, InputStream data) { - return loadNetwork(filename, data, LocalComputationManager.getDefault()); - } - - /** - * Loads a network from a raw input stream, trying to guess the format from the specified filename, - * and using importers and post processors defined as services. - * Import will be performed using import configuration defined in default platform config, - * and with no importer-specific parameters. - * Post processors will use the default {@link LocalComputationManager}, as defined in - * default platform config. - * Please note that the input stream must be from a simple file, not a zipped one. - * - * @param filename The name of the file to be imported. - * @param data The raw data from which the network should be loaded - * @param reporter The reporter used for functional logs - * @return The loaded network - */ - public static Network loadNetwork(String filename, InputStream data, Reporter reporter) { - return loadNetwork(filename, data, LocalComputationManager.getDefault(), ImportConfig.CACHE.get(), null, new ImportersServiceLoader(), reporter); - } - - public static Network loadNetwork(ReadOnlyDataSource dataSource) { - return loadNetwork(dataSource, null); - } - - public static Network loadNetwork(ReadOnlyDataSource dataSource, Properties properties) { - return loadNetwork(dataSource, properties, Reporter.NO_OP); - } - - public static Network loadNetwork(ReadOnlyDataSource dataSource, Properties properties, Reporter reporter) { - Importer importer = Importer.find(dataSource); - if (importer != null) { - return importer.importData(dataSource, NetworkFactory.findDefault(), properties, reporter); - } - throw new PowsyblException(UNSUPPORTED_FILE_FORMAT_OR_INVALID_FILE); - } - - public static void loadNetworks(Path dir, boolean parallel, ImportersLoader loader, ComputationManager computationManager, ImportConfig config, Properties parameters, Consumer consumer, Consumer listener, Reporter reporter) throws IOException, InterruptedException, ExecutionException { - if (!Files.isDirectory(dir)) { - throw new PowsyblException("Directory " + dir + " does not exist or is not a regular directory"); - } - for (Importer importer : Importer.list(loader, computationManager, config)) { - Importers.importAll(dir, importer, parallel, parameters, consumer, listener, reporter); - } - } - - public static void loadNetworks(Path dir, boolean parallel, ImportersLoader loader, ComputationManager computationManager, ImportConfig config, Properties parameters, Consumer consumer, Consumer listener) throws IOException, InterruptedException, ExecutionException { - loadNetworks(dir, parallel, loader, computationManager, config, parameters, consumer, listener, Reporter.NO_OP); - } - - public static void loadNetworks(Path dir, boolean parallel, ImportersLoader loader, ComputationManager computationManager, ImportConfig config, Consumer consumer, Consumer listener) throws IOException, InterruptedException, ExecutionException { - loadNetworks(dir, parallel, loader, computationManager, config, null, consumer, listener); - } - - public static void loadNetworks(Path dir, boolean parallel, ComputationManager computationManager, ImportConfig config, Properties parameters, Consumer consumer, Consumer listener) throws IOException, InterruptedException, ExecutionException { - loadNetworks(dir, parallel, new ImportersServiceLoader(), computationManager, config, parameters, consumer, listener); - } - - public static void loadNetworks(Path dir, boolean parallel, ComputationManager computationManager, ImportConfig config, Consumer consumer, Consumer listener) throws IOException, InterruptedException, ExecutionException { - loadNetworks(dir, parallel, new ImportersServiceLoader(), computationManager, config, consumer, listener); - } - - public static void loadNetworks(Path dir, boolean parallel, ComputationManager computationManager, ImportConfig config, Consumer consumer) throws IOException, InterruptedException, ExecutionException { - loadNetworks(dir, parallel, computationManager, config, consumer, null); - } - - public static void loadNetworks(Path dir, boolean parallel, Consumer consumer) throws IOException, InterruptedException, ExecutionException { - loadNetworks(dir, parallel, LocalComputationManager.getDefault(), ImportConfig.CACHE.get(), consumer); - } - - public static void loadNetworks(Path dir, boolean parallel, Consumer consumer, Consumer listener) throws IOException, InterruptedException, ExecutionException { - loadNetworks(dir, parallel, LocalComputationManager.getDefault(), ImportConfig.CACHE.get(), consumer, listener); - } - - public static void loadNetworks(Path dir, Consumer consumer) throws IOException, InterruptedException, ExecutionException { - loadNetworks(dir, false, LocalComputationManager.getDefault(), ImportConfig.CACHE.get(), consumer); - } -} diff --git a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/CreateBranchFeederBaysTest.java b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/CreateBranchFeederBaysTest.java index 84e9fa43144..c7b55991977 100644 --- a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/CreateBranchFeederBaysTest.java +++ b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/CreateBranchFeederBaysTest.java @@ -8,12 +8,8 @@ import com.powsybl.commons.PowsyblException; import com.powsybl.commons.reporter.Reporter; -import com.powsybl.iidm.import_.Importers; import com.powsybl.iidm.modification.NetworkModification; -import com.powsybl.iidm.network.Line; -import com.powsybl.iidm.network.LineAdder; -import com.powsybl.iidm.network.Network; -import com.powsybl.iidm.network.TwoWindingsTransformerAdder; +import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.ConnectablePosition; import com.powsybl.iidm.xml.AbstractXmlConverterTest; import com.powsybl.iidm.xml.NetworkXml; @@ -34,7 +30,7 @@ */ public class CreateBranchFeederBaysTest extends AbstractXmlConverterTest { - private Network network = Importers.loadNetwork("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); + private Network network = Network.read("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); @Test public void baseLineTest() throws IOException { @@ -186,7 +182,7 @@ public void testException() { .setB2(0.0); //wrong network - Network network1 = Importers.loadNetwork("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); + Network network1 = Network.read("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); CreateBranchFeederBays modification0 = new CreateBranchFeederBaysBuilder(). withBranchAdder(lineAdder) .withBbsId1("bbs1") @@ -253,7 +249,7 @@ public void baseTwoWindingsTransformerTest() throws IOException { @Test public void testWithoutExtension() { - network = Importers.loadNetwork("testNetworkNodeBreakerWithoutExtensions.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreakerWithoutExtensions.xiidm")); + network = Network.read("testNetworkNodeBreakerWithoutExtensions.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreakerWithoutExtensions.xiidm")); LineAdder lineAdder = network.newLine() .setId("lineTest") .setR(1.0) diff --git a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/CreateCouplingDeviceTest.java b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/CreateCouplingDeviceTest.java index 585233c91ee..ad4789bd729 100644 --- a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/CreateCouplingDeviceTest.java +++ b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/CreateCouplingDeviceTest.java @@ -8,7 +8,6 @@ import com.powsybl.commons.PowsyblException; import com.powsybl.commons.reporter.Reporter; -import com.powsybl.iidm.import_.Importers; import com.powsybl.iidm.modification.NetworkModification; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.xml.AbstractXmlConverterTest; @@ -27,7 +26,7 @@ public class CreateCouplingDeviceTest extends AbstractXmlConverterTest { @Test public void createCouplingDevice2BusbarSectionsSameSectionIndex() throws IOException { - Network network = Importers.loadNetwork("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); + Network network = Network.read("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); NetworkModification couplingDeviceModif = new CreateCouplingDeviceBuilder() .withBusbarSectionId1("bbs1") .withBusbarSectionId2("bbs3") @@ -40,7 +39,7 @@ public void createCouplingDevice2BusbarSectionsSameSectionIndex() throws IOExcep @Test public void createCouplingDevice2BusbarSectionsDifferentSectionIndex() throws IOException { - Network network = Importers.loadNetwork("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); + Network network = Network.read("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); NetworkModification couplingDeviceModif = new CreateCouplingDeviceBuilder() .withBusbarSectionId1("bbs1") .withBusbarSectionId2("bbs2") @@ -52,7 +51,7 @@ public void createCouplingDevice2BusbarSectionsDifferentSectionIndex() throws IO @Test public void createCouplingDeviceThrowsException() { - Network network = Importers.loadNetwork("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); + Network network = Network.read("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); NetworkModification couplingDeviceModifWrongBbs = new CreateCouplingDeviceBuilder() .withBusbarSectionId1("bbs") @@ -78,7 +77,7 @@ public void createCouplingDeviceThrowsException() { @Test public void createCouplingDeviceWithoutPositionExtensions() throws IOException { - Network network = Importers.loadNetwork("testNetworkNodeBreakerWithoutExtensions.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreakerWithoutExtensions.xiidm")); + Network network = Network.read("testNetworkNodeBreakerWithoutExtensions.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreakerWithoutExtensions.xiidm")); NetworkModification modification = new CreateCouplingDeviceBuilder() .withBusbarSectionId1("bbs1") .withBusbarSectionId2("bbs2") @@ -90,7 +89,7 @@ public void createCouplingDeviceWithoutPositionExtensions() throws IOException { @Test public void createCouplingDevice3BusbarSections() throws IOException { - Network network = Importers.loadNetwork("testNetwork3BusbarSections.xiidm", getClass().getResourceAsStream("/testNetwork3BusbarSections.xiidm")); + Network network = Network.read("testNetwork3BusbarSections.xiidm", getClass().getResourceAsStream("/testNetwork3BusbarSections.xiidm")); NetworkModification modification = new CreateCouplingDeviceBuilder() .withBusbarSectionId1("VLTEST13") .withBusbarSectionId2("VLTEST23") diff --git a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/CreateFeederBayTest.java b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/CreateFeederBayTest.java index 166870ac2dd..15c3ef2c8e0 100644 --- a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/CreateFeederBayTest.java +++ b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/CreateFeederBayTest.java @@ -8,7 +8,6 @@ import com.powsybl.commons.PowsyblException; import com.powsybl.commons.reporter.Reporter; -import com.powsybl.iidm.import_.Importers; import com.powsybl.iidm.modification.NetworkModification; import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.ConnectablePosition; @@ -33,7 +32,7 @@ public class CreateFeederBayTest extends AbstractXmlConverterTest { @Test public void baseLoadTest() throws IOException { - Network network = Importers.loadNetwork("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); + Network network = Network.read("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); LoadAdder loadAdder = network.getVoltageLevel("vl1").newLoad() .setId("newLoad") .setLoadType(LoadType.UNDEFINED) @@ -53,7 +52,7 @@ public void baseLoadTest() throws IOException { @Test public void getUnusedOrderPositionAfter() { - Network network = Importers.loadNetwork("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); + Network network = Network.read("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); LoadAdder loadAdder = network.getVoltageLevel("vl1").newLoad() .setId("newLoad") .setLoadType(LoadType.UNDEFINED) @@ -80,7 +79,7 @@ public void getUnusedOrderPositionAfter() { @Test public void getUnusedOrderPositionBefore() { - Network network = Importers.loadNetwork("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); + Network network = Network.read("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); LoadAdder loadAdder = network.getVoltageLevel("vl1").newLoad() .setId("newLoad") .setLoadType(LoadType.UNDEFINED) @@ -107,14 +106,14 @@ public void getUnusedOrderPositionBefore() { @Test public void testException() { - Network network = Importers.loadNetwork("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); + Network network = Network.read("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); LoadAdder loadAdder = network.getVoltageLevel("vl1").newLoad() .setId("newLoad") .setLoadType(LoadType.UNDEFINED) .setP0(0) .setQ0(0); //wrong network - Network network1 = Importers.loadNetwork("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); + Network network1 = Network.read("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); CreateFeederBay modification0 = new CreateFeederBayBuilder(). withInjectionAdder(loadAdder) .withBbsId("bbs1") @@ -147,7 +146,7 @@ public void testException() { @Test public void baseGeneratorTest() throws IOException { - Network network = Importers.loadNetwork("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); + Network network = Network.read("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); GeneratorAdder generatorAdder = network.getVoltageLevel("vl1").newGenerator() .setId("newGenerator") .setVoltageRegulatorOn(true) @@ -172,7 +171,7 @@ public void baseGeneratorTest() throws IOException { @Test public void baseEquipmentsTest() throws IOException { - Network network = Importers.loadNetwork("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); + Network network = Network.read("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); BatteryAdder batteryAdder = network.getVoltageLevel("vl1").newBattery() .setId("newBattery") .setMaxP(9999) @@ -291,7 +290,7 @@ public void baseEquipmentsTest() throws IOException { @Test public void testWithoutExtension() { - Network network = Importers.loadNetwork("testNetworkNodeBreakerWithoutExtensions.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreakerWithoutExtensions.xiidm")); + Network network = Network.read("testNetworkNodeBreakerWithoutExtensions.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreakerWithoutExtensions.xiidm")); LoadAdder loadAdder = network.getVoltageLevel("vl1").newLoad() .setId("newLoad") .setLoadType(LoadType.UNDEFINED) @@ -320,7 +319,7 @@ public void testWithoutExtension() { @Test public void testExtensionsAreCreatedIfNoOtherConnectables() { - Network network = Importers.loadNetwork("network_one_voltage_level.xiidm", getClass().getResourceAsStream("/network_one_voltage_level.xiidm")); + Network network = Network.read("network_one_voltage_level.xiidm", getClass().getResourceAsStream("/network_one_voltage_level.xiidm")); LoadAdder loadAdder = network.getVoltageLevel("VLTEST").newLoad() .setId("newLoad") .setLoadType(LoadType.UNDEFINED) diff --git a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/TopologyModificationUtilsTest.java b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/TopologyModificationUtilsTest.java index a0d9327612e..ed6459ea948 100644 --- a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/TopologyModificationUtilsTest.java +++ b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/TopologyModificationUtilsTest.java @@ -6,11 +6,7 @@ */ package com.powsybl.iidm.modification.topology; -import com.powsybl.iidm.import_.Importers; -import com.powsybl.iidm.network.BusbarSection; -import com.powsybl.iidm.network.Network; -import com.powsybl.iidm.network.TopologyKind; -import com.powsybl.iidm.network.VoltageLevel; +import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.BusbarSectionPosition; import com.powsybl.iidm.network.impl.extensions.BusbarSectionPositionImpl; import com.powsybl.iidm.xml.AbstractXmlConverterTest; @@ -34,7 +30,7 @@ public class TopologyModificationUtilsTest extends AbstractXmlConverterTest { @Test public void testFeederOrders() { - Network network = Importers.loadNetwork("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); + Network network = Network.read("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); Set feederOrders = TopologyModificationUtils.getFeederPositions(network.getVoltageLevel("vl1")); assertEquals(13, feederOrders.size()); assertTrue(feederOrders.contains(100)); @@ -46,7 +42,7 @@ public void testFeederOrders() { @Test public void testGetPositionsByConnectable() { - Network network = Importers.loadNetwork("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); + Network network = Network.read("testNetworkNodeBreaker.xiidm", getClass().getResourceAsStream("/testNetworkNodeBreaker.xiidm")); Map> positionsByConnectable = getFeederPositionsByConnectable(network.getVoltageLevel("vl1")); assertTrue(positionsByConnectable.containsKey("load1")); assertEquals(List.of(70), positionsByConnectable.get("line1")); @@ -55,7 +51,7 @@ public void testGetPositionsByConnectable() { @Test public void testGetPositionsByConnectableWithInternalLine() { - Network network = Importers.loadNetwork("network-node-breaker-with-new-internal-line.xml", getClass().getResourceAsStream("/network-node-breaker-with-new-internal-line.xml")); + Network network = Network.read("network-node-breaker-with-new-internal-line.xml", getClass().getResourceAsStream("/network-node-breaker-with-new-internal-line.xml")); Map> positionsByConnectable = getFeederPositionsByConnectable(network.getVoltageLevel("vl1")); assertEquals(List.of(14, 105), positionsByConnectable.get("lineTest")); assertEquals(14, positionsByConnectable.size()); @@ -81,7 +77,7 @@ public void testGetUnusedPositionsWithEmptyVoltageLevel() { @Test public void testNoConnectablePositionExt() { - Network network = Importers.loadNetwork("network-nb-no-connectable-position.xiidm", getClass().getResourceAsStream("/network-nb-no-connectable-position.xiidm")); + Network network = Network.read("network-nb-no-connectable-position.xiidm", getClass().getResourceAsStream("/network-nb-no-connectable-position.xiidm")); Optional> unusedOrderPositionsBefore = TopologyModificationUtils.getUnusedOrderPositionsBefore(network.getBusbarSection("vl_test_1_1")); Optional> unusedOrderPositionsAfter = TopologyModificationUtils.getUnusedOrderPositionsAfter(network.getBusbarSection("vl_test_1_1")); assertEquals(0, (int) unusedOrderPositionsBefore.map(Range::getMinimum).orElse(-1)); diff --git a/iidm/iidm-scripting/pom.xml b/iidm/iidm-scripting/pom.xml index 1f388223a58..0908f7dab04 100644 --- a/iidm/iidm-scripting/pom.xml +++ b/iidm/iidm-scripting/pom.xml @@ -61,11 +61,6 @@ powsybl-iidm-api ${project.version} - - ${project.groupId} - powsybl-iidm-converter-api - ${project.version} - ${project.groupId} powsybl-scripting diff --git a/iidm/iidm-scripting/src/main/groovy/com/powsybl/iidm/network/scripting/NetworkLoadSaveGroovyScriptExtension.groovy b/iidm/iidm-scripting/src/main/groovy/com/powsybl/iidm/network/scripting/NetworkLoadSaveGroovyScriptExtension.groovy index cda30528885..22b30dcd836 100644 --- a/iidm/iidm-scripting/src/main/groovy/com/powsybl/iidm/network/scripting/NetworkLoadSaveGroovyScriptExtension.groovy +++ b/iidm/iidm-scripting/src/main/groovy/com/powsybl/iidm/network/scripting/NetworkLoadSaveGroovyScriptExtension.groovy @@ -9,13 +9,11 @@ package com.powsybl.iidm.network.scripting import com.google.auto.service.AutoService import com.powsybl.computation.ComputationManager import com.powsybl.computation.local.LocalComputationManager -import com.powsybl.iidm.export.Exporters -import com.powsybl.iidm.export.ExportersLoader -import com.powsybl.iidm.export.ExportersServiceLoader -import com.powsybl.iidm.import_.ImportConfig -import com.powsybl.iidm.import_.Importers -import com.powsybl.iidm.import_.ImportersLoader -import com.powsybl.iidm.import_.ImportersServiceLoader +import com.powsybl.iidm.network.ExportersLoader +import com.powsybl.iidm.network.ExportersServiceLoader +import com.powsybl.iidm.network.ImportConfig +import com.powsybl.iidm.network.ImportersLoader +import com.powsybl.iidm.network.ImportersServiceLoader import com.powsybl.iidm.network.Network import com.powsybl.scripting.groovy.GroovyScriptExtension @@ -51,11 +49,11 @@ class NetworkLoadSaveGroovyScriptExtension implements GroovyScriptExtension { @Override void load(Binding binding, ComputationManager computationManager) { binding.loadNetwork = { String file, Properties parameters = null -> - Importers.loadNetwork(fileSystem.getPath(file), LocalComputationManager.getDefault(), + Network.read(fileSystem.getPath(file), LocalComputationManager.getDefault(), importConfig, parameters, importersLoader) } binding.saveNetwork = { String format, Network network, Properties parameters = null, String file -> - Exporters.export(exportersLoader, format, network, parameters, fileSystem.getPath(file)) + network.write(exportersLoader, format, parameters, fileSystem.getPath(file)) } } diff --git a/iidm/iidm-scripting/src/main/java/com/powsybl/iidm/network/scripting/GroovyScriptPostProcessor.java b/iidm/iidm-scripting/src/main/java/com/powsybl/iidm/network/scripting/GroovyScriptPostProcessor.java index 2b71cdf4330..f6b3772e061 100644 --- a/iidm/iidm-scripting/src/main/java/com/powsybl/iidm/network/scripting/GroovyScriptPostProcessor.java +++ b/iidm/iidm-scripting/src/main/java/com/powsybl/iidm/network/scripting/GroovyScriptPostProcessor.java @@ -10,7 +10,7 @@ import com.powsybl.commons.PowsyblException; import com.powsybl.commons.config.PlatformConfig; import com.powsybl.computation.ComputationManager; -import com.powsybl.iidm.import_.ImportPostProcessor; +import com.powsybl.iidm.network.ImportPostProcessor; import com.powsybl.iidm.network.Network; import groovy.lang.Binding; import groovy.lang.GroovyShell; diff --git a/iidm/iidm-scripting/src/main/java/com/powsybl/iidm/network/scripting/JavaScriptPostProcessor.java b/iidm/iidm-scripting/src/main/java/com/powsybl/iidm/network/scripting/JavaScriptPostProcessor.java index 11afbf4baf9..8ac664b4558 100644 --- a/iidm/iidm-scripting/src/main/java/com/powsybl/iidm/network/scripting/JavaScriptPostProcessor.java +++ b/iidm/iidm-scripting/src/main/java/com/powsybl/iidm/network/scripting/JavaScriptPostProcessor.java @@ -11,7 +11,7 @@ import com.powsybl.commons.PowsyblException; import com.powsybl.commons.config.PlatformConfig; import com.powsybl.computation.ComputationManager; -import com.powsybl.iidm.import_.ImportPostProcessor; +import com.powsybl.iidm.network.ImportPostProcessor; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.util.Networks; import org.slf4j.Logger; diff --git a/iidm/iidm-scripting/src/test/java/com/powsybl/iidm/network/scripting/NetworkLoadSaveGroovyScriptExtensionTest.java b/iidm/iidm-scripting/src/test/java/com/powsybl/iidm/network/scripting/NetworkLoadSaveGroovyScriptExtensionTest.java index 70f4f01afcd..c10d1f570e8 100644 --- a/iidm/iidm-scripting/src/test/java/com/powsybl/iidm/network/scripting/NetworkLoadSaveGroovyScriptExtensionTest.java +++ b/iidm/iidm-scripting/src/test/java/com/powsybl/iidm/network/scripting/NetworkLoadSaveGroovyScriptExtensionTest.java @@ -8,9 +8,9 @@ import com.google.common.jimfs.Configuration; import com.google.common.jimfs.Jimfs; -import com.powsybl.iidm.export.ExportersLoaderList; -import com.powsybl.iidm.import_.ImportConfig; -import com.powsybl.iidm.import_.ImportersLoaderList; +import com.powsybl.iidm.network.ExportersLoaderList; +import com.powsybl.iidm.network.ImportConfig; +import com.powsybl.iidm.network.ImportersLoaderList; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; import com.powsybl.iidm.xml.NetworkXml; diff --git a/iidm/iidm-xml-converter/pom.xml b/iidm/iidm-xml-converter/pom.xml index c2bd92c235f..851a45b8905 100644 --- a/iidm/iidm-xml-converter/pom.xml +++ b/iidm/iidm-xml-converter/pom.xml @@ -70,11 +70,6 @@ powsybl-iidm-extensions ${project.version} - - com.powsybl - powsybl-iidm-converter-api - ${project.version} - diff --git a/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/XMLExporter.java b/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/XMLExporter.java index 452251e1452..16d8f8b8e3d 100644 --- a/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/XMLExporter.java +++ b/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/XMLExporter.java @@ -14,7 +14,7 @@ import com.powsybl.commons.extensions.ExtensionProvider; import com.powsybl.commons.extensions.ExtensionProviders; import com.powsybl.commons.extensions.ExtensionXmlSerializer; -import com.powsybl.iidm.export.Exporter; +import com.powsybl.iidm.network.Exporter; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.TopologyLevel; import com.powsybl.commons.parameters.Parameter; diff --git a/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/XMLImporter.java b/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/XMLImporter.java index 75fc1215ed9..0796ad4abb6 100644 --- a/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/XMLImporter.java +++ b/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/XMLImporter.java @@ -20,7 +20,7 @@ import com.powsybl.commons.extensions.ExtensionProviders; import com.powsybl.commons.extensions.ExtensionXmlSerializer; import com.powsybl.commons.xml.XmlUtil; -import com.powsybl.iidm.import_.Importer; +import com.powsybl.iidm.network.Importer; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.NetworkFactory; import com.powsybl.commons.parameters.Parameter; diff --git a/iidm/iidm-xml-converter/src/test/java/com/powsybl/iidm/xml/SkipExtensionTest.java b/iidm/iidm-xml-converter/src/test/java/com/powsybl/iidm/xml/SkipExtensionTest.java index fe9f7928e79..55161278268 100644 --- a/iidm/iidm-xml-converter/src/test/java/com/powsybl/iidm/xml/SkipExtensionTest.java +++ b/iidm/iidm-xml-converter/src/test/java/com/powsybl/iidm/xml/SkipExtensionTest.java @@ -7,7 +7,6 @@ package com.powsybl.iidm.xml; -import com.powsybl.iidm.export.Exporters; import com.powsybl.iidm.network.Network; import org.junit.Test; @@ -33,7 +32,7 @@ public void testSkipExtension() throws IOException { // Write the file Path networkFile = tmpDir.resolve("noExtension.xiidm"); - Exporters.export("XIIDM", network, properties, networkFile); + network.write("XIIDM", properties, networkFile); // Compare compareXml(getVersionedNetworkAsStream("noExtension.xml", IidmXmlVersion.V_1_0), Files.newInputStream(networkFile)); diff --git a/iidm/iidm-xml-converter/src/test/java/com/powsybl/iidm/xml/XMLExporterTest.java b/iidm/iidm-xml-converter/src/test/java/com/powsybl/iidm/xml/XMLExporterTest.java index c1ecc62eae6..c927f5db45f 100644 --- a/iidm/iidm-xml-converter/src/test/java/com/powsybl/iidm/xml/XMLExporterTest.java +++ b/iidm/iidm-xml-converter/src/test/java/com/powsybl/iidm/xml/XMLExporterTest.java @@ -10,8 +10,10 @@ import com.google.common.jimfs.Jimfs; import com.powsybl.commons.PowsyblException; import com.powsybl.commons.datasource.MemDataSource; -import com.powsybl.iidm.export.Exporters; -import com.powsybl.iidm.network.*; +import com.powsybl.iidm.network.Bus; +import com.powsybl.iidm.network.Network; +import com.powsybl.iidm.network.Terminal; +import com.powsybl.iidm.network.VoltageLevel; import com.powsybl.iidm.network.extensions.SlackTerminalAdder; import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; import com.powsybl.iidm.network.test.MultipleExtensionsTestNetworkFactory; @@ -28,7 +30,6 @@ import static com.powsybl.commons.ComparisonUtils.compareXml; import static com.powsybl.iidm.xml.IidmXmlConstants.CURRENT_IIDM_XML_VERSION; import static org.junit.Assert.*; -import static org.junit.Assert.assertNotNull; /** * @author Chamseddine BENHAMED @@ -78,10 +79,10 @@ public void exportOldVersionWithoutNewExtensions() throws IOException { Properties params = new Properties(); params.setProperty(XMLExporter.VERSION, IidmXmlVersion.V_1_2.toString(".")); params.setProperty(XMLExporter.THROW_EXCEPTION_IF_EXTENSION_NOT_FOUND, "true"); - assertThrows(PowsyblException.class, () -> Exporters.export("XIIDM", network, params, + assertThrows(PowsyblException.class, () -> network.write("XIIDM", params, workingDir)); try { - Exporters.export("XIIDM", network, params, workingDir); + network.write("XIIDM", params, workingDir); fail(); } catch (PowsyblException exception) { assertEquals("Version V_1_2 does not support slackTerminal extension", exception.getMessage()); diff --git a/iidm/pom.xml b/iidm/pom.xml index e65fc3efd47..2f27b6d0885 100644 --- a/iidm/pom.xml +++ b/iidm/pom.xml @@ -26,7 +26,6 @@ iidm-api iidm-comparator - iidm-converter-api iidm-extensions iidm-impl iidm-mergingview diff --git a/loadflow/loadflow-api/pom.xml b/loadflow/loadflow-api/pom.xml index bcb6786e5dd..b10f7d77317 100644 --- a/loadflow/loadflow-api/pom.xml +++ b/loadflow/loadflow-api/pom.xml @@ -54,11 +54,6 @@ powsybl-iidm-api ${project.version} - - ${project.groupId} - powsybl-iidm-converter-api - ${project.version} - diff --git a/loadflow/loadflow-api/src/main/java/com/powsybl/loadflow/tools/RunLoadFlowTool.java b/loadflow/loadflow-api/src/main/java/com/powsybl/loadflow/tools/RunLoadFlowTool.java index 2bbfe5abd68..cc4e193ace2 100644 --- a/loadflow/loadflow-api/src/main/java/com/powsybl/loadflow/tools/RunLoadFlowTool.java +++ b/loadflow/loadflow-api/src/main/java/com/powsybl/loadflow/tools/RunLoadFlowTool.java @@ -9,12 +9,10 @@ import com.google.auto.service.AutoService; import com.powsybl.commons.PowsyblException; import com.powsybl.commons.io.table.*; -import com.powsybl.iidm.export.Exporter; -import com.powsybl.iidm.export.Exporters; -import com.powsybl.iidm.import_.ImportConfig; -import com.powsybl.iidm.import_.Importers; +import com.powsybl.iidm.network.Exporter; +import com.powsybl.iidm.network.ImportConfig; import com.powsybl.iidm.network.Network; -import com.powsybl.iidm.tools.ConversionToolUtils; +import com.powsybl.iidm.network.tools.ConversionToolUtils; import com.powsybl.loadflow.LoadFlow; import com.powsybl.loadflow.LoadFlowParameters; import com.powsybl.loadflow.LoadFlowResult; @@ -38,7 +36,7 @@ import java.util.Arrays; import java.util.Properties; -import static com.powsybl.iidm.tools.ConversionToolUtils.*; +import static com.powsybl.iidm.network.tools.ConversionToolUtils.*; /** * @author Christian Biasuzzi @@ -149,7 +147,7 @@ public void run(CommandLine line, ToolRunningContext context) throws Exception { context.getOutputStream().println("Loading network '" + caseFile + "'"); Properties inputParams = readProperties(line, ConversionToolUtils.OptionType.IMPORT, context); - Network network = Importers.loadNetwork(caseFile, context.getShortTimeExecutionComputationManager(), ImportConfig.load(), inputParams); + Network network = Network.read(caseFile, context.getShortTimeExecutionComputationManager(), ImportConfig.load(), inputParams); if (network == null) { throw new PowsyblException("Case '" + caseFile + "' not found"); } @@ -172,7 +170,7 @@ public void run(CommandLine line, ToolRunningContext context) throws Exception { if (outputCaseFile != null) { String outputCaseFormat = line.getOptionValue(OUTPUT_CASE_FORMAT); Properties outputParams = readProperties(line, ConversionToolUtils.OptionType.EXPORT, context); - Exporters.export(outputCaseFormat, network, outputParams, outputCaseFile); + network.write(outputCaseFormat, outputParams, outputCaseFile); } } diff --git a/loadflow/loadflow-results-completion/src/main/java/com/powsybl/loadflow/resultscompletion/LoadFlowResultsCompletionPostProcessor.java b/loadflow/loadflow-results-completion/src/main/java/com/powsybl/loadflow/resultscompletion/LoadFlowResultsCompletionPostProcessor.java index 2d3fa2a115c..380bc925659 100644 --- a/loadflow/loadflow-results-completion/src/main/java/com/powsybl/loadflow/resultscompletion/LoadFlowResultsCompletionPostProcessor.java +++ b/loadflow/loadflow-results-completion/src/main/java/com/powsybl/loadflow/resultscompletion/LoadFlowResultsCompletionPostProcessor.java @@ -14,7 +14,7 @@ import com.google.auto.service.AutoService; import com.powsybl.commons.config.PlatformConfig; import com.powsybl.computation.ComputationManager; -import com.powsybl.iidm.import_.ImportPostProcessor; +import com.powsybl.iidm.network.ImportPostProcessor; import com.powsybl.iidm.network.Network; import com.powsybl.loadflow.LoadFlowParameters; diff --git a/loadflow/loadflow-validation/src/main/java/com/powsybl/loadflow/validation/ValidationTool.java b/loadflow/loadflow-validation/src/main/java/com/powsybl/loadflow/validation/ValidationTool.java index 7f363d9b802..54e51f51575 100644 --- a/loadflow/loadflow-validation/src/main/java/com/powsybl/loadflow/validation/ValidationTool.java +++ b/loadflow/loadflow-validation/src/main/java/com/powsybl/loadflow/validation/ValidationTool.java @@ -10,11 +10,10 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Sets; import com.powsybl.commons.PowsyblException; -import com.powsybl.iidm.import_.ImportConfig; -import com.powsybl.iidm.import_.Importers; +import com.powsybl.iidm.network.ImportConfig; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.VariantManagerConstants; -import com.powsybl.iidm.tools.ConversionToolUtils; +import com.powsybl.iidm.network.tools.ConversionToolUtils; import com.powsybl.loadflow.LoadFlow; import com.powsybl.loadflow.LoadFlowParameters; import com.powsybl.loadflow.validation.io.ValidationWriters; @@ -35,7 +34,7 @@ import java.util.Set; import java.util.stream.Collectors; -import static com.powsybl.iidm.tools.ConversionToolUtils.*; +import static com.powsybl.iidm.network.tools.ConversionToolUtils.*; /** * @@ -194,7 +193,7 @@ public void run(CommandLine line, ToolRunningContext context) throws Exception { private Network loadNetwork(Path caseFile, CommandLine line, ToolRunningContext context) throws IOException { context.getOutputStream().println("Loading case " + caseFile); Properties inputParams = readProperties(line, ConversionToolUtils.OptionType.IMPORT, context); - Network network = Importers.loadNetwork(caseFile, context.getShortTimeExecutionComputationManager(), ImportConfig.load(), inputParams); + Network network = Network.read(caseFile, context.getShortTimeExecutionComputationManager(), ImportConfig.load(), inputParams); if (network == null) { throw new PowsyblException("Case " + caseFile + " not found"); } diff --git a/matpower/matpower-converter/pom.xml b/matpower/matpower-converter/pom.xml index c772751d886..d723d7de6b7 100644 --- a/matpower/matpower-converter/pom.xml +++ b/matpower/matpower-converter/pom.xml @@ -40,7 +40,7 @@ ${project.groupId} - powsybl-iidm-converter-api + powsybl-iidm-api ${project.version} diff --git a/matpower/matpower-converter/src/main/java/com/powsybl/matpower/converter/MatpowerExporter.java b/matpower/matpower-converter/src/main/java/com/powsybl/matpower/converter/MatpowerExporter.java index 9333e7ca67d..a6e8ca7e269 100644 --- a/matpower/matpower-converter/src/main/java/com/powsybl/matpower/converter/MatpowerExporter.java +++ b/matpower/matpower-converter/src/main/java/com/powsybl/matpower/converter/MatpowerExporter.java @@ -10,7 +10,7 @@ import com.powsybl.commons.PowsyblException; import com.powsybl.commons.datasource.DataSource; import com.powsybl.commons.reporter.Reporter; -import com.powsybl.iidm.export.Exporter; +import com.powsybl.iidm.network.Exporter; import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.SlackTerminal; import com.powsybl.commons.parameters.Parameter; diff --git a/matpower/matpower-converter/src/main/java/com/powsybl/matpower/converter/MatpowerImporter.java b/matpower/matpower-converter/src/main/java/com/powsybl/matpower/converter/MatpowerImporter.java index 9390b564518..c92cbd909df 100644 --- a/matpower/matpower-converter/src/main/java/com/powsybl/matpower/converter/MatpowerImporter.java +++ b/matpower/matpower-converter/src/main/java/com/powsybl/matpower/converter/MatpowerImporter.java @@ -14,7 +14,7 @@ import com.powsybl.commons.parameters.Parameter; import com.powsybl.commons.parameters.ParameterDefaultValueConfig; import com.powsybl.commons.parameters.ParameterType; -import com.powsybl.iidm.import_.Importer; +import com.powsybl.iidm.network.Importer; import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.SlackTerminal; import com.powsybl.iidm.network.util.ContainersMapping; diff --git a/matpower/matpower-converter/src/test/java/com/powsybl/matpower/converter/MatpowerExporterTest.java b/matpower/matpower-converter/src/test/java/com/powsybl/matpower/converter/MatpowerExporterTest.java index ca995da410b..cd3574a30ea 100644 --- a/matpower/matpower-converter/src/test/java/com/powsybl/matpower/converter/MatpowerExporterTest.java +++ b/matpower/matpower-converter/src/test/java/com/powsybl/matpower/converter/MatpowerExporterTest.java @@ -10,7 +10,6 @@ import com.google.common.io.ByteStreams; import com.powsybl.cgmes.conformity.CgmesConformity1ModifiedCatalog; import com.powsybl.commons.datasource.MemDataSource; -import com.powsybl.iidm.import_.Importers; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; import com.powsybl.matpower.model.MatpowerModel; @@ -49,7 +48,7 @@ public void testEsgTutu1() throws IOException { @Test public void testMicroGridBe() throws IOException { - Network network = Importers.loadNetwork(CgmesConformity1ModifiedCatalog.microGridBaseCaseBERatioPhaseTapChangerTabular().dataSource()); + Network network = Network.read(CgmesConformity1ModifiedCatalog.microGridBaseCaseBERatioPhaseTapChangerTabular().dataSource()); exportToMatAndCompareTo(network, "/be.json"); } } diff --git a/matpower/matpower-converter/src/test/java/com/powsybl/matpower/converter/MatpowerImporterTest.java b/matpower/matpower-converter/src/test/java/com/powsybl/matpower/converter/MatpowerImporterTest.java index 0b11c687c0e..1c27c0bc9c4 100644 --- a/matpower/matpower-converter/src/test/java/com/powsybl/matpower/converter/MatpowerImporterTest.java +++ b/matpower/matpower-converter/src/test/java/com/powsybl/matpower/converter/MatpowerImporterTest.java @@ -8,7 +8,7 @@ import com.powsybl.commons.AbstractConverterTest; import com.powsybl.commons.datasource.FileDataSource; -import com.powsybl.iidm.import_.Importer; +import com.powsybl.iidm.network.Importer; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.NetworkFactory; import com.powsybl.iidm.xml.NetworkXml; diff --git a/pom.xml b/pom.xml index bba9bc72235..5835950f508 100644 --- a/pom.xml +++ b/pom.xml @@ -382,11 +382,6 @@ powsybl-iidm-comparator ${project.version} - - ${project.groupId} - powsybl-iidm-converter-api - ${project.version} - ${project.groupId} powsybl-iidm-extensions diff --git a/powerfactory/powerfactory-converter/pom.xml b/powerfactory/powerfactory-converter/pom.xml index e508fbab191..29458c28998 100644 --- a/powerfactory/powerfactory-converter/pom.xml +++ b/powerfactory/powerfactory-converter/pom.xml @@ -41,10 +41,6 @@ com.powsybl powsybl-iidm-api - - com.powsybl - powsybl-iidm-converter-api - com.powsybl powsybl-iidm-extensions diff --git a/powerfactory/powerfactory-converter/src/main/java/com/powsybl/powerfactory/converter/PowerFactoryImporter.java b/powerfactory/powerfactory-converter/src/main/java/com/powsybl/powerfactory/converter/PowerFactoryImporter.java index fdd4608f7d2..e3f6f88101e 100644 --- a/powerfactory/powerfactory-converter/src/main/java/com/powsybl/powerfactory/converter/PowerFactoryImporter.java +++ b/powerfactory/powerfactory-converter/src/main/java/com/powsybl/powerfactory/converter/PowerFactoryImporter.java @@ -11,7 +11,7 @@ import com.google.common.io.ByteStreams; import com.powsybl.commons.datasource.DataSource; import com.powsybl.commons.datasource.ReadOnlyDataSource; -import com.powsybl.iidm.import_.Importer; +import com.powsybl.iidm.network.Importer; import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.util.ContainersMapping; import com.powsybl.commons.parameters.Parameter; diff --git a/psse/psse-converter/pom.xml b/psse/psse-converter/pom.xml index 9b6432ea7ee..8697bc1fda6 100644 --- a/psse/psse-converter/pom.xml +++ b/psse/psse-converter/pom.xml @@ -44,7 +44,7 @@ ${project.groupId} - powsybl-iidm-converter-api + powsybl-iidm-api ${project.version} diff --git a/psse/psse-converter/src/main/java/com/powsybl/psse/converter/PsseExporter.java b/psse/psse-converter/src/main/java/com/powsybl/psse/converter/PsseExporter.java index a41a5a6dd03..ce4d312c1a1 100644 --- a/psse/psse-converter/src/main/java/com/powsybl/psse/converter/PsseExporter.java +++ b/psse/psse-converter/src/main/java/com/powsybl/psse/converter/PsseExporter.java @@ -9,7 +9,7 @@ import com.google.auto.service.AutoService; import com.google.common.collect.ImmutableList; import com.powsybl.commons.datasource.DataSource; -import com.powsybl.iidm.export.Exporter; +import com.powsybl.iidm.network.Exporter; import com.powsybl.iidm.network.*; import com.powsybl.commons.parameters.Parameter; import com.powsybl.psse.converter.extensions.PsseConversionContextExtension; diff --git a/psse/psse-converter/src/main/java/com/powsybl/psse/converter/PsseImporter.java b/psse/psse-converter/src/main/java/com/powsybl/psse/converter/PsseImporter.java index f53b38bb52e..68997018a4e 100644 --- a/psse/psse-converter/src/main/java/com/powsybl/psse/converter/PsseImporter.java +++ b/psse/psse-converter/src/main/java/com/powsybl/psse/converter/PsseImporter.java @@ -14,7 +14,7 @@ import com.powsybl.commons.parameters.Parameter; import com.powsybl.commons.parameters.ParameterDefaultValueConfig; import com.powsybl.commons.parameters.ParameterType; -import com.powsybl.iidm.import_.Importer; +import com.powsybl.iidm.network.Importer; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.NetworkFactory; import com.powsybl.iidm.network.Substation; diff --git a/psse/psse-converter/src/test/java/com/powsybl/psse/converter/PsseImporterTest.java b/psse/psse-converter/src/test/java/com/powsybl/psse/converter/PsseImporterTest.java index 205493c6572..ed141200198 100644 --- a/psse/psse-converter/src/test/java/com/powsybl/psse/converter/PsseImporterTest.java +++ b/psse/psse-converter/src/test/java/com/powsybl/psse/converter/PsseImporterTest.java @@ -10,7 +10,7 @@ import com.powsybl.commons.datasource.ReadOnlyDataSource; import com.powsybl.commons.datasource.ResourceDataSource; import com.powsybl.commons.datasource.ResourceSet; -import com.powsybl.iidm.import_.Importer; +import com.powsybl.iidm.network.Importer; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.NetworkFactory; import com.powsybl.iidm.network.impl.NetworkFactoryImpl; diff --git a/security-analysis/security-analysis-api/pom.xml b/security-analysis/security-analysis-api/pom.xml index b2cbf1b8dc9..561e81229df 100644 --- a/security-analysis/security-analysis-api/pom.xml +++ b/security-analysis/security-analysis-api/pom.xml @@ -61,11 +61,6 @@ powsybl-iidm-api ${project.version} - - ${project.groupId} - powsybl-iidm-converter-api - ${project.version} - ${project.groupId} powsybl-iidm-xml-converter diff --git a/security-analysis/security-analysis-api/src/main/java/com/powsybl/security/tools/SecurityAnalysisTool.java b/security-analysis/security-analysis-api/src/main/java/com/powsybl/security/tools/SecurityAnalysisTool.java index 4a69baa8cf9..1dd523bb353 100644 --- a/security-analysis/security-analysis-api/src/main/java/com/powsybl/security/tools/SecurityAnalysisTool.java +++ b/security-analysis/security-analysis-api/src/main/java/com/powsybl/security/tools/SecurityAnalysisTool.java @@ -16,13 +16,12 @@ import com.powsybl.computation.ComputationManager; import com.powsybl.computation.Partition; import com.powsybl.contingency.ContingenciesProviders; -import com.powsybl.iidm.import_.ImportConfig; -import com.powsybl.iidm.import_.Importers; -import com.powsybl.iidm.import_.ImportersLoader; -import com.powsybl.iidm.import_.ImportersServiceLoader; +import com.powsybl.iidm.network.ImportConfig; +import com.powsybl.iidm.network.ImportersLoader; +import com.powsybl.iidm.network.ImportersServiceLoader; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.VariantManagerConstants; -import com.powsybl.iidm.tools.ConversionToolUtils; +import com.powsybl.iidm.network.tools.ConversionToolUtils; import com.powsybl.loadflow.LoadFlowResult; import com.powsybl.security.*; import com.powsybl.security.action.ActionList; @@ -56,7 +55,7 @@ import java.util.function.Supplier; import java.util.stream.Collectors; -import static com.powsybl.iidm.tools.ConversionToolUtils.*; +import static com.powsybl.iidm.network.tools.ConversionToolUtils.*; import static com.powsybl.security.tools.SecurityAnalysisToolConstants.*; import static com.powsybl.tools.ToolConstants.TASK; import static com.powsybl.tools.ToolConstants.TASK_COUNT; @@ -257,7 +256,7 @@ static Network readNetwork(CommandLine line, ToolRunningContext context, Importe .orElseThrow(AssertionError::new); Properties inputParams = readProperties(line, ConversionToolUtils.OptionType.IMPORT, context); context.getOutputStream().println("Loading network '" + caseFile + "'"); - Network network = Importers.loadNetwork(caseFile, context.getShortTimeExecutionComputationManager(), ImportConfig.load(), inputParams, importersLoader); + Network network = Network.read(caseFile, context.getShortTimeExecutionComputationManager(), ImportConfig.load(), inputParams, importersLoader); network.getVariantManager().allowVariantMultiThreadAccess(true); return network; } diff --git a/security-analysis/security-analysis-api/src/test/java/com/powsybl/security/NetworkImporterMock.java b/security-analysis/security-analysis-api/src/test/java/com/powsybl/security/NetworkImporterMock.java index 6e2f75552db..cdcf5411aaa 100644 --- a/security-analysis/security-analysis-api/src/test/java/com/powsybl/security/NetworkImporterMock.java +++ b/security-analysis/security-analysis-api/src/test/java/com/powsybl/security/NetworkImporterMock.java @@ -8,7 +8,7 @@ import com.google.auto.service.AutoService; import com.powsybl.commons.datasource.ReadOnlyDataSource; -import com.powsybl.iidm.import_.Importer; +import com.powsybl.iidm.network.Importer; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.NetworkFactory; import com.powsybl.iidm.network.VariantManager; diff --git a/security-analysis/security-analysis-api/src/test/java/com/powsybl/security/tools/SecurityAnalysisToolTest.java b/security-analysis/security-analysis-api/src/test/java/com/powsybl/security/tools/SecurityAnalysisToolTest.java index 6afb5e35087..67321e38b20 100644 --- a/security-analysis/security-analysis-api/src/test/java/com/powsybl/security/tools/SecurityAnalysisToolTest.java +++ b/security-analysis/security-analysis-api/src/test/java/com/powsybl/security/tools/SecurityAnalysisToolTest.java @@ -17,7 +17,7 @@ import com.powsybl.computation.ComputationExceptionBuilder; import com.powsybl.computation.ComputationManager; import com.powsybl.contingency.ContingenciesProvider; -import com.powsybl.iidm.import_.ImportersLoaderList; +import com.powsybl.iidm.network.ImportersLoaderList; import com.powsybl.iidm.network.Network; import com.powsybl.security.*; import com.powsybl.security.action.Action; diff --git a/security-analysis/security-analysis-default/pom.xml b/security-analysis/security-analysis-default/pom.xml index 082b7b5c4df..5e657c9a08f 100644 --- a/security-analysis/security-analysis-default/pom.xml +++ b/security-analysis/security-analysis-default/pom.xml @@ -61,11 +61,6 @@ powsybl-iidm-api ${project.version} - - ${project.groupId} - powsybl-iidm-converter-api - ${project.version} - ${project.groupId} powsybl-iidm-xml-converter diff --git a/sensitivity-analysis-api/src/main/java/com/powsybl/sensitivity/SensitivityAnalysisTool.java b/sensitivity-analysis-api/src/main/java/com/powsybl/sensitivity/SensitivityAnalysisTool.java index faf12c5710e..9a0c52df9b8 100644 --- a/sensitivity-analysis-api/src/main/java/com/powsybl/sensitivity/SensitivityAnalysisTool.java +++ b/sensitivity-analysis-api/src/main/java/com/powsybl/sensitivity/SensitivityAnalysisTool.java @@ -21,10 +21,9 @@ import com.powsybl.contingency.Contingency; import com.powsybl.contingency.contingency.list.ContingencyList; import com.powsybl.contingency.json.ContingencyJsonModule; -import com.powsybl.iidm.import_.ImportConfig; -import com.powsybl.iidm.import_.Importers; +import com.powsybl.iidm.network.ImportConfig; import com.powsybl.iidm.network.Network; -import com.powsybl.iidm.tools.ConversionToolUtils; +import com.powsybl.iidm.network.tools.ConversionToolUtils; import com.powsybl.sensitivity.json.JsonSensitivityAnalysisParameters; import com.powsybl.sensitivity.json.SensitivityJsonModule; import com.powsybl.tools.Command; @@ -44,7 +43,7 @@ import java.util.Properties; import java.util.concurrent.TimeUnit; -import static com.powsybl.iidm.tools.ConversionToolUtils.*; +import static com.powsybl.iidm.network.tools.ConversionToolUtils.*; /** * @author Sebastien Murgey {@literal } @@ -179,7 +178,7 @@ public void run(CommandLine line, ToolRunningContext context) throws Exception { context.getOutputStream().println("Loading network '" + caseFile + "'"); Properties inputParams = readProperties(line, ConversionToolUtils.OptionType.IMPORT, context); - Network network = Importers.loadNetwork(caseFile, context.getShortTimeExecutionComputationManager(), ImportConfig.load(), inputParams); + Network network = Network.read(caseFile, context.getShortTimeExecutionComputationManager(), ImportConfig.load(), inputParams); if (network == null) { throw new PowsyblException("Case '" + caseFile + "' not found"); } diff --git a/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/tools/ShortCircuitAnalysisTool.java b/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/tools/ShortCircuitAnalysisTool.java index 2eb84b9b6ee..f3520103d7a 100644 --- a/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/tools/ShortCircuitAnalysisTool.java +++ b/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/tools/ShortCircuitAnalysisTool.java @@ -8,7 +8,6 @@ import com.google.auto.service.AutoService; import com.powsybl.computation.ComputationManager; -import com.powsybl.iidm.import_.Importers; import com.powsybl.iidm.network.Network; import com.powsybl.shortcircuit.*; import com.powsybl.shortcircuit.converter.ShortCircuitAnalysisResultExporters; @@ -86,7 +85,7 @@ static Network readNetwork(CommandLine line, ToolRunningContext context) { Path caseFile = options.getPath(CASE_FILE_OPTION) .orElseThrow(AssertionError::new); context.getOutputStream().println("Loading network '" + caseFile + "'"); - return Importers.loadNetwork(caseFile); + return Network.read(caseFile); } static ShortCircuitInput readInput(CommandLine line, ToolRunningContext context) throws ParseException { diff --git a/ucte/ucte-converter/pom.xml b/ucte/ucte-converter/pom.xml index 7da5b39a0cb..075dbdb3459 100644 --- a/ucte/ucte-converter/pom.xml +++ b/ucte/ucte-converter/pom.xml @@ -50,7 +50,7 @@ ${project.groupId} - powsybl-iidm-converter-api + powsybl-iidm-api ${project.version} diff --git a/ucte/ucte-converter/src/main/java/com/powsybl/ucte/converter/UcteExporter.java b/ucte/ucte-converter/src/main/java/com/powsybl/ucte/converter/UcteExporter.java index af9f62096db..a6d02fe2959 100644 --- a/ucte/ucte-converter/src/main/java/com/powsybl/ucte/converter/UcteExporter.java +++ b/ucte/ucte-converter/src/main/java/com/powsybl/ucte/converter/UcteExporter.java @@ -13,7 +13,7 @@ import com.powsybl.commons.datasource.DataSource; import com.powsybl.commons.util.ServiceLoaderCache; import com.powsybl.entsoe.util.MergedXnode; -import com.powsybl.iidm.export.Exporter; +import com.powsybl.iidm.network.Exporter; import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.SlackTerminal; import com.powsybl.commons.parameters.Parameter; diff --git a/ucte/ucte-converter/src/main/java/com/powsybl/ucte/converter/UcteImporter.java b/ucte/ucte-converter/src/main/java/com/powsybl/ucte/converter/UcteImporter.java index fe010146457..9c997b25b60 100644 --- a/ucte/ucte-converter/src/main/java/com/powsybl/ucte/converter/UcteImporter.java +++ b/ucte/ucte-converter/src/main/java/com/powsybl/ucte/converter/UcteImporter.java @@ -17,7 +17,7 @@ import com.powsybl.commons.datasource.ReadOnlyDataSource; import com.powsybl.commons.reporter.Reporter; import com.powsybl.entsoe.util.*; -import com.powsybl.iidm.import_.Importer; +import com.powsybl.iidm.network.Importer; import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.SlackTerminal; import com.powsybl.ucte.network.*; diff --git a/ucte/ucte-converter/src/test/java/com/powsybl/ucte/converter/UcteImporterReporterTest.java b/ucte/ucte-converter/src/test/java/com/powsybl/ucte/converter/UcteImporterReporterTest.java index 442dcfdf58d..efb6237470d 100644 --- a/ucte/ucte-converter/src/test/java/com/powsybl/ucte/converter/UcteImporterReporterTest.java +++ b/ucte/ucte-converter/src/test/java/com/powsybl/ucte/converter/UcteImporterReporterTest.java @@ -16,7 +16,7 @@ import com.powsybl.commons.datasource.ResourceDataSource; import com.powsybl.commons.datasource.ResourceSet; import com.powsybl.commons.reporter.*; -import com.powsybl.iidm.import_.Importers; +import com.powsybl.iidm.network.Importers; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.NetworkFactory; import org.junit.Test; @@ -71,7 +71,7 @@ public void roundTripReporterJsonTest() throws Exception { String filename = "frVoltageRegulatingXnode.uct"; ReporterModel reporter = new ReporterModel("roundTripReporterJsonTest", "Test importing UCTE file frVoltageRegulatingXnode.uct"); reporter.report("novalueReport", "No value report"); - Importers.loadNetwork(filename, getClass().getResourceAsStream("/" + filename), reporter); + Network.read(filename, getClass().getResourceAsStream("/" + filename), reporter); roundTripTest(reporter, ReporterModelSerializer::write, ReporterModelDeserializer::read, "/frVoltageRegulatingXnodeReport.json"); // Testing deserializing with unknown specified dictionary