Skip to content

Commit

Permalink
Add extensions getter to Importer (#3067)
Browse files Browse the repository at this point in the history
* Add extensions getter to Importer

Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
  • Loading branch information
geofjamg authored Sep 18, 2024
1 parent 14d0c0b commit e9e9053
Show file tree
Hide file tree
Showing 20 changed files with 182 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ public String getFormat() {
return FORMAT;
}

@Override
public List<String> getSupportedExtensions() {
return List.of("xml");
}

@Override
public Network importData(ReadOnlyDataSource ds, NetworkFactory networkFactory, Properties p, ReportNode reportNode) {
Objects.requireNonNull(ds);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.cgmes.conversion.test;

import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import com.powsybl.cgmes.conversion.CgmesImport;
import com.powsybl.commons.config.InMemoryPlatformConfig;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
*/
class CgmesImporterMetaInfoTest {

@Test
void test() throws IOException {
try (var fs = Jimfs.newFileSystem(Configuration.unix())) {
var importer = new CgmesImport(new InMemoryPlatformConfig(fs));
assertEquals("CGMES", importer.getFormat());
assertEquals("ENTSO-E CGMES version 2.4.15", importer.getComment());
assertEquals(List.of("xml"), importer.getSupportedExtensions());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public String getFormat() {
return FORMAT;
}

@Override
public List<String> getSupportedExtensions() {
return List.of(EXT);
}

@Override
public List<Parameter> getParameters() {
return Collections.singletonList(IGNORE_BASE_VOLTAGE_PARAMETER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

import static com.powsybl.commons.test.ComparisonUtils.assertXmlEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -40,6 +41,7 @@ void baseTest() {
Importer importer = new IeeeCdfImporter();
assertEquals("IEEE-CDF", importer.getFormat());
assertEquals("IEEE Common Data Format to IIDM converter", importer.getComment());
assertEquals(List.of("txt"), importer.getSupportedExtensions());
assertEquals(1, importer.getParameters().size());
assertEquals("ignore-base-voltage", importer.getParameters().get(0).getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public String getFormat() {
return importer.getFormat();
}

@Override
public List<String> getSupportedExtensions() {
return importer.getSupportedExtensions();
}

@Override
public List<Parameter> getParameters() {
return importer.getParameters();
Expand Down Expand Up @@ -276,6 +281,10 @@ static Importer find(ReadOnlyDataSource dataSource) {
*/
String getFormat();

default List<String> getSupportedExtensions() {
return Collections.emptyList();
}

/**
* Get a description of import parameters
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.List;
import java.util.Properties;

/**
Expand All @@ -26,6 +27,11 @@ public String getFormat() {
return "TST";
}

@Override
public List<String> getSupportedExtensions() {
return List.of("tst");
}

@Override
public String getComment() {
return "Dummy importer to test Importers";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Properties;
import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -106,6 +103,11 @@ private String findExtension(ReadOnlyDataSource dataSource) throws IOException {

protected abstract String[] getExtensions();

@Override
public List<String> getSupportedExtensions() {
return Arrays.asList(getExtensions());
}

@Override
public boolean exists(ReadOnlyDataSource dataSource) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.iidm.serde;

import org.junit.jupiter.api.Test;

import java.util.List;

import static com.powsybl.iidm.serde.IidmSerDeConstants.CURRENT_IIDM_VERSION;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
*/
class BinaryImporterTest {

@Test
void testMetaInfos() {
var importer = new BinaryImporter();
assertEquals("BIIDM", importer.getFormat());
assertEquals("IIDM binary v " + CURRENT_IIDM_VERSION.toString(".") + " importer", importer.getComment());
assertEquals(List.of("biidm", "bin"), importer.getSupportedExtensions());
assertEquals(5, importer.getParameters().size());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.iidm.serde;

import org.junit.jupiter.api.Test;

import java.util.List;

import static com.powsybl.iidm.serde.IidmSerDeConstants.CURRENT_IIDM_VERSION;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
*/
class JsonImporterTest {

@Test
void testMetaInfos() {
var importer = new JsonImporter();
assertEquals("JIIDM", importer.getFormat());
assertEquals("IIDM JSON v " + CURRENT_IIDM_VERSION.toString(".") + " importer", importer.getComment());
assertEquals(List.of("jiidm", "json"), importer.getSupportedExtensions());
assertEquals(5, importer.getParameters().size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;

import static com.powsybl.commons.test.TestUtil.normalizeLineSeparator;
Expand Down Expand Up @@ -132,22 +133,15 @@ void backwardCompatibilityTest() throws IOException {
}

@Test
void getFormat() {
void testMetaInfos() {
assertEquals("XIIDM", importer.getFormat());
}

@Test
void getParameters() {
assertEquals("IIDM XML v " + CURRENT_IIDM_VERSION.toString(".") + " importer", importer.getComment());
assertEquals(List.of("xiidm", "iidm", "xml"), importer.getSupportedExtensions());
assertEquals(5, importer.getParameters().size());
assertEquals("iidm.import.xml.throw-exception-if-extension-not-found", importer.getParameters().get(0).getName());
assertEquals(Arrays.asList("iidm.import.xml.throw-exception-if-extension-not-found", "throwExceptionIfExtensionNotFound"), importer.getParameters().get(0).getNames());
}

@Test
void getComment() {
assertEquals("IIDM XML v " + CURRENT_IIDM_VERSION.toString(".") + " importer", importer.getComment());
}

@Test
void exists() {
assertTrue(importer.exists(new DirectoryDataSource(fileSystem.getPath("/"), "test0")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,11 @@ public String getFormat() {
return MatpowerConstants.FORMAT;
}

@Override
public List<String> getSupportedExtensions() {
return Collections.singletonList(MatpowerConstants.EXT);
}

@Override
public void copy(ReadOnlyDataSource fromDataSource, DataSource toDataSource) {
Objects.requireNonNull(fromDataSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.time.Month;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Properties;

import static com.powsybl.commons.test.ComparisonUtils.assertXmlEquals;
Expand All @@ -50,6 +51,7 @@ void baseTest() {
Importer importer = new MatpowerImporter();
assertEquals("MATPOWER", importer.getFormat());
assertEquals("MATPOWER Format to IIDM converter", importer.getComment());
assertEquals(List.of("mat"), importer.getSupportedExtensions());
assertEquals(1, importer.getParameters().size());
assertEquals("matpower.import.ignore-base-voltage", importer.getParameters().get(0).getName());
}
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,11 @@
<artifactId>powsybl-powerfactory-dgs</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-powerfactory-db</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-powerfactory-converter</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions powerfactory/powerfactory-converter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,10 @@
<artifactId>powsybl-powerfactory-dgs</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-powerfactory-db</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public String getFormat() {
return FORMAT;
}

@Override
public List<String> getSupportedExtensions() {
return PowerFactoryDataLoader.find(StudyCase.class).stream().map(PowerFactoryDataLoader::getExtension).toList();
}

@Override
public String getComment() {
return "PowerFactory to IIDM converter";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

Expand All @@ -44,6 +45,7 @@ void testBase() {
assertEquals("POWER-FACTORY", importer.getFormat());
assertTrue(importer.getParameters().isEmpty());
assertEquals("PowerFactory to IIDM converter", importer.getComment());
assertEquals(List.of("json", "dgs", "properties"), importer.getSupportedExtensions());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public String getFormat() {
return FORMAT;
}

@Override
public List<String> getSupportedExtensions() {
return Arrays.asList(EXTENSIONS);
}

@Override
public List<Parameter> getParameters() {
return Collections.singletonList(IGNORE_BASE_VOLTAGE_PARAMETER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Properties;

import static com.powsybl.commons.test.ComparisonUtils.assertXmlEquals;
Expand All @@ -44,6 +45,7 @@ void baseTest() {
Importer importer = new PsseImporter();
assertEquals("PSS/E", importer.getFormat());
assertEquals("PSS/E Format to IIDM converter", importer.getComment());
assertEquals(List.of("raw", "RAW", "rawx", "RAWX"), importer.getSupportedExtensions());
assertEquals(1, importer.getParameters().size());
assertEquals("psse.import.ignore-base-voltage", importer.getParameters().get(0).getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,11 @@ public String getFormat() {
return "UCTE";
}

@Override
public List<String> getSupportedExtensions() {
return Arrays.asList(EXTENSIONS);
}

@Override
public String getComment() {
return "UCTE-DEF";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
*/
package com.powsybl.ucte.converter;

import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.config.InMemoryPlatformConfig;
import com.powsybl.commons.datasource.ReadOnlyDataSource;
import com.powsybl.commons.datasource.ResourceDataSource;
import com.powsybl.commons.datasource.ResourceSet;
Expand All @@ -18,6 +21,7 @@
import com.powsybl.ucte.converter.util.UcteConstants;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.List;
import java.util.Properties;
import java.util.Set;
Expand Down Expand Up @@ -345,4 +349,14 @@ void testDontCreateAreas() {
assertEquals(0, network.getAreaTypeCount());
assertEquals(0, network.getAreaCount());
}

@Test
void testMetaInfos() throws IOException {
try (var fs = Jimfs.newFileSystem(Configuration.unix())) {
var importer = new UcteImporter(new InMemoryPlatformConfig(fs));
assertEquals("UCTE", importer.getFormat());
assertEquals("UCTE-DEF", importer.getComment());
assertEquals(List.of("uct", "UCT"), importer.getSupportedExtensions());
}
}
}

0 comments on commit e9e9053

Please sign in to comment.