Skip to content

Commit

Permalink
Migration of the parameters from study-server (#59)
Browse files Browse the repository at this point in the history
The parameters are now stored directly in this service. Only the UUID for each study is stored in study-server.

Signed-off-by: Florent MILLOT <millotflo@gmail.com>
  • Loading branch information
flomillot authored Feb 7, 2024
1 parent 1431da1 commit 9eed97f
Show file tree
Hide file tree
Showing 33 changed files with 1,461 additions and 214 deletions.
19 changes: 0 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
<properties>
<powsybl-ws-dependencies.version>2.7.0</powsybl-ws-dependencies.version>
<liquibase-hibernate-package>org.gridsuite.sensitivityanalysis.server</liquibase-hibernate-package>
<mockito-inline.version>3.11.1</mockito-inline.version>
<db-util.version>1.0.5</db-util.version>
</properties>

Expand Down Expand Up @@ -222,11 +221,6 @@
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand All @@ -248,19 +242,6 @@
<version>${db-util.version}</version>
<scope>test</scope>
</dependency>
<!-- Needed to mock SensitivityAnalysis.Runner (which happens to be a final class) in SensitivityAnalysisControllerTest -->
<!-- see "mockito-inline" in https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.testing.spring-boot-applications.mocking-beans -->
<!-- otherwise we get the following exception:
Cannot mock/spy class com.powsybl.sensitivity.SensitivityAnalysis.Runner
Mockito cannot mock/spy because :
- final class
-->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mockito-inline.version}</version>
<scope>test</scope>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,17 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.gridsuite.sensitivityanalysis.server.dto.SensitivityAnalysisCsvFileInfos;
import org.gridsuite.sensitivityanalysis.server.dto.SensitivityAnalysisInputData;
import org.gridsuite.sensitivityanalysis.server.dto.SensitivityAnalysisStatus;
import org.gridsuite.sensitivityanalysis.server.dto.SensitivityResultFilterOptions;
import org.gridsuite.sensitivityanalysis.server.dto.SensitivityRunQueryResult;
import org.gridsuite.sensitivityanalysis.server.dto.*;
import org.gridsuite.sensitivityanalysis.server.dto.nonevacuatedenergy.NonEvacuatedEnergyInputData;
import org.gridsuite.sensitivityanalysis.server.dto.nonevacuatedenergy.NonEvacuatedEnergyStatus;
import org.gridsuite.sensitivityanalysis.server.service.SensitivityAnalysisRunContext;
import org.gridsuite.sensitivityanalysis.server.dto.parameters.LoadFlowParametersValues;
import org.gridsuite.sensitivityanalysis.server.dto.resultselector.ResultTab;
import org.gridsuite.sensitivityanalysis.server.dto.resultselector.ResultsSelector;
import org.gridsuite.sensitivityanalysis.server.service.SensitivityAnalysisService;
import org.gridsuite.sensitivityanalysis.server.service.SensitivityAnalysisWorkerService;
import org.springframework.http.HttpHeaders;
import org.gridsuite.sensitivityanalysis.server.service.nonevacuatedenergy.NonEvacuatedEnergyRunContext;
import org.gridsuite.sensitivityanalysis.server.service.nonevacuatedenergy.NonEvacuatedEnergyService;
import org.gridsuite.sensitivityanalysis.server.dto.SensitivityFactorsIdsByGroup;
import org.gridsuite.sensitivityanalysis.server.dto.resultselector.ResultTab;
import org.gridsuite.sensitivityanalysis.server.dto.resultselector.ResultsSelector;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -41,9 +36,7 @@
import java.util.UUID;

import static org.gridsuite.sensitivityanalysis.server.service.NotificationService.HEADER_USER_ID;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM;
import static org.springframework.http.MediaType.TEXT_PLAIN_VALUE;
import static org.springframework.http.MediaType.*;

