Skip to content

Commit 2df95cd

Browse files
authored
Change the the request type to get elements ids. (#566)
Signed-off-by: AAJELLAL <[email protected]>
1 parent 9442586 commit 2df95cd

File tree

5 files changed

+39
-52
lines changed

5 files changed

+39
-52
lines changed

src/main/java/org/gridsuite/study/server/StudyController.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,17 +423,16 @@ public ResponseEntity<String> getSubstationGraphics(
423423
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getSubstationsGraphics(networkStoreService.getNetworkUuid(studyUuid), nodeUuid, substationsIds));
424424
}
425425

426-
@GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/network-map/equipments-ids")
426+
@PostMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/network-map/equipments-ids")
427427
@Operation(summary = "Get equipment ids ")
428428
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The list of equipment ids")})
429429
public ResponseEntity<String> getNetworkElementsIds(
430430
@PathVariable("studyUuid") UUID studyUuid,
431431
@PathVariable("nodeUuid") UUID nodeUuid,
432-
@Parameter(description = "Substations id") @RequestParam(name = "substationsIds", required = false) List<String> substationsIds,
433-
@Parameter(description = "Should get in upstream built node ?") @RequestParam(value = "inUpstreamBuiltParentNode", required = false, defaultValue = "false") boolean inUpstreamBuiltParentNode,
434-
@Parameter(description = "equipment type") @RequestParam(name = "equipmentType") String equipmentType) {
432+
@RequestBody String equipmentInfos,
433+
@Parameter(description = "Should get in upstream built node ?") @RequestParam(value = "inUpstreamBuiltParentNode", required = false, defaultValue = "false") boolean inUpstreamBuiltParentNode) {
435434

436-
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getNetworkElementsIds(studyUuid, nodeUuid, substationsIds, inUpstreamBuiltParentNode, equipmentType));
435+
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getNetworkElementsIds(studyUuid, nodeUuid, inUpstreamBuiltParentNode, equipmentInfos));
437436
}
438437

439438
@GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/network-map/substations/{substationId}")

src/main/java/org/gridsuite/study/server/service/NetworkMapService.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
import org.gridsuite.study.server.dto.InfoTypeParameters;
1919
import org.springframework.beans.factory.annotation.Autowired;
2020
import org.springframework.core.ParameterizedTypeReference;
21+
import org.springframework.http.HttpHeaders;
2122
import org.springframework.http.HttpMethod;
2223
import org.springframework.http.HttpStatus;
24+
import org.springframework.http.MediaType;
25+
import org.springframework.http.HttpEntity;
2326
import org.springframework.stereotype.Service;
2427
import org.springframework.web.client.HttpStatusCodeException;
2528
import org.springframework.web.client.RestTemplate;
@@ -158,20 +161,19 @@ public String getEquipmentsMapData(UUID networkUuid, String variantId, List<Stri
158161
return restTemplate.getForObject(networkMapServerBaseUri + url, String.class);
159162
}
160163

