-
Notifications
You must be signed in to change notification settings - Fork 2
get network element ids from filters #1111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
e933374
b460629
cc4cabf
f25a70a
7276d43
d44653d
cf58e0c
82f3f39
a72c073
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -120,6 +120,29 @@ public String exportFilters(UUID networkUuid, List<UUID> filtersUuid, String var | |||||
| return restTemplate.getForObject(uriComponent.toUriString(), String.class); | ||||||
| } | ||||||
|
|
||||||
| public List<String> convertFiltersToNetworkElementIds(UUID networkUuid, List<UUID> filtersUuid, String variantId) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think here too "evaluate" would be the right word :
Suggested change
like for the very similar function : |
||||||
| Objects.requireNonNull(networkUuid); | ||||||
| Objects.requireNonNull(filtersUuid); | ||||||
| String endPointUrl = getBaseUri() + DELIMITER + FILTER_API_VERSION + FILTERS_END_POINT_EXPORT + DELIMITER + "onlyIds"; | ||||||
|
|
||||||
| UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(endPointUrl); | ||||||
| uriComponentsBuilder.queryParam(NETWORK_UUID, networkUuid); | ||||||
| if (!StringUtils.isBlank(variantId)) { | ||||||
| uriComponentsBuilder.queryParam(QUERY_PARAM_VARIANT_ID, variantId); | ||||||
| } | ||||||
| uriComponentsBuilder.queryParam(IDS, filtersUuid); | ||||||
| var uriComponent = uriComponentsBuilder.buildAndExpand(); | ||||||
|
|
||||||
| HttpHeaders headers = new HttpHeaders(); | ||||||
| headers.setContentType(MediaType.APPLICATION_JSON); | ||||||
| return restTemplate.exchange( | ||||||
| uriComponent.toUri(), | ||||||
| HttpMethod.GET, | ||||||
| new HttpEntity<>(headers), | ||||||
| new ParameterizedTypeReference<List<String>>() { } | ||||||
| ).getBody(); | ||||||
| } | ||||||
|
|
||||||
| public String evaluateFilters(UUID networkUuid, String filters) { | ||||||
| Objects.requireNonNull(networkUuid); | ||||||
| Objects.requireNonNull(filters); | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2529,13 +2529,13 @@ public List<String> evaluateGlobalFilter(@NonNull final UUID nodeUuid, @NonNull | |
| } | ||
|
|
||
| @Transactional | ||
| public String getNetworkElementsInfosByGlobalFilter(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, EquipmentType equipmentType, String infoType, GlobalFilter filter) { | ||
| // Get the list of equipment ids that match the filter | ||
| List<String> equipmentIds = self.evaluateGlobalFilter(nodeUuid, rootNetworkUuid, List.of(equipmentType), filter); | ||
|
|
||
| public String getNetworkElementsInfosFromFilters(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, EquipmentType equipmentType, String infoType, List<UUID> filterUuids) { | ||
| // Get the requested info for the filtered equipment ids | ||
| UUID nodeUuidToSearchIn = getNodeUuidToSearchIn(nodeUuid, rootNetworkUuid, true); | ||
| StudyEntity studyEntity = getStudy(studyUuid); | ||
| String variantId = networkModificationTreeService.getVariantId(nodeUuidToSearchIn, rootNetworkUuid); | ||
| // Get the list of equipment ids that match the filter | ||
| List<String> equipmentIds = filterService.convertFiltersToNetworkElementIds(rootNetworkService.getNetworkUuid(rootNetworkUuid), filterUuids, variantId); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
is called 2 successive times here. Could be refactored. |
||
| LoadFlowParameters loadFlowParameters = loadFlowService.getCommonParameters(studyEntity); | ||
|
|
||
| return networkMapService.getElementsInfosByIds( | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -22,7 +22,6 @@ | |||||
| import mockwebserver3.junit5.internal.MockWebServerExtension; | ||||||
| import okhttp3.Headers; | ||||||
| import okhttp3.HttpUrl; | ||||||
| import org.gridsuite.filter.utils.EquipmentType; | ||||||
| import org.gridsuite.study.server.dto.ComputationType; | ||||||
| import org.gridsuite.study.server.dto.IdentifiableInfos; | ||||||
| import org.gridsuite.study.server.networkmodificationtree.dto.AbstractNode; | ||||||
|
|
@@ -56,20 +55,24 @@ | |||||
| import org.springframework.test.web.servlet.MvcResult; | ||||||
| import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; | ||||||
| import org.springframework.util.LinkedMultiValueMap; | ||||||
|
|
||||||
| import java.net.URLEncoder; | ||||||
| import java.nio.charset.StandardCharsets; | ||||||
| import java.util.List; | ||||||
| import java.util.Map; | ||||||
| import java.util.Objects; | ||||||
| import java.util.UUID; | ||||||
| import java.util.stream.Collectors; | ||||||
|
|
||||||
| import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; | ||||||
| import static org.gridsuite.study.server.StudyConstants.*; | ||||||
| import static org.gridsuite.study.server.dto.InfoTypeParameters.QUERY_PARAM_DC_POWERFACTOR; | ||||||
| import static org.hamcrest.MatcherAssert.assertThat; | ||||||
| import static org.junit.jupiter.api.Assertions.*; | ||||||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||||||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||||||
| import static org.mockito.Mockito.*; | ||||||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; | ||||||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||||||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||||||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | ||||||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||||||
|
|
||||||
|
|
@@ -709,7 +712,7 @@ void testGetAllNetworkElementsInfos(final MockWebServer server) throws Exception | |||||
| } | ||||||
|
|
||||||
| @Test | ||||||
| void testGetNetworkElementsInfosByGlobalFilter(final MockWebServer server) throws Exception { | ||||||
| void testGetNetworkElementsInfosFromFilters(final MockWebServer server) throws Exception { | ||||||
| networkMapService.setNetworkMapServerBaseUri(wireMockServer.baseUrl()); | ||||||
|
|
||||||
| // Create study | ||||||
|
|
@@ -720,25 +723,21 @@ void testGetNetworkElementsInfosByGlobalFilter(final MockWebServer server) throw | |||||
|
|
||||||
| String equipmentType = "GENERATOR"; | ||||||
| String infoType = "FORM"; | ||||||
| String globalFilterBody = """ | ||||||
| { | ||||||
| "genericFilter": ["550e8400-e29b-41d4-a716-446655440000"] | ||||||
| } | ||||||
| """; | ||||||
| UUID filterUuid = UUID.randomUUID(); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this would be simpler to just use a list here :
Suggested change
This is always used as a list later anyway. |
||||||
|
|
||||||
| // Response from global filter evaluation | ||||||
| String globalFilterEvaluateResponse = "[\"GEN1\",\"GEN2\"]"; | ||||||
| String filterEvaluateResponse = "[\"GEN1\",\"GEN2\"]"; | ||||||
|
|
||||||
| // Response from elements-by-ids endpoint | ||||||
| String elementsInfosResponse = mapper.writeValueAsString(List.of( | ||||||
| IdentifiableInfos.builder().id("GEN1").name("Generator 1").build(), | ||||||
| IdentifiableInfos.builder().id("GEN2").name("Generator 2").build() | ||||||
| )); | ||||||
|
|
||||||
| UUID globalFilterStubUuid = wireMockStubs.stubGlobalFilterEvaluate( | ||||||
| UUID globalFilterStubUuid = wireMockStubs.stubEvaluateFiltersToEquipmentIds( | ||||||
| NETWORK_UUID_STRING, | ||||||
| List.of(EquipmentType.GENERATOR), | ||||||
| globalFilterEvaluateResponse | ||||||
| List.of(filterUuid), | ||||||
| filterEvaluateResponse | ||||||
| ); | ||||||
|
|
||||||
| UUID elementsByIdsStubUuid = wireMockStubs.stubNetworkElementsByIdsPost( | ||||||
|
|
@@ -748,12 +747,12 @@ void testGetNetworkElementsInfosByGlobalFilter(final MockWebServer server) throw | |||||
| elementsInfosResponse | ||||||
| ); | ||||||
|
|
||||||
| MvcResult mvcResult = mockMvc.perform(post("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/network/elements-by-global-filter", | ||||||
| MvcResult mvcResult = mockMvc.perform(post("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/network/elements-from-filters", | ||||||
| studyUuid, firstRootNetworkUuid, rootNodeUuid) | ||||||
| .queryParam("equipmentType", equipmentType) | ||||||
| .queryParam("infoType", infoType) | ||||||
| .contentType(MediaType.APPLICATION_JSON) | ||||||
| .content(globalFilterBody)) | ||||||
| .content(objectMapper.writeValueAsString(List.of(filterUuid)))) | ||||||
| .andExpect(status().isOk()) | ||||||
| .andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||||||
| .andReturn(); | ||||||
|
|
@@ -765,7 +764,7 @@ void testGetNetworkElementsInfosByGlobalFilter(final MockWebServer server) throw | |||||
| assertTrue(resultList.stream().anyMatch(info -> "GEN1".equals(info.getId()) && "Generator 1".equals(info.getName()))); | ||||||
| assertTrue(resultList.stream().anyMatch(info -> "GEN2".equals(info.getId()) && "Generator 2".equals(info.getName()))); | ||||||
|
|
||||||
| wireMockStubs.verifyGlobalFilterEvaluate(globalFilterStubUuid, NETWORK_UUID_STRING, List.of(EquipmentType.GENERATOR)); | ||||||
| wireMockStubs.verifyEvaluateFiltersToEquipmentIds(globalFilterStubUuid, List.of(filterUuid.toString()), NETWORK_UUID_STRING); | ||||||
| wireMockStubs.verifyNetworkElementsByIdsPost(elementsByIdsStubUuid, NETWORK_UUID_STRING, equipmentType, infoType, "[\"GEN1\",\"GEN2\"]"); | ||||||
|
|
||||||
| assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/parameters/" + LOADFLOW_PARAMETERS_UUID_STRING))); | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -450,6 +450,25 @@ public UUID stubGlobalFilterEvaluate(String networkUuid, List<EquipmentType> equ | |||||
| ).getId(); | ||||||
| } | ||||||
|
|
||||||
| public UUID stubEvaluateFiltersToEquipmentIds(String networkUuid, List<UUID> filterUuids, String responseBody) { | ||||||
| MappingBuilder requestPatternBuilder = WireMock.get(WireMock.urlPathEqualTo("/v1/filters/export/onlyIds")) | ||||||
| .withQueryParam(NETWORK_UUID, WireMock.equalTo(networkUuid)); | ||||||
| for (UUID filterUuid : filterUuids) { | ||||||
| requestPatternBuilder.withQueryParam(IDS, WireMock.equalTo(filterUuid.toString())); | ||||||
| } | ||||||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||||||
| return wireMock.stubFor(requestPatternBuilder.willReturn(WireMock.ok().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).withBody(responseBody)) | ||||||
| ).getId(); | ||||||
| } | ||||||
|
|
||||||
| public void verifyEvaluateFiltersToEquipmentIds(UUID stubUuid, List<String> filtersUuid, String networkUuid) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this would be clearer to use the filters exactly like in the
Suggested change
|
||||||
| Map<String, StringValuePattern> queryParams = new HashMap<>(); | ||||||
| queryParams.put(NETWORK_UUID, WireMock.equalTo(networkUuid)); | ||||||
| for (String filterUuid : filtersUuid) { | ||||||
| queryParams.put(IDS, WireMock.equalTo(filterUuid)); | ||||||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||||||
| } | ||||||
| verifyGetRequest(wireMock, stubUuid, "/v1/filters/export/onlyIds", queryParams); | ||||||
| } | ||||||
|
|
||||||
| public UUID stubFilterEvaluateNotFoundError(String networkUuid) { | ||||||
| return wireMock.stubFor(WireMock.post(WireMock.urlPathEqualTo("/v1/filters/evaluate")) | ||||||
| .withQueryParam(NETWORK_UUID, WireMock.equalTo(networkUuid)) | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.