Skip to content

Commit

Permalink
IOException not catched
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
  • Loading branch information
flo-dup committed Jun 24, 2024
1 parent b64d1a5 commit 20110e9
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,17 @@ public class OdreGeoDataAdder {
protected OdreGeoDataAdder() {
}

public static void fillNetworkSubstationsGeoDataFromFile(Network network, Path path, OdreConfig odreConfig) {
public static void fillNetworkSubstationsGeoDataFromFile(Network network, Path path, OdreConfig odreConfig) throws IOException {
fillNetworkSubstationsGeoData(network, OdreGeoDataCsvLoader.getSubstationsGeoData(path, odreConfig));
}

public static void fillNetworkGeoDataFromFiles(Network network, Path aerialLinesFilePath,
Path undergroundLinesFilePath, Path substationPath, OdreConfig odreConfig) {
Path undergroundLinesFilePath, Path substationPath, OdreConfig odreConfig) throws IOException {
try (Reader substationReader = InputUtils.toReader(substationPath)) {
Map<String, SubstationGeoData> substations = GeographicDataParser.parseSubstations(substationReader, odreConfig);
fillNetworkSubstationsGeoData(network, substations.values());
fillNetworkLinesGeoData(network,
OdreGeoDataCsvLoader.getLinesGeoData(aerialLinesFilePath, undergroundLinesFilePath, substations, odreConfig));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
Expand Down Expand Up @@ -76,7 +77,7 @@ public String getName() {
}

@Override
public void process(Network network, ComputationManager computationManager) {
public void process(Network network, ComputationManager computationManager) throws IOException {
if (Files.exists(substationsFilePath)) {
boolean aerialLinesPresent = Files.exists(aerialLinesFilePath);
boolean undergroundLinesPresent = Files.exists(undergroundLinesFilePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,26 @@ public class OdreGeoDataCsvLoader {
protected OdreGeoDataCsvLoader() {
}

public static Collection<SubstationGeoData> getSubstationsGeoData(Path path, OdreConfig odreConfig) {
public static Collection<SubstationGeoData> getSubstationsGeoData(Path path, OdreConfig odreConfig) throws IOException {
try (Reader reader = InputUtils.toReader(path)) {
return GeographicDataParser.parseSubstations(reader, odreConfig).values();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

public static Collection<LineGeoData> getLinesGeoData(Path aerialLinesFilePath, Path undergroundLinesFilePath,
Path substationPath, OdreConfig odreConfig) {
Path substationPath, OdreConfig odreConfig) throws IOException {
try (Reader substationReader = InputUtils.toReader(substationPath)) {
return getLinesGeoData(aerialLinesFilePath, undergroundLinesFilePath, GeographicDataParser.parseSubstations(substationReader, odreConfig), odreConfig);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

public static Collection<LineGeoData> getLinesGeoData(Path aerialLinesFilePath, Path undergroundLinesFilePath,
Map<String, SubstationGeoData> substations, OdreConfig odreConfig) {

Map<String, SubstationGeoData> substations, OdreConfig odreConfig) throws IOException {
try (Reader aerialReader = InputUtils.toReader(aerialLinesFilePath);
Reader undergroundReader = InputUtils.toReader(undergroundLinesFilePath)) {

Map<String, LineGeoData> lineGeoDataMap = GeographicDataParser.parseLines(aerialReader, undergroundReader, substations, odreConfig);
return lineGeoDataMap.values();

} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -40,7 +41,7 @@ void setUp() {

@ParameterizedTest
@MethodSource("provideTestArguments")
void addSubstationsGeoDataFromFile(String descr, String directory, OdreConfig config) throws URISyntaxException {
void addSubstationsGeoDataFromFile(String descr, String directory, OdreConfig config) throws URISyntaxException, IOException {
Path substationsPath = Paths.get(getClass()
.getClassLoader().getResource(directory + "substations.csv").toURI());

Expand All @@ -61,7 +62,7 @@ void addSubstationsGeoDataFromFile(String descr, String directory, OdreConfig co

@ParameterizedTest
@MethodSource("provideTestArguments")
void addLinesGeoDataFromFile(String descr, String directory, OdreConfig config) throws URISyntaxException {
void addLinesGeoDataFromFile(String descr, String directory, OdreConfig config) throws URISyntaxException, IOException {
Path substationsPath = Paths.get(getClass()
.getClassLoader().getResource(directory + "substations.csv").toURI());
Path aerialLinesFile = Paths.get(getClass()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.powsybl.iidm.geodata.elements.LineGeoData;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -23,7 +24,7 @@
class OdreGeoDataCsvLoaderTest {

@Test
void validSubstationsLineParsing() throws URISyntaxException {
void validSubstationsLineParsing() throws URISyntaxException, IOException {
Path substationsPath = Paths.get(getClass()
.getClassLoader().getResource("valid-line-name/substations.csv").toURI());
Path undergroundLinesPath = Paths.get(getClass()
Expand Down

0 comments on commit 20110e9

Please sign in to comment.