Skip to content

Commit c470c99

Browse files
BIG REDO SQUASH!
1 parent 8ac44bd commit c470c99

13 files changed

+1050
-165
lines changed

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

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,23 @@
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;
1513
import io.swagger.v3.oas.annotations.media.Schema;
1614
import io.swagger.v3.oas.annotations.responses.ApiResponse;
1715
import io.swagger.v3.oas.annotations.responses.ApiResponses;
1816
import io.swagger.v3.oas.annotations.tags.Tag;
1917
import org.gridsuite.shortcircuit.server.dto.*;
20-
import org.gridsuite.shortcircuit.server.service.ShortCircuitRunContext;
2118
import org.gridsuite.shortcircuit.server.service.ShortCircuitService;
2219
import org.springframework.data.domain.Page;
2320
import org.springframework.data.domain.Pageable;
2421
import org.springframework.http.MediaType;
2522
import org.springframework.http.ResponseEntity;
2623
import org.springframework.web.bind.annotation.*;
2724

28-
import java.util.*;
25+
import java.util.List;
26+
import java.util.Optional;
27+
import java.util.UUID;
2928

3029
import static com.powsybl.shortcircuit.Fault.FaultType;
3130
import static org.gridsuite.shortcircuit.server.computation.service.NotificationService.HEADER_USER_ID;
@@ -44,31 +43,21 @@ public ShortCircuitController(ShortCircuitService shortCircuitService) {
4443
this.shortCircuitService = shortCircuitService;
4544
}
4645

47-
private static ShortCircuitParameters getNonNullParameters(ShortCircuitParameters parameters) {
48-
ShortCircuitParameters shortCircuitParameters = parameters != null ? parameters : new ShortCircuitParameters();
49-
shortCircuitParameters.setDetailedReport(false);
50-
return shortCircuitParameters;
51-
}
52-
5346
@PostMapping(value = "/networks/{networkUuid}/run-and-save", produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
5447
@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))})})
48+
@ApiResponse(responseCode = "200", description = "The short circuit analysis has been performed")
5949
public ResponseEntity<UUID> runAndSave(@Parameter(description = "Network UUID") @PathVariable("networkUuid") UUID networkUuid,
6050
@Parameter(description = "Variant Id") @RequestParam(name = "variantId", required = false) String variantId,
6151
@Parameter(description = "Result receiver") @RequestParam(name = "receiver", required = false) String receiver,
6252
@Parameter(description = "reportUuid") @RequestParam(name = "reportUuid", required = false) UUID reportUuid,
6353
@Parameter(description = "reporterId") @RequestParam(name = "reporterId", required = false) String reporterId,
6454
@Parameter(description = "The type name for the report") @RequestParam(name = "reportType", required = false) String reportType,
6555
@Parameter(description = "Bus Id - Used for analysis targeting one bus") @RequestParam(name = "busId", required = false) String busId,
66-
@RequestBody(required = false) ShortCircuitParameters parameters,
56+
@Parameter(description = "ID of parameters to use") @RequestParam(name = "parametersUuid", required = false) Optional<UUID> parametersUuid,
57+
@Parameter(description = "Parameters (full or partial) to use on top of the ones designed by parametersUuid", schema = @Schema(implementation = ShortCircuitParametersInfos.class))
58+
@RequestBody(required = false) Optional<ShortCircuitParametersInfos> parameters,
6759
@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);
60+
return ResponseEntity.ok().contentType(APPLICATION_JSON).body(shortCircuitService.runAndSaveResult(networkUuid, variantId, receiver, reportUuid, reporterId, reportType, userId, busId, parametersUuid, parameters));
7261
}
7362

