25
25
import org .springframework .web .client .RestTemplate ;
26
26
import org .springframework .web .util .UriComponentsBuilder ;
27
27
28
- import java .util .HashMap ;
29
28
import java .util .List ;
30
29
import java .util .Map ;
31
30
import java .util .UUID ;
32
31
33
32
import static org .gridsuite .study .server .StudyConstants .*;
34
33
import static org .gridsuite .study .server .StudyException .Type .*;
35
- import static org .gridsuite .study .server .dto .InfoTypeParameters .QUERY_PARAM_DC_POWERFACTOR ;
36
34
import static org .gridsuite .study .server .utils .StudyUtils .handleHttpError ;
37
35
38
36
@ Service
39
37
public class NetworkMapService {
40
-
41
- static final String QUERY_PARAM_LINE_ID = "lineId" ;
42
-
43
38
private final RestTemplate restTemplate ;
44
39
45
40
private String networkMapServerBaseUri ;
@@ -50,47 +45,49 @@ public NetworkMapService(RemoteServicesProperties remoteServicesProperties, Rest
50
45
this .restTemplate = restTemplate ;
51
46
}
52
47
53
- public String getElementsInfos (UUID networkUuid , String variantId , List <String > substationsIds , String elementType , List <Double > nominalVoltages , String infoType , double dcPowerFactor ) {
48
+ public String getElementsInfos (UUID networkUuid ,
49
+ String variantId ,
50
+ List <String > substationsIds ,
51
+ String elementType ,
52
+ List <Double > nominalVoltages ,
53
+ String infoType ,
54
+ Map <String , String > optionalParameters ) {
54
55
String path = DELIMITER + NETWORK_MAP_API_VERSION + "/networks/{networkUuid}/elements" ;
55
56
UriComponentsBuilder builder = UriComponentsBuilder .fromPath (path );
56
-
57
57
if (!StringUtils .isBlank (variantId )) {
58
58
builder = builder .queryParam (QUERY_PARAM_VARIANT_ID , variantId );
59
59
}
60
-
61
60
builder = builder .queryParam (QUERY_PARAM_INFO_TYPE , infoType )
62
61
.queryParam (QUERY_PARAM_ELEMENT_TYPE , elementType );
63
-
64
62
if (nominalVoltages != null && !nominalVoltages .isEmpty ()) {
65
63
builder = builder .queryParam (QUERY_PARAM_NOMINAL_VOLTAGES , nominalVoltages );
66
64
}
67
- InfoTypeParameters infoTypeParameters = InfoTypeParameters .builder ()
68
- .optionalParameters (Map .of (QUERY_PARAM_DC_POWERFACTOR , String .valueOf (dcPowerFactor )))
69
- .build ();
70
- queryParamInfoTypeParameters (infoTypeParameters , builder );
65
+ queryParamInfoTypeParameters (InfoTypeParameters .builder ()
66
+ .optionalParameters (optionalParameters )
67
+ .build (), builder );
71
68
String url = builder .buildAndExpand (networkUuid ).toUriString ();
72
-
73
69
HttpHeaders headers = new HttpHeaders ();
74
70
headers .setContentType (MediaType .APPLICATION_JSON );
75
71
HttpEntity <List <String >> httpEntity = new HttpEntity <>(substationsIds , headers );
76
72
return restTemplate .postForObject (networkMapServerBaseUri + url , httpEntity , String .class );
77
73
}
78
74
79
- public String getElementInfos (UUID networkUuid , String variantId , String elementType , String infoType ,
80
- double dcPowerFactor , String elementId ) {
75
+ public String getElementInfos (UUID networkUuid ,
76
+ String variantId ,
77
+ String elementType ,
78
+ String infoType ,
79
+ Map <String , String > optionalParameters ,
80
+ String elementId ) {
81
81
String path = DELIMITER + NETWORK_MAP_API_VERSION + "/networks/{networkUuid}/elements/{elementId}" ;
82
82
UriComponentsBuilder builder = UriComponentsBuilder .fromPath (path );
83
83
if (!StringUtils .isBlank (variantId )) {
84
84
builder = builder .queryParam (QUERY_PARAM_VARIANT_ID , variantId );
85
85
}
86
- builder = builder .queryParam (QUERY_PARAM_ELEMENT_TYPE , elementType );
87
- builder = builder .queryParam (QUERY_PARAM_INFO_TYPE , infoType );
88
- Map <String , String > optionalParams = new HashMap <>();
89
- optionalParams .put (QUERY_PARAM_DC_POWERFACTOR , String .valueOf (dcPowerFactor ));
90
- InfoTypeParameters infoTypeParameters = InfoTypeParameters .builder ()
91
- .optionalParameters (optionalParams )
92
- .build ();
93
- queryParamInfoTypeParameters (infoTypeParameters , builder );
86
+ builder = builder .queryParam (QUERY_PARAM_INFO_TYPE , infoType )
87
+ .queryParam (QUERY_PARAM_ELEMENT_TYPE , elementType );
88
+ queryParamInfoTypeParameters (InfoTypeParameters .builder ()
89
+ .optionalParameters (optionalParameters )
90
+ .build (), builder );
94
91
95
92
try {
96
93
return restTemplate .getForObject (networkMapServerBaseUri + builder .build ().toUriString (), String .class , networkUuid , elementId );
@@ -105,6 +102,25 @@ public String getElementInfos(UUID networkUuid, String variantId, String element
105
102
}
106
103
}
107
104
105
+ public String getAllElementsInfos (UUID networkUuid ,
106
+ String variantId ,
107
+ List <String > substationsIds ,
108
+ Map <String , Map <String , String >> optionalParameters ) {
109
+ String path = DELIMITER + NETWORK_MAP_API_VERSION + "/networks/{networkUuid}/all" ;
110
+ UriComponentsBuilder builder = UriComponentsBuilder .fromPath (path );
111
+ if (!StringUtils .isBlank (variantId )) {
112
+ builder = builder .queryParam (QUERY_PARAM_VARIANT_ID , variantId );
113
+ }
114
+ builder = builder .queryParam (QUERY_PARAM_INFO_TYPE , "TAB" );
115
+ if (substationsIds != null ) {
116
+ builder = builder .queryParam (QUERY_PARAM_SUBSTATION_ID , substationsIds );
117
+ }
118
+ HttpHeaders headers = new HttpHeaders ();
119
+ headers .setContentType (MediaType .APPLICATION_JSON );
120
+ HttpEntity <?> httpEntity = new HttpEntity <>(optionalParameters , headers );
121
+ return restTemplate .postForObject (networkMapServerBaseUri + builder .buildAndExpand (networkUuid ).toUriString (), httpEntity , String .class );
122
+ }
123
+
108
124
private void queryParamInfoTypeParameters (InfoTypeParameters infoTypesParameters , UriComponentsBuilder builder ) {
109
125
infoTypesParameters .getOptionalParameters ().forEach ((key , value ) -> builder .queryParam (String .format (QUERY_FORMAT_OPTIONAL_PARAMS , key ), value ));
110
126
}
@@ -164,8 +180,7 @@ public String getElementsIds(UUID networkUuid, String variantId, List<String> su
164
180
return restTemplate .postForObject (networkMapServerBaseUri + url , httpEntity , String .class );
165
181
}
166
182
167
- public String getEquipmentsMapData (UUID networkUuid , String variantId , List <String > substationsIds ,
168
- String equipmentPath ) {
183
+ public String getEquipmentsMapData (UUID networkUuid , String variantId , List <String > substationsIds , String equipmentPath ) {
169
184
String path = DELIMITER + NETWORK_MAP_API_VERSION + "/networks/{networkUuid}/" + equipmentPath ;
170
185
UriComponentsBuilder builder = UriComponentsBuilder
171
186
.fromPath (path );
0 commit comments