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
22 changes: 22 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
<antlr4.version>4.10.1</antlr4.version>
<sonar.organization>gridsuite</sonar.organization>
<sonar.projectKey>org.gridsuite:loadflow-server</sonar.projectKey>
<!-- To remove after when using gridsuite dependencies release and computation version containing merged PR: https://github.com/gridsuite/computation/pull/19 -->
<gridsuite-computation.version>1.7.0</gridsuite-computation.version>
<powsybl-ws-commons.version>1.34.0</powsybl-ws-commons.version>
<gridsuite-filter.version>1.15.0</gridsuite-filter.version>
</properties>

<build>
Expand Down Expand Up @@ -93,6 +97,24 @@

<dependencyManagement>
<dependencies>
<!-- To remove when integrate in next release of gridsuite-dependencies or powsybl-ws-dependencies -->
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-ws-commons</artifactId>
<version>${powsybl-ws-commons.version}</version>
</dependency>

<dependency>
<groupId>org.gridsuite</groupId>
<artifactId>gridsuite-computation</artifactId>
<version>${gridsuite-computation.version}</version>
</dependency>

<dependency>
<groupId>org.gridsuite</groupId>
<artifactId>gridsuite-filter</artifactId>
<version>${gridsuite-filter.version}</version>
</dependency>

<dependency>
<groupId>org.antlr</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.gridsuite.loadflow.server;

