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
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
<mockwebserver3.version>5.0.0-alpha.14</mockwebserver3.version>
<sonar.organization>gridsuite</sonar.organization>
<sonar.projectKey>org.gridsuite:sensitivity-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-SNAPSHOT</gridsuite-computation.version>
<powsybl-ws-commons.version>1.34.0-SNAPSHOT</powsybl-ws-commons.version>
</properties>

<build>
Expand Down Expand Up @@ -145,6 +148,7 @@
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-ws-commons</artifactId>
<version>${powsybl-ws-commons.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
Expand Down Expand Up @@ -173,6 +177,7 @@
<dependency>
<groupId>org.gridsuite</groupId>
<artifactId>gridsuite-computation</artifactId>
<version>${gridsuite-computation.version}</version>
</dependency>

<!-- Runtime dependencies -->
Expand Down
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/.
*/
package org.gridsuite.sensitivityanalysis.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:sensitivity-analysis-server}") String name) {
this.name = name;
}

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

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.gridsuite.sensitivityanalysis.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 = { SensitivityAnalysisApplication.class, NetworkStoreService.class, NotificationService.class })
@SpringBootApplication(scanBasePackageClasses = {SensitivityAnalysisApplication.class, NetworkStoreService.class, NotificationService.class, ComputationExceptionHandler.class})
public class SensitivityAnalysisApplication {
public static void main(String[] args) {
SpringApplication.run(SensitivityAnalysisApplication.class, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.powsybl.sensitivity.SensitivityAnalysisResult;
import com.powsybl.sensitivity.SensitivityFunctionType;
import org.gridsuite.computation.ComputationException;
import org.gridsuite.computation.error.ComputationException;
import org.gridsuite.computation.dto.GlobalFilter;
import org.gridsuite.computation.dto.ReportInfos;
import org.gridsuite.computation.dto.ResourceFilterDTO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.powsybl.sensitivity.SensitivityAnalysisProvider;
import com.univocity.parsers.csv.CsvFormat;
import org.gridsuite.computation.error.ComputationException;
import org.gridsuite.computation.dto.GlobalFilter;
import org.gridsuite.computation.dto.ResourceFilterDTO;
import org.gridsuite.computation.service.AbstractComputationService;
import org.gridsuite.computation.service.NotificationService;
import org.gridsuite.computation.service.UuidGeneratorService;
import com.univocity.parsers.csv.CsvWriter;
import com.univocity.parsers.csv.CsvWriterSettings;
import org.gridsuite.sensitivityanalysis.server.SensibilityAnalysisException;
import org.gridsuite.sensitivityanalysis.server.dto.*;
import org.gridsuite.sensitivityanalysis.server.dto.resultselector.ResultTab;
import org.gridsuite.sensitivityanalysis.server.dto.resultselector.ResultsSelector;
Expand All @@ -27,13 +27,15 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.text.NumberFormat;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import static org.gridsuite.sensitivityanalysis.server.SensibilityAnalysisException.Type.*;
import static org.gridsuite.computation.error.ComputationBusinessErrorCode.INVALID_EXPORT_PARAMS;
import static org.gridsuite.computation.error.ComputationBusinessErrorCode.RESULT_NOT_FOUND;

/**
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
Expand Down Expand Up @@ -149,11 +151,11 @@ public byte[] exportSensitivityResultsAsCsv(UUID resultUuid, SensitivityAnalysis
sensitivityAnalysisCsvFileInfos.getSensitivityFunctionType() == null ||
sensitivityAnalysisCsvFileInfos.getResultTab() == null ||
CollectionUtils.isEmpty(sensitivityAnalysisCsvFileInfos.getCsvHeaders())) {
throw new SensibilityAnalysisException(INVALID_EXPORT_PARAMS, "Missing information to export sensitivity result as csv : Sensitivity result tab, sensitivity function type and csv file headers must be provided");
throw new ComputationException(INVALID_EXPORT_PARAMS, "Missing information to export sensitivity result as csv : Sensitivity result tab, sensitivity function type and csv file headers must be provided");
}
SensitivityRunQueryResult result = getRunResult(resultUuid, networkUuid, variantId, selector, resourceFilters, globalFilter);
if (result == null) {
throw new SensibilityAnalysisException(RESULT_NOT_FOUND, "The sensitivity analysis result '" + resultUuid + "' does not exist");
throw new ComputationException(RESULT_NOT_FOUND, "The sensitivity analysis result '" + resultUuid + "' does not exist");
}

try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Expand Down Expand Up @@ -192,7 +194,7 @@ public byte[] exportSensitivityResultsAsCsv(UUID resultUuid, SensitivityAnalysis
csvWriter.close();
return outputStream.toByteArray();
} catch (IOException e) {
throw new SensibilityAnalysisException(FILE_EXPORT_ERROR, e.getMessage());
throw new UncheckedIOException("Error occured during data csv export", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* 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.sensitivityanalysis.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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ void queryResultWithInvalidGlobalFilterJsonTest() throws Exception {
mockMvc.perform(get("/" + VERSION + "/results/{resultUuid}", resultUuid)
.param("selector", mapper.writeValueAsString(selector))
.param("globalFilters", "invalid-json"))
.andExpect(status().isBadRequest());
.andExpect(status().isInternalServerError());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
package org.gridsuite.sensitivityanalysis.server.service;

import com.powsybl.sensitivity.SensitivityFunctionType;
import org.gridsuite.computation.error.ComputationException;
import org.gridsuite.computation.dto.ReportInfos;
import org.gridsuite.computation.service.NotificationService;
import org.gridsuite.sensitivityanalysis.server.SensibilityAnalysisException;
import org.gridsuite.sensitivityanalysis.server.dto.*;
import org.gridsuite.sensitivityanalysis.server.dto.parameters.SensitivityAnalysisParametersInfos;
import org.gridsuite.sensitivityanalysis.server.dto.resultselector.ResultTab;
Expand Down Expand Up @@ -181,7 +181,7 @@ void testExportCsvThrowsIfResultUuidIsNotPresent() {
.language("en")
.build();
final UUID resultUuid = UUID.randomUUID();
assertThrows(SensibilityAnalysisException.class, () -> analysisService.exportSensitivityResultsAsCsv(resultUuid, sensitivityAnalysisCsvFileInfos, null, null, null, null, null));
assertThrows(ComputationException.class, () -> analysisService.exportSensitivityResultsAsCsv(resultUuid, sensitivityAnalysisCsvFileInfos, null, null, null, null, null));
}

private static SensitivityRunQueryResult.SensitivityRunQueryResultBuilder getDefaultQueryBuilder() {
Expand Down
Loading