Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
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 @@ -48,6 +48,10 @@
<mockwebserver3.version>5.0.0-alpha.14</mockwebserver3.version>
<sonar.organization>gridsuite</sonar.organization>
<sonar.projectKey>org.gridsuite:shortcircuit-analysis-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 @@ -87,6 +91,24 @@
<dependencyManagement>
<dependencies>
<!-- overrides of imports -->
<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><!-- To remove when integrate in next release of gridsuite-dependencies or powsybl-ws-dependencies -->
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp-bom</artifactId>
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.shortcircuit.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:shortcircuit-server}") String name) {
this.name = name;
}

@Override
public String serverName() {
return name;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.gridsuite.shortcircuit.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 Etienne Homer <etienne.homer at rte-france.com>
*/
@SuppressWarnings("checkstyle:HideUtilityClassConstructor")
@SpringBootApplication(scanBasePackageClasses = { ShortCircuitApplication.class, NetworkStoreService.class, NotificationService.class })
@SpringBootApplication(scanBasePackageClasses = {ShortCircuitApplication.class, NetworkStoreService.class, NotificationService.class, ComputationExceptionHandler.class})
public class ShortCircuitApplication {
public static void main(String[] args) {
SpringApplication.run(ShortCircuitApplication.class, args);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright (c) 2024, 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.shortcircuit.server.error;

import com.powsybl.ws.commons.error.AbstractBusinessException;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;

import java.util.Objects;

/**
* @author David SARTORI <david.sartori_externe at rte-france.com>
*/
@Getter
public class ShortCircuitException extends AbstractBusinessException {

private final ShortcircuitBusinessErrorCode errorCode;

public ShortCircuitException(ShortcircuitBusinessErrorCode errorCode, String message) {
super(Objects.requireNonNull(message, "message must not be null"));
this.errorCode = Objects.requireNonNull(errorCode, "errorCode must not be null");
}

@NotNull
@Override
public ShortcircuitBusinessErrorCode getBusinessErrorCode() {
return errorCode;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* 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/.
* SPDX-License-Identifier: MPL-2.0
*/
package org.gridsuite.shortcircuit.server.error;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyright


import com.powsybl.ws.commons.error.BusinessErrorCode;

/**
* @author Hugo Marcellin <hugo.marcelin at rte-france.com>
*/
public enum ShortcircuitBusinessErrorCode implements BusinessErrorCode {
BUS_OUT_OF_VOLTAGE("shortcircuit.busOutOfVoltage"),
MISSING_EXTENSION_DATA("shortcircuit.missingExtensionData"),
INCONSISTENT_VOLTAGE_LEVELS("shortcircuit.inconsistentVoltageLevels"),;

private final String code;

ShortcircuitBusinessErrorCode(String code) {
this.code = code;
}

public String value() {
return code;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* 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.shortcircuit.server.error;

import com.powsybl.ws.commons.error.AbstractBusinessExceptionHandler;
import com.powsybl.ws.commons.error.PowsyblWsProblemDetail;
import com.powsybl.ws.commons.error.ServerNameProvider;
import jakarta.servlet.http.HttpServletRequest;
import lombok.NonNull;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
* @author Hugo Marcellin <hugo.marcelin at rte-france.com>
*/

@ControllerAdvice
public class ShortcircuitExceptionHandler extends AbstractBusinessExceptionHandler<ShortCircuitException, ShortcircuitBusinessErrorCode> {
protected ShortcircuitExceptionHandler(ServerNameProvider serverNameProvider) {
super(serverNameProvider);
}

@Override
protected @NonNull ShortcircuitBusinessErrorCode getBusinessCode(ShortCircuitException e) {
return e.getBusinessErrorCode();
}

@Override
protected HttpStatus mapStatus(ShortcircuitBusinessErrorCode businessErrorCode) {
return switch (businessErrorCode) {
case BUS_OUT_OF_VOLTAGE, INCONSISTENT_VOLTAGE_LEVELS, MISSING_EXTENSION_DATA ->
HttpStatus.INTERNAL_SERVER_ERROR;
};
}

@ExceptionHandler(ShortCircuitException.class)
protected ResponseEntity<PowsyblWsProblemDetail> handleShortcircuitException(
ShortCircuitException exception, HttpServletRequest request) {
return super.handleDomainException(exception, request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.gridsuite.computation.service.AbstractFilterService;
import org.gridsuite.filter.utils.EquipmentType;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.stereotype.Service;

import java.util.*;
Expand All @@ -22,10 +23,10 @@
@Slf4j
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 @@ -6,15 +6,14 @@
*/
package org.gridsuite.shortcircuit.server.service;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;

import com.powsybl.commons.config.PlatformConfig;
import com.powsybl.commons.parameters.Parameter;
import com.powsybl.commons.parameters.ParameterScope;
import com.powsybl.shortcircuit.ShortCircuitAnalysisProvider;
import lombok.Getter;
import lombok.NonNull;
import org.apache.commons.lang3.tuple.Pair;
import org.gridsuite.shortcircuit.server.ShortCircuitException;
import org.gridsuite.computation.error.ComputationException;
import org.gridsuite.shortcircuit.server.dto.ShortCircuitParametersInfos;
import org.gridsuite.shortcircuit.server.dto.ShortCircuitParametersValues;
import org.gridsuite.shortcircuit.server.entities.parameters.ShortCircuitParametersEntity;
Expand All @@ -24,13 +23,10 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.powsybl.commons.config.PlatformConfig;
import com.powsybl.commons.parameters.Parameter;
import com.powsybl.commons.parameters.ParameterScope;
import com.powsybl.shortcircuit.ShortCircuitAnalysisProvider;
import java.util.*;
import java.util.stream.Collectors;

import lombok.Getter;
import lombok.NonNull;
import static org.gridsuite.computation.error.ComputationBusinessErrorCode.PARAMETERS_NOT_FOUND;

/**
* @author Sylvain Bouzols <sylvain.bouzols at rte-france.com>
Expand Down Expand Up @@ -93,7 +89,7 @@ public Optional<ShortCircuitParametersValues> getParametersValues(UUID parameter

public ShortCircuitParametersValues getParametersValues(UUID parametersUuid) {
return parametersRepository.findById(parametersUuid)
.map(this::toShortCircuitParametersValues).orElseThrow(() -> new ShortCircuitException(ShortCircuitException.Type.PARAMETERS_NOT_FOUND,
.map(this::toShortCircuitParametersValues).orElseThrow(() -> new ComputationException(PARAMETERS_NOT_FOUND,
"ShortCircuit parameters '" + parametersUuid + "' not found"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
import com.univocity.parsers.csv.CsvWriter;
import com.univocity.parsers.csv.CsvWriterSettings;
import org.apache.commons.lang3.StringUtils;
import org.gridsuite.computation.error.ComputationException;
import org.gridsuite.computation.dto.GlobalFilter;
import org.gridsuite.computation.dto.ResourceFilterDTO;
import org.gridsuite.computation.s3.ComputationS3Service;
import org.gridsuite.computation.service.AbstractComputationService;
import org.gridsuite.computation.service.NotificationService;
import org.gridsuite.computation.service.UuidGeneratorService;
import org.gridsuite.shortcircuit.server.ShortCircuitException;
import org.gridsuite.shortcircuit.server.dto.*;
import org.gridsuite.shortcircuit.server.entities.*;
import org.slf4j.Logger;
Expand All @@ -34,6 +34,7 @@

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.text.NumberFormat;
import java.util.*;
Expand All @@ -43,8 +44,9 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import static org.gridsuite.computation.error.ComputationBusinessErrorCode.INVALID_EXPORT_PARAMS;
import static org.gridsuite.computation.error.ComputationBusinessErrorCode.RESULT_NOT_FOUND;
import static org.gridsuite.computation.utils.FilterUtils.fromStringFiltersToDTO;
import static org.gridsuite.shortcircuit.server.ShortCircuitException.Type.*;

/**
* @author Etienne Homer <etienne.homer at rte-france.com>
Expand Down Expand Up @@ -253,16 +255,16 @@ public byte[] exportToCsv(ShortCircuitAnalysisResult result, CsvExportParams csv
csvWriter.close();
return outputStream.toByteArray();
} catch (IOException e) {
throw new ShortCircuitException(FILE_EXPORT_ERROR, e.getMessage());
throw new UncheckedIOException("Error occurred while writing data to csv file", e);
}
}

public byte[] getZippedCsvExportResult(UUID resultUuid, ShortCircuitAnalysisResult result, CsvExportParams csvExportParams) {
if (result == null) {
throw new ShortCircuitException(RESULT_NOT_FOUND, "The short circuit analysis result '" + resultUuid + "' does not exist");
throw new ComputationException(RESULT_NOT_FOUND, "The short circuit analysis result '" + resultUuid + "' does not exist");
}
if (Objects.isNull(csvExportParams) || Objects.isNull(csvExportParams.csvHeader()) || Objects.isNull(csvExportParams.enumValueTranslations())) {
throw new ShortCircuitException(INVALID_EXPORT_PARAMS, "Missing information to export short-circuit result as csv: file headers and enum translation must be provided");
throw new ComputationException(INVALID_EXPORT_PARAMS, "Missing information to export short-circuit result as csv: file headers and enum translation must be provided");
}
return exportToCsv(result, csvExportParams);
}
Expand Down
Loading