Skip to content

Commit 1257d6f

Browse files
committed
Throw exception when failing to build coordinate
1 parent c513d8e commit 1257d6f

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased/Snapshot]
88

9+
### Added
10+
11+
### Fixed
12+
13+
### Changed
14+
- `SqlIdCoordinateSource.createCooridinateValue` now throws an exception when the coordinate can not be built [#911](https://github.com/ie3-institute/PowerSystemDataModel/issues/911)
15+
916
## [4.0.0] - 2023-08-01
1017

1118
### Added

src/main/java/edu/ie3/datamodel/io/source/sql/SqlIdCoordinateSource.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,27 +173,18 @@ public List<CoordinateDistance> getClosestCoordinates(
173173

174174
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
175175

176-
private Optional<CoordinateValue> createCoordinateValue(Map<String, String> fieldToValues) {
176+
private CoordinateValue createCoordinateValue(Map<String, String> fieldToValues) {
177177
fieldToValues.remove("distance");
178178

179179
SimpleFactoryData simpleFactoryData = new SimpleFactoryData(fieldToValues, Pair.class);
180-
Optional<Pair<Integer, Point>> pair = factory.get(simpleFactoryData).getData();
181180

182-
if (pair.isEmpty()) {
183-
return Optional.empty();
184-
} else {
185-
Pair<Integer, Point> data = pair.get();
186-
return Optional.of(new CoordinateValue(data.getKey(), data.getValue()));
187-
}
181+
Pair<Integer, Point> pair = factory.get(simpleFactoryData).getOrThrow();
182+
return new CoordinateValue(pair.getKey(), pair.getValue());
188183
}
189184

190185
private List<CoordinateValue> executeQueryToList(
191186
String query, SqlDataSource.AddParams addParams) {
192-
return dataSource
193-
.executeQuery(query, addParams)
194-
.map(this::createCoordinateValue)
195-
.flatMap(Optional::stream)
196-
.toList();
187+
return dataSource.executeQuery(query, addParams).map(this::createCoordinateValue).toList();
197188
}
198189

199190
/**

0 commit comments

Comments
 (0)