Skip to content

Commit

Permalink
Add loadflow parameters controller (#82)
Browse files Browse the repository at this point in the history
Signed-off-by: Ayoub LABIDI <ayoub.labidi@protonmail.com>
  • Loading branch information
ayolab authored Jan 26, 2024
1 parent dadc6d7 commit 15ac580
Show file tree
Hide file tree
Showing 18 changed files with 874 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
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.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 +37,11 @@
@Tag(name = "loadflow-server")
public class LoadFlowController {

@Autowired
private LoadFlowService loadFlowService;
private final LoadFlowService loadFlowService;

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

@PostMapping(value = "/networks/{networkUuid}/run-and-save", produces = APPLICATION_JSON_VALUE)
@Operation(summary = "Run a load flow on a network")
Expand All @@ -53,21 +54,18 @@ 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()
.networkUuid(networkUuid)
.variantId(variantId)
.receiver(receiver)
.provider(providerToUse)
.parameters(loadflowParams)
.reportContext(ReportContext.builder().reportId(reportId).reportName(reportName).reportType(reportType).build())
.userId(userId)
.limitReduction(limitReduction)
.build();
UUID resultUuid = loadFlowService.runAndSaveResult(loadFlowRunContext);
UUID resultUuid = loadFlowService.runAndSaveResult(loadFlowRunContext, provider, parametersUuid);
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(resultUuid);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* 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.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")
@ApiResponse(responseCode = "200", description = "parameters were created")
public ResponseEntity<UUID> createParameters(
@RequestBody LoadFlowParametersInfos parametersInfos) {
return ResponseEntity.ok(parametersService.createParameters(parametersInfos));
}

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

@PostMapping(value = "/{sourceParametersUuid}")
@Operation(summary = "Duplicate parameters")
@ApiResponse(responseCode = "200", description = "parameters were duplicated")
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<LoadFlowParametersInfos> 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<LoadFlowParametersInfos>> getAllParameters() {
return ResponseEntity.ok().body(parametersService.getAllParameters());
}

@PutMapping(value = "/{uuid}", consumes = 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 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,29 @@
/**
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.Builder;

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>
*/
@Builder
public record LoadFlowParametersInfos(
UUID uuid,
LoadFlowParameters commonParameters,
Map<String, Map<String, String>> specificParametersPerProvider) {
public LoadFlowParametersEntity toEntity() {
return new LoadFlowParametersEntity(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,18 @@
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;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Map;

/**
* @author David Braquart <david.braquart@rte-france.com>
*/
@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class LoadFlowParametersInfos {

private LoadFlowParameters commonParameters;

private Map<String, String> specificParameters;
}
public record LoadFlowParametersValues(
LoadFlowParameters commonParameters,
Map<String, String> specificParameters
) { }
Loading

0 comments on commit 15ac580

Please sign in to comment.