import com.powsybl.network.store.client.NetworkStoreService;
import org.gridsuite.computation.error.ComputationExceptionHandler;
import org.gridsuite.computation.service.NotificationService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand All @@ -15,7 +16,7 @@
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
@SuppressWarnings("checkstyle:HideUtilityClassConstructor")
@SpringBootApplication(scanBasePackageClasses = { LoadFlowApplication.class, NetworkStoreService.class, NotificationService.class })
@SpringBootApplication(scanBasePackageClasses = {LoadFlowApplication.class, NetworkStoreService.class, NotificationService.class, ComputationExceptionHandler.class})
public class LoadFlowApplication {
public static void main(String[] args) {
SpringApplication.run(LoadFlowApplication.class, args);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* 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.loadflow.server;

import com.powsybl.ws.commons.error.ServerNameProvider;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
* @author Hugo Marcellin <hugo.marcelin at rte-france.com>
*/
@Component
public class PropertyServerNameProvider implements ServerNameProvider {
private final String name;

public PropertyServerNameProvider(@Value("${spring.application.name:loadflow-server}") String name) {
this.name = name;
}

@Override
public String serverName() {
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.gridsuite.filter.utils.EquipmentType;
import org.gridsuite.loadflow.server.dto.Column;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.stereotype.Service;

import java.util.List;
Expand All @@ -28,10 +29,10 @@
@Service
public class FilterService extends AbstractFilterService {

public FilterService(
NetworkStoreService networkStoreService,
@Value("${gridsuite.services.filter-server.base-uri:http://filter-server/}") String filterServerBaseUri) {
super(networkStoreService, filterServerBaseUri);
public FilterService(RestTemplateBuilder restTemplateBuilder,
NetworkStoreService networkStoreService,
@Value("${gridsuite.services.filter-server.base-uri:http://filter-server/}") String filterServerBaseUri) {
super(restTemplateBuilder, networkStoreService, filterServerBaseUri);
}

public Optional<ResourceFilterDTO> getResourceFilter(@NonNull UUID networkUuid, @NonNull String variantId, @NonNull GlobalFilter globalFilter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.Range;
import org.gridsuite.computation.ComputationException;
import org.gridsuite.computation.error.ComputationBusinessErrorCode;
import org.gridsuite.computation.error.ComputationException;
import org.gridsuite.loadflow.server.dto.parameters.LimitReductionsByVoltageLevel;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -67,41 +68,41 @@ private List<LimitReductionsByVoltageLevel.LimitReduction> getLimitReductionsByD

private void assertValidConfig(List<List<Double>> values) {
if (voltageLevels.isEmpty()) {
throw new ComputationException(ComputationException.Type.LIMIT_REDUCTION_CONFIG_ERROR, "No configuration for voltage levels");
throw new ComputationException(ComputationBusinessErrorCode.LIMIT_REDUCTION_CONFIG_ERROR, "No configuration for voltage levels");
}

if (limitDurations.isEmpty()) {
throw new ComputationException(ComputationException.Type.LIMIT_REDUCTION_CONFIG_ERROR, "No configuration for limit durations");
throw new ComputationException(ComputationBusinessErrorCode.LIMIT_REDUCTION_CONFIG_ERROR, "No configuration for limit durations");
}

if (values.isEmpty() || values.get(0).isEmpty()) {
throw new ComputationException(ComputationException.Type.LIMIT_REDUCTION_CONFIG_ERROR, "No values provided");
throw new ComputationException(ComputationBusinessErrorCode.LIMIT_REDUCTION_CONFIG_ERROR, "No values provided");
}

int nbValuesByVl = values.get(0).size();
if (values.stream().anyMatch(valuesByVl -> valuesByVl.size() != nbValuesByVl)) {
throw new ComputationException(ComputationException.Type.LIMIT_REDUCTION_CONFIG_ERROR, "Number of values for a voltage level is incorrect");
throw new ComputationException(ComputationBusinessErrorCode.LIMIT_REDUCTION_CONFIG_ERROR, "Number of values for a voltage level is incorrect");
}

if (voltageLevels.size() < values.size()) {
throw new ComputationException(ComputationException.Type.LIMIT_REDUCTION_CONFIG_ERROR, "Too many values provided for voltage levels");
throw new ComputationException(ComputationBusinessErrorCode.LIMIT_REDUCTION_CONFIG_ERROR, "Too many values provided for voltage levels");
}

if (voltageLevels.size() > values.size()) {
throw new ComputationException(ComputationException.Type.LIMIT_REDUCTION_CONFIG_ERROR, "Not enough values provided for voltage levels");
throw new ComputationException(ComputationBusinessErrorCode.LIMIT_REDUCTION_CONFIG_ERROR, "Not enough values provided for voltage levels");
}

if (limitDurations.size() < nbValuesByVl - 1) {
throw new ComputationException(ComputationException.Type.LIMIT_REDUCTION_CONFIG_ERROR, "Too many values provided for limit durations");
throw new ComputationException(ComputationBusinessErrorCode.LIMIT_REDUCTION_CONFIG_ERROR, "Too many values provided for limit durations");
}

if (limitDurations.size() > nbValuesByVl - 1) {
throw new ComputationException(ComputationException.Type.LIMIT_REDUCTION_CONFIG_ERROR, "Not enough values provided for limit durations");
throw new ComputationException(ComputationBusinessErrorCode.LIMIT_REDUCTION_CONFIG_ERROR, "Not enough values provided for limit durations");
}

values.forEach(valuesByVl -> {
if (valuesByVl.stream().anyMatch(v -> !Range.of(0.0, 1.0).contains(v))) {
throw new ComputationException(ComputationException.Type.LIMIT_REDUCTION_CONFIG_ERROR, "Value not between 0 and 1");
throw new ComputationException(ComputationBusinessErrorCode.LIMIT_REDUCTION_CONFIG_ERROR, "Value not between 0 and 1");
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.powsybl.loadflow.LoadFlowResult;
import com.powsybl.security.LimitViolationType;
import lombok.AllArgsConstructor;
import org.gridsuite.computation.ComputationException;
import org.gridsuite.computation.dto.GlobalFilter;
import org.gridsuite.computation.dto.ResourceFilterDTO;
import org.gridsuite.computation.service.AbstractComputationResultService;
Expand All @@ -37,6 +36,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.UncheckedIOException;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -290,7 +290,7 @@ private LoadFlowModificationInfos loadFlowModificationsToDTO(String jsonString)
try {
return objectMapper.readValue(jsonString, LoadFlowModificationInfos.class);
} catch (JsonProcessingException e) {
throw new ComputationException("Invalid json string for modifications !");
throw new UncheckedIOException("Invalid json string for modifications !", e);
}
}

Expand All @@ -301,7 +301,7 @@ private String modificationsToJsonString(LoadFlowModificationInfos loadFlowModif
try {
return objectMapper.writeValueAsString(loadFlowModificationInfos);
} catch (JsonProcessingException e) {
throw new ComputationException("Invalid modifications for json string !");
throw new UncheckedIOException("Invalid modifications for json string !", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.Map;
import java.util.UUID;

import org.gridsuite.computation.ComputationException;
import org.gridsuite.computation.error.ComputationException;
import org.gridsuite.loadflow.server.dto.parameters.LimitReductionsByVoltageLevel;
import org.gridsuite.loadflow.server.dto.parameters.LoadFlowParametersInfos;
import org.gridsuite.loadflow.server.dto.parameters.LoadFlowParametersValues;
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.loadflow.server;

import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Mohamed Ben-rejeb {@literal <mohamed.ben-rejeb at rte-france.com>}
*/
class PropertyServerNameProviderTest {

@Test
void returnsProvidedName() {
PropertyServerNameProvider provider = new PropertyServerNameProvider("custom-server");
assertThat(provider.serverName()).isEqualTo("custom-server");
}
}