13
13
import org .gridsuite .network .map .dto .definition .bus .BusTabInfos ;
14
14
import org .gridsuite .network .map .dto .utils .ElementUtils ;
15
15
16
+ import java .util .Optional ;
17
+
18
+ import static org .gridsuite .network .map .dto .InfoTypeParameters .QUERY_PARAM_LOAD_NETWORK_COMPONENTS ;
16
19
import static org .gridsuite .network .map .dto .utils .ElementUtils .getProperties ;
17
20
import static org .gridsuite .network .map .dto .utils .ElementUtils .mapCountry ;
18
21
@@ -25,27 +28,34 @@ private BusInfosMapper() {
25
28
}
26
29
27
30
public static ElementInfos toData (Identifiable <?> identifiable , InfoTypeParameters infoTypeParameters ) {
31
+ boolean shouldLoadNetworkComponents = Optional .ofNullable (infoTypeParameters .getOptionalParameters ().get (QUERY_PARAM_LOAD_NETWORK_COMPONENTS ))
32
+ .map (Boolean ::valueOf )
33
+ .orElse (false );
28
34
return switch (infoTypeParameters .getInfoType ()) {
29
35
case LIST -> ElementInfosMapper .toListInfos (identifiable );
30
- case TAB -> toTabInfos (identifiable );
36
+ case TAB -> toTabInfos (identifiable , shouldLoadNetworkComponents );
31
37
default -> throw new UnsupportedOperationException ("TODO" );
32
38
};
33
39
}
34
40
35
- private static BusTabInfos toTabInfos (Identifiable <?> identifiable ) {
41
+ private static BusTabInfos toTabInfos (Identifiable <?> identifiable , boolean shouldLoadNetworkComponents ) {
36
42
Bus bus = (Bus ) identifiable ;
37
43
BusTabInfos .BusTabInfosBuilder <?, ?> builder = BusTabInfos .builder ().id (bus .getId ())
38
44
.angle (bus .getAngle ())
39
45
.v (bus .getV ())
40
46
.voltageLevelId (bus .getVoltageLevel ().getId ())
41
47
.nominalVoltage (bus .getVoltageLevel ().getNominalV ())
42
48
.country (mapCountry (bus .getVoltageLevel ().getSubstation ().orElse (null )))
43
- .synchronousComponentNum (bus .getSynchronousComponent ().getNum ())
44
49
.properties (getProperties (bus ))
45
- .connectedComponentNum (bus .getConnectedComponent ().getNum ())
46
50
.substationProperties (bus .getVoltageLevel ().getSubstation ().map (ElementUtils ::getProperties ).orElse (null ))
47
51
.voltageLevelProperties (getProperties (bus .getVoltageLevel ()));
48
52
53
+ if (shouldLoadNetworkComponents ) {
54
+ builder
55
+ .synchronousComponentNum (bus .getSynchronousComponent ().getNum ())
56
+ .connectedComponentNum (bus .getConnectedComponent ().getNum ());
57
+ }
58
+
49
59
return builder .build ();
50
60
}
51
61
}
0 commit comments