8
8
9
9
import com .powsybl .commons .PowsyblException ;
10
10
import com .powsybl .iidm .network .*;
11
+ import com .powsybl .iidm .network .HvdcConverterStation .HvdcType ;
11
12
import com .powsybl .network .store .client .NetworkStoreService ;
12
13
import com .powsybl .network .store .client .PreloadingStrategy ;
13
14
import org .gridsuite .network .map .dto .*;
18
19
import org .springframework .context .annotation .ComponentScan ;
19
20
import org .springframework .http .HttpStatus ;
20
21
import org .springframework .lang .NonNull ;
22
+ import org .springframework .lang .Nullable ;
21
23
import org .springframework .stereotype .Service ;
22
24
import org .springframework .web .server .ResponseStatusException ;
23
25
@@ -52,7 +54,7 @@ private static PreloadingStrategy getPreloadingStrategy(@NonNull List<String> su
52
54
return substationsIds .isEmpty () ? PreloadingStrategy .COLLECTION : PreloadingStrategy .NONE ;
53
55
}
54
56
55
- public List <String > getSubstationsIds (UUID networkUuid , String variantId , List <Double > nominalVoltages ) {
57
+ private List <String > getSubstationsIds (UUID networkUuid , String variantId , List <Double > nominalVoltages ) {
56
58
Network network = getNetwork (networkUuid , PreloadingStrategy .COLLECTION , variantId );
57
59
return network .getSubstationStream ()
58
60
.filter (substation -> nominalVoltages == null ||
@@ -129,7 +131,7 @@ public List<String> getVoltageLevelBusbarSectionsIds(UUID networkUuid, String vo
129
131
.map (BusbarSection ::getId ).collect (Collectors .toList ());
130
132
}
131
133
132
- private List <String > getHvdcLinesIdsByHvdcType (UUID networkUuid , String variantId , @ NonNull List <String > substationsIds , List <Double > nominalVoltages , HvdcConverterStation . HvdcType type ) {
134
+ private List <String > getHvdcLinesIdsByHvdcType (UUID networkUuid , String variantId , @ NonNull List <String > substationsIds , List <Double > nominalVoltages , HvdcType type ) {
133
135
Network network = getNetwork (networkUuid , getPreloadingStrategy (substationsIds ), variantId );
134
136
Stream <HvdcLine > hvdcLineStream = (substationsIds .isEmpty () && nominalVoltages == null )
135
137
? network .getHvdcLineStream ()
@@ -149,11 +151,11 @@ private List<String> getHvdcLinesIds(UUID networkUuid, String variantId, @NonNul
149
151
}
150
152
151
153
private List <String > getHvdcLinesLccIds (UUID networkUuid , String variantId , @ NonNull List <String > substationsIds , List <Double > nominalVoltages ) {
152
- return getHvdcLinesIdsByHvdcType (networkUuid , variantId , substationsIds , nominalVoltages , HvdcConverterStation . HvdcType .LCC );
154
+ return getHvdcLinesIdsByHvdcType (networkUuid , variantId , substationsIds , nominalVoltages , HvdcType .LCC );
153
155
}
154
156
155
157
private List <String > getHvdcLinesVscIds (UUID networkUuid , String variantId , @ NonNull List <String > substationsIds , List <Double > nominalVoltages ) {
156
- return getHvdcLinesIdsByHvdcType (networkUuid , variantId , substationsIds , nominalVoltages , HvdcConverterStation . HvdcType .VSC );
158
+ return getHvdcLinesIdsByHvdcType (networkUuid , variantId , substationsIds , nominalVoltages , HvdcType .VSC );
157
159
}
158
160
159
161
private List <String > getTieLinesIds (UUID networkUuid , String variantId , @ NonNull List <String > substationsIds , List <Double > nominalVoltages ) {
@@ -172,7 +174,7 @@ private List<String> getTieLinesIds(UUID networkUuid, String variantId, @NonNull
172
174
}
173
175
}
174
176
175
- private List <ElementInfos > getSubstationsInfos (Network network , @ NonNull List <String > substationsId , InfoTypeParameters infoTypeParameters , List <Double > nominalVoltages ) {
177
+ private static List <ElementInfos > getSubstationsInfos (Network network , @ NonNull List <String > substationsId , InfoTypeParameters infoTypeParameters , List <Double > nominalVoltages ) {
176
178
Stream <Substation > substations = substationsId .isEmpty () ? network .getSubstationStream () : substationsId .stream ().map (network ::getSubstation );
177
179
return substations
178
180
.filter (substation -> nominalVoltages == null ||
@@ -181,13 +183,13 @@ private List<ElementInfos> getSubstationsInfos(Network network, @NonNull List<St
181
183
.toList ();
182
184
}
183
185
184
- private List <ElementInfos > getVoltageLevelsInfos (Network network , @ NonNull List <String > substationsId , InfoTypeParameters infoTypeParameters , List <Double > nominalVoltages ) {
186
+ private static List <ElementInfos > getVoltageLevelsInfos (Network network , @ NonNull List <String > substationsId , InfoTypeParameters infoTypeParameters , List <Double > nominalVoltages ) {
185
187
return getVoltageLevelStream (network , substationsId , nominalVoltages )
186
188
.map (c -> ElementType .VOLTAGE_LEVEL .getInfosGetter ().apply (c , infoTypeParameters ))
187
189
.toList ();
188
190
}
189
191
190
- private List <ElementInfos > getHvdcLinesInfosByHvdcType (Network network , @ NonNull List <String > substationsId , InfoTypeParameters infoTypeParameters , List <Double > nominalVoltages , HvdcConverterStation . HvdcType type ) {
192
+ private static List <ElementInfos > getHvdcLinesInfosByHvdcType (Network network , @ NonNull List <String > substationsId , InfoTypeParameters infoTypeParameters , List <Double > nominalVoltages , HvdcType type ) {
191
193
Stream <HvdcLine > hvdcLineStream = substationsId .isEmpty ()
192
194
? network .getHvdcLineStream ()
193
195
: substationsId .stream ()
@@ -204,26 +206,29 @@ private List<ElementInfos> getHvdcLinesInfosByHvdcType(Network network, @NonNull
204
206
return hvdcLineStream .map (c -> getElementTypeByHvdcType (type ).getInfosGetter ().apply (c , infoTypeParameters )).toList ();
205
207
}
206
208
207
- private ElementType getElementTypeByHvdcType (HvdcConverterStation .HvdcType type ) {
208
- if (type == HvdcConverterStation .HvdcType .LCC ) {
209
+ @ SuppressWarnings ({
210
+ "java:S6880" , // can't use switch-case for an enum value that can be null because java desugar it with `switch(enum.ordinal())`
211
+ })
212
+ private static ElementType getElementTypeByHvdcType (@ Nullable final HvdcType type ) {
213
+ if (type == HvdcType .LCC ) {
209
214
return ElementType .HVDC_LINE_LCC ;
210
- } else if (type == HvdcConverterStation . HvdcType .VSC ) {
215
+ } else if (type == HvdcType .VSC ) {
211
216
return ElementType .HVDC_LINE_VSC ;
212
217
} else {
213
218
return ElementType .HVDC_LINE ;
214
219
}
215
220
}
216
221
217
- private List <ElementInfos > getHvdcLinesInfos (Network network , @ NonNull List <String > substationsId , InfoTypeParameters infoTypeParameters , List <Double > nominalVoltages ) {
222
+ private static List <ElementInfos > getHvdcLinesInfos (Network network , @ NonNull List <String > substationsId , InfoTypeParameters infoTypeParameters , List <Double > nominalVoltages ) {
218
223
return getHvdcLinesInfosByHvdcType (network , substationsId , infoTypeParameters , nominalVoltages , null );
219
224
}
220
225
221
- private List <ElementInfos > getHvdcLinesLccInfos (Network network , @ NonNull List <String > substationsId , InfoTypeParameters infoTypeParameters , List <Double > nominalVoltages ) {
222
- return getHvdcLinesInfosByHvdcType (network , substationsId , infoTypeParameters , nominalVoltages , HvdcConverterStation . HvdcType .LCC );
226
+ private static List <ElementInfos > getHvdcLinesLccInfos (Network network , @ NonNull List <String > substationsId , InfoTypeParameters infoTypeParameters , List <Double > nominalVoltages ) {
227
+ return getHvdcLinesInfosByHvdcType (network , substationsId , infoTypeParameters , nominalVoltages , HvdcType .LCC );
223
228
}
224
229
225
- private List <ElementInfos > getHvdcLinesVscInfos (Network network , @ NonNull List <String > substationsId , InfoTypeParameters infoTypeParameters , List <Double > nominalVoltages ) {
226
- return getHvdcLinesInfosByHvdcType (network , substationsId , infoTypeParameters , nominalVoltages , HvdcConverterStation . HvdcType .VSC );
230
+ private static List <ElementInfos > getHvdcLinesVscInfos (Network network , @ NonNull List <String > substationsId , InfoTypeParameters infoTypeParameters , List <Double > nominalVoltages ) {
231
+ return getHvdcLinesInfosByHvdcType (network , substationsId , infoTypeParameters , nominalVoltages , HvdcType .VSC );
227
232
}
228
233
229
234
private List <ElementInfos > getTieLinesInfos (Network network , @ NonNull List <String > substationsId , InfoTypeParameters infoTypeParameters , List <Double > nominalVoltages ) {
@@ -254,9 +259,9 @@ private List<ElementInfos> getBusesInfos(Network network, @NonNull List<String>
254
259
.toList ();
255
260
}
256
261
257
- private List <ElementInfos > getElementsInfos (Network network , @ NonNull List <String > substationsIds , ElementType elementType , InfoTypeParameters infoTypeParameters , List <Double > nominalVoltages ) {
258
- Class <? extends Connectable > elementClass = (Class <? extends Connectable >) elementType .getElementClass ();
259
- Stream <? extends Connectable > connectables = substationsIds .isEmpty () ?
262
+ 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 () ?
260
265
getConnectableStream (network , elementType ) :
261
266
substationsIds .stream ()
262
267
.flatMap (substationId -> network .getSubstation (substationId ).getVoltageLevelStream ())
@@ -342,15 +347,15 @@ private List<String> getConnectablesIds(UUID networkUuid, String variantId, @Non
342
347
}
343
348
}
344
349
345
- private Stream <VoltageLevel > getVoltageLevelStream (Network network , @ NonNull List <String > substationsIds , List <Double > nominalVoltages ) {
350
+ private static Stream <VoltageLevel > getVoltageLevelStream (Network network , @ NonNull List <String > substationsIds , List <Double > nominalVoltages ) {
346
351
Stream <VoltageLevel > voltageLevelStream =
347
352
substationsIds .isEmpty () ?
348
353
network .getVoltageLevelStream () :
349
354
substationsIds .stream ().flatMap (substationId -> network .getSubstation (substationId ).getVoltageLevelStream ());
350
355
return voltageLevelStream .filter (voltageLevel -> nominalVoltages == null || nominalVoltages .contains (voltageLevel .getNominalV ()));
351
356
}
352
357
353
- public Stream <? extends Connectable > getConnectableStream (Network network , ElementType elementType ) {
358
+ private static Stream <? extends Connectable <?> > getConnectableStream (Network network , ElementType elementType ) {
354
359
return switch (elementType ) {
355
360
case BUSBAR_SECTION , BUS -> network .getBusbarSectionStream ();
356
361
case GENERATOR -> network .getGeneratorStream ();
0 commit comments