@@ -240,13 +240,32 @@ boolean emptyOrEquals(String emptyable, String s) {
240
240
return emptyable .isEmpty () || s .equals (emptyable );
241
241
}
242
242
243
+ /**
244
+ * returns the line gps coordinates in the network order with the substations
245
+ * coordinates added at each extremity.
246
+ *
247
+ * returns null when the substations at the end of the line are missing.
248
+ */
243
249
private LineGeoData getLineGeoDataWithEndSubstations (Map <String , LineGeoData > linesGeoDataDb , Map <String , SubstationGeoData > substationGeoDataDb , Line line ) {
244
250
LineGeoData geoData = linesGeoDataDb .get (line .getId ());
245
251
Substation sub1 = line .getTerminal1 ().getVoltageLevel ().getSubstation ();
246
252
Substation sub2 = line .getTerminal2 ().getVoltageLevel ().getSubstation ();
247
- Coordinate substation1Coordinate = substationGeoDataDb .get (sub1 .getId ()).getCoordinate ();
248
- Coordinate substation2Coordinate = substationGeoDataDb .get (sub2 .getId ()).getCoordinate ();
253
+ SubstationGeoData substation1GeoData = substationGeoDataDb .get (sub1 .getId ());
254
+ SubstationGeoData substation2GeoData = substationGeoDataDb .get (sub2 .getId ());
255
+
256
+ // TODO: we return null here even if we have line data
257
+ // because the method is called "withEndSubstations"...
258
+ // We could refactor this in separate methods if we ever have a
259
+ // need to return the line in the network order without the substations
260
+ if (substation1GeoData == null || substation2GeoData == null ) {
261
+ LOGGER .error ("line {} has substations with unknown gps positions({}={}, {}={})" , line .getId (),
262
+ sub1 .getId (), substation1GeoData ,
263
+ sub2 .getId (), substation2GeoData );
264
+ return null ;
265
+ }
249
266
267
+ Coordinate substation1Coordinate = substation1GeoData .getCoordinate ();
268
+ Coordinate substation2Coordinate = substation2GeoData .getCoordinate ();
250
269
if (geoData == null || geoData .getCoordinates ().isEmpty () || (geoData .getSubstationStart ().isEmpty () && geoData .getSubstationEnd ().isEmpty ())) {
251
270
return new LineGeoData (line .getId (), sub1 .getNullableCountry (), sub2 .getNullableCountry (), sub1 .getId (), sub2 .getId (),
252
271
List .of (substation1Coordinate , substation2Coordinate ));
@@ -303,7 +322,8 @@ List<LineGeoData> getLines(Network network, Set<Country> countries) {
303
322
lines .stream ().flatMap (line -> line .getTerminals ().stream ().map (term -> term .getVoltageLevel ().getSubstation ().getNullableCountry ()).filter (Objects ::nonNull ))
304
323
.collect (Collectors .toSet ());
305
324
Map <String , SubstationGeoData > substationGeoDataDb = getSubstationMap (network , countryAndNextTo );
306
- List <LineGeoData > lineGeoData = lines .stream ().map (line -> getLineGeoDataWithEndSubstations (linesGeoDataDb , substationGeoDataDb , line )).collect (Collectors .toList ());
325
+ List <LineGeoData > lineGeoData = lines .stream ().map (line -> getLineGeoDataWithEndSubstations (linesGeoDataDb , substationGeoDataDb , line ))
326
+ .filter (Objects ::nonNull ).collect (Collectors .toList ());
307
327
LOGGER .info ("{} lines read from DB in {} ms" , linesGeoDataDb .size (), stopWatch .getTime (TimeUnit .MILLISECONDS ));
308
328
309
329
return lineGeoData ;
0 commit comments