Skip to content

Commit 5c3590b

Browse files
Move parameters from study-server (#81)
1 parent bb88a75 commit 5c3590b

17 files changed

+1316
-29
lines changed

src/main/java/org/gridsuite/shortcircuit/server/ShortCircuitController.java

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,22 @@
88

99
import com.fasterxml.jackson.core.JsonProcessingException;
1010
import com.powsybl.security.LimitViolationType;
11-
import com.powsybl.shortcircuit.ShortCircuitParameters;
1211
import io.swagger.v3.oas.annotations.Operation;
1312
import io.swagger.v3.oas.annotations.Parameter;
14-
import io.swagger.v3.oas.annotations.media.Content;
15-
import io.swagger.v3.oas.annotations.media.Schema;
1613
import io.swagger.v3.oas.annotations.responses.ApiResponse;
1714
import io.swagger.v3.oas.annotations.responses.ApiResponses;
1815
import io.swagger.v3.oas.annotations.tags.Tag;
1916
import org.gridsuite.shortcircuit.server.dto.*;
20-
import org.gridsuite.shortcircuit.server.service.ShortCircuitRunContext;
2117
import org.gridsuite.shortcircuit.server.service.ShortCircuitService;
2218
import org.springframework.data.domain.Page;
2319
import org.springframework.data.domain.Pageable;
2420
import org.springframework.http.MediaType;
2521
import org.springframework.http.ResponseEntity;
2622
import org.springframework.web.bind.annotation.*;
2723

28-
import java.util.*;
24+
import java.util.List;
25+
import java.util.Optional;
26+
import java.util.UUID;
2927

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

47-
private static ShortCircuitParameters getNonNullParameters(ShortCircuitParameters parameters) {
48-
ShortCircuitParameters shortCircuitParameters = parameters != null ? parameters : new ShortCircuitParameters();
49-
shortCircuitParameters.setDetailedReport(false);
50-
return shortCircuitParameters;
51-
}
52-
53-
@PostMapping(value = "/networks/{networkUuid}/run-and-save", produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
45+
@PostMapping(value = "/networks/{networkUuid}/run-and-save", produces = APPLICATION_JSON_VALUE)
5446
@Operation(summary = "Run a short circuit analysis on a network")
55-
@ApiResponses(value = {@ApiResponse(responseCode = "200",
56-
description = "The short circuit analysis has been performed",
57-
content = {@Content(mediaType = APPLICATION_JSON_VALUE,
58-
schema = @Schema(implementation = ShortCircuitParameters.class))})})
47+
@ApiResponse(responseCode = "200", description = "The short circuit analysis has been performed")
5948
public ResponseEntity<UUID> runAndSave(@Parameter(description = "Network UUID") @PathVariable("networkUuid") UUID networkUuid,
6049
@Parameter(description = "Variant Id") @RequestParam(name = "variantId", required = false) String variantId,
6150
@Parameter(description = "Result receiver") @RequestParam(name = "receiver", required = false) String receiver,
6251
@Parameter(description = "reportUuid") @RequestParam(name = "reportUuid", required = false) UUID reportUuid,
6352
@Parameter(description = "reporterId") @RequestParam(name = "reporterId", required = false) String reporterId,
6453
@Parameter(description = "The type name for the report") @RequestParam(name = "reportType", required = false) String reportType,
6554
@Parameter(description = "Bus Id - Used for analysis targeting one bus") @RequestParam(name = "busId", required = false) String busId,
66-
@RequestBody(required = false) ShortCircuitParameters parameters,
55+
@Parameter(description = "ID of parameters to use, fallback on default ones if none") @RequestParam(name = "parametersUuid") Optional<UUID> parametersUuid,
6756
@RequestHeader(HEADER_USER_ID) String userId) {
68-
ShortCircuitParameters nonNullParameters = getNonNullParameters(parameters);
69-
ShortCircuitRunContext runContext = new ShortCircuitRunContext(networkUuid, variantId, receiver, nonNullParameters, reportUuid, reporterId, reportType, userId, null, busId);
70-
UUID resultUuid = shortCircuitService.runAndSaveResult(runContext);
71-
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(resultUuid);
57+
return ResponseEntity.ok().contentType(APPLICATION_JSON).body(shortCircuitService.runAndSaveResult(networkUuid, variantId, receiver, reportUuid, reporterId, reportType, userId, busId, parametersUuid));
7258
}
7359

7460
@GetMapping(value = "/results/{resultUuid}", produces = APPLICATION_JSON_VALUE)
@@ -181,5 +167,4 @@ public ResponseEntity<List<FaultType>> getFaultTypes(@Parameter(description = "R
181167
public ResponseEntity<List<LimitViolationType>> getLimitTypes(@Parameter(description = "Result UUID") @PathVariable("resultUuid") UUID resultUuid) {
182168
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(shortCircuitService.getLimitTypes(resultUuid));
183169
}
184-
185170
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright (c) 2024, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.shortcircuit.server;
8+
9+
import io.swagger.v3.oas.annotations.Operation;
10+
import io.swagger.v3.oas.annotations.Parameter;
11+
import io.swagger.v3.oas.annotations.media.Schema;
12+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
13+
import io.swagger.v3.oas.annotations.tags.Tag;
14+
import org.gridsuite.shortcircuit.server.dto.ShortCircuitParametersInfos;
15+
import org.gridsuite.shortcircuit.server.service.ShortCircuitService;
16+
import org.springframework.http.ResponseEntity;
17+
import org.springframework.web.bind.annotation.*;
18+
19+
import java.util.UUID;
20+
21+
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
22+
23+
@RestController
24+
@RequestMapping(path = "/" + ShortCircuitApi.API_VERSION + "/parameters", produces = APPLICATION_JSON_VALUE)
25+
@Tag(name = "Short circuit server analysis parameters")
26+
public class ShortCircuitParametersController {
27+
public static final String DUPLICATE_FROM = "duplicateFrom";
28+
29+
private final ShortCircuitService shortCircuitService;
30+
31+
public ShortCircuitParametersController(ShortCircuitService shortCircuitService) {
32+
this.shortCircuitService = shortCircuitService;
33+
}
34+
35+
@GetMapping(path = "/{parametersUuid}")
36+
@Operation(summary = "Get the parameters for an analysis")
37+
@ApiResponse(responseCode = "200", description = "The parameters asked")
38+
@ApiResponse(responseCode = "404", description = "The parameters don't exists")
39+
public ResponseEntity<ShortCircuitParametersInfos> getParameters(@Parameter(description = "UUID of parameters") @PathVariable("parametersUuid") UUID parametersUuid) {
40+
return ResponseEntity.of(shortCircuitService.getParameters(parametersUuid));
41+
}
42+
43+
@PostMapping(consumes = APPLICATION_JSON_VALUE)
44+
@Operation(summary = "Create a new set of parameters for an analysis using given parameters")
45+
@ApiResponse(responseCode = "200", description = "The new parameters entity ID")
46+
public ResponseEntity<UUID> createParameters(@Parameter(description = "Parameters to save") @RequestBody ShortCircuitParametersInfos parameters) {
47+
return ResponseEntity.ok(shortCircuitService.createParameters(parameters));
48+
}
49+
50+
@PostMapping(path = "/default")
51+
@Operation(summary = "Create a new set of parameters for an analysis using default parameters")
52+
@ApiResponse(responseCode = "200", description = "The new parameters entity ID")
53+
public ResponseEntity<UUID> createDefaultParameters() {
54+
return ResponseEntity.ok(shortCircuitService.createParameters(null));
55+
}
56+
57+
@PostMapping(params = { DUPLICATE_FROM })
58+
@Operation(summary = "Duplicate the parameters of an analysis")
59+
@ApiResponse(responseCode = "200", description = "The new parameters ID")
60+
@ApiResponse(responseCode = "404", description = "The parameters don't exist")
61+
public ResponseEntity<UUID> duplicateParameters(@Parameter(description = "UUID of parameters to duplicate") @RequestParam(name = DUPLICATE_FROM) UUID sourceParametersUuid) {
62+
return ResponseEntity.of(shortCircuitService.duplicateParameters(sourceParametersUuid));
63+
}
64+
65+
@DeleteMapping(path = "/{parametersUuid}")
66+
@Operation(summary = "Delete a set of parameters")
67+
@ApiResponse(responseCode = "204", description = "The parameters are successfully deleted")
68+
@ApiResponse(responseCode = "404", description = "The parameters don't exists")
69+
public ResponseEntity<Void> deleteParameters(@Parameter(description = "UUID of parameters") @PathVariable("parametersUuid") UUID parametersUuid) {
70+
return (shortCircuitService.deleteParameters(parametersUuid) ? ResponseEntity.noContent() : ResponseEntity.notFound()).build();
71+
}
72+
73+
@PutMapping(path = "/{parametersUuid}", consumes = APPLICATION_JSON_VALUE)
74+
@Operation(summary = "Update parameters for an analysis or reset them to default ones")
75+
@ApiResponse(responseCode = "204", description = "The parameters are successfully updated")
76+
@ApiResponse(responseCode = "404", description = "The parameters don't exists")
77+
public ResponseEntity<Void> updateOrResetParameters(@Parameter(description = "UUID of parameters") @PathVariable("parametersUuid") UUID parametersUuid,
78+
@Parameter(description = "Parameters to save instead of default ones", schema = @Schema(implementation = ShortCircuitParametersInfos.class))
79+
@RequestBody(required = false) ShortCircuitParametersInfos parameters) {
80+
return (shortCircuitService.updateOrResetParameters(parametersUuid, parameters) ? ResponseEntity.noContent() : ResponseEntity.notFound()).build();
81+
}
82+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2024, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.shortcircuit.server.dto;
8+
9+
import com.fasterxml.jackson.annotation.JsonProperty;
10+
import com.fasterxml.jackson.annotation.JsonProperty.Access;
11+
import com.powsybl.shortcircuit.ShortCircuitParameters;
12+
import com.powsybl.shortcircuit.VoltageRange;
13+
import lombok.Builder;
14+
import lombok.extern.jackson.Jacksonized;
15+
import org.gridsuite.shortcircuit.server.service.ShortCircuitService;
16+
17+
import java.util.List;
18+
19+
/**
20+
* @since 1.7.0
21+
*/
22+
@Builder
23+
@Jacksonized
24+
public record ShortCircuitParametersInfos(
25+
ShortCircuitPredefinedConfiguration predefinedParameters,
26+
ShortCircuitParameters parameters
27+
) {
28+
@JsonProperty(access = Access.READ_ONLY)
29+
public List<VoltageRange> cei909VoltageRanges() {
30+
return ShortCircuitService.CEI909_VOLTAGE_PROFILE;
31+
}
32+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2024, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.shortcircuit.server.dto;
8+
9+
/**
10+
* @since 1.7.0
11+
*/
12+
public enum ShortCircuitPredefinedConfiguration {
13+
ICC_MAX_WITH_CEI909,
14+
ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP,
15+
ICC_MIN_WITH_NOMINAL_VOLTAGE_MAP
16+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Copyright (c) 2024, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.shortcircuit.server.entities;
8+
9+
import com.powsybl.shortcircuit.InitialVoltageProfileMode;
10+
import com.powsybl.shortcircuit.StudyType;
11+
import jakarta.persistence.*;
12+
import lombok.*;
13+
import lombok.experimental.Accessors;
14+
import org.gridsuite.shortcircuit.server.dto.ShortCircuitPredefinedConfiguration;
15+
16+
import java.util.UUID;
17+
18+
/**
19+
* @since 1.7.0
20+
*/
21+
@Builder
22+
@NoArgsConstructor
23+
@AllArgsConstructor
24+
@Accessors(chain = true)
25+
@Getter
26+
@Setter
27+
@Entity
28+
@Table(name = "shortcircuit_parameters")
29+
public class ShortCircuitParametersEntity {
30+
31+
public ShortCircuitParametersEntity(boolean withLimitViolations, boolean withVoltageResult, boolean withFeederResult, StudyType studyType,
32+
double minVoltageDropProportionalThreshold, ShortCircuitPredefinedConfiguration predefinedParameters,
33+
boolean withLoads, boolean withShuntCompensators, boolean withVscConverterStations, boolean withNeutralPosition,
34+
InitialVoltageProfileMode initialVoltageProfileMode) {
35+
this(null, withLimitViolations, withVoltageResult, withFeederResult, studyType, minVoltageDropProportionalThreshold,
36+
predefinedParameters, withLoads, withShuntCompensators, withVscConverterStations, withNeutralPosition, initialVoltageProfileMode);
37+
}
38+
39+
public ShortCircuitParametersEntity(@NonNull final ShortCircuitParametersEntity sourceToClone) {
40+
this(sourceToClone.isWithLimitViolations(),
41+
sourceToClone.isWithVoltageResult(),
42+
sourceToClone.isWithFeederResult(),
43+
sourceToClone.getStudyType(),
44+
sourceToClone.getMinVoltageDropProportionalThreshold(),
45+
sourceToClone.getPredefinedParameters(),
46+
sourceToClone.isWithLoads(),
47+
sourceToClone.isWithShuntCompensators(),
48+
sourceToClone.isWithVscConverterStations(),
49+
sourceToClone.isWithNeutralPosition(),
50+
sourceToClone.getInitialVoltageProfileMode());
51+
}
52+
53+
@Id
54+
@GeneratedValue(strategy = GenerationType.AUTO)
55+
@Column(name = "id")
56+
private UUID id;
57+
58+
@Builder.Default
59+
@Column(name = "withLimitViolations", columnDefinition = "boolean default true")
60+
private boolean withLimitViolations = true;
61+
62+
@Builder.Default
63+
@Column(name = "withVoltageResult", columnDefinition = "boolean default false")
64+
private boolean withVoltageResult = false;
65+
66+
@Builder.Default
67+
@Column(name = "withFeederResult", columnDefinition = "boolean default true")
68+
private boolean withFeederResult = true;
69+
70+
@Builder.Default
71+
@Column(name = "studyType", columnDefinition = "varchar(255) default 'TRANSIENT'")
72+
@Enumerated(EnumType.STRING)
73+
private StudyType studyType = StudyType.TRANSIENT;
74+
75+
@Builder.Default
76+
@Column(name = "minVoltageDropProportionalThreshold", columnDefinition = "double precision default 20.0")
77+
private double minVoltageDropProportionalThreshold = 20.0;
78+
79+
@Builder.Default
80+
@Column(name = "predefinedParameters", columnDefinition = "varchar(255) default 'ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP'")
81+
@Enumerated(EnumType.STRING)
82+
private ShortCircuitPredefinedConfiguration predefinedParameters = ShortCircuitPredefinedConfiguration.ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP;
83+
84+
@Builder.Default
85+
@Column(name = "withLoads", columnDefinition = "boolean default false")
86+
private boolean withLoads = false;
87+
88+
@Builder.Default
89+
@Column(name = "withShuntCompensators", columnDefinition = "boolean default false")
90+
private boolean withShuntCompensators = false;
91+
92+
@Builder.Default
93+
@Column(name = "withVscConverterStations", columnDefinition = "boolean default true")
94+
private boolean withVscConverterStations = true;
95+
96+
@Builder.Default
97+
@Column(name = "withNeutralPosition", columnDefinition = "boolean default true")
98+
private boolean withNeutralPosition = true;
99+
100+
@Builder.Default
101+
@Column(name = "initialVoltageProfileMode", columnDefinition = "varchar(255) default 'NOMINAL'")
102+
@Enumerated(EnumType.STRING)
103+
private InitialVoltageProfileMode initialVoltageProfileMode = InitialVoltageProfileMode.NOMINAL;
104+
105+
public ShortCircuitParametersEntity updateWith(final ShortCircuitParametersEntity source) {
106+
return this.setWithLimitViolations(source.isWithLimitViolations())
107+
.setWithVoltageResult(source.isWithVoltageResult())
108+
.setWithFeederResult(source.isWithFeederResult())
109+
.setStudyType(source.getStudyType())
110+
.setMinVoltageDropProportionalThreshold(source.getMinVoltageDropProportionalThreshold())
111+
.setPredefinedParameters(source.getPredefinedParameters())
112+
.setWithLoads(source.isWithLoads())
113+
.setWithShuntCompensators(source.isWithShuntCompensators())
114+
.setWithVscConverterStations(source.isWithVscConverterStations())
115+
.setWithNeutralPosition(source.isWithNeutralPosition())
116+
.setInitialVoltageProfileMode(source.getInitialVoltageProfileMode());
117+
}
118+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright (c) 2024, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.shortcircuit.server.repositories;
8+
9+
import org.gridsuite.shortcircuit.server.entities.ShortCircuitParametersEntity;
10+
import org.springframework.data.jpa.repository.JpaRepository;
11+
import org.springframework.stereotype.Repository;
12+
13+
import java.util.UUID;
14+
15+
@Repository
16+
public interface ParametersRepository extends JpaRepository<ShortCircuitParametersEntity, UUID> {
17+
}

0 commit comments

Comments
 (0)