Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,22 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.powsybl.security.LimitViolationType;
import com.powsybl.shortcircuit.ShortCircuitParameters;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
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.shortcircuit.server.dto.*;
import org.gridsuite.shortcircuit.server.service.ShortCircuitRunContext;
import org.gridsuite.shortcircuit.server.service.ShortCircuitService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

import static com.powsybl.shortcircuit.Fault.FaultType;
import static org.gridsuite.shortcircuit.server.computation.service.NotificationService.HEADER_USER_ID;
Expand All @@ -44,31 +42,19 @@ public ShortCircuitController(ShortCircuitService shortCircuitService) {
this.shortCircuitService = shortCircuitService;
}

private static ShortCircuitParameters getNonNullParameters(ShortCircuitParameters parameters) {
ShortCircuitParameters shortCircuitParameters = parameters != null ? parameters : new ShortCircuitParameters();
shortCircuitParameters.setDetailedReport(false);
return shortCircuitParameters;
}

@PostMapping(value = "/networks/{networkUuid}/run-and-save", produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
@PostMapping(value = "/networks/{networkUuid}/run-and-save", produces = APPLICATION_JSON_VALUE)
@Operation(summary = "Run a short circuit analysis on a network")
@ApiResponses(value = {@ApiResponse(responseCode = "200",
description = "The short circuit analysis has been performed",
content = {@Content(mediaType = APPLICATION_JSON_VALUE,
schema = @Schema(implementation = ShortCircuitParameters.class))})})
@ApiResponse(responseCode = "200", description = "The short circuit analysis has been performed")
public ResponseEntity<UUID> runAndSave(@Parameter(description = "Network UUID") @PathVariable("networkUuid") UUID networkUuid,
@Parameter(description = "Variant Id") @RequestParam(name = "variantId", required = false) String variantId,
@Parameter(description = "Result receiver") @RequestParam(name = "receiver", required = false) String receiver,
@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) String reportType,
@Parameter(description = "Bus Id - Used for analysis targeting one bus") @RequestParam(name = "busId", required = false) String busId,
@RequestBody(required = false) ShortCircuitParameters parameters,
@Parameter(description = "ID of parameters to use, fallback on default ones if none") @RequestParam(name = "parametersUuid") Optional<UUID> parametersUuid,
@RequestHeader(HEADER_USER_ID) String userId) {
ShortCircuitParameters nonNullParameters = getNonNullParameters(parameters);
ShortCircuitRunContext runContext = new ShortCircuitRunContext(networkUuid, variantId, receiver, nonNullParameters, reportUuid, reporterId, reportType, userId, null, busId);
UUID resultUuid = shortCircuitService.runAndSaveResult(runContext);
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(resultUuid);
return ResponseEntity.ok().contentType(APPLICATION_JSON).body(shortCircuitService.runAndSaveResult(networkUuid, variantId, receiver, reportUuid, reporterId, reportType, userId, busId, parametersUuid));
}