7463
@GetMapping(value = "/results/{resultUuid}", produces = APPLICATION_JSON_VALUE)
@@ -181,5 +170,4 @@ public ResponseEntity<List<FaultType>> getFaultTypes(@Parameter(description = "R
181170
public ResponseEntity<List<LimitViolationType>> getLimitTypes(@Parameter(description = "Result UUID") @PathVariable("resultUuid") UUID resultUuid) {
182171
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(shortCircuitService.getLimitTypes(resultUuid));
183172
}
184-
185173
}
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(required = false) 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 a set of 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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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_NOMINAL_VOLTAGE_MAP,
14+
ICC_MAX_WITH_CEI909
15+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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 AnalysisParametersEntity {
30+
31+
public AnalysisParametersEntity(boolean withLimitViolations, boolean withVoltageResult, boolean withFortescueResult, boolean withFeederResult,
32+
StudyType studyType, double minVoltageDropProportionalThreshold, ShortCircuitPredefinedConfiguration predefinedParameters,
33+
boolean withLoads, boolean withShuntCompensators, boolean withVscConverterStations, boolean withNeutralPosition,
34+
InitialVoltageProfileMode initialVoltageProfileMode) {
35+
this(null, withLimitViolations, withVoltageResult, withFortescueResult, withFeederResult, studyType, minVoltageDropProportionalThreshold,
36+
predefinedParameters, withLoads, withShuntCompensators, withVscConverterStations, withNeutralPosition, initialVoltageProfileMode);
37+
}
38+
39+
@Id
40+
@GeneratedValue(strategy = GenerationType.AUTO)
41+
@Column(name = "id")
42+
private UUID id;
43+
44+
@Builder.Default
45+
@Column(name = "withLimitViolations", columnDefinition = "boolean default true")
46+
private boolean withLimitViolations = true;
47+
48+
@Builder.Default
49+
@Column(name = "withVoltageResult", columnDefinition = "boolean default false")
50+
private boolean withVoltageResult = false;
51+
52+
@Builder.Default
53+
@Column(name = "withFortescueResult", columnDefinition = "boolean default false")
54+
private boolean withFortescueResult = false;
55+
56+
@Builder.Default
57+
@Column(name = "withFeederResult", columnDefinition = "boolean default true")
58+
private boolean withFeederResult = true;
59+
60+
@Builder.Default
61+
@Column(name = "studyType", columnDefinition = "varchar(255) default 'TRANSIENT'")
62+
@Enumerated(EnumType.STRING)
63+
private StudyType studyType = StudyType.TRANSIENT;
64+
65+
@Builder.Default
66+
@Column(name = "minVoltageDropProportionalThreshold", columnDefinition = "double precision default 20.0")
67+
private double minVoltageDropProportionalThreshold = 20.0;
68+
69+
@Builder.Default
70+
@Column(name = "predefinedParameters", columnDefinition = "varchar(255) default 'ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP'")
71+
@Enumerated(EnumType.STRING)
72+
private ShortCircuitPredefinedConfiguration predefinedParameters = ShortCircuitPredefinedConfiguration.ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP;
73+
74+
@Builder.Default
75+
@Column(name = "withLoads", columnDefinition = "boolean default false")
76+
private boolean withLoads = false;
77+
78+
@Builder.Default
79+
@Column(name = "withShuntCompensators", columnDefinition = "boolean default false")
80+
private boolean withShuntCompensators = false;
81+
82+
@Builder.Default
83+
@Column(name = "withVscConverterStations", columnDefinition = "boolean default true")
84+
private boolean withVscConverterStations = true;
85+
86+
@Builder.Default
87+
@Column(name = "withNeutralPosition", columnDefinition = "boolean default true")
88+
private boolean withNeutralPosition = true;
89+
90+
@Builder.Default
91+
@Column(name = "initialVoltageProfileMode", columnDefinition = "varchar(255) default 'NOMINAL'")
92+
@Enumerated(EnumType.STRING)
93+
private InitialVoltageProfileMode initialVoltageProfileMode = InitialVoltageProfileMode.NOMINAL;
94+
}
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.AnalysisParametersEntity;
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<AnalysisParametersEntity, UUID> {
17+
}

0 commit comments

Comments
 (0)