/**
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
Expand Down Expand Up @@ -87,9 +80,10 @@ public ResponseEntity<SensitivityAnalysisResult> run(@Parameter(description = "N
@Parameter(description = "reportUuid") @RequestParam(name = "reportUuid", required = false) UUID reportUuid,
@Parameter(description = "reporterId") @RequestParam(name = "reporterId", required = false) String reporterId,
@Parameter(description = "The type name for the report") @RequestParam(name = "reportType", required = false, defaultValue = "SensitivityAnalysis") String reportType,
@RequestBody SensitivityAnalysisInputData sensitivityAnalysisInputData,
@Parameter(description = "parametersUuid") @RequestParam(name = "parametersUuid", required = false) UUID parametersUuid,
@RequestBody LoadFlowParametersValues loadFlowParametersValues,
@RequestHeader(HEADER_USER_ID) String userId) {
SensitivityAnalysisResult result = workerService.run(new SensitivityAnalysisRunContext(networkUuid, variantId, sensitivityAnalysisInputData, null, provider, reportUuid, reporterId, reportType, userId));
SensitivityAnalysisResult result = workerService.run(networkUuid, variantId, provider, new ReportInfos(reportUuid, reporterId, reportType), userId, parametersUuid, loadFlowParametersValues);
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(result);
}

Expand All @@ -106,9 +100,10 @@ public ResponseEntity<UUID> runAndSave(@Parameter(description = "Network UUID")
@Parameter(description = "reportUuid") @RequestParam(name = "reportUuid", required = false) UUID reportUuid,
@Parameter(description = "reporterId") @RequestParam(name = "reporterId", required = false) String reporterId,
@Parameter(description = "The type name for the report") @RequestParam(name = "reportType", required = false, defaultValue = "SensitivityAnalysis") String reportType,
@RequestBody SensitivityAnalysisInputData sensitivityAnalysisInputData,
@Parameter(description = "parametersUuid") @RequestParam(name = "parametersUuid", required = false) UUID parametersUuid,
@RequestBody LoadFlowParametersValues loadFlowParametersValues,
@RequestHeader(HEADER_USER_ID) String userId) {
UUID resultUuid = service.runAndSaveResult(new SensitivityAnalysisRunContext(networkUuid, variantId, sensitivityAnalysisInputData, receiver, provider, reportUuid, reporterId, reportType, userId));
UUID resultUuid = service.runAndSaveResult(networkUuid, variantId, receiver, provider, new ReportInfos(reportUuid, reporterId, reportType), userId, parametersUuid, loadFlowParametersValues);
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(resultUuid);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* 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.sensitivityanalysis.server;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.gridsuite.sensitivityanalysis.server.dto.parameters.SensitivityAnalysisParametersInfos;
import org.gridsuite.sensitivityanalysis.server.service.SensitivityAnalysisParametersService;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

/**
* @author Florent MILLOT <florent.millot at rte-france.com>
*/

