Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.beans.PropertyEditorSupport;
import java.util.*;
Expand Down Expand Up @@ -2154,14 +2153,6 @@ public ResponseEntity<Void> setNetworkVisualizationParametersValues(
return ResponseEntity.ok().build();
}

@PostMapping(value = "/studies/network-visualizations/nad-positions-config", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@Operation(summary = "create a nad positions configuration using data from a csv")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The nad positions configuration created")})
public ResponseEntity<Void> createNadPositionsConfigFromCsv(@RequestParam("file") MultipartFile file) {
studyService.createNadPositionsConfigFromCsv(file);
return ResponseEntity.ok().build();
}

@GetMapping(value = "/optional-services")
@Operation(summary = "Get all the optional services and their status")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "List of optional services")})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.*;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.util.UriComponentsBuilder;

import java.util.List;
Expand All @@ -31,13 +31,6 @@
@Service
public class SingleLineDiagramService {

static final String QUERY_PARAM_DEPTH = "depth";
static final String QUERY_PARAM_INIT_WITH_GEO_DATA = "withGeoData";
static final String QUERY_PARAM_ELEMENT_PARAMS = "elementParams";
static final String NOT_FOUND = " not found";
static final String VOLTAGE_LEVEL = "Voltage level ";
static final String ELEMENT = "Element";

private final RestTemplate restTemplate;

private String singleLineDiagramServerBaseUri;
Expand Down Expand Up @@ -155,27 +148,4 @@ public void deleteDiagramConfigs(List<UUID> configUuids) {
public void setSingleLineDiagramServerBaseUri(String singleLineDiagramServerBaseUri) {
this.singleLineDiagramServerBaseUri = singleLineDiagramServerBaseUri;
}

public void addParameters(UriComponentsBuilder uriComponentsBuilder, String variantId) {
if (!StringUtils.isBlank(variantId)) {
uriComponentsBuilder.queryParam(QUERY_PARAM_VARIANT_ID, variantId);
}
}

public void createNadPositionsConfigFromCsv(MultipartFile file) {
var path = UriComponentsBuilder.fromPath(DELIMITER + SINGLE_LINE_DIAGRAM_API_VERSION +
"/network-area-diagram/config/positions").buildAndExpand()
.toUriString();

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);

MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("file_name", file.getOriginalFilename());
body.add("file", file.getResource());

HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);

restTemplate.exchange(singleLineDiagramServerBaseUri + path, HttpMethod.POST, requestEntity, Void.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.util.UriUtils;

import java.io.UncheckedIOException;
Expand Down Expand Up @@ -3912,11 +3911,6 @@ public boolean updateSpreadsheetParameters(UUID studyUuid, SpreadsheetParameters
return studyEntity.isPresent();
}

@Transactional
public void createNadPositionsConfigFromCsv(MultipartFile file) {
singleLineDiagramService.createNadPositionsConfigFromCsv(file);
}

private List<CurrentLimitViolationInfos> getCurrentLimitViolations(UUID nodeUuid, UUID rootNetworkUuid) {
UUID resultUuid = rootNetworkNodeInfoService.getComputationResultUuid(nodeUuid, rootNetworkUuid, LOAD_FLOW);
if (resultUuid == null) {
Expand Down
32 changes: 5 additions & 27 deletions src/test/java/org/gridsuite/study/server/StudyServiceTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com)
* Copyright (c) 2026, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
Expand All @@ -16,8 +16,8 @@
import org.gridsuite.study.server.repository.networkmodificationtree.NodeRepository;
import org.gridsuite.study.server.service.*;
import org.gridsuite.study.server.utils.TestUtils;
import org.gridsuite.study.server.utils.wiremock.WireMockStubs;
import org.gridsuite.study.server.utils.elasticsearch.DisableElasticsearch;
import org.gridsuite.study.server.utils.wiremock.WireMockStubs;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -26,19 +26,16 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.context.bean.override.mockito.MockitoSpyBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;

import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@AutoConfigureMockMvc
@SpringBootTest
Expand All @@ -49,7 +46,7 @@

private WireMockServer wireMockServer;

private WireMockStubs wireMockStubs;

Check warning on line 49 in src/test/java/org/gridsuite/study/server/StudyServiceTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused "wireMockStubs" private field.

See more on https://sonarcloud.io/project/issues?id=org.gridsuite%3Astudy-server&issues=AZ4xM4hbGVej_5GpoDPG&open=AZ4xM4hbGVej_5GpoDPG&pullRequest=993

@Autowired
private MockMvc mockMvc;
Expand Down Expand Up @@ -78,25 +75,6 @@
singleLineDiagramService.setSingleLineDiagramServerBaseUri(wireMockServer.baseUrl());
}

@Test
void testImportCsv() throws Exception {
String csvContent = """
voltageLevelId;equipmentType;xPosition;yPosition;xLabelPosition;yLabelPosition
VL1;4;100;200;110;210""";

MockMultipartFile file = new MockMultipartFile(
"file", "positions.csv", "text/csv", csvContent.getBytes(StandardCharsets.UTF_8)
);
UUID positionsFromCsvUuid = wireMockStubs.stubCreatePositionsFromCsv();
mockMvc.perform(MockMvcRequestBuilders.multipart("/v1/studies/network-visualizations/nad-positions-config")
.file(file)
.contentType(MediaType.MULTIPART_FORM_DATA_VALUE))
.andExpect(status().isOk());

// assert API calls have been made
wireMockStubs.verifyStubCreatePositionsFromCsv(positionsFromCsvUuid);
}

@Test
void testBuildFirstLevelChildren() {
UUID studyUuid = UUID.randomUUID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public class WireMockStubs {
public static final String URI_NETWORK_DATA = "/v1/networks";

private static final String URI_NETWORK_MODIFICATION = "/v1/network-modifications";
private static final String URI_NETWORK_AREA_DIAGRAM = "/v1/network-area-diagram/config/positions";

private static final String URI_NETWORK_MODIFICATION_GROUPS = "/v1/groups";

Expand Down Expand Up @@ -526,24 +525,6 @@ public void verifySearchModifications(UUID stubUuid, String networkUuid, String
"userInput", WireMock.equalTo(userInput)));
}

public UUID stubCreatePositionsFromCsv() {
MappingBuilder mappingBuilder = WireMock.post(WireMock.urlPathEqualTo(URI_NETWORK_AREA_DIAGRAM))
.withHeader("Content-Type", WireMock.containing("multipart/form-data"))
.withMultipartRequestBody(WireMock.aMultipart()
.withName("file")
.withHeader("Content-Disposition", WireMock.containing("filename=\"positions.csv\""))
)
.withMultipartRequestBody(WireMock.aMultipart()
.withName("file_name")
.withBody(WireMock.equalTo("positions.csv"))
);
return wireMock.stubFor(mappingBuilder.willReturn(WireMock.ok().withHeader("Content-Type", "application/json"))).getId();
}

public void verifyStubCreatePositionsFromCsv(UUID stubUuid) {
verifyPostRequest(wireMock, stubUuid, URI_NETWORK_AREA_DIAGRAM, true, Map.of(), null);
}

public UUID stubPccMinRun(String networkUuid, String variantId, String resultUuid) {
return wireMock.stubFor(WireMock.post(WireMock.urlPathMatching("/v1/networks/" + networkUuid + "/run-and-save.*"))
.withQueryParam("variantId", WireMock.equalTo(variantId))
Expand Down
Loading