161-
public String getElementsIds(UUID networkUuid, String variantId, List<String> substationsIds, String elementType) {
164+
public String getElementsIds(UUID networkUuid, String variantId, String equipmentInfos) {
162165
String path = DELIMITER + NETWORK_MAP_API_VERSION + "/networks/{networkUuid}/elements-ids";
163166

164167
UriComponentsBuilder builder = UriComponentsBuilder
165168
.fromPath(path);
166-
if (substationsIds != null) {
167-
builder = builder.queryParam(QUERY_PARAM_SUBSTATIONS_IDS, substationsIds);
168-
}
169169
if (!StringUtils.isBlank(variantId)) {
170170
builder = builder.queryParam(QUERY_PARAM_VARIANT_ID, variantId);
171171
}
172-
builder = builder.queryParam(QUERY_PARAM_ELEMENT_TYPE, elementType);
173172
String url = builder.buildAndExpand(networkUuid).toUriString();
174-
return restTemplate.getForObject(networkMapServerBaseUri + url, String.class);
173+
HttpHeaders headers = new HttpHeaders();
174+
headers.setContentType(MediaType.APPLICATION_JSON);
175+
HttpEntity<String> httpEntity = new HttpEntity<>(equipmentInfos, headers);
176+
return restTemplate.postForObject(networkMapServerBaseUri + url, httpEntity, String.class);
175177
}
176178

177179
public String getEquipmentMapData(UUID networkUuid, String variantId, String equipmentPath, String equipmentId) {

src/main/java/org/gridsuite/study/server/service/StudyService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,10 +1946,10 @@ public DynamicSimulationStatus getDynamicSimulationStatus(UUID nodeUuid) {
19461946

19471947
// --- Dynamic Simulation service methods END --- //
19481948

1949-
public String getNetworkElementsIds(UUID studyUuid, UUID nodeUuid, List<String> substationsIds, boolean inUpstreamBuiltParentNode, String equipmentType) {
1949+
public String getNetworkElementsIds(UUID studyUuid, UUID nodeUuid, boolean inUpstreamBuiltParentNode, String equipmentInfos) {
19501950
UUID nodeUuidToSearchIn = getNodeUuidToSearchIn(nodeUuid, inUpstreamBuiltParentNode);
19511951
return networkMapService.getElementsIds(networkStoreService.getNetworkUuid(studyUuid), networkModificationTreeService.getVariantId(nodeUuidToSearchIn),
1952-
substationsIds, equipmentType);
1952+
equipmentInfos);
19531953
}
19541954

19551955
@Transactional(readOnly = true)

src/test/java/org/gridsuite/study/server/NetworkMapTest.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@
5454
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
5555

5656
import java.io.IOException;
57-
import java.util.List;
58-
import java.util.Map;
59-
import java.util.Objects;
60-
import java.util.UUID;
57+
import java.util.*;
6158

6259
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
6360
import static org.gridsuite.study.server.StudyConstants.*;
@@ -66,6 +63,7 @@
6663
import static org.junit.Assert.assertEquals;
6764
import static org.junit.Assert.assertTrue;
6865
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
66+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
6967
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
7068
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
7169

@@ -262,8 +260,8 @@ public void testGetHvdcLinesMapServer() throws Exception {
262260

263261
//get the hvdc lines ids of a network
264262
String hvdcLineIdsAsString = List.of("hvdc-line1", "hvdc-line2", "hvdc-line3").toString();
265-
getNetworkElementsIds(studyNameUserIdUuid, rootNodeUuid, "HVDC_LINE", List.of(), hvdcLineIdsAsString);
266-
getNetworkElementsIds(studyNameUserIdUuid, rootNodeUuid, "HVDC_LINE", List.of("S1"), hvdcLineIdsAsString);
263+
getNetworkElementsIds(studyNameUserIdUuid, rootNodeUuid, hvdcLineIdsAsString, mapper.writeValueAsString(createRequestBody("HVDC_LINE", List.of())));
264+
getNetworkElementsIds(studyNameUserIdUuid, rootNodeUuid, hvdcLineIdsAsString, mapper.writeValueAsString(createRequestBody("HVDC_LINE", List.of("S1"))));
267265
}
268266

269267
@Test
@@ -283,7 +281,7 @@ public void testGet2wtMapServer() throws Exception {
283281

284282
//get the 2wt ids of a network
285283
String twtIdsAsString = List.of("twt1", "twt2", "twt3").toString();
286-
getNetworkElementsIds(studyNameUserIdUuid, rootNodeUuid, "TWO_WINDINGS_TRANSFORMER", List.of(), twtIdsAsString);
284+
getNetworkElementsIds(studyNameUserIdUuid, rootNodeUuid, twtIdsAsString, mapper.writeValueAsString(createRequestBody("TWO_WINDINGS_TRANSFORMER", List.of())));
287285
assertTrue(TestUtils.getRequestsDone(3, server).stream().anyMatch(r -> r.matches("/v1/parameters/" + LOADFLOW_PARAMETERS_UUID_STRING)));
288286
}
289287

@@ -316,7 +314,7 @@ public void testGetSubstationMapServer() throws Exception {
316314

317315
//get the substation ids of a network
318316
String substationIdsAsString = List.of("substation1", "substation2", "substation3").toString();
319-
getNetworkElementsIds(studyNameUserIdUuid, rootNodeUuid, "SUBSTATION", List.of(), substationIdsAsString);
317+
getNetworkElementsIds(studyNameUserIdUuid, rootNodeUuid, substationIdsAsString, mapper.writeValueAsString(createRequestBody("SUBSTATION", List.of())));
320318
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/parameters/" + LOADFLOW_PARAMETERS_UUID_STRING)));
321319
}
322320

@@ -520,17 +518,15 @@ private RootNode getRootNode(UUID study) throws Exception {
520518
}
521519

522520
@SneakyThrows
523-
private MvcResult getNetworkElementsIds(UUID studyUuid, UUID rootNodeUuid, String elementType, List<String> substationsIds, String responseBody) {
524-
UUID stubUuid = wireMockUtils.stubNetworkElementsIdsGet(NETWORK_UUID_STRING, elementType, responseBody);
525-
MockHttpServletRequestBuilder mockHttpServletRequestBuilder = get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-map/equipments-ids", studyUuid, rootNodeUuid)
526-
.queryParam(QUERY_PARAM_EQUIPMENT_TYPE, elementType);
527-
if (!substationsIds.isEmpty()) {
528-
mockHttpServletRequestBuilder.queryParam(QUERY_PARAM_SUBSTATIONS_IDS, substationsIds.stream().toArray(String[]::new));
529-
}
521+
private MvcResult getNetworkElementsIds(UUID studyUuid, UUID rootNodeUuid, String responseBody, String requestBody) {
522+
UUID stubUuid = wireMockUtils.stubNetworkElementsIdsPost(NETWORK_UUID_STRING, responseBody);
523+
524+
MockHttpServletRequestBuilder mockHttpServletRequestBuilder = post("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-map/equipments-ids", studyUuid, rootNodeUuid)
525+
.content(requestBody);
530526
MvcResult mvcResult = mockMvc.perform(mockHttpServletRequestBuilder)
531527
.andExpect(status().isOk())
532528
.andReturn();
533-
wireMockUtils.verifyNetworkElementsIdsGet(stubUuid, NETWORK_UUID_STRING, elementType);
529+
wireMockUtils.verifyNetworkElementsIdsPost(stubUuid, NETWORK_UUID_STRING, requestBody);
534530

535531
return mvcResult;
536532
}
@@ -717,6 +713,13 @@ public void testGetNominalVoltagesError() throws Exception {
717713
wireMockUtils.verifyNominalVoltagesGet(stubUuid, NETWORK_UUID_STRING);
718714
}
719715

716+
private Map<String, Object> createRequestBody(String elementType, List<String> substationsIds) {
717+
Map<String, Object> requestBody = new HashMap<>();
718+
requestBody.put("elementType", elementType);
719+
requestBody.put("substationsIds", substationsIds);
720+
return requestBody;
721+
}
722+
720723
private void cleanDB() {
721724
studyRepository.findAll().forEach(s -> networkModificationTreeService.doDeleteTree(s.getId()));
722725
studyRepository.deleteAll();

src/test/java/org/gridsuite/study/server/utils/WireMockUtils.java

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder;
1414
import com.github.tomakehurst.wiremock.matching.StringValuePattern;
1515
import com.github.tomakehurst.wiremock.stubbing.ServeEvent;
16-
import lombok.NonNull;
1716

1817
import java.util.List;
1918
import java.util.Map;
@@ -88,15 +87,16 @@ public void verifyNetworkElementsInfosGet(UUID stubUuid, String networkUuid, Str
8887
QUERY_PARAM_INFO_TYPE, WireMock.equalTo(infoType)));
8988
}
9089

91-
public UUID stubNetworkElementsIdsGet(String networkUuid, String elementType, String responseBody) {
92-
return wireMock.stubFor(WireMock.get(WireMock.urlPathEqualTo(URI_NETWORK_DATA + DELIMITER + networkUuid + DELIMITER + "elements-ids"))
93-
.withQueryParam(QUERY_PARAM_ELEMENT_TYPE, WireMock.equalTo(elementType))
90+
public UUID stubNetworkElementsIdsPost(String networkUuid, String responseBody) {
91+
return wireMock.stubFor(WireMock.post(WireMock.urlPathEqualTo(URI_NETWORK_DATA + DELIMITER + networkUuid + DELIMITER + "elements-ids"))
9492
.willReturn(WireMock.ok().withBody(responseBody))
9593
).getId();
9694
}
9795

98-
public void verifyNetworkElementsIdsGet(UUID stubUuid, String networkUuid, String elementType) {
99-
verifyGetRequest(stubUuid, URI_NETWORK_DATA + DELIMITER + networkUuid + DELIMITER + "elements-ids", Map.of(QUERY_PARAM_ELEMENT_TYPE, WireMock.equalTo(elementType)));
96+
public void verifyNetworkElementsIdsPost(UUID stubUuid, String networkUuid, String requestBody) {
97+
verifyPostRequest(stubUuid, URI_NETWORK_DATA + DELIMITER + networkUuid + DELIMITER + "elements-ids", false,
98+
Map.of(),
99+
requestBody);
100100
}
101101

102102
public UUID stubNetworkEquipmentsInfosGet(String networkUuid, String equipmentPath, String responseBody) {
@@ -109,17 +109,6 @@ public void verifyNetworkEquipmentsInfosGet(UUID stubUuid, String networkUuid, S
109109
verifyGetRequest(stubUuid, URI_NETWORK_DATA + DELIMITER + networkUuid + DELIMITER + equipmentPath, Map.of());
110110
}
111111

112-
public UUID stubNetworkEquipmentsInfosGet(String networkUuid, String infoTypePath, String equipmentType, String responseBody) {
113-
return wireMock.stubFor(WireMock.get(WireMock.urlPathEqualTo(URI_NETWORK_DATA + DELIMITER + networkUuid + DELIMITER + infoTypePath))
114-
.withQueryParam(QUERY_PARAM_EQUIPMENT_TYPE, WireMock.equalTo(equipmentType))
115-
.willReturn(WireMock.ok().withBody(responseBody))
116-
).getId();
117-
}
118-
119-
public void verifyNetworkEquipmentsInfosGet(UUID stubUuid, String networkUuid, String infoTypePath, String equipmentType) {
120-
verifyGetRequest(stubUuid, URI_NETWORK_DATA + DELIMITER + networkUuid + DELIMITER + infoTypePath, Map.of(QUERY_PARAM_EQUIPMENT_TYPE, WireMock.equalTo(equipmentType)));
121-
}
122-
123112
public UUID stubNetworkEquipmentInfosGet(String networkUuid, String infoTypePath, String equipmentId, String responseBody) {
124113
return wireMock.stubFor(WireMock.get(WireMock.urlPathEqualTo(URI_NETWORK_DATA + DELIMITER + networkUuid + DELIMITER + infoTypePath + DELIMITER + equipmentId))
125114
.willReturn(WireMock.ok().withBody(responseBody))
@@ -353,12 +342,6 @@ public void verifyDisableCaseExpiration(UUID stubUuid, String caseUuid) {
353342
verifyPutRequest(stubUuid, "/v1/cases/" + caseUuid + "/disableExpiration", false, Map.of(), null);
354343
}
355344

356-
public void verifyActuatorHealth(@NonNull final String serviceName, final UUID stubUuid, final int nbServer) {
357-
RequestPatternBuilder requestBuilder = WireMock.getRequestedFor(WireMock.urlPathEqualTo("/" + serviceName + "/actuator/health"));
358-
wireMock.verify(nbServer, requestBuilder);
359-
removeRequestForStub(stubUuid, nbServer);
360-
}
361-
362345
public UUID stubCountriesGet(String networkUuid, String responseBody) {
363346
return wireMock.stubFor(WireMock.get(WireMock.urlPathEqualTo("/v1/networks/" + networkUuid + "/countries"))
364347
.willReturn(WireMock.ok().withBody(responseBody))

0 commit comments

Comments
 (0)