Skip to content

Commit c02ea74

Browse files
Move shortcircuit parameters (#569)
1 parent 2227bf2 commit c02ea74

27 files changed

+334
-525
lines changed

src/main/java/org/gridsuite/study/server/StudyController.java

+11-15
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
import java.nio.charset.StandardCharsets;
5555
import java.util.*;
5656

57-
import static org.gridsuite.study.server.StudyConstants.*;
57+
import static org.gridsuite.study.server.StudyConstants.CASE_FORMAT;
58+
import static org.gridsuite.study.server.StudyConstants.HEADER_USER_ID;
5859

5960
/**
6061
* @author Abdelsalem Hedhili <abdelsalem.hedhili at rte-france.com>
@@ -628,18 +629,14 @@ public ResponseEntity<Void> stopLoadFlow(@Parameter(description = "Study uuid")
628629

629630
@PutMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/shortcircuit/run")
630631
@Operation(summary = "run short circuit analysis on study")
631-
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The short circuit analysis has started")})
632+
@ApiResponse(responseCode = "200", description = "The short circuit analysis has started")
632633
public ResponseEntity<Void> runShortCircuit(
633634
@PathVariable("studyUuid") UUID studyUuid,
634635
@PathVariable("nodeUuid") UUID nodeUuid,
635-
@RequestParam(value = "busId", required = false) String busId,
636+
@RequestParam(value = "busId", required = false) Optional<String> busId,
636637
@RequestHeader(HEADER_USER_ID) String userId) {
637638
studyService.assertIsNodeNotReadOnly(nodeUuid);
638-
if (busId == null) {
639-
studyService.runShortCircuit(studyUuid, nodeUuid, userId);
640-
} else {
641-
studyService.runShortCircuit(studyUuid, nodeUuid, userId, busId);
642-
}
639+
studyService.runShortCircuit(studyUuid, nodeUuid, busId, userId);
643640
return ResponseEntity.ok().build();
644641
}
645642

@@ -914,22 +911,21 @@ public ResponseEntity<String> getDynamicSimulationProvider(@PathVariable("studyU
914911
return ResponseEntity.ok().body(studyService.getDynamicSimulationProvider(studyUuid));
915912
}
916913

917-
@PostMapping(value = "/studies/{studyUuid}/short-circuit-analysis/parameters")
914+
@PostMapping(value = "/studies/{studyUuid}/short-circuit-analysis/parameters", consumes = MediaType.APPLICATION_JSON_VALUE)
918915
@Operation(summary = "set short-circuit analysis parameters on study, reset to default ones if empty body")
919-
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The short-circuit analysis parameters are set")})
916+
@ApiResponse(responseCode = "200", description = "The short-circuit analysis parameters are set")
920917
public ResponseEntity<Void> setShortCircuitParameters(
921918
@PathVariable("studyUuid") UUID studyUuid,
922-
@RequestBody(required = false) ShortCircuitParametersInfos shortCircuitParametersInfos,
919+
@RequestBody(required = false) String shortCircuitParametersInfos,
923920
@RequestHeader(HEADER_USER_ID) String userId) {
924921
studyService.setShortCircuitParameters(studyUuid, shortCircuitParametersInfos, userId);
925922
return ResponseEntity.ok().build();
926923
}
927924

928-
@GetMapping(value = "/studies/{studyUuid}/short-circuit-analysis/parameters")
925+
@GetMapping(value = "/studies/{studyUuid}/short-circuit-analysis/parameters", produces = MediaType.APPLICATION_JSON_VALUE)
929926
@Operation(summary = "Get short-circuit analysis parameters on study")
930-
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The short-circuit analysis parameters")})
931-
public ResponseEntity<ShortCircuitParametersInfos> getShortCircuitParameters(
932-
@PathVariable("studyUuid") UUID studyUuid) {
927+
@ApiResponse(responseCode = "200", description = "The short-circuit analysis parameters return by shortcircuit-server")
928+
public ResponseEntity<String> getShortCircuitParameters(@PathVariable("studyUuid") UUID studyUuid) {
933929
return ResponseEntity.ok().body(studyService.getShortCircuitParametersInfo(studyUuid));
934930
}
935931

src/main/java/org/gridsuite/study/server/StudyException.java

+3
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ public enum Type {
9494
LOADFLOW_PARAMETERS_NOT_FOUND,
9595
GET_LOADFLOW_DEFAULT_PROVIDER_FAILED,
9696
UPDATE_LOADFLOW_PROVIDER_FAILED,
97+
UPDATE_SHORTCIRCUIT_PARAMETERS_FAILED,
98+
CREATE_SHORTCIRCUIT_PARAMETERS_FAILED,
99+
GET_SHORTCIRCUIT_PARAMETERS_FAILED,
97100
SENSITIVITY_ANALYSIS_PARAMETERS_NOT_FOUND,
98101
GET_SENSITIVITY_ANALYSIS_PARAMETERS_FAILED,
99102
CREATE_SENSITIVITY_ANALYSIS_PARAMETERS_FAILED,

src/main/java/org/gridsuite/study/server/dto/ShortCircuitParametersInfos.java

-28
This file was deleted.

src/main/java/org/gridsuite/study/server/dto/ShortCircuitPredefinedConfiguration.java

+2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
/**
1010
* @author AJELLAL Ali <[email protected]>
11+
* @deprecated for delete
1112
*/
13+
@Deprecated(forRemoval = true, since = "1.7.0")
1214
public enum ShortCircuitPredefinedConfiguration {
1315
ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP,
1416
ICC_MAX_WITH_CEI909,

src/main/java/org/gridsuite/study/server/repository/ShortCircuitParametersEntity.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,25 @@
88

99
import com.powsybl.shortcircuit.InitialVoltageProfileMode;
1010
import com.powsybl.shortcircuit.StudyType;
11-
import lombok.*;
12-
1311
import jakarta.persistence.*;
12+
import lombok.*;
1413
import org.gridsuite.study.server.dto.ShortCircuitPredefinedConfiguration;
1514

1615
import java.util.UUID;
1716

1817
/**
1918
* @author Abdelsalem Hedhili <abdelsalem.hedhili at rte-france.com>
19+
* @deprecated to remove when the data is migrated into the shortcircuit-server
2020
*/
21+
@Deprecated(forRemoval = true, since = "1.7.0")
2122
@Builder
2223
@NoArgsConstructor
2324
@AllArgsConstructor
2425
@Getter
2526
@Setter
2627
@Entity
2728
@Table(name = "shortCircuitParameters")
28-
public class ShortCircuitParametersEntity {
29+
class ShortCircuitParametersEntity {
2930

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

src/main/java/org/gridsuite/study/server/repository/StudyEntity.java

+9-13
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@
66
*/
77
package org.gridsuite.study.server.repository;
88

9+
import jakarta.persistence.*;
910
import lombok.*;
10-
import org.gridsuite.study.server.dto.ShortCircuitPredefinedConfiguration;
1111
import org.gridsuite.study.server.dto.StudyIndexationStatus;
12-
import org.gridsuite.study.server.repository.sensianalysis.SensitivityAnalysisParametersEntity;
1312
import org.gridsuite.study.server.repository.nonevacuatedenergy.NonEvacuatedEnergyParametersEntity;
13+
import org.gridsuite.study.server.repository.sensianalysis.SensitivityAnalysisParametersEntity;
1414
import org.gridsuite.study.server.repository.voltageinit.StudyVoltageInitParametersEntity;
15-
import org.gridsuite.study.server.service.shortcircuit.ShortCircuitService;
16-
17-
import jakarta.persistence.*;
1815

1916
import java.util.Map;
2017
import java.util.UUID;
@@ -23,7 +20,6 @@
2320
* @author Abdelsalem Hedhili <abdelsalem.hedhili at rte-france.com>
2421
* @author Chamseddine Benhamed <chamseddine.benhamed at rte-france.com>
2522
*/
26-
2723
@NoArgsConstructor
2824
@AllArgsConstructor
2925
@Getter
@@ -102,6 +98,10 @@ public class StudyEntity extends AbstractManuallyAssignedIdentifierEntity<UUID>
10298
))
10399
private LoadFlowParametersEntity loadFlowParameters;
104100

101+
/**
102+
* @deprecated to remove when the data is migrated into the shortcircuit-server
103+
*/
104+
@Deprecated(forRemoval = true, since = "1.7.0")
105105
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
106106
@JoinColumn(name = "shortCircuitParametersEntity_id",
107107
referencedColumnName = "id",
@@ -110,6 +110,9 @@ public class StudyEntity extends AbstractManuallyAssignedIdentifierEntity<UUID>
110110
))
111111
private ShortCircuitParametersEntity shortCircuitParameters;
112112

113+
@Column(name = "shortCircuitParametersUuid")
114+
private UUID shortCircuitParametersUuid;
115+
113116
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
114117
@JoinColumn(name = "dynamicSimulationParametersEntity_id",
115118
referencedColumnName = "id",
@@ -180,13 +183,6 @@ public class StudyEntity extends AbstractManuallyAssignedIdentifierEntity<UUID>
180183
))
181184
private StudyVoltageInitParametersEntity voltageInitParameters;
182185

