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

Add loadflow parameters controller #82

Merged
merged 22 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.gridsuite.loadflow.server.dto.LimitViolationInfos;
import org.gridsuite.loadflow.server.dto.LoadFlowParametersInfos;
import org.gridsuite.loadflow.server.dto.LoadFlowResult;
import org.gridsuite.loadflow.server.dto.LoadFlowStatus;
import org.gridsuite.loadflow.server.service.LoadFlowRunContext;
import org.gridsuite.loadflow.server.service.LoadFlowService;
import org.gridsuite.loadflow.server.service.parameters.LoadFlowParametersService;
import org.gridsuite.loadflow.server.utils.ReportContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -39,8 +38,13 @@
@Tag(name = "loadflow-server")
public class LoadFlowController {

@Autowired
private LoadFlowService loadFlowService;
private final LoadFlowService loadFlowService;
private final LoadFlowParametersService parametersService;
ayolab marked this conversation as resolved.
Show resolved Hide resolved

public LoadFlowController(LoadFlowService loadFlowService, LoadFlowParametersService parametersService) {
this.loadFlowService = loadFlowService;
this.parametersService = parametersService;
}

@PostMapping(value = "/networks/{networkUuid}/run-and-save", produces = APPLICATION_JSON_VALUE)
@Operation(summary = "Run a load flow on a network")
Expand All @@ -53,16 +57,16 @@ public ResponseEntity<UUID> run(@Parameter(description = "Network UUID") @PathVa
@Parameter(description = "reporterId") @RequestParam(name = "reporterId", required = false) String reportName,
@Parameter(description = "The type name for the report") @RequestParam(name = "reportType", required = false, defaultValue = "LoadFlow") String reportType,
@Parameter(description = "The limit reduction") @RequestParam(name = "limitReduction", required = false, defaultValue = "0.8F") Float limitReduction,
@RequestHeader(HEADER_USER_ID) String userId,
@RequestBody(required = false) LoadFlowParametersInfos loadflowParams
@Parameter(description = "parametersUuid") @RequestParam(name = "parametersUuid", required = false) UUID parametersUuid,
@RequestHeader(HEADER_USER_ID) String userId
) {
String providerToUse = provider != null ? provider : loadFlowService.getDefaultProvider();
LoadFlowRunContext loadFlowRunContext = LoadFlowRunContext.builder()
ayolab marked this conversation as resolved.
Show resolved Hide resolved
.networkUuid(networkUuid)
.variantId(variantId)
.receiver(receiver)
.provider(providerToUse)
.parameters(loadflowParams)
.parameters(parametersService.getParametersValues(parametersUuid, providerToUse))
.reportContext(ReportContext.builder().reportId(reportId).reportName(reportName).reportType(reportType).build())
.userId(userId)
.limitReduction(limitReduction)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* 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.loadflow.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.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;

import org.gridsuite.loadflow.server.dto.parameters.LoadFlowParametersInfos;
import org.gridsuite.loadflow.server.service.parameters.LoadFlowParametersService;
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 Ayoub LABIDI <ayoub.labidi at rte-france.com>
*/
@RestController
@RequestMapping(value = "/" + LoadFlowApi.API_VERSION + "/parameters")
@Tag(name = "LoadFlow parameters")
public class LoadFlowParametersController {

private final LoadFlowParametersService parametersService;

public LoadFlowParametersController(LoadFlowParametersService parametersService) {
this.parametersService = parametersService;
}

@PostMapping(value = "", consumes = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Create parameters")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "parameters were created")})
ayolab marked this conversation as resolved.
Show resolved Hide resolved
public ResponseEntity<UUID> createParameters(
@RequestBody LoadFlowParametersInfos parametersInfos) {
return ResponseEntity.ok().body(parametersService.createParameters(parametersInfos));
ayolab marked this conversation as resolved.
Show resolved Hide resolved
}

@PostMapping(value = "/default")
@Operation(summary = "Create default parameters")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Default parameters were created")})
ayolab marked this conversation as resolved.
Show resolved Hide resolved
public ResponseEntity<UUID> createDefaultParameters() {
return ResponseEntity.ok().body(parametersService.createDefaultParameters());
ayolab marked this conversation as resolved.
Show resolved Hide resolved
}

@PostMapping(value = "")
ayolab marked this conversation as resolved.
Show resolved Hide resolved
@Operation(summary = "Duplicate parameters")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "parameters were duplicated")})
ayolab marked this conversation as resolved.
Show resolved Hide resolved
public ResponseEntity<UUID> duplicateParameters(
@RequestParam("duplicateFrom") UUID sourceParametersUuid) {
return ResponseEntity.ok().body(parametersService.duplicateParameters(sourceParametersUuid));
}

@GetMapping(value = "/{uuid}", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get parameters")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "parameters were returned"),
@ApiResponse(responseCode = "404", description = "parameters were not found")})
ayolab marked this conversation as resolved.
Show resolved Hide resolved
public ResponseEntity<LoadFlowParametersInfos> getParameters(
@Parameter(description = "parameters UUID") @PathVariable("uuid") UUID parametersUuid) {
LoadFlowParametersInfos parameters = parametersService.getParameters(parametersUuid);
return parameters != null ? ResponseEntity.ok().body(parametersService.getParameters(parametersUuid))
flomillot marked this conversation as resolved.
Show resolved Hide resolved
: ResponseEntity.notFound().build();
}

@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<LoadFlowParametersInfos>> getAllParameters() {
return ResponseEntity.ok().body(parametersService.getAllParameters());
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return ResponseEntity.ok().body(parametersService.getAllParameters());
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(parametersService.getAllParameters());

}

@PutMapping(value = "/{uuid}", consumes = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Update parameters")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "parameters were updated")})
ayolab marked this conversation as resolved.
Show resolved Hide resolved
public ResponseEntity<Void> updateParameters(
@Parameter(description = "parameters UUID") @PathVariable("uuid") UUID parametersUuid,
@RequestBody LoadFlowParametersInfos parametersInfos) {
parametersService.updateParameters(parametersUuid, parametersInfos);
return ResponseEntity.ok().build();
}

@DeleteMapping(value = "/{uuid}")
@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,39 @@
/**
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.loadflow.server.dto.parameters;

import com.powsybl.loadflow.LoadFlowParameters;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Map;
import java.util.UUID;

import org.gridsuite.loadflow.server.entities.parameters.LoadFlowParametersEntity;

/**
* @author Ayoub LABIDI <ayoub.labidi at rte-france.com>
*/
@Getter
@AllArgsConstructor
@Builder
@NoArgsConstructor
public class LoadFlowParametersInfos {

private UUID uuid;

private LoadFlowParameters commonParameters;

private Map<String, Map<String, String>> specificParametersPerProvider;

public LoadFlowParametersEntity toEntity() {
return new LoadFlowParametersEntity(this);
}
}
ayolab marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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.dto;
package org.gridsuite.loadflow.server.dto.parameters;

import com.powsybl.loadflow.LoadFlowParameters;
import lombok.AllArgsConstructor;
Expand All @@ -21,7 +21,7 @@
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class LoadFlowParametersInfos {
public class LoadFlowParametersValues {
ayolab marked this conversation as resolved.
Show resolved Hide resolved

private LoadFlowParameters commonParameters;

Expand Down
Loading
Loading