11
11
import com .powsybl .iidm .network .HvdcConverterStation .HvdcType ;
12
12
import com .powsybl .network .store .client .NetworkStoreService ;
13
13
import com .powsybl .network .store .client .PreloadingStrategy ;
14
+ import lombok .AllArgsConstructor ;
14
15
import org .gridsuite .network .map .dto .*;
15
16
import org .gridsuite .network .map .dto .definition .hvdc .HvdcShuntCompensatorsInfos ;
16
17
import org .gridsuite .network .map .dto .mapper .ElementInfosMapper ;
17
18
import org .gridsuite .network .map .dto .mapper .HvdcInfosMapper ;
18
- import org .springframework .beans .factory .annotation .Autowired ;
19
19
import org .springframework .context .annotation .ComponentScan ;
20
20
import org .springframework .http .HttpStatus ;
21
21
import org .springframework .lang .NonNull ;
33
33
*/
34
34
@ ComponentScan (basePackageClasses = {NetworkStoreService .class })
35
35
@ Service
36
+ @ AllArgsConstructor
36
37
public class NetworkMapService {
37
-
38
- @ Autowired
39
- private NetworkStoreService networkStoreService ;
38
+ private final NetworkStoreService networkStoreService ;
40
39
41
40
private Network getNetwork (UUID networkUuid , PreloadingStrategy strategy , String variantId ) {
42
41
try {
@@ -250,8 +249,8 @@ private List<ElementInfos> getTieLinesInfos(Network network, @NonNull List<Strin
250
249
private List <ElementInfos > getBusesInfos (Network network , @ NonNull List <String > substationsId , InfoTypeParameters infoTypeParameters ) {
251
250
Stream <Bus > buses = substationsId .isEmpty () ? network .getBusView ().getBusStream () :
252
251
network .getBusView ().getBusStream ()
253
- .filter (bus -> bus .getVoltageLevel ().getSubstation ().stream ().anyMatch (substation -> substationsId .contains (substation .getId ())))
254
252
.filter (Objects ::nonNull )
253
+ .filter (bus -> bus .getVoltageLevel ().getSubstation ().stream ().anyMatch (substation -> substationsId .contains (substation .getId ())))
255
254
.distinct ();
256
255
return buses
257
256
.map (c -> ElementType .BUS .getInfosGetter ().apply (c , infoTypeParameters ))
@@ -260,14 +259,16 @@ private List<ElementInfos> getBusesInfos(Network network, @NonNull List<String>
260
259
}
261
260
262
261
private static List <ElementInfos > getElementsInfos (Network network , @ NonNull List <String > substationsIds , ElementType elementType , InfoTypeParameters infoTypeParameters , List <Double > nominalVoltages ) {
263
- Class <? extends Connectable <?>> elementClass = (Class <? extends Connectable <?>>) elementType .getElementClass ();
264
- Stream <? extends Connectable <?>> connectables = substationsIds .isEmpty () ?
265
- getConnectableStream (network , elementType ) :
262
+ if (!elementType .isConnectable ()) { // early break if not supported
263
+ throw new IllegalStateException ("Unexpected non-connectable element type: " + elementType );
264
+ }
265
+ final Stream <? extends Connectable <?>> connectables = substationsIds .isEmpty () ?
266
+ elementType .getConnectableStream (network ) :
266
267
substationsIds .stream ()
267
268
.flatMap (substationId -> network .getSubstation (substationId ).getVoltageLevelStream ())
268
269
.filter (voltageLevel -> (elementType != ElementType .BUSBAR_SECTION || voltageLevel .getTopologyKind () != TopologyKind .BUS_BREAKER )
269
270
&& (nominalVoltages == null || nominalVoltages .contains (voltageLevel .getNominalV ())))
270
- .flatMap (voltageLevel -> voltageLevel . getConnectableStream ( elementClass ) )
271
+ .flatMap (elementType :: getVoltageLevelConnectableStream )
271
272
.distinct ();
272
273
return connectables
273
274
.map (c -> elementType .getInfosGetter ().apply (c , infoTypeParameters ))
@@ -277,13 +278,15 @@ private static List<ElementInfos> getElementsInfos(Network network, @NonNull Lis
277
278
public List <ElementInfos > getElementsInfos (UUID networkUuid , String variantId , @ NonNull List <String > substationsIds , ElementType equipmentType , InfoTypeParameters infoTypeParameters , List <Double > nominalVoltages ) {
278
279
Network network = getNetwork (networkUuid , getPreloadingStrategy (substationsIds ), variantId );
279
280
return switch (equipmentType ) {
281
+ // types that don't implement `Connectable<>` interface
280
282
case SUBSTATION -> getSubstationsInfos (network , substationsIds , infoTypeParameters , nominalVoltages );
281
283
case VOLTAGE_LEVEL -> getVoltageLevelsInfos (network , substationsIds , infoTypeParameters , nominalVoltages );
282
284
case HVDC_LINE -> getHvdcLinesInfos (network , substationsIds , infoTypeParameters , nominalVoltages );
283
285
case HVDC_LINE_LCC -> getHvdcLinesLccInfos (network , substationsIds , infoTypeParameters , nominalVoltages );
284
286
case HVDC_LINE_VSC -> getHvdcLinesVscInfos (network , substationsIds , infoTypeParameters , nominalVoltages );
285
287
case TIE_LINE -> getTieLinesInfos (network , substationsIds , infoTypeParameters , nominalVoltages );
286
288
case BUS -> getBusesInfos (network , substationsIds , infoTypeParameters );
289
+ // for others, it's okay
287
290
default -> getElementsInfos (network , substationsIds , equipmentType , infoTypeParameters , nominalVoltages );
288
291
};
289
292
}
@@ -314,33 +317,36 @@ public HvdcShuntCompensatorsInfos getHvdcLineShuntCompensators(UUID networkUuid,
314
317
Network network = getNetwork (networkUuid , PreloadingStrategy .NONE , variantId );
315
318
HvdcLine hvdcLine = network .getHvdcLine (hvdcId );
316
319
if (hvdcLine == null ) {
317
- // called from a modification, then we must support un-existing equipment
320
+ // called from a modification, then we must support unexisting equipment
318
321
return HvdcShuntCompensatorsInfos .builder ().id (hvdcId ).build ();
319
322
}
320
323
return HvdcInfosMapper .toHvdcShuntCompensatorsInfos (hvdcLine );
321
324
}
322
325
323
326
public List <String > getElementsIds (UUID networkUuid , String variantId , @ NonNull List <String > substationsIds , ElementType elementType , List <Double > nominalVoltages ) {
324
327
return switch (elementType ) {
328
+ // types that don't implement `Connectable<>` interface
325
329
case SUBSTATION -> getSubstationsIds (networkUuid , variantId , nominalVoltages );
326
330
case TIE_LINE -> getTieLinesIds (networkUuid , variantId , substationsIds , nominalVoltages );
327
331
case HVDC_LINE -> getHvdcLinesIds (networkUuid , variantId , substationsIds , nominalVoltages );
328
332
case HVDC_LINE_LCC -> getHvdcLinesLccIds (networkUuid , variantId , substationsIds , nominalVoltages );
329
333
case HVDC_LINE_VSC -> getHvdcLinesVscIds (networkUuid , variantId , substationsIds , nominalVoltages );
330
334
case VOLTAGE_LEVEL -> getVoltageLevelsIds (networkUuid , variantId , substationsIds , nominalVoltages );
335
+ // for others, it's okay
331
336
default -> getConnectablesIds (networkUuid , variantId , substationsIds , elementType , nominalVoltages );
332
337
};
333
338
}
334
339
335
340
private List <String > getConnectablesIds (UUID networkUuid , String variantId , @ NonNull List <String > substationsIds , ElementType elementType , List <Double > nominalVoltages ) {
336
341
Network network = getNetwork (networkUuid , getPreloadingStrategy (substationsIds ), variantId );
337
342
if (substationsIds .isEmpty () && nominalVoltages == null ) {
338
- return getConnectableStream (network , elementType )
339
- .map (Connectable ::getId )
340
- .toList ();
343
+ return elementType .getConnectableStream (network ).map (Connectable ::getId ).toList ();
341
344
} else {
345
+ if (!elementType .isConnectable ()) { // early break if not supported
346
+ throw new IllegalStateException ("Unexpected non-connectable element type: " + elementType );
347
+ }
342
348
return getVoltageLevelStream (network , substationsIds , nominalVoltages )
343
- .flatMap (voltageLevel -> voltageLevel . getConnectableStream (( Class <? extends Connectable >) elementType . getElementClass ()) )
349
+ .flatMap (elementType :: getVoltageLevelConnectableStream )
344
350
.map (Connectable ::getId )
345
351
.distinct ()
346
352
.collect (Collectors .toList ());
@@ -355,24 +361,6 @@ private static Stream<VoltageLevel> getVoltageLevelStream(Network network, @NonN
355
361
return voltageLevelStream .filter (voltageLevel -> nominalVoltages == null || nominalVoltages .contains (voltageLevel .getNominalV ()));
356
362
}
357
363
358
- private static Stream <? extends Connectable <?>> getConnectableStream (Network network , ElementType elementType ) {
359
- return switch (elementType ) {
360
- case BUSBAR_SECTION , BUS -> network .getBusbarSectionStream ();
361
- case GENERATOR -> network .getGeneratorStream ();
362
- case LINE -> network .getLineStream ();
363
- case TWO_WINDINGS_TRANSFORMER -> network .getTwoWindingsTransformerStream ();
364
- case THREE_WINDINGS_TRANSFORMER -> network .getThreeWindingsTransformerStream ();
365
- case BATTERY -> network .getBatteryStream ();
366
- case DANGLING_LINE -> network .getDanglingLineStream ();
367
- case LCC_CONVERTER_STATION -> network .getLccConverterStationStream ();
368
- case VSC_CONVERTER_STATION -> network .getVscConverterStationStream ();
369
- case LOAD -> network .getLoadStream ();
370
- case SHUNT_COMPENSATOR -> network .getShuntCompensatorStream ();
371
- case STATIC_VAR_COMPENSATOR -> network .getStaticVarCompensatorStream ();
372
- default -> throw new IllegalStateException ("Unexpected connectable type:" + elementType );
373
- };
374
- }
375
-
376
364
public Set <Country > getCountries (UUID networkUuid , String variantId ) {
377
365
Network network = getNetwork (networkUuid , PreloadingStrategy .COLLECTION , variantId );
378
366
return network .getSubstationStream ()
0 commit comments