Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration of the parameters from study-server #59

Merged
merged 21 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9107dc2
Migration of the parameters from study-server.
flomillot Dec 28, 2023
d227693
checkstyle
flomillot Dec 28, 2023
ed329db
Sonar
flomillot Jan 2, 2024
6b0d8de
Add createDefaultParameters endpoints
flomillot Jan 16, 2024
0e32582
Change LoadFlowParametersInfos to LoadFlowParametersValues class.
flomillot Jan 17, 2024
b489497
Refactor getParameters method in SensitivityAnalysisParametersService…
flomillot Jan 17, 2024
d72a7a1
Merge remote-tracking branch 'origin/main' into parameters-migration
flomillot Jan 29, 2024
918b727
Update from other PR comments
flomillot Jan 29, 2024
c158635
Merge remote-tracking branch 'origin/main' into parameters-migration
flomillot Jan 30, 2024
46510ef
optimize imports
flomillot Jan 30, 2024
fd28f57
Refactor SensitivityAnalysisParametersEntity to remove date and name …
flomillot Jan 31, 2024
f6be896
Sonar
flomillot Jan 31, 2024
7cf3bf0
Update doc
flomillot Jan 31, 2024
a626798
Fix alert Sonar
Feb 5, 2024
c33b0ad
Revert "Fix alert Sonar"
Feb 5, 2024
ef93175
PR remarks
flomillot Feb 6, 2024
29b9d86
Merge remote-tracking branch 'origin/main' into parameters-migration
flomillot Feb 6, 2024
d220b54
Update db.changelog-master.yaml to include the correct changeset files.
flomillot Feb 6, 2024
1451969
Refactor test to remove unnecessary content in post request
flomillot Feb 6, 2024
dcee2fb
Add content to the request body in SensitivityAnalysisControllerTest.…
flomillot Feb 6, 2024
4ea7473
Refactor copy method in SensitivityAnalysisParametersEntity to use to…
flomillot Feb 7, 2024
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
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,
SlimaneAmar marked this conversation as resolved.
Show resolved Hide resolved
@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
Loading