-
Notifications
You must be signed in to change notification settings - Fork 0
Move parameters from study-server #81
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c470c99
BIG REDO SQUASH!
Tristan-WorkGH 7bcee84
review
Tristan-WorkGH 86dfba8
review
Tristan-WorkGH 2120011
Merge remote-tracking branch 'origin/main' into move_parameters
Tristan-WorkGH bf4715e
review
Tristan-WorkGH 3ad7b5c
Merge remote-tracking branch 'origin/main' into move_parameters
Tristan-WorkGH 7dd5946
Fix tests
Tristan-WorkGH 4997bd5
Remove unused `FortescueResult` from parameters
Tristan-WorkGH 4fdc3ef
simplify
Tristan-WorkGH 9ffd91e
review
Tristan-WorkGH 132fb50
clarify new()
Tristan-WorkGH 48a5b21
review
Tristan-WorkGH 8af2c18
revert
Tristan-WorkGH 25491b7
clean comments
Tristan-WorkGH File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/main/java/org/gridsuite/shortcircuit/server/ShortCircuitParametersController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/org/gridsuite/shortcircuit/server/dto/ShortCircuitParametersInfos.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/org/gridsuite/shortcircuit/server/dto/ShortCircuitPredefinedConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
118 changes: 118 additions & 0 deletions
118
src/main/java/org/gridsuite/shortcircuit/server/entities/ShortCircuitParametersEntity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
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()); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/org/gridsuite/shortcircuit/server/repositories/ParametersRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
Tristan-WorkGH marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@Repository | ||
public interface ParametersRepository extends JpaRepository<ShortCircuitParametersEntity, UUID> { | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in order for the data migration script to work, the parameters table must have the same name as the one defined in study-server
There was a problem hiding this comment.
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