Skip to content
Merged
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
44 changes: 0 additions & 44 deletions src/main/java/org/gridsuite/geodata/server/GeoDataException.java

This file was deleted.

39 changes: 15 additions & 24 deletions src/main/java/org/gridsuite/geodata/server/GeoDataService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.UncheckedIOException;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.CompletableFuture;
Expand All @@ -38,8 +39,6 @@
import java.util.stream.Stream;

import static java.lang.Math.round;
import static org.gridsuite.geodata.server.GeoDataException.Type.FAILED_LINES_LOADING;
import static org.gridsuite.geodata.server.GeoDataException.Type.FAILED_SUBSTATIONS_LOADING;

/**
* @author Chamseddine Benhamed <chamseddine.benhamed at rte-france.com>
Expand Down Expand Up @@ -429,7 +428,7 @@ void saveLines(List<LineGeoData> linesGeoData) {
}
lineRepository.saveAll(linesEntities);
} catch (JsonProcessingException e) {
throw new GeoDataException(GeoDataException.Type.PARSING_ERROR, e);
throw new UncheckedIOException("Parsing error", e);
}
}

Expand Down Expand Up @@ -546,34 +545,26 @@ private Pair<Substation, Substation> getSubstations(Identifiable<?> identifiable

public CompletableFuture<List<SubstationGeoData>> getSubstationsData(Network network, Set<Country> countrySet, List<String> substationIds) {
return geoDataExecutionService.supplyAsync(() -> {
try {
if (substationIds != null) {
if (!countrySet.isEmpty()) {
LOGGER.warn("Countries will not be taken into account to filter substation position.");
}
return getSubstationsByIds(network, new HashSet<>(substationIds));
} else {
return getSubstationsByCountries(network, countrySet);
if (substationIds != null) {
if (!countrySet.isEmpty()) {
LOGGER.warn("Countries will not be taken into account to filter substation position.");
}
} catch (Exception e) {
throw new GeoDataException(FAILED_SUBSTATIONS_LOADING, e);
return getSubstationsByIds(network, new HashSet<>(substationIds));
} else {
return getSubstationsByCountries(network, countrySet);
}
});
}

public CompletableFuture<List<LineGeoData>> getLinesData(Network network, Set<Country> countrySet, List<String> lineIds) {
return geoDataExecutionService.supplyAsync(() -> {
try {
if (lineIds != null) {
if (!countrySet.isEmpty()) {
LOGGER.warn("Countries will not be taken into account to filter line position.");
}
return getLinesByIds(network, new HashSet<>(lineIds));
} else {
return getLinesByCountries(network, countrySet);
if (lineIds != null) {
if (!countrySet.isEmpty()) {
LOGGER.warn("Countries will not be taken into account to filter line position.");
}
} catch (Exception e) {
throw new GeoDataException(FAILED_LINES_LOADING, e);
return getLinesByIds(network, new HashSet<>(lineIds));
} else {
return getLinesByCountries(network, countrySet);
}
});
}
Expand Down Expand Up @@ -618,7 +609,7 @@ public LineGeoData toDto(LineEntity lineEntity) {
toDto(lineEntity.getCoordinates())
);
} catch (JsonProcessingException e) {
throw new GeoDataException(GeoDataException.Type.PARSING_ERROR, e);
throw new UncheckedIOException("Parsing error", e);
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@
import com.powsybl.network.store.client.NetworkStoreService;
import com.powsybl.network.store.client.PreloadingStrategy;
import com.powsybl.network.store.client.RestClientImpl;
import com.powsybl.ws.commons.error.BaseExceptionHandler;
import org.gridsuite.geodata.server.dto.LineGeoData;
import org.gridsuite.geodata.server.dto.SubstationGeoData;
import org.gridsuite.geodata.server.repositories.LineRepository;
import org.gridsuite.geodata.server.repositories.SubstationRepository;
import org.hamcrest.core.StringContains;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.ResultActions;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -47,6 +51,7 @@
* @author Chamseddine Benhamed <chamseddine.benhamed at rte-france.com>
*/
@WebMvcTest(GeoDataController.class)
@Import(BaseExceptionHandler.class)
class GeoDataControllerTest {

@Autowired
Expand Down Expand Up @@ -116,7 +121,7 @@ void test() throws Exception {

mvc.perform(post("/" + VERSION + "/substations/infos?networkUuid=" + networkUuid + "&variantId=" + WRONG_VARIANT_ID)
.contentType(APPLICATION_JSON))
.andExpect(content().string("Variant '" + WRONG_VARIANT_ID + "' not found"))
.andExpect(content().string(StringContains.containsString("Variant '" + WRONG_VARIANT_ID + "' not found")))
.andExpect(status().isInternalServerError());

mockMvcResultActions = mvc.perform(post("/" + VERSION + "/lines/infos?networkUuid=" + networkUuid)
Expand All @@ -137,7 +142,7 @@ void test() throws Exception {

mvc.perform(post("/" + VERSION + "/lines/infos?networkUuid=" + networkUuid + "&variantId=" + WRONG_VARIANT_ID)
.contentType(APPLICATION_JSON))
.andExpect(content().string("Variant '" + WRONG_VARIANT_ID + "' not found"))
.andExpect(content().string(StringContains.containsString("Variant '" + WRONG_VARIANT_ID + "' not found")))
.andExpect(status().isInternalServerError());

String substationJson = objectMapper.writeValueAsString(Collections.singleton(
Expand Down Expand Up @@ -217,7 +222,7 @@ void testGetLinesError() throws Exception {
Network testNetwork = EurostagTutorialExample1Factory.create();
given(service.getNetwork(networkUuid)).willReturn(testNetwork);
given(service.getNetwork(networkUuid, PreloadingStrategy.COLLECTION)).willReturn(testNetwork);
given(lineRepository.findAllById(any())).willThrow(new GeoDataException(GeoDataException.Type.PARSING_ERROR, new RuntimeException("Error parsing")));
given(lineRepository.findAllById(any())).willThrow(new UncheckedIOException("Parsing error", new IOException("IO")));

MvcResult mvcResult = mvc.perform(post("/" + VERSION + "/lines/infos?networkUuid=" + networkUuid)
.contentType(APPLICATION_JSON))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) 2025, 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/.
*/
package org.gridsuite.geodata.server;

import com.powsybl.ws.commons.error.ServerNameProvider;
import org.springframework.stereotype.Component;

/**
* @author Mohamed Ben-rejeb {@literal <mohamed.ben-rejeb at rte-france.com>}
*/
@Component
public class GeoDataServerNameProvider implements ServerNameProvider {

@Override
public String serverName() {
return "geo-data-server";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.UncheckedIOException;
import java.util.*;

import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -521,7 +522,7 @@ void testLineCoordinatesError() {
.substationEnd("substation2")
.build(), true, "coordinates_error");

assertThrows(GeoDataException.class, () ->
assertThrows(UncheckedIOException.class, () ->
geoDataService.toDto(lineEntity));
}

Expand Down