@RestController
@RequestMapping(value = "/" + SensitivityAnalysisApi.API_VERSION + "/parameters")
@Tag(name = "Sensitivity analysis parameters")
public class SensitivityAnalysisParametersController {

private final SensitivityAnalysisParametersService parametersService;

public SensitivityAnalysisParametersController(SensitivityAnalysisParametersService parametersService) {
this.parametersService = parametersService;
}

@PostMapping(value = "/default", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Create default parameters")
@ApiResponse(responseCode = "200", description = "Default parameters were created")
public ResponseEntity<UUID> createDefaultParameters() {
return ResponseEntity.ok(parametersService.createDefaultParameters());
}

@PostMapping(value = "", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Create parameters")
@ApiResponse(responseCode = "200", description = "parameters were created")
public ResponseEntity<UUID> createParameters(
@RequestBody SensitivityAnalysisParametersInfos parametersInfos) {
return ResponseEntity.ok(parametersService.createParameters(parametersInfos));
}

@PostMapping(value = "/{sourceParametersUuid}", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Duplicate parameters")
@ApiResponse(responseCode = "200", description = "parameters were duplicated")
@ApiResponse(responseCode = "404", description = "source parameters were not found")
public ResponseEntity<UUID> duplicateParameters(
@Parameter(description = "source parameters UUID") @PathVariable("sourceParametersUuid") UUID sourceParametersUuid) {
return ResponseEntity.of(parametersService.duplicateParameters(sourceParametersUuid));
}

@GetMapping(value = "/{uuid}", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get parameters")
@ApiResponse(responseCode = "200", description = "parameters were returned")
@ApiResponse(responseCode = "404", description = "parameters were not found")
public ResponseEntity<SensitivityAnalysisParametersInfos> getParameters(
@Parameter(description = "parameters UUID") @PathVariable("uuid") UUID parametersUuid) {
return ResponseEntity.of(parametersService.getParameters(parametersUuid));
}

@GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get all parameters")
@ApiResponse(responseCode = "200", description = "the list of all parameters was returned")
public ResponseEntity<List<SensitivityAnalysisParametersInfos>> getAllParameters() {
return ResponseEntity.ok(parametersService.getAllParameters());
}

@PutMapping(value = "/{uuid}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Update parameters")
@ApiResponse(responseCode = "200", description = "parameters were updated")
public ResponseEntity<Void> updateParameters(
@Parameter(description = "parameters UUID") @PathVariable("uuid") UUID parametersUuid,
@RequestBody SensitivityAnalysisParametersInfos parametersInfos) {
parametersService.updateParameters(parametersUuid, parametersInfos);
return ResponseEntity.ok().build();
}

@DeleteMapping(value = "/{uuid}", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Delete parameters")
@ApiResponse(responseCode = "200", description = "parameters were deleted")
public ResponseEntity<Void> deleteParameters(
@Parameter(description = "parameters UUID") @PathVariable("uuid") UUID parametersUuid) {
parametersService.deleteParameters(parametersUuid);
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* 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.sensitivityanalysis.server.dto;

import java.util.UUID;

/**
* @author Florent MILLOT <florent.millot at rte-france.com>
*/
public record ReportInfos(
UUID reportUuid,
String reporterId,
String reportType
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.gridsuite.sensitivityanalysis.server.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand All @@ -18,6 +19,7 @@
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
Expand All @@ -30,4 +32,6 @@ public class SensitivityHVDC {
List<EquipmentsContainer> hvdcs;

List<EquipmentsContainer> contingencies;

boolean activated;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.gridsuite.sensitivityanalysis.server.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand All @@ -18,6 +19,7 @@
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
Expand All @@ -28,5 +30,7 @@ public class SensitivityInjection {
List<EquipmentsContainer> injections;

List<EquipmentsContainer> contingencies;

boolean activated;
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.gridsuite.sensitivityanalysis.server.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand All @@ -18,6 +19,7 @@
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
Expand All @@ -30,4 +32,6 @@ public class SensitivityInjectionsSet {
SensitivityAnalysisInputData.DistributionType distributionType;

List<EquipmentsContainer> contingencies;

boolean activated;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.gridsuite.sensitivityanalysis.server.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand All @@ -18,6 +19,7 @@
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
Expand All @@ -28,5 +30,7 @@ public class SensitivityNodes {
List<EquipmentsContainer> equipmentsInVoltageRegulation;

List<EquipmentsContainer> contingencies;

boolean activated;
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.gridsuite.sensitivityanalysis.server.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand All @@ -18,6 +19,7 @@
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
Expand All @@ -30,5 +32,7 @@ public class SensitivityPST {
List<EquipmentsContainer> psts;

List<EquipmentsContainer> contingencies;

boolean activated;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
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.sensitivityanalysis.server.dto.parameters;

import com.powsybl.loadflow.LoadFlowParameters;
import lombok.Builder;

import java.util.Map;

/**
* @author David Braquart <david.braquart at rte-france.com>
*/
@Builder
public record LoadFlowParametersValues(
LoadFlowParameters commonParameters,
Map<String, String> specificParameters) {
}
Loading

0 comments on commit 9eed97f

Please sign in to comment.