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 f118fbd4d27..6dffe400655 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 @@ -176,7 +176,8 @@ private Network importData1(ReadOnlyDataSource ds, NetworkFactory networkFactory return new Conversion(cgmes, config(p), activatedPreProcessors(p), activatedPostProcessors(p), networkFactory).convert(conversionReportNode); } - public void updateData(Network network, ReadOnlyDataSource ds, Properties p, ReportNode reportNode) { + @Override + public void update(Network network, ReadOnlyDataSource ds, Properties p, ReportNode reportNode) { TripleStoreOptions tripleStoreOptions = new TripleStoreOptions(); tripleStoreOptions.setQueryCatalog("-update"); ReadOnlyDataSource alternativeDataSourceForBoundary = null; diff --git a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/ConversionUtil.java b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/ConversionUtil.java index 6feea04ca8e..831706c9d42 100644 --- a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/ConversionUtil.java +++ b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/ConversionUtil.java @@ -8,7 +8,6 @@ package com.powsybl.cgmes.conversion.test; import com.powsybl.cgmes.conversion.CgmesExport; -import com.powsybl.cgmes.conversion.CgmesImport; import com.powsybl.cgmes.conversion.CgmesImportPostProcessor; import com.powsybl.cgmes.conversion.Conversion; import com.powsybl.cgmes.model.CgmesModel; @@ -17,7 +16,6 @@ import com.powsybl.commons.datasource.ReadOnlyDataSource; import com.powsybl.commons.datasource.ResourceDataSource; import com.powsybl.commons.datasource.ResourceSet; -import com.powsybl.commons.report.ReportNode; import com.powsybl.iidm.network.Network; import com.powsybl.triplestore.api.TripleStoreFactory; @@ -102,7 +100,7 @@ public static Network readCgmesResources(Properties properties, String dir, Stri public static void readCgmesResources(Network network, String dir, String... files) { ReadOnlyDataSource ds = new ResourceDataSource("CGMES input file(s)", new ResourceSet(dir, files)); - new CgmesImport().updateData(network, ds, new Properties(), ReportNode.NO_OP); + network.update(ds); } public static String writeCgmesProfile(Network network, String profile, Path outDir) throws IOException { diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Importer.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Importer.java index bf18803ba0c..5828fc5dcfa 100644 --- a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Importer.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Importer.java @@ -346,4 +346,27 @@ default Network importData(ReadOnlyDataSource dataSource, NetworkFactory network default void copy(ReadOnlyDataSource fromDataSource, DataSource toDataSource) { throw new UnsupportedOperationException("Copy not implemented"); } + + /** + * Update a given network with contents coming from a data source. + * + * @param network network + * @param dataSource data source + * @param parameters some properties to configure the import + * @param reportNode the reportNode used for functional logs + */ + default void update(Network network, ReadOnlyDataSource dataSource, Properties parameters, ReportNode reportNode) { + update(network, dataSource, parameters); + } + + /** + * Update a given network with contents coming from a data source. + * + * @param network network + * @param dataSource data source + * @param parameters some properties to configure the import + */ + default void update(Network network, ReadOnlyDataSource dataSource, Properties parameters) { + throw new UnsupportedOperationException("Importer do not implement updates"); + } } 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 8197882ca70..764c862e2a3 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 @@ -401,6 +401,29 @@ static void readAll(Path dir, Consumer consumer) throws IOException, In readAll(dir, false, LocalComputationManager.getDefault(), ImportConfig.CACHE.get(), consumer); } + default void update(ReadOnlyDataSource dataSource) { + update(dataSource, null); + } + + default void update(ReadOnlyDataSource dataSource, Properties properties) { + update(dataSource, properties, ReportNode.NO_OP); + } + + default void update(ReadOnlyDataSource dataSource, Properties parameters, ReportNode reportNode) { + update(dataSource, LocalComputationManager.getDefault(), ImportConfig.load(), parameters, + new ImportersServiceLoader(), reportNode); + } + + default void update(ReadOnlyDataSource dataSource, ComputationManager computationManager, ImportConfig config, Properties parameters, + ImportersLoader loader, ReportNode reportNode) { + Importer importer = Importer.find(dataSource, loader, computationManager, config); + if (importer != null) { + importer.update(this, dataSource, parameters, reportNode); + } else { + throw new PowsyblException(Importers.UNSUPPORTED_FILE_FORMAT_OR_INVALID_FILE); + } + } + /** * A global bus/breaker view of the network. *