183-
public ShortCircuitParametersEntity getShortCircuitParameters() {
184-
if (this.shortCircuitParameters == null) {
185-
this.setShortCircuitParameters(ShortCircuitService.toEntity(ShortCircuitService.getDefaultShortCircuitParameters(), ShortCircuitPredefinedConfiguration.ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP));
186-
}
187-
return this.shortCircuitParameters;
188-
}
189-
190186
@Value
191187
public static class StudyNetworkUuid {
192188
UUID networkUuid;

src/main/java/org/gridsuite/study/server/service/ConsumerService.java

+34-26
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import com.fasterxml.jackson.core.JsonProcessingException;
1111
import com.fasterxml.jackson.databind.ObjectMapper;
12-
import com.powsybl.shortcircuit.ShortCircuitParameters;
1312
import org.apache.commons.lang3.StringUtils;
1413
import org.apache.logging.log4j.util.Strings;
1514
import org.gridsuite.study.server.dto.*;
@@ -67,6 +66,7 @@ public class ConsumerService {
6766
private final UserAdminService userAdminService;
6867
private final NetworkModificationTreeService networkModificationTreeService;
6968
private final StudyRepository studyRepository;
69+
private final ShortCircuitService shortCircuitService;
7070

7171
@Autowired
7272
public ConsumerService(ObjectMapper objectMapper,
@@ -75,6 +75,7 @@ public ConsumerService(ObjectMapper objectMapper,
7575
SecurityAnalysisService securityAnalysisService,
7676
CaseService caseService,
7777
LoadFlowService loadFlowService,
78+
ShortCircuitService shortCircuitService,
7879
UserAdminService userAdminService,
7980
NetworkModificationTreeService networkModificationTreeService,
8081
SensitivityAnalysisService sensitivityAnalysisService,
@@ -89,6 +90,7 @@ public ConsumerService(ObjectMapper objectMapper,
8990
this.networkModificationTreeService = networkModificationTreeService;
9091
this.sensitivityAnalysisService = sensitivityAnalysisService;
9192
this.studyRepository = studyRepository;
93+
this.shortCircuitService = shortCircuitService;
9294
}
9395

9496
@Bean
@@ -183,10 +185,9 @@ public Consumer<Message<String>> consumeCaseImportSucceeded() {
183185
if (receiverString != null) {
184186
CaseImportReceiver receiver;
185187
try {
186-
receiver = objectMapper.readValue(URLDecoder.decode(receiverString, StandardCharsets.UTF_8),
187-
CaseImportReceiver.class);
188+
receiver = objectMapper.readValue(URLDecoder.decode(receiverString, StandardCharsets.UTF_8), CaseImportReceiver.class);
188189
} catch (JsonProcessingException e) {
189-
LOGGER.error(e.toString());
190+
LOGGER.error("Error while parsing CaseImportReceiver data", e);
190191
return;
191192
}
192193

@@ -198,23 +199,21 @@ public Consumer<Message<String>> consumeCaseImportSucceeded() {
198199

199200
StudyEntity studyEntity = studyRepository.findById(studyUuid).orElse(null);
200201
try {
201-
ShortCircuitParameters shortCircuitParameters = ShortCircuitService.getDefaultShortCircuitParameters();
202-
DynamicSimulationParametersInfos dynamicSimulationParameters = DynamicSimulationService.getDefaultDynamicSimulationParameters();
203202
if (studyEntity != null) {
204203
// if studyEntity is not null, it means we are recreating network for existing study
205204
// we only update network infos sent by network conversion server
206205
studyService.updateStudyNetwork(studyEntity, userId, networkInfos);
207206
} else {
208-
UserProfileInfos userProfileInfos = getUserProfile(userId);
209-
UUID loadFlowParametersUuid = createDefaultLoadFlowParameters(userId, userProfileInfos);
207+
DynamicSimulationParametersInfos dynamicSimulationParameters = DynamicSimulationService.getDefaultDynamicSimulationParameters();
208+
UUID loadFlowParametersUuid = createDefaultLoadFlowParameters(userId, getUserProfile(userId));
209+
UUID shortCircuitParametersUuid = createDefaultShortCircuitAnalysisParameters();
210210
UUID securityAnalysisParametersUuid = createDefaultSecurityAnalysisParameters();
211211
UUID sensitivityAnalysisParametersUuid = createDefaultSensitivityAnalysisParameters();
212-
studyService.insertStudy(studyUuid, userId, networkInfos, caseFormat, caseUuid, caseName, loadFlowParametersUuid, ShortCircuitService.toEntity(shortCircuitParameters, ShortCircuitPredefinedConfiguration.ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP), DynamicSimulationService.toEntity(dynamicSimulationParameters, objectMapper), null, securityAnalysisParametersUuid, sensitivityAnalysisParametersUuid, importParameters, importReportUuid);
212+
studyService.insertStudy(studyUuid, userId, networkInfos, caseFormat, caseUuid, caseName, loadFlowParametersUuid, shortCircuitParametersUuid, DynamicSimulationService.toEntity(dynamicSimulationParameters, objectMapper), null, securityAnalysisParametersUuid, sensitivityAnalysisParametersUuid, importParameters, importReportUuid);
213213
}
214-
215214
caseService.disableCaseExpiration(caseUuid);
216215
} catch (Exception e) {
217-
LOGGER.error(e.toString(), e);
216+
LOGGER.error("Error while importing case", e);
218217
} finally {
219218
// if studyEntity is already existing, we don't delete anything in the end of the process
220219
if (studyEntity == null) {
@@ -250,19 +249,37 @@ private UUID createDefaultLoadFlowParameters(String userId, UserProfileInfos use
250249
// no profile, or no/bad LF parameters in profile => use default values
251250
try {
252251
return loadFlowService.createDefaultLoadFlowParameters();
253-
} catch (Exception e) {
254-
LOGGER.error(e.toString(), e);
252+
} catch (final Exception e) {
253+
LOGGER.error("Error while creating default parameters for LoadFlow analysis", e);
254+
return null;
255+
}
256+
}
257+
258+
private UUID createDefaultShortCircuitAnalysisParameters() {
259+
try {
260+
return shortCircuitService.createParameters(null);
261+
} catch (final Exception e) {
262+
LOGGER.error("Error while creating default parameters for ShortCircuit analysis", e);
263+
return null;
255264
}
256-
return null;
257265
}
258266

259267
private UUID createDefaultSensitivityAnalysisParameters() {
260268
try {
261269
return sensitivityAnalysisService.createDefaultSensitivityAnalysisParameters();
262-
} catch (Exception e) {
263-
LOGGER.error(e.toString(), e);
270+
} catch (final Exception e) {
271+
LOGGER.error("Error while creating default parameters for Sensitivity analysis", e);
272+
return null;
273+
}
274+
}
275+
276+
private UUID createDefaultSecurityAnalysisParameters() {
277+
try {
278+
return securityAnalysisService.createDefaultSecurityAnalysisParameters();
279+
} catch (final Exception e) {
280+
LOGGER.error("Error while creating default parameters for Security analysis", e);
281+
return null;
264282
}
265-
return null;
266283
}
267284

268285
@Bean
@@ -499,15 +516,6 @@ public Consumer<Message<String>> consumeVoltageInitFailed() {
499516
return message -> consumeCalculationFailed(message, VOLTAGE_INITIALIZATION);
500517
}
501518

502-
private UUID createDefaultSecurityAnalysisParameters() {
503-
try {
504-
return securityAnalysisService.createDefaultSecurityAnalysisParameters();
505-
} catch (Exception e) {
506-
LOGGER.error(e.toString(), e);
507-
}
508-
return null;
509-
}
510-
511519
@Bean
512520
public Consumer<Message<String>> consumeStateEstimationResult() {
513521
return message -> consumeCalculationResult(message, STATE_ESTIMATION);

0 commit comments

Comments
 (0)