@GetMapping(value = "/results/{resultUuid}", produces = APPLICATION_JSON_VALUE)
Expand Down Expand Up @@ -181,5 +167,4 @@ public ResponseEntity<List<FaultType>> getFaultTypes(@Parameter(description = "R
public ResponseEntity<List<LimitViolationType>> getLimitTypes(@Parameter(description = "Result UUID") @PathVariable("resultUuid") UUID resultUuid) {
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(shortCircuitService.getLimitTypes(resultUuid));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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.shortcircuit.server;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.gridsuite.shortcircuit.server.dto.ShortCircuitParametersInfos;
import org.gridsuite.shortcircuit.server.service.ShortCircuitService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

@RestController
@RequestMapping(path = "/" + ShortCircuitApi.API_VERSION + "/parameters", produces = APPLICATION_JSON_VALUE)
@Tag(name = "Short circuit server analysis parameters")
public class ShortCircuitParametersController {
public static final String DUPLICATE_FROM = "duplicateFrom";

private final ShortCircuitService shortCircuitService;

public ShortCircuitParametersController(ShortCircuitService shortCircuitService) {
this.shortCircuitService = shortCircuitService;
}

@GetMapping(path = "/{parametersUuid}")
@Operation(summary = "Get the parameters for an analysis")
@ApiResponse(responseCode = "200", description = "The parameters asked")
@ApiResponse(responseCode = "404", description = "The parameters don't exists")
public ResponseEntity<ShortCircuitParametersInfos> getParameters(@Parameter(description = "UUID of parameters") @PathVariable("parametersUuid") UUID parametersUuid) {
return ResponseEntity.of(shortCircuitService.getParameters(parametersUuid));
}

@PostMapping(consumes = APPLICATION_JSON_VALUE)
@Operation(summary = "Create a new set of parameters for an analysis using given parameters")
@ApiResponse(responseCode = "200", description = "The new parameters entity ID")
public ResponseEntity<UUID> createParameters(@Parameter(description = "Parameters to save") @RequestBody ShortCircuitParametersInfos parameters) {
return ResponseEntity.ok(shortCircuitService.createParameters(parameters));
}

@PostMapping(path = "/default")
@Operation(summary = "Create a new set of parameters for an analysis using default parameters")
@ApiResponse(responseCode = "200", description = "The new parameters entity ID")
public ResponseEntity<UUID> createDefaultParameters() {
return ResponseEntity.ok(shortCircuitService.createParameters(null));
}

@PostMapping(params = { DUPLICATE_FROM })
@Operation(summary = "Duplicate the parameters of an analysis")
@ApiResponse(responseCode = "200", description = "The new parameters ID")
@ApiResponse(responseCode = "404", description = "The parameters don't exist")
public ResponseEntity<UUID> duplicateParameters(@Parameter(description = "UUID of parameters to duplicate") @RequestParam(name = DUPLICATE_FROM) UUID sourceParametersUuid) {
return ResponseEntity.of(shortCircuitService.duplicateParameters(sourceParametersUuid));
}

@DeleteMapping(path = "/{parametersUuid}")
@Operation(summary = "Delete a set of parameters")
@ApiResponse(responseCode = "204", description = "The parameters are successfully deleted")
@ApiResponse(responseCode = "404", description = "The parameters don't exists")
public ResponseEntity<Void> deleteParameters(@Parameter(description = "UUID of parameters") @PathVariable("parametersUuid") UUID parametersUuid) {
return (shortCircuitService.deleteParameters(parametersUuid) ? ResponseEntity.noContent() : ResponseEntity.notFound()).build();
}

@PutMapping(path = "/{parametersUuid}", consumes = APPLICATION_JSON_VALUE)
@Operation(summary = "Update parameters for an analysis or reset them to default ones")
@ApiResponse(responseCode = "204", description = "The parameters are successfully updated")
@ApiResponse(responseCode = "404", description = "The parameters don't exists")
public ResponseEntity<Void> updateOrResetParameters(@Parameter(description = "UUID of parameters") @PathVariable("parametersUuid") UUID parametersUuid,
@Parameter(description = "Parameters to save instead of default ones", schema = @Schema(implementation = ShortCircuitParametersInfos.class))
@RequestBody(required = false) ShortCircuitParametersInfos parameters) {
return (shortCircuitService.updateOrResetParameters(parametersUuid, parameters) ? ResponseEntity.noContent() : ResponseEntity.notFound()).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.shortcircuit.server.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonProperty.Access;
import com.powsybl.shortcircuit.ShortCircuitParameters;
import com.powsybl.shortcircuit.VoltageRange;
import lombok.Builder;
import lombok.extern.jackson.Jacksonized;
import org.gridsuite.shortcircuit.server.service.ShortCircuitService;

import java.util.List;

/**
* @since 1.7.0
*/
@Builder
@Jacksonized
public record ShortCircuitParametersInfos(
ShortCircuitPredefinedConfiguration predefinedParameters,
ShortCircuitParameters parameters
) {
@JsonProperty(access = Access.READ_ONLY)
public List<VoltageRange> cei909VoltageRanges() {
return ShortCircuitService.CEI909_VOLTAGE_PROFILE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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.shortcircuit.server.dto;

/**
* @since 1.7.0
*/
public enum ShortCircuitPredefinedConfiguration {
ICC_MAX_WITH_CEI909,
ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP,
ICC_MIN_WITH_NOMINAL_VOLTAGE_MAP
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* 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.shortcircuit.server.entities;

import com.powsybl.shortcircuit.InitialVoltageProfileMode;
import com.powsybl.shortcircuit.StudyType;
import jakarta.persistence.*;
import lombok.*;
import lombok.experimental.Accessors;
import org.gridsuite.shortcircuit.server.dto.ShortCircuitPredefinedConfiguration;

import java.util.UUID;

/**
* @since 1.7.0
*/
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@Getter
@Setter
@Entity
@Table(name = "shortcircuit_parameters")
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
@Table(name = "shortcircuit_parameters")
@Table(name = "short_circuit_parameters")

in order for the data migration script to work, the parameters table must have the same name as the one defined in study-server

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Problem fixed in gridsuite/deployment#417

public class ShortCircuitParametersEntity {

public ShortCircuitParametersEntity(boolean withLimitViolations, boolean withVoltageResult, boolean withFeederResult, StudyType studyType,
double minVoltageDropProportionalThreshold, ShortCircuitPredefinedConfiguration predefinedParameters,
boolean withLoads, boolean withShuntCompensators, boolean withVscConverterStations, boolean withNeutralPosition,
InitialVoltageProfileMode initialVoltageProfileMode) {
this(null, withLimitViolations, withVoltageResult, withFeederResult, studyType, minVoltageDropProportionalThreshold,
predefinedParameters, withLoads, withShuntCompensators, withVscConverterStations, withNeutralPosition, initialVoltageProfileMode);
}

public ShortCircuitParametersEntity(@NonNull final ShortCircuitParametersEntity sourceToClone) {
this(sourceToClone.isWithLimitViolations(),
sourceToClone.isWithVoltageResult(),
sourceToClone.isWithFeederResult(),
sourceToClone.getStudyType(),
sourceToClone.getMinVoltageDropProportionalThreshold(),
sourceToClone.getPredefinedParameters(),
sourceToClone.isWithLoads(),
sourceToClone.isWithShuntCompensators(),
sourceToClone.isWithVscConverterStations(),
sourceToClone.isWithNeutralPosition(),
sourceToClone.getInitialVoltageProfileMode());
}

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private UUID id;

@Builder.Default
@Column(name = "withLimitViolations", columnDefinition = "boolean default true")
private boolean withLimitViolations = true;

@Builder.Default
@Column(name = "withVoltageResult", columnDefinition = "boolean default false")
private boolean withVoltageResult = false;

@Builder.Default
@Column(name = "withFeederResult", columnDefinition = "boolean default true")
private boolean withFeederResult = true;

@Builder.Default
@Column(name = "studyType", columnDefinition = "varchar(255) default 'TRANSIENT'")
@Enumerated(EnumType.STRING)
private StudyType studyType = StudyType.TRANSIENT;

@Builder.Default
@Column(name = "minVoltageDropProportionalThreshold", columnDefinition = "double precision default 20.0")
private double minVoltageDropProportionalThreshold = 20.0;

@Builder.Default
@Column(name = "predefinedParameters", columnDefinition = "varchar(255) default 'ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP'")
@Enumerated(EnumType.STRING)
private ShortCircuitPredefinedConfiguration predefinedParameters = ShortCircuitPredefinedConfiguration.ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP;

@Builder.Default
@Column(name = "withLoads", columnDefinition = "boolean default false")
private boolean withLoads = false;

@Builder.Default
@Column(name = "withShuntCompensators", columnDefinition = "boolean default false")
private boolean withShuntCompensators = false;

@Builder.Default
@Column(name = "withVscConverterStations", columnDefinition = "boolean default true")
private boolean withVscConverterStations = true;

@Builder.Default
@Column(name = "withNeutralPosition", columnDefinition = "boolean default true")
private boolean withNeutralPosition = true;

@Builder.Default
@Column(name = "initialVoltageProfileMode", columnDefinition = "varchar(255) default 'NOMINAL'")
@Enumerated(EnumType.STRING)
private InitialVoltageProfileMode initialVoltageProfileMode = InitialVoltageProfileMode.NOMINAL;

public ShortCircuitParametersEntity updateWith(final ShortCircuitParametersEntity source) {
return this.setWithLimitViolations(source.isWithLimitViolations())
.setWithVoltageResult(source.isWithVoltageResult())
.setWithFeederResult(source.isWithFeederResult())
.setStudyType(source.getStudyType())
.setMinVoltageDropProportionalThreshold(source.getMinVoltageDropProportionalThreshold())
.setPredefinedParameters(source.getPredefinedParameters())
.setWithLoads(source.isWithLoads())
.setWithShuntCompensators(source.isWithShuntCompensators())
.setWithVscConverterStations(source.isWithVscConverterStations())
.setWithNeutralPosition(source.isWithNeutralPosition())
.setInitialVoltageProfileMode(source.getInitialVoltageProfileMode());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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.shortcircuit.server.repositories;

import org.gridsuite.shortcircuit.server.entities.ShortCircuitParametersEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.UUID;

@Repository
public interface ParametersRepository extends JpaRepository<ShortCircuitParametersEntity, UUID> {
}
Loading