diff --git a/src/main/java/org/gridsuite/study/server/StudyController.java b/src/main/java/org/gridsuite/study/server/StudyController.java index 383e66525..97a612fed 100644 --- a/src/main/java/org/gridsuite/study/server/StudyController.java +++ b/src/main/java/org/gridsuite/study/server/StudyController.java @@ -54,7 +54,8 @@ import java.nio.charset.StandardCharsets; import java.util.*; -import static org.gridsuite.study.server.StudyConstants.*; +import static org.gridsuite.study.server.StudyConstants.CASE_FORMAT; +import static org.gridsuite.study.server.StudyConstants.HEADER_USER_ID; /** * @author Abdelsalem Hedhili @@ -628,18 +629,14 @@ public ResponseEntity stopLoadFlow(@Parameter(description = "Study uuid") @PutMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/shortcircuit/run") @Operation(summary = "run short circuit analysis on study") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The short circuit analysis has started")}) + @ApiResponse(responseCode = "200", description = "The short circuit analysis has started") public ResponseEntity runShortCircuit( @PathVariable("studyUuid") UUID studyUuid, @PathVariable("nodeUuid") UUID nodeUuid, - @RequestParam(value = "busId", required = false) String busId, + @RequestParam(value = "busId", required = false) Optional busId, @RequestHeader(HEADER_USER_ID) String userId) { studyService.assertIsNodeNotReadOnly(nodeUuid); - if (busId == null) { - studyService.runShortCircuit(studyUuid, nodeUuid, userId); - } else { - studyService.runShortCircuit(studyUuid, nodeUuid, userId, busId); - } + studyService.runShortCircuit(studyUuid, nodeUuid, busId, userId); return ResponseEntity.ok().build(); } @@ -914,22 +911,21 @@ public ResponseEntity getDynamicSimulationProvider(@PathVariable("studyU return ResponseEntity.ok().body(studyService.getDynamicSimulationProvider(studyUuid)); } - @PostMapping(value = "/studies/{studyUuid}/short-circuit-analysis/parameters") + @PostMapping(value = "/studies/{studyUuid}/short-circuit-analysis/parameters", consumes = MediaType.APPLICATION_JSON_VALUE) @Operation(summary = "set short-circuit analysis parameters on study, reset to default ones if empty body") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The short-circuit analysis parameters are set")}) + @ApiResponse(responseCode = "200", description = "The short-circuit analysis parameters are set") public ResponseEntity setShortCircuitParameters( @PathVariable("studyUuid") UUID studyUuid, - @RequestBody(required = false) ShortCircuitParametersInfos shortCircuitParametersInfos, + @RequestBody(required = false) String shortCircuitParametersInfos, @RequestHeader(HEADER_USER_ID) String userId) { studyService.setShortCircuitParameters(studyUuid, shortCircuitParametersInfos, userId); return ResponseEntity.ok().build(); } - @GetMapping(value = "/studies/{studyUuid}/short-circuit-analysis/parameters") + @GetMapping(value = "/studies/{studyUuid}/short-circuit-analysis/parameters", produces = MediaType.APPLICATION_JSON_VALUE) @Operation(summary = "Get short-circuit analysis parameters on study") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The short-circuit analysis parameters")}) - public ResponseEntity getShortCircuitParameters( - @PathVariable("studyUuid") UUID studyUuid) { + @ApiResponse(responseCode = "200", description = "The short-circuit analysis parameters return by shortcircuit-server") + public ResponseEntity getShortCircuitParameters(@PathVariable("studyUuid") UUID studyUuid) { return ResponseEntity.ok().body(studyService.getShortCircuitParametersInfo(studyUuid)); } diff --git a/src/main/java/org/gridsuite/study/server/StudyException.java b/src/main/java/org/gridsuite/study/server/StudyException.java index 3be5ec5b3..e0d8bfc9d 100644 --- a/src/main/java/org/gridsuite/study/server/StudyException.java +++ b/src/main/java/org/gridsuite/study/server/StudyException.java @@ -94,6 +94,9 @@ public enum Type { LOADFLOW_PARAMETERS_NOT_FOUND, GET_LOADFLOW_DEFAULT_PROVIDER_FAILED, UPDATE_LOADFLOW_PROVIDER_FAILED, + UPDATE_SHORTCIRCUIT_PARAMETERS_FAILED, + CREATE_SHORTCIRCUIT_PARAMETERS_FAILED, + GET_SHORTCIRCUIT_PARAMETERS_FAILED, SENSITIVITY_ANALYSIS_PARAMETERS_NOT_FOUND, GET_SENSITIVITY_ANALYSIS_PARAMETERS_FAILED, CREATE_SENSITIVITY_ANALYSIS_PARAMETERS_FAILED, diff --git a/src/main/java/org/gridsuite/study/server/dto/ShortCircuitParametersInfos.java b/src/main/java/org/gridsuite/study/server/dto/ShortCircuitParametersInfos.java deleted file mode 100644 index 4fe236a79..000000000 --- a/src/main/java/org/gridsuite/study/server/dto/ShortCircuitParametersInfos.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2023, 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.study.server.dto; - -import com.powsybl.shortcircuit.ShortCircuitParameters; -import com.powsybl.shortcircuit.VoltageRange; -import lombok.*; - -import java.util.List; - -/** - * @author AJELLAL Ali - */ - -@NoArgsConstructor -@AllArgsConstructor -@Getter -@Setter -@Builder -public class ShortCircuitParametersInfos { - private ShortCircuitPredefinedConfiguration predefinedParameters; - private ShortCircuitParameters parameters; - private List cei909VoltageRanges; -} diff --git a/src/main/java/org/gridsuite/study/server/dto/ShortCircuitPredefinedConfiguration.java b/src/main/java/org/gridsuite/study/server/dto/ShortCircuitPredefinedConfiguration.java index 0d478472e..7b8abef71 100644 --- a/src/main/java/org/gridsuite/study/server/dto/ShortCircuitPredefinedConfiguration.java +++ b/src/main/java/org/gridsuite/study/server/dto/ShortCircuitPredefinedConfiguration.java @@ -8,7 +8,9 @@ /** * @author AJELLAL Ali + * @deprecated for delete */ +@Deprecated(forRemoval = true, since = "1.7.0") public enum ShortCircuitPredefinedConfiguration { ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP, ICC_MAX_WITH_CEI909, diff --git a/src/main/java/org/gridsuite/study/server/repository/ShortCircuitParametersEntity.java b/src/main/java/org/gridsuite/study/server/repository/ShortCircuitParametersEntity.java index 2651283b4..9f3acb8d1 100644 --- a/src/main/java/org/gridsuite/study/server/repository/ShortCircuitParametersEntity.java +++ b/src/main/java/org/gridsuite/study/server/repository/ShortCircuitParametersEntity.java @@ -8,16 +8,17 @@ import com.powsybl.shortcircuit.InitialVoltageProfileMode; import com.powsybl.shortcircuit.StudyType; -import lombok.*; - import jakarta.persistence.*; +import lombok.*; import org.gridsuite.study.server.dto.ShortCircuitPredefinedConfiguration; import java.util.UUID; /** * @author Abdelsalem Hedhili + * @deprecated to remove when the data is migrated into the shortcircuit-server */ +@Deprecated(forRemoval = true, since = "1.7.0") @Builder @NoArgsConstructor @AllArgsConstructor @@ -25,7 +26,7 @@ @Setter @Entity @Table(name = "shortCircuitParameters") -public class ShortCircuitParametersEntity { +class ShortCircuitParametersEntity { 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) { this(null, withLimitViolations, withVoltageResult, withFortescueResult, withFeederResult, studyType, minVoltageDropProportionalThreshold, predefinedParameters, withLoads, withShuntCompensators, withVscConverterStations, withNeutralPosition, initialVoltageProfileMode); diff --git a/src/main/java/org/gridsuite/study/server/repository/StudyEntity.java b/src/main/java/org/gridsuite/study/server/repository/StudyEntity.java index b0b29c318..2a3c01915 100644 --- a/src/main/java/org/gridsuite/study/server/repository/StudyEntity.java +++ b/src/main/java/org/gridsuite/study/server/repository/StudyEntity.java @@ -6,15 +6,12 @@ */ package org.gridsuite.study.server.repository; +import jakarta.persistence.*; import lombok.*; -import org.gridsuite.study.server.dto.ShortCircuitPredefinedConfiguration; import org.gridsuite.study.server.dto.StudyIndexationStatus; -import org.gridsuite.study.server.repository.sensianalysis.SensitivityAnalysisParametersEntity; import org.gridsuite.study.server.repository.nonevacuatedenergy.NonEvacuatedEnergyParametersEntity; +import org.gridsuite.study.server.repository.sensianalysis.SensitivityAnalysisParametersEntity; import org.gridsuite.study.server.repository.voltageinit.StudyVoltageInitParametersEntity; -import org.gridsuite.study.server.service.shortcircuit.ShortCircuitService; - -import jakarta.persistence.*; import java.util.Map; import java.util.UUID; @@ -23,7 +20,6 @@ * @author Abdelsalem Hedhili * @author Chamseddine Benhamed */ - @NoArgsConstructor @AllArgsConstructor @Getter @@ -102,6 +98,10 @@ public class StudyEntity extends AbstractManuallyAssignedIdentifierEntity )) private LoadFlowParametersEntity loadFlowParameters; + /** + * @deprecated to remove when the data is migrated into the shortcircuit-server + */ + @Deprecated(forRemoval = true, since = "1.7.0") @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) @JoinColumn(name = "shortCircuitParametersEntity_id", referencedColumnName = "id", @@ -110,6 +110,9 @@ public class StudyEntity extends AbstractManuallyAssignedIdentifierEntity )) private ShortCircuitParametersEntity shortCircuitParameters; + @Column(name = "shortCircuitParametersUuid") + private UUID shortCircuitParametersUuid; + @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) @JoinColumn(name = "dynamicSimulationParametersEntity_id", referencedColumnName = "id", @@ -180,13 +183,6 @@ public class StudyEntity extends AbstractManuallyAssignedIdentifierEntity )) private StudyVoltageInitParametersEntity voltageInitParameters; - public ShortCircuitParametersEntity getShortCircuitParameters() { - if (this.shortCircuitParameters == null) { - this.setShortCircuitParameters(ShortCircuitService.toEntity(ShortCircuitService.getDefaultShortCircuitParameters(), ShortCircuitPredefinedConfiguration.ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP)); - } - return this.shortCircuitParameters; - } - @Value public static class StudyNetworkUuid { UUID networkUuid; diff --git a/src/main/java/org/gridsuite/study/server/service/ConsumerService.java b/src/main/java/org/gridsuite/study/server/service/ConsumerService.java index c7fdc3b5c..f03e4ee8b 100644 --- a/src/main/java/org/gridsuite/study/server/service/ConsumerService.java +++ b/src/main/java/org/gridsuite/study/server/service/ConsumerService.java @@ -9,7 +9,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.powsybl.shortcircuit.ShortCircuitParameters; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.util.Strings; import org.gridsuite.study.server.dto.*; @@ -67,6 +66,7 @@ public class ConsumerService { private final UserAdminService userAdminService; private final NetworkModificationTreeService networkModificationTreeService; private final StudyRepository studyRepository; + private final ShortCircuitService shortCircuitService; @Autowired public ConsumerService(ObjectMapper objectMapper, @@ -75,6 +75,7 @@ public ConsumerService(ObjectMapper objectMapper, SecurityAnalysisService securityAnalysisService, CaseService caseService, LoadFlowService loadFlowService, + ShortCircuitService shortCircuitService, UserAdminService userAdminService, NetworkModificationTreeService networkModificationTreeService, SensitivityAnalysisService sensitivityAnalysisService, @@ -89,6 +90,7 @@ public ConsumerService(ObjectMapper objectMapper, this.networkModificationTreeService = networkModificationTreeService; this.sensitivityAnalysisService = sensitivityAnalysisService; this.studyRepository = studyRepository; + this.shortCircuitService = shortCircuitService; } @Bean @@ -183,10 +185,9 @@ public Consumer> consumeCaseImportSucceeded() { if (receiverString != null) { CaseImportReceiver receiver; try { - receiver = objectMapper.readValue(URLDecoder.decode(receiverString, StandardCharsets.UTF_8), - CaseImportReceiver.class); + receiver = objectMapper.readValue(URLDecoder.decode(receiverString, StandardCharsets.UTF_8), CaseImportReceiver.class); } catch (JsonProcessingException e) { - LOGGER.error(e.toString()); + LOGGER.error("Error while parsing CaseImportReceiver data", e); return; } @@ -198,23 +199,21 @@ public Consumer> consumeCaseImportSucceeded() { StudyEntity studyEntity = studyRepository.findById(studyUuid).orElse(null); try { - ShortCircuitParameters shortCircuitParameters = ShortCircuitService.getDefaultShortCircuitParameters(); - DynamicSimulationParametersInfos dynamicSimulationParameters = DynamicSimulationService.getDefaultDynamicSimulationParameters(); if (studyEntity != null) { // if studyEntity is not null, it means we are recreating network for existing study // we only update network infos sent by network conversion server studyService.updateStudyNetwork(studyEntity, userId, networkInfos); } else { - UserProfileInfos userProfileInfos = getUserProfile(userId); - UUID loadFlowParametersUuid = createDefaultLoadFlowParameters(userId, userProfileInfos); + DynamicSimulationParametersInfos dynamicSimulationParameters = DynamicSimulationService.getDefaultDynamicSimulationParameters(); + UUID loadFlowParametersUuid = createDefaultLoadFlowParameters(userId, getUserProfile(userId)); + UUID shortCircuitParametersUuid = createDefaultShortCircuitAnalysisParameters(); UUID securityAnalysisParametersUuid = createDefaultSecurityAnalysisParameters(); UUID sensitivityAnalysisParametersUuid = createDefaultSensitivityAnalysisParameters(); - 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); + studyService.insertStudy(studyUuid, userId, networkInfos, caseFormat, caseUuid, caseName, loadFlowParametersUuid, shortCircuitParametersUuid, DynamicSimulationService.toEntity(dynamicSimulationParameters, objectMapper), null, securityAnalysisParametersUuid, sensitivityAnalysisParametersUuid, importParameters, importReportUuid); } - caseService.disableCaseExpiration(caseUuid); } catch (Exception e) { - LOGGER.error(e.toString(), e); + LOGGER.error("Error while importing case", e); } finally { // if studyEntity is already existing, we don't delete anything in the end of the process if (studyEntity == null) { @@ -250,19 +249,37 @@ private UUID createDefaultLoadFlowParameters(String userId, UserProfileInfos use // no profile, or no/bad LF parameters in profile => use default values try { return loadFlowService.createDefaultLoadFlowParameters(); - } catch (Exception e) { - LOGGER.error(e.toString(), e); + } catch (final Exception e) { + LOGGER.error("Error while creating default parameters for LoadFlow analysis", e); + return null; + } + } + + private UUID createDefaultShortCircuitAnalysisParameters() { + try { + return shortCircuitService.createParameters(null); + } catch (final Exception e) { + LOGGER.error("Error while creating default parameters for ShortCircuit analysis", e); + return null; } - return null; } private UUID createDefaultSensitivityAnalysisParameters() { try { return sensitivityAnalysisService.createDefaultSensitivityAnalysisParameters(); - } catch (Exception e) { - LOGGER.error(e.toString(), e); + } catch (final Exception e) { + LOGGER.error("Error while creating default parameters for Sensitivity analysis", e); + return null; + } + } + + private UUID createDefaultSecurityAnalysisParameters() { + try { + return securityAnalysisService.createDefaultSecurityAnalysisParameters(); + } catch (final Exception e) { + LOGGER.error("Error while creating default parameters for Security analysis", e); + return null; } - return null; } @Bean @@ -499,15 +516,6 @@ public Consumer> consumeVoltageInitFailed() { return message -> consumeCalculationFailed(message, VOLTAGE_INITIALIZATION); } - private UUID createDefaultSecurityAnalysisParameters() { - try { - return securityAnalysisService.createDefaultSecurityAnalysisParameters(); - } catch (Exception e) { - LOGGER.error(e.toString(), e); - } - return null; - } - @Bean public Consumer> consumeStateEstimationResult() { return message -> consumeCalculationResult(message, STATE_ESTIMATION); diff --git a/src/main/java/org/gridsuite/study/server/service/StudyService.java b/src/main/java/org/gridsuite/study/server/service/StudyService.java index f9501ba6e..70a69cdaa 100644 --- a/src/main/java/org/gridsuite/study/server/service/StudyService.java +++ b/src/main/java/org/gridsuite/study/server/service/StudyService.java @@ -8,12 +8,11 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.powsybl.commons.report.*; +import com.powsybl.commons.report.ReportNode; import com.powsybl.iidm.network.Network; import com.powsybl.loadflow.LoadFlowParameters; import com.powsybl.network.store.model.VariantInfos; import com.powsybl.sensitivity.SensitivityAnalysisParameters; -import com.powsybl.shortcircuit.ShortCircuitParameters; import com.powsybl.timeseries.DoubleTimeSeries; import lombok.NonNull; import org.gridsuite.study.server.StudyConstants; @@ -483,10 +482,24 @@ public void deleteEquipmentIndexes(UUID networkUuid) { public CreatedStudyBasicInfos insertStudy(UUID studyUuid, String userId, NetworkInfos networkInfos, String caseFormat, UUID caseUuid, String caseName, UUID loadFlowParametersUuid, - ShortCircuitParametersEntity shortCircuitParametersEntity, DynamicSimulationParametersEntity dynamicSimulationParametersEntity, + UUID shortCircuitParametersUuid, DynamicSimulationParametersEntity dynamicSimulationParametersEntity, UUID voltageInitParametersUuid, UUID securityAnalysisParametersUuid, UUID sensitivityAnalysisParametersUuid, Map importParameters, UUID importReportUuid) { - StudyEntity studyEntity = insertStudyEntity(studyUuid, userId, networkInfos.getNetworkUuid(), networkInfos.getNetworkId(), caseFormat, caseUuid, caseName, loadFlowParametersUuid, importReportUuid, shortCircuitParametersEntity, dynamicSimulationParametersEntity, voltageInitParametersUuid, securityAnalysisParametersUuid, sensitivityAnalysisParametersUuid, importParameters); + Objects.requireNonNull(studyUuid); + Objects.requireNonNull(userId); + UUID networkUuid = Objects.requireNonNull(networkInfos.getNetworkUuid()); + String networkId = Objects.requireNonNull(networkInfos.getNetworkId()); + Objects.requireNonNull(caseFormat); + Objects.requireNonNull(caseUuid); + Objects.requireNonNull(shortCircuitParametersUuid); + Objects.requireNonNull(importParameters); + + StudyEntity studyEntity = self.saveStudyThenCreateBasicTree(new StudyEntity(studyUuid, networkUuid, networkId, caseFormat, caseUuid, caseName, + null, null, null, defaultNonEvacuatedEnergyProvider, defaultDynamicSimulationProvider, + loadFlowParametersUuid, null, null, shortCircuitParametersUuid, dynamicSimulationParametersEntity, voltageInitParametersUuid, null, securityAnalysisParametersUuid, + null, sensitivityAnalysisParametersUuid, null, importParameters, StudyIndexationStatus.INDEXED, new StudyVoltageInitParametersEntity()), + importReportUuid); + CreatedStudyBasicInfos createdStudyBasicInfos = StudyService.toCreatedStudyBasicInfos(studyEntity); studyInfosService.add(createdStudyBasicInfos); @@ -526,16 +539,19 @@ private StudyEntity insertDuplicatedStudy(BasicStudyInfos studyInfos, UUID sourc copiedLoadFlowParametersUuid = loadflowService.duplicateLoadFlowParameters(sourceStudy.getLoadFlowParametersUuid()); } - UUID securityAnalysisParametersUuid = sourceStudy.getSecurityAnalysisParametersUuid(); + UUID copiedShortCircuitParametersUuid = null; + if (sourceStudy.getShortCircuitParametersUuid() != null) { + copiedShortCircuitParametersUuid = shortCircuitService.duplicateParameters(sourceStudy.getShortCircuitParametersUuid()); + } + UUID copiedSecurityAnalysisParametersUuid = null; - if (securityAnalysisParametersUuid != null) { - copiedSecurityAnalysisParametersUuid = securityAnalysisService.duplicateSecurityAnalysisParameters(securityAnalysisParametersUuid); + if (sourceStudy.getSecurityAnalysisParametersUuid() != null) { + copiedSecurityAnalysisParametersUuid = securityAnalysisService.duplicateSecurityAnalysisParameters(sourceStudy.getSecurityAnalysisParametersUuid()); } - UUID sensitivityAnalysisParametersUuid = sourceStudy.getSensitivityAnalysisParametersUuid(); UUID copiedSensitivityAnalysisParametersUuid = null; - if (sensitivityAnalysisParametersUuid != null) { - copiedSensitivityAnalysisParametersUuid = sensitivityAnalysisService.duplicateSensitivityAnalysisParameters(sensitivityAnalysisParametersUuid); + if (sourceStudy.getSensitivityAnalysisParametersUuid() != null) { + copiedSensitivityAnalysisParametersUuid = sensitivityAnalysisService.duplicateSensitivityAnalysisParameters(sourceStudy.getSensitivityAnalysisParametersUuid()); } NonEvacuatedEnergyParametersInfos nonEvacuatedEnergyParametersInfos = sourceStudy.getNonEvacuatedEnergyParameters() == null ? @@ -547,8 +563,6 @@ private StudyEntity insertDuplicatedStudy(BasicStudyInfos studyInfos, UUID sourc copiedVoltageInitParametersUuid = voltageInitService.duplicateVoltageInitParameters(sourceStudy.getVoltageInitParametersUuid()); } - ShortCircuitParameters shortCircuitParameters = ShortCircuitService.fromEntity(sourceStudy.getShortCircuitParameters()); - ShortCircuitPredefinedConfiguration shortCircuitPredefinedConfiguration = sourceStudy.getShortCircuitParameters().getPredefinedParameters(); DynamicSimulationParametersInfos dynamicSimulationParameters = sourceStudy.getDynamicSimulationParameters() != null ? DynamicSimulationService.fromEntity(sourceStudy.getDynamicSimulationParameters(), objectMapper) : DynamicSimulationService.getDefaultDynamicSimulationParameters(); StudyEntity studyEntity = StudyEntity.builder() @@ -560,7 +574,7 @@ private StudyEntity insertDuplicatedStudy(BasicStudyInfos studyInfos, UUID sourc .nonEvacuatedEnergyProvider(sourceStudy.getNonEvacuatedEnergyProvider()) .dynamicSimulationProvider(sourceStudy.getDynamicSimulationProvider()) .dynamicSimulationParameters(DynamicSimulationService.toEntity(dynamicSimulationParameters, objectMapper)) - .shortCircuitParameters(ShortCircuitService.toEntity(shortCircuitParameters, shortCircuitPredefinedConfiguration)) + .shortCircuitParametersUuid(copiedShortCircuitParametersUuid) .voltageInitParametersUuid(copiedVoltageInitParametersUuid) .sensitivityAnalysisParametersUuid(copiedSensitivityAnalysisParametersUuid) .nonEvacuatedEnergyParameters(NonEvacuatedEnergyService.toEntity(nonEvacuatedEnergyParametersInfos)) @@ -889,24 +903,33 @@ public void updateDynamicSimulationProvider(UUID studyUuid, String provider, Str }); } - public ShortCircuitParameters getShortCircuitParameters(UUID studyUuid) { - return studyRepository.findById(studyUuid) - .map(studyEntity -> ShortCircuitService.fromEntity(studyEntity.getShortCircuitParameters())) - .orElse(null); - } - - public ShortCircuitParametersInfos getShortCircuitParametersInfo(UUID studyUuid) { - return studyRepository.findById(studyUuid) - .map(studyEntity -> ShortCircuitService.toShortCircuitParametersInfo(studyEntity.getShortCircuitParameters())) - .orElse(null); + @Transactional + public String getShortCircuitParametersInfo(UUID studyUuid) { + StudyEntity studyEntity = studyRepository.findById(studyUuid).orElseThrow(() -> new StudyException(STUDY_NOT_FOUND)); + if (studyEntity.getShortCircuitParametersUuid() == null) { + studyEntity.setShortCircuitParametersUuid(shortCircuitService.createParameters(null)); + studyRepository.save(studyEntity); + } + return shortCircuitService.getParameters(studyEntity.getShortCircuitParametersUuid()); } @Transactional - public void setShortCircuitParameters(UUID studyUuid, ShortCircuitParametersInfos shortCircuitParametersInfos, String userId) { - Objects.requireNonNull(shortCircuitParametersInfos); - Objects.requireNonNull(shortCircuitParametersInfos.getParameters()); - ShortCircuitParametersEntity shortCircuitParametersEntity = ShortCircuitService.toEntity(shortCircuitParametersInfos.getParameters(), shortCircuitParametersInfos.getPredefinedParameters()); - updateShortCircuitParameters(studyUuid, shortCircuitParametersEntity); + public void setShortCircuitParameters(UUID studyUuid, @Nullable String shortCircuitParametersInfos, String userId) { + StudyEntity studyEntity = studyRepository.findById(studyUuid).orElseThrow(() -> new StudyException(STUDY_NOT_FOUND)); + /* +-----------------------+----------------+-----------------------------------------+ + * | entity.parametersUuid | parametersInfo | action | + * | no | no | create default ones | + * | no | yes | create new ones | + * | yes | no | reset existing ones (with default ones) | + * | yes | yes | update existing ones | + * +-----------------------+----------------+-----------------------------------------+ + */ + if (studyEntity.getShortCircuitParametersUuid() != null) { + shortCircuitService.updateParameters(studyEntity.getShortCircuitParametersUuid(), shortCircuitParametersInfos); + } else { + studyEntity.setShortCircuitParametersUuid(shortCircuitService.createParameters(shortCircuitParametersInfos)); + studyRepository.save(studyEntity); + } notificationService.emitElementUpdated(studyUuid, userId); } @@ -1012,26 +1035,6 @@ public void invalidateVoltageInitStatusOnAllNodes(UUID studyUuid) { voltageInitService.invalidateVoltageInitStatus(networkModificationTreeService.getComputationResultUuids(studyUuid, VOLTAGE_INITIALIZATION)); } - private StudyEntity insertStudyEntity(UUID uuid, String userId, UUID networkUuid, String networkId, - String caseFormat, UUID caseUuid, String caseName, UUID loadFlowParametersUuid, - UUID importReportUuid, ShortCircuitParametersEntity shortCircuitParameters, DynamicSimulationParametersEntity dynamicSimulationParameters, - UUID voltageInitParametersUuid, UUID securityAnalysisParametersUuid, UUID sensitivityAnalysisParametersUuid, - Map importParameters) { - Objects.requireNonNull(uuid); - Objects.requireNonNull(userId); - Objects.requireNonNull(networkUuid); - Objects.requireNonNull(networkId); - Objects.requireNonNull(caseFormat); - Objects.requireNonNull(caseUuid); - Objects.requireNonNull(shortCircuitParameters); - Objects.requireNonNull(importParameters); - - StudyEntity studyEntity = new StudyEntity(uuid, networkUuid, networkId, caseFormat, caseUuid, caseName, null, null, null, defaultNonEvacuatedEnergyProvider, defaultDynamicSimulationProvider, - loadFlowParametersUuid, null, shortCircuitParameters, dynamicSimulationParameters, voltageInitParametersUuid, null, securityAnalysisParametersUuid, - null, sensitivityAnalysisParametersUuid, null, importParameters, StudyIndexationStatus.INDEXED, new StudyVoltageInitParametersEntity()); - return self.saveStudyThenCreateBasicTree(studyEntity, importReportUuid); - } - @Transactional public StudyEntity updateStudyEntityNetwork(StudyEntity studyEntity, NetworkInfos networkInfos) { if (networkInfos != null) { @@ -1142,11 +1145,6 @@ private void removeLoadFlowParameters(@Nullable UUID lfParametersUuid) { } } - public void updateShortCircuitParameters(UUID studyUuid, ShortCircuitParametersEntity shortCircuitParametersEntity) { - Optional studyEntity = studyRepository.findById(studyUuid); - studyEntity.ifPresent(studyEntity1 -> studyEntity1.setShortCircuitParameters(shortCircuitParametersEntity)); - } - public void updateDynamicSimulationParameters(UUID studyUuid, DynamicSimulationParametersEntity dynamicSimulationParametersEntity) { Optional studyEntity = studyRepository.findById(studyUuid); studyEntity.ifPresent(studyEntity1 -> { @@ -1750,31 +1748,14 @@ public UUID runSensitivityAnalysis(UUID studyUuid, UUID nodeUuid, String userId) return result; } - public UUID runShortCircuit(UUID studyUuid, UUID nodeUuid, String userId) { - Optional prevResultUuidOpt = networkModificationTreeService.getComputationResultUuid(nodeUuid, SHORT_CIRCUIT); - prevResultUuidOpt.ifPresent(shortCircuitService::deleteShortCircuitAnalysisResult); - - ShortCircuitParameters shortCircuitParameters = getShortCircuitParameters(studyUuid); - shortCircuitParameters.setWithFortescueResult(false); - UUID result = shortCircuitService.runShortCircuit(studyUuid, nodeUuid, null, shortCircuitParameters, userId); - - updateComputationResultUuid(nodeUuid, result, SHORT_CIRCUIT); - - notificationService.emitStudyChanged(studyUuid, nodeUuid, NotificationService.UPDATE_TYPE_SHORT_CIRCUIT_STATUS); - return result; - } - - public UUID runShortCircuit(UUID studyUuid, UUID nodeUuid, String userId, String busId) { - Optional prevResultUuidOpt = networkModificationTreeService.getComputationResultUuid(nodeUuid, ComputationType.SHORT_CIRCUIT_ONE_BUS); - prevResultUuidOpt.ifPresent(shortCircuitService::deleteShortCircuitAnalysisResult); - - ShortCircuitParameters shortCircuitParameters = getShortCircuitParameters(studyUuid); - shortCircuitParameters.setWithFortescueResult(true); - UUID result = shortCircuitService.runShortCircuit(studyUuid, nodeUuid, busId, shortCircuitParameters, userId); - - updateComputationResultUuid(nodeUuid, result, ComputationType.SHORT_CIRCUIT_ONE_BUS); - - notificationService.emitStudyChanged(studyUuid, nodeUuid, NotificationService.UPDATE_TYPE_ONE_BUS_SHORT_CIRCUIT_STATUS); + public UUID runShortCircuit(UUID studyUuid, UUID nodeUuid, Optional busId, String userId) { + networkModificationTreeService.getComputationResultUuid(nodeUuid, busId.isEmpty() ? SHORT_CIRCUIT : SHORT_CIRCUIT_ONE_BUS) + .ifPresent(shortCircuitService::deleteShortCircuitAnalysisResult); + final Optional parametersUuid = studyRepository.findById(studyUuid).map(StudyEntity::getShortCircuitParametersUuid); + final UUID result = shortCircuitService.runShortCircuit(studyUuid, nodeUuid, busId.orElse(null), parametersUuid, userId); + updateComputationResultUuid(nodeUuid, result, busId.isEmpty() ? SHORT_CIRCUIT : SHORT_CIRCUIT_ONE_BUS); + notificationService.emitStudyChanged(studyUuid, nodeUuid, + busId.isEmpty() ? NotificationService.UPDATE_TYPE_SHORT_CIRCUIT_STATUS : NotificationService.UPDATE_TYPE_ONE_BUS_SHORT_CIRCUIT_STATUS); return result; } diff --git a/src/main/java/org/gridsuite/study/server/service/shortcircuit/ShortCircuitService.java b/src/main/java/org/gridsuite/study/server/service/shortcircuit/ShortCircuitService.java index a7427dbed..77af61a6e 100644 --- a/src/main/java/org/gridsuite/study/server/service/shortcircuit/ShortCircuitService.java +++ b/src/main/java/org/gridsuite/study/server/service/shortcircuit/ShortCircuitService.java @@ -9,15 +9,14 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.powsybl.shortcircuit.InitialVoltageProfileMode; import com.powsybl.shortcircuit.ShortCircuitParameters; -import com.powsybl.shortcircuit.StudyType; -import com.powsybl.shortcircuit.VoltageRange; +import lombok.Setter; import org.apache.commons.lang3.StringUtils; import org.gridsuite.study.server.RemoteServicesProperties; import org.gridsuite.study.server.StudyException; -import org.gridsuite.study.server.dto.*; -import org.gridsuite.study.server.repository.ShortCircuitParametersEntity; +import org.gridsuite.study.server.dto.ComputationType; +import org.gridsuite.study.server.dto.NodeReceiver; +import org.gridsuite.study.server.dto.ShortCircuitStatus; import org.gridsuite.study.server.service.NetworkModificationTreeService; import org.gridsuite.study.server.service.NetworkService; import org.gridsuite.study.server.service.StudyService; @@ -25,6 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Pageable; import org.springframework.http.*; +import org.springframework.lang.Nullable; import org.springframework.stereotype.Service; import org.springframework.web.client.HttpStatusCodeException; import org.springframework.web.client.RestTemplate; @@ -53,20 +53,12 @@ public class ShortCircuitService extends AbstractComputationService { static final String RESULT_UUID = "resultUuid"; - static final List CEI909_VOLTAGE_PROFILE = List.of( - new VoltageRange(10.0, 199.99, 1.1), - new VoltageRange(200.0, 299.99, 1.09), - new VoltageRange(300.0, 500.0, 1.05) - ); - + @Setter private String shortCircuitServerBaseUri; private final NetworkService networkStoreService; - - NetworkModificationTreeService networkModificationTreeService; - + private final NetworkModificationTreeService networkModificationTreeService; private final ObjectMapper objectMapper; - private final RestTemplate restTemplate; @Autowired @@ -82,7 +74,7 @@ public ShortCircuitService(RemoteServicesProperties remoteServicesProperties, this.objectMapper = objectMapper; } - public UUID runShortCircuit(UUID studyUuid, UUID nodeUuid, String busId, ShortCircuitParameters shortCircuitParameters, String userId) { + public UUID runShortCircuit(UUID studyUuid, UUID nodeUuid, String busId, Optional parametersUuid, String userId) { UUID networkUuid = networkStoreService.getNetworkUuid(studyUuid); String variantId = getVariantId(nodeUuid); UUID reportUuid = getReportUuid(nodeUuid); @@ -100,7 +92,8 @@ public UUID runShortCircuit(UUID studyUuid, UUID nodeUuid, String busId, ShortCi .queryParam("reportUuid", reportUuid.toString()) .queryParam("reporterId", nodeUuid.toString()) .queryParam("reportType", StringUtils.isBlank(busId) ? StudyService.ReportType.SHORT_CIRCUIT.reportKey : - StudyService.ReportType.SHORT_CIRCUIT_ONE_BUS.reportKey); + StudyService.ReportType.SHORT_CIRCUIT_ONE_BUS.reportKey) + .queryParamIfPresent("parametersUuid", parametersUuid); if (!StringUtils.isBlank(busId)) { uriComponentsBuilder.queryParam("busId", busId); @@ -115,7 +108,7 @@ public UUID runShortCircuit(UUID studyUuid, UUID nodeUuid, String busId, ShortCi headers.set(HEADER_USER_ID, userId); headers.setContentType(MediaType.APPLICATION_JSON); - HttpEntity httpEntity = new HttpEntity<>(shortCircuitParameters, headers); + HttpEntity httpEntity = new HttpEntity<>(headers); return restTemplate.exchange(shortCircuitServerBaseUri + path, HttpMethod.POST, httpEntity, UUID.class).getBody(); } @@ -262,57 +255,6 @@ private UUID getReportUuid(UUID nodeUuid) { return networkModificationTreeService.getReportUuid(nodeUuid); } - public static ShortCircuitParametersEntity toEntity(ShortCircuitParameters parameters, ShortCircuitPredefinedConfiguration shortCircuitPredefinedConfiguration) { - Objects.requireNonNull(parameters); - return new ShortCircuitParametersEntity(parameters.isWithLimitViolations(), - parameters.isWithVoltageResult(), - parameters.isWithFortescueResult(), - parameters.isWithFeederResult(), - parameters.getStudyType(), - parameters.getMinVoltageDropProportionalThreshold(), - parameters.isWithLoads(), - parameters.isWithShuntCompensators(), - parameters.isWithVSCConverterStations(), - parameters.isWithNeutralPosition(), - parameters.getInitialVoltageProfileMode(), - shortCircuitPredefinedConfiguration); - } - - public static ShortCircuitParameters fromEntity(ShortCircuitParametersEntity entity) { - Objects.requireNonNull(entity); - List voltageRanges = InitialVoltageProfileMode.CONFIGURED.equals(entity.getInitialVoltageProfileMode()) ? CEI909_VOLTAGE_PROFILE : null; - return newShortCircuitParameters(entity.getStudyType(), entity.getMinVoltageDropProportionalThreshold(), entity.isWithFeederResult(), entity.isWithLimitViolations(), entity.isWithVoltageResult(), entity.isWithFortescueResult(), entity.isWithLoads(), entity.isWithShuntCompensators(), entity.isWithVscConverterStations(), entity.isWithNeutralPosition(), entity.getInitialVoltageProfileMode(), voltageRanges); - } - - public static ShortCircuitParameters copy(ShortCircuitParameters shortCircuitParameters) { - return newShortCircuitParameters(shortCircuitParameters.getStudyType(), shortCircuitParameters.getMinVoltageDropProportionalThreshold(), shortCircuitParameters.isWithFeederResult(), shortCircuitParameters.isWithLimitViolations(), shortCircuitParameters.isWithVoltageResult(), shortCircuitParameters.isWithFortescueResult(), shortCircuitParameters.isWithLoads(), shortCircuitParameters.isWithShuntCompensators(), shortCircuitParameters.isWithVSCConverterStations(), shortCircuitParameters.isWithNeutralPosition(), shortCircuitParameters.getInitialVoltageProfileMode(), shortCircuitParameters.getVoltageRanges()); - } - - public static ShortCircuitParameters newShortCircuitParameters(StudyType studyType, double minVoltageDropProportionalThreshold, boolean withFeederResult, boolean withLimitViolations, boolean withVoltageResult, boolean withFortescueResult, boolean withLoads, boolean withShuntCompensators, boolean withVscConverterStations, boolean withNeutralPosition, InitialVoltageProfileMode initialVoltageProfileMode, List voltageRanges) { - return new ShortCircuitParameters() - .setStudyType(studyType) - .setMinVoltageDropProportionalThreshold(minVoltageDropProportionalThreshold) - .setWithFeederResult(withFeederResult) - .setWithLimitViolations(withLimitViolations) - .setWithVoltageResult(withVoltageResult) - .setWithFortescueResult(withFortescueResult) - .setWithLoads(withLoads) - .setWithShuntCompensators(withShuntCompensators) - .setWithVSCConverterStations(withVscConverterStations) - .setWithNeutralPosition(withNeutralPosition) - .setInitialVoltageProfileMode(initialVoltageProfileMode) - // the voltageRanges is not taken in account when initialVoltageProfileMode=NOMINAL - .setVoltageRanges(voltageRanges); - } - - public static ShortCircuitParameters getDefaultShortCircuitParameters() { - return newShortCircuitParameters(StudyType.TRANSIENT, 20, true, true, false, false, false, false, true, true, InitialVoltageProfileMode.NOMINAL, null); - } - - public void setShortCircuitServerBaseUri(String shortCircuitServerBaseUri) { - this.shortCircuitServerBaseUri = shortCircuitServerBaseUri; - } - public void deleteShortCircuitAnalysisResult(UUID uuid) { String path = UriComponentsBuilder.fromPath(DELIMITER + SHORT_CIRCUIT_API_VERSION + "/results/{resultUuid}") .buildAndExpand(uuid) @@ -345,15 +287,6 @@ public void assertShortCircuitAnalysisNotRunning(UUID nodeUuid) { } } - public static ShortCircuitParametersInfos toShortCircuitParametersInfo(ShortCircuitParametersEntity entity) { - Objects.requireNonNull(entity); - return ShortCircuitParametersInfos.builder() - .predefinedParameters(entity.getPredefinedParameters()) - .parameters(fromEntity(entity)) - .cei909VoltageRanges(CEI909_VOLTAGE_PROFILE) - .build(); - } - public void invalidateShortCircuitStatus(List uuids) { if (!uuids.isEmpty()) { String path = UriComponentsBuilder @@ -368,4 +301,63 @@ public void invalidateShortCircuitStatus(List uuids) { public List getEnumValues(String enumName, UUID resultUuid) { return getEnumValues(enumName, resultUuid, SHORT_CIRCUIT_API_VERSION, shortCircuitServerBaseUri, SHORT_CIRCUIT_ANALYSIS_NOT_FOUND, restTemplate); } + + private UriComponentsBuilder getBaseUriForParameters() { + return UriComponentsBuilder.fromUriString(shortCircuitServerBaseUri).pathSegment(SHORT_CIRCUIT_API_VERSION, "parameters"); + } + + public UUID createParameters(@Nullable final String parametersInfos) { + final UriComponentsBuilder uri = getBaseUriForParameters(); + try { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(List.of(MediaType.APPLICATION_JSON)); + if (StringUtils.isBlank(parametersInfos)) { + return restTemplate.postForObject(uri.pathSegment("default").build().toUri(), new HttpEntity<>(headers), UUID.class); + } else { + headers.setContentType(MediaType.APPLICATION_JSON); + return restTemplate.postForObject(uri.build().toUri(), new HttpEntity<>(parametersInfos, headers), UUID.class); + } + } catch (final HttpStatusCodeException e) { + throw handleHttpError(e, CREATE_SHORTCIRCUIT_PARAMETERS_FAILED); + } + } + + public void updateParameters(final UUID parametersUuid, final String parametersInfos) { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + try { + restTemplate.put(getBaseUriForParameters() + .pathSegment("{parametersUuid}") + .buildAndExpand(parametersUuid) + .toUri(), new HttpEntity<>(parametersInfos, headers)); + } catch (final HttpStatusCodeException e) { + throw handleHttpError(e, UPDATE_SHORTCIRCUIT_PARAMETERS_FAILED); + } + } + + public String getParameters(UUID parametersUuid) { + try { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(List.of(MediaType.APPLICATION_JSON)); + return restTemplate.exchange(getBaseUriForParameters() + .pathSegment("{parametersUuid}") + .buildAndExpand(parametersUuid) + .toUri(), HttpMethod.GET, new HttpEntity<>(headers), String.class).getBody(); + } catch (final HttpStatusCodeException e) { + throw handleHttpError(e, GET_SHORTCIRCUIT_PARAMETERS_FAILED); + } + } + + public UUID duplicateParameters(UUID parametersUuid) { + try { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(List.of(MediaType.APPLICATION_JSON)); + return restTemplate.postForObject(getBaseUriForParameters() + .queryParam("duplicateFrom", parametersUuid) + .build() + .toUri(), new HttpEntity<>(headers), UUID.class); + } catch (final HttpStatusCodeException e) { + throw handleHttpError(e, CREATE_SHORTCIRCUIT_PARAMETERS_FAILED); + } + } } diff --git a/src/main/resources/db/changelog/changesets/changelog_20240510T112233Z.xml b/src/main/resources/db/changelog/changesets/changelog_20240510T112233Z.xml new file mode 100644 index 000000000..b31fbb960 --- /dev/null +++ b/src/main/resources/db/changelog/changesets/changelog_20240510T112233Z.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/src/main/resources/db/changelog/db.changelog-master.yaml b/src/main/resources/db/changelog/db.changelog-master.yaml index dafa8df52..6ef3b9a96 100644 --- a/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/src/main/resources/db/changelog/db.changelog-master.yaml @@ -222,19 +222,20 @@ databaseChangeLog: - include: file: changesets/changelog_20231225T150247Z.xml - relativeTochangelogFile: true - + relativeToChangelogFile: true - include: file: changesets/changelog_20231228T143308Z.xml relativeToChangelogFile: true - - include: file: changesets/changelog_20240404T091326Z.xml relativeToChangelogFile: true - include: file: changesets/changelog_20240522T150750Z.xml relativeToChangelogFile: true - - include: file: changesets/changelog_20240530T113417Z.xml relativeToChangelogFile: true + - include: + file: changesets/changelog_20240510T112233Z.xml + relativeToChangelogFile: true + diff --git a/src/test/java/org/gridsuite/study/server/LoadFlowTest.java b/src/test/java/org/gridsuite/study/server/LoadFlowTest.java index e5f7e8bf0..a21b10966 100644 --- a/src/test/java/org/gridsuite/study/server/LoadFlowTest.java +++ b/src/test/java/org/gridsuite/study/server/LoadFlowTest.java @@ -23,19 +23,16 @@ import org.gridsuite.study.server.dto.LimitViolationInfos; import org.gridsuite.study.server.dto.LoadFlowParametersInfos; import org.gridsuite.study.server.dto.NodeReceiver; -import org.gridsuite.study.server.dto.ShortCircuitPredefinedConfiguration; import org.gridsuite.study.server.networkmodificationtree.dto.BuildStatus; import org.gridsuite.study.server.networkmodificationtree.dto.InsertMode; import org.gridsuite.study.server.networkmodificationtree.dto.NetworkModificationNode; import org.gridsuite.study.server.networkmodificationtree.dto.RootNode; import org.gridsuite.study.server.notification.NotificationService; -import org.gridsuite.study.server.repository.ShortCircuitParametersEntity; import org.gridsuite.study.server.repository.StudyEntity; import org.gridsuite.study.server.repository.StudyRepository; import org.gridsuite.study.server.repository.networkmodificationtree.NetworkModificationNodeInfoRepository; import org.gridsuite.study.server.repository.nonevacuatedenergy.NonEvacuatedEnergyParametersEntity; import org.gridsuite.study.server.service.*; -import org.gridsuite.study.server.service.shortcircuit.ShortCircuitService; import org.gridsuite.study.server.utils.TestUtils; import org.gridsuite.study.server.utils.elasticsearch.DisableElasticsearch; import org.jetbrains.annotations.NotNull; @@ -788,10 +785,9 @@ public void testLoadFlowParameters() throws Exception { } private StudyEntity insertDummyStudy(UUID networkUuid, UUID caseUuid, UUID loadFlowParametersUuid) { - ShortCircuitParametersEntity defaultShortCircuitParametersEntity = ShortCircuitService.toEntity(ShortCircuitService.getDefaultShortCircuitParameters(), ShortCircuitPredefinedConfiguration.ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP); NonEvacuatedEnergyParametersEntity defaultNonEvacuatedEnergyParametersEntity = NonEvacuatedEnergyService.toEntity(NonEvacuatedEnergyService.getDefaultNonEvacuatedEnergyParametersInfos()); StudyEntity studyEntity = TestUtils.createDummyStudy(networkUuid, caseUuid, "", - loadFlowParametersUuid, defaultShortCircuitParametersEntity, null, null, + loadFlowParametersUuid, null, null, null, defaultNonEvacuatedEnergyParametersEntity); var study = studyRepository.save(studyEntity); networkModificationTreeService.createRoot(studyEntity, null); diff --git a/src/test/java/org/gridsuite/study/server/NetworkMapTest.java b/src/test/java/org/gridsuite/study/server/NetworkMapTest.java index cf2ce46ae..39909f6e9 100644 --- a/src/test/java/org/gridsuite/study/server/NetworkMapTest.java +++ b/src/test/java/org/gridsuite/study/server/NetworkMapTest.java @@ -24,19 +24,16 @@ import okhttp3.mockwebserver.RecordedRequest; import org.gridsuite.study.server.dto.IdentifiableInfos; import org.gridsuite.study.server.dto.LoadFlowParametersInfos; -import org.gridsuite.study.server.dto.ShortCircuitPredefinedConfiguration; import org.gridsuite.study.server.networkmodificationtree.dto.RootNode; -import org.gridsuite.study.server.repository.ShortCircuitParametersEntity; import org.gridsuite.study.server.repository.StudyEntity; import org.gridsuite.study.server.repository.StudyRepository; import org.gridsuite.study.server.service.LoadFlowService; import org.gridsuite.study.server.service.NetworkMapService; import org.gridsuite.study.server.service.NetworkModificationTreeService; -import org.gridsuite.study.server.service.shortcircuit.ShortCircuitService; -import org.gridsuite.study.server.utils.WireMockUtils; -import org.gridsuite.study.server.utils.elasticsearch.DisableElasticsearch; import org.gridsuite.study.server.utils.MatcherJson; import org.gridsuite.study.server.utils.TestUtils; +import org.gridsuite.study.server.utils.WireMockUtils; +import org.gridsuite.study.server.utils.elasticsearch.DisableElasticsearch; import org.jetbrains.annotations.NotNull; import org.junit.After; import org.junit.Before; @@ -501,8 +498,7 @@ public void testGetBusesOrBusbarSections() throws Exception { } private StudyEntity insertDummyStudy(UUID networkUuid, UUID caseUuid) { - ShortCircuitParametersEntity defaultShortCircuitParametersEntity = ShortCircuitService.toEntity(ShortCircuitService.getDefaultShortCircuitParameters(), ShortCircuitPredefinedConfiguration.ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP); - StudyEntity studyEntity = TestUtils.createDummyStudy(networkUuid, caseUuid, "", LOADFLOW_PARAMETERS_UUID, defaultShortCircuitParametersEntity, null, null, null); + StudyEntity studyEntity = TestUtils.createDummyStudy(networkUuid, caseUuid, "", LOADFLOW_PARAMETERS_UUID, null, null, null, null); var study = studyRepository.save(studyEntity); networkModificationTreeService.createRoot(studyEntity, null); return study; diff --git a/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java b/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java index a0bb5de73..bb09afe9a 100644 --- a/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java +++ b/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java @@ -32,12 +32,10 @@ import org.gridsuite.study.server.dto.BuildInfos; import org.gridsuite.study.server.dto.CreatedStudyBasicInfos; import org.gridsuite.study.server.dto.impacts.SimpleElementImpact.SimpleImpactType; -import org.gridsuite.study.server.dto.ShortCircuitPredefinedConfiguration; import org.gridsuite.study.server.dto.modification.*; import org.gridsuite.study.server.networkmodificationtree.dto.*; import org.gridsuite.study.server.notification.NotificationService; import org.gridsuite.study.server.notification.dto.NetworkImpactsInfos; -import org.gridsuite.study.server.repository.ShortCircuitParametersEntity; import org.gridsuite.study.server.repository.StudyEntity; import org.gridsuite.study.server.repository.StudyRepository; import org.gridsuite.study.server.service.*; @@ -2803,8 +2801,7 @@ private void checkNodesInvalidationMessagesReceived(UUID studyNameUserIdUuid, Li } private StudyEntity insertDummyStudy(UUID networkUuid, UUID caseUuid, String caseFormat) { - ShortCircuitParametersEntity defaultShortCircuitParametersEntity = ShortCircuitService.toEntity(ShortCircuitService.getDefaultShortCircuitParameters(), ShortCircuitPredefinedConfiguration.ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP); - StudyEntity studyEntity = TestUtils.createDummyStudy(networkUuid, caseUuid, caseFormat, UUID.randomUUID(), defaultShortCircuitParametersEntity, null, null, null); + StudyEntity studyEntity = TestUtils.createDummyStudy(networkUuid, caseUuid, caseFormat, UUID.randomUUID(), null, null, null, null); var study = studyRepository.save(studyEntity); networkModificationTreeService.createRoot(studyEntity, null); return study; diff --git a/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java b/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java index d69177699..4c2d077e0 100644 --- a/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java +++ b/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java @@ -34,7 +34,6 @@ import org.gridsuite.study.server.networkmodificationtree.dto.*; import org.gridsuite.study.server.networkmodificationtree.entities.NodeType; import org.gridsuite.study.server.notification.NotificationService; -import org.gridsuite.study.server.repository.ShortCircuitParametersEntity; import org.gridsuite.study.server.repository.StudyEntity; import org.gridsuite.study.server.repository.StudyRepository; import org.gridsuite.study.server.repository.networkmodificationtree.NetworkModificationNodeInfoRepository; @@ -323,7 +322,7 @@ StudyEntity createDummyStudy(UUID networkUuid) { .caseName("caseName1") .networkId("netId") .networkUuid(networkUuid) - .shortCircuitParameters(new ShortCircuitParametersEntity()) + .shortCircuitParametersUuid(UUID.randomUUID()) .build(); } diff --git a/src/test/java/org/gridsuite/study/server/NetworkModificationUnitTest.java b/src/test/java/org/gridsuite/study/server/NetworkModificationUnitTest.java index a3477e068..15d30b8bc 100644 --- a/src/test/java/org/gridsuite/study/server/NetworkModificationUnitTest.java +++ b/src/test/java/org/gridsuite/study/server/NetworkModificationUnitTest.java @@ -7,14 +7,12 @@ package org.gridsuite.study.server; import com.powsybl.network.store.client.NetworkStoreService; -import org.gridsuite.study.server.dto.ShortCircuitPredefinedConfiguration; import org.gridsuite.study.server.networkmodificationtree.dto.BuildStatus; import org.gridsuite.study.server.networkmodificationtree.dto.NodeBuildStatus; import org.gridsuite.study.server.networkmodificationtree.entities.NetworkModificationNodeInfoEntity; import org.gridsuite.study.server.networkmodificationtree.entities.NodeEntity; import org.gridsuite.study.server.networkmodificationtree.entities.NodeType; import org.gridsuite.study.server.notification.NotificationService; -import org.gridsuite.study.server.repository.ShortCircuitParametersEntity; import org.gridsuite.study.server.repository.StudyEntity; import org.gridsuite.study.server.repository.StudyRepository; import org.gridsuite.study.server.repository.networkmodificationtree.NetworkModificationNodeInfoRepository; @@ -24,7 +22,6 @@ import org.gridsuite.study.server.service.NetworkService; import org.gridsuite.study.server.service.NonEvacuatedEnergyService; import org.gridsuite.study.server.service.ReportService; -import org.gridsuite.study.server.service.shortcircuit.ShortCircuitService; import org.gridsuite.study.server.utils.TestUtils; import org.gridsuite.study.server.utils.elasticsearch.DisableElasticsearch; import org.junit.jupiter.api.AfterEach; @@ -182,10 +179,9 @@ private void checkUpdateModelsStatusMessagesReceived(UUID studyUuid, UUID nodeUu } private StudyEntity insertStudy(UUID networkUuid, UUID caseUuid) { - ShortCircuitParametersEntity defaultShortCircuitParametersEntity = ShortCircuitService.toEntity(ShortCircuitService.getDefaultShortCircuitParameters(), ShortCircuitPredefinedConfiguration.ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP); NonEvacuatedEnergyParametersEntity defaultNonEvacuatedEnergyParametersEntity = NonEvacuatedEnergyService.toEntity(NonEvacuatedEnergyService.getDefaultNonEvacuatedEnergyParametersInfos()); StudyEntity studyEntity = TestUtils.createDummyStudy(networkUuid, caseUuid, "", - UUID.randomUUID(), defaultShortCircuitParametersEntity, null, null, defaultNonEvacuatedEnergyParametersEntity); + UUID.randomUUID(), null, null, null, defaultNonEvacuatedEnergyParametersEntity); return studyRepository.save(studyEntity); } diff --git a/src/test/java/org/gridsuite/study/server/NonEvacuatedEnergyTest.java b/src/test/java/org/gridsuite/study/server/NonEvacuatedEnergyTest.java index ab8f43d47..8915392cf 100644 --- a/src/test/java/org/gridsuite/study/server/NonEvacuatedEnergyTest.java +++ b/src/test/java/org/gridsuite/study/server/NonEvacuatedEnergyTest.java @@ -25,7 +25,6 @@ import okhttp3.mockwebserver.RecordedRequest; import org.gridsuite.study.server.dto.ComputationType; import org.gridsuite.study.server.dto.NodeReceiver; -import org.gridsuite.study.server.dto.ShortCircuitPredefinedConfiguration; import org.gridsuite.study.server.dto.nonevacuatedenergy.*; import org.gridsuite.study.server.dto.sensianalysis.EquipmentsContainer; import org.gridsuite.study.server.networkmodificationtree.dto.BuildStatus; @@ -33,13 +32,11 @@ import org.gridsuite.study.server.networkmodificationtree.dto.NetworkModificationNode; import org.gridsuite.study.server.networkmodificationtree.dto.RootNode; import org.gridsuite.study.server.notification.NotificationService; -import org.gridsuite.study.server.repository.ShortCircuitParametersEntity; import org.gridsuite.study.server.repository.StudyEntity; import org.gridsuite.study.server.repository.StudyRepository; import org.gridsuite.study.server.repository.networkmodificationtree.NetworkModificationNodeInfoRepository; import org.gridsuite.study.server.repository.nonevacuatedenergy.NonEvacuatedEnergyParametersEntity; import org.gridsuite.study.server.service.*; -import org.gridsuite.study.server.service.shortcircuit.ShortCircuitService; import org.gridsuite.study.server.utils.SendInput; import org.gridsuite.study.server.utils.TestUtils; import org.gridsuite.study.server.utils.elasticsearch.DisableElasticsearch; @@ -66,7 +63,10 @@ import org.springframework.test.web.servlet.MvcResult; import java.io.IOException; -import java.util.*; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.UUID; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static org.gridsuite.study.server.StudyConstants.HEADER_RECEIVER; @@ -507,9 +507,8 @@ public void testNonEvacuatedEnergyFailedForNotification() throws Exception { } private StudyEntity insertDummyStudy(UUID networkUuid, UUID caseUuid) { - ShortCircuitParametersEntity defaultShortCircuitParametersEntity = ShortCircuitService.toEntity(ShortCircuitService.getDefaultShortCircuitParameters(), ShortCircuitPredefinedConfiguration.ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP); NonEvacuatedEnergyParametersEntity nonEvacuatedEnergyParametersEntity = NonEvacuatedEnergyService.toEntity(NonEvacuatedEnergyService.getDefaultNonEvacuatedEnergyParametersInfos()); - StudyEntity studyEntity = TestUtils.createDummyStudy(networkUuid, caseUuid, "", UUID.randomUUID(), defaultShortCircuitParametersEntity, null, null, + StudyEntity studyEntity = TestUtils.createDummyStudy(networkUuid, caseUuid, "", UUID.randomUUID(), null, null, null, nonEvacuatedEnergyParametersEntity); var study = studyRepository.save(studyEntity); networkModificationTreeService.createRoot(studyEntity, null); @@ -517,10 +516,8 @@ private StudyEntity insertDummyStudy(UUID networkUuid, UUID caseUuid) { } private StudyEntity insertDummyStudyWithSpecificParams(UUID networkUuid, UUID caseUuid) { - - ShortCircuitParametersEntity defaultShortCircuitParametersEntity = ShortCircuitService.toEntity(ShortCircuitService.getDefaultShortCircuitParameters(), ShortCircuitPredefinedConfiguration.ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP); NonEvacuatedEnergyParametersEntity nonEvacuatedEnergyParametersEntity = NonEvacuatedEnergyService.toEntity(NonEvacuatedEnergyService.getDefaultNonEvacuatedEnergyParametersInfos()); - StudyEntity studyEntity = TestUtils.createDummyStudy(networkUuid, caseUuid, "", UUID.randomUUID(), defaultShortCircuitParametersEntity, null, null, + StudyEntity studyEntity = TestUtils.createDummyStudy(networkUuid, caseUuid, "", UUID.randomUUID(), null, null, null, nonEvacuatedEnergyParametersEntity); var study = studyRepository.save(studyEntity); networkModificationTreeService.createRoot(studyEntity, null); diff --git a/src/test/java/org/gridsuite/study/server/SecurityAnalysisTest.java b/src/test/java/org/gridsuite/study/server/SecurityAnalysisTest.java index c84d4dc70..155e87c76 100644 --- a/src/test/java/org/gridsuite/study/server/SecurityAnalysisTest.java +++ b/src/test/java/org/gridsuite/study/server/SecurityAnalysisTest.java @@ -26,17 +26,14 @@ import okhttp3.mockwebserver.RecordedRequest; import org.gridsuite.study.server.dto.LoadFlowParametersInfos; import org.gridsuite.study.server.dto.NodeReceiver; -import org.gridsuite.study.server.dto.ShortCircuitPredefinedConfiguration; import org.gridsuite.study.server.networkmodificationtree.dto.*; import org.gridsuite.study.server.notification.NotificationService; -import org.gridsuite.study.server.repository.ShortCircuitParametersEntity; import org.gridsuite.study.server.repository.StudyEntity; import org.gridsuite.study.server.repository.StudyRepository; import org.gridsuite.study.server.repository.networkmodificationtree.NetworkModificationNodeInfoRepository; import org.gridsuite.study.server.repository.nonevacuatedenergy.NonEvacuatedEnergyParametersEntity; import org.gridsuite.study.server.service.*; import org.gridsuite.study.server.service.securityanalysis.SecurityAnalysisResultType; -import org.gridsuite.study.server.service.shortcircuit.ShortCircuitService; import org.gridsuite.study.server.utils.TestUtils; import org.gridsuite.study.server.utils.elasticsearch.DisableElasticsearch; import org.jetbrains.annotations.NotNull; @@ -66,8 +63,8 @@ import static org.gridsuite.study.server.StudyConstants.HEADER_RECEIVER; import static org.gridsuite.study.server.StudyConstants.HEADER_USER_ID; -import static org.gridsuite.study.server.dto.ComputationType.SECURITY_ANALYSIS; import static org.gridsuite.study.server.dto.ComputationType.LOAD_FLOW; +import static org.gridsuite.study.server.dto.ComputationType.SECURITY_ANALYSIS; import static org.gridsuite.study.server.utils.TestUtils.getBinaryAsBuffer; import static org.junit.Assert.*; import static org.mockito.ArgumentMatchers.any; @@ -581,10 +578,9 @@ private void testSecurityAnalysisWithNodeUuid(UUID studyUuid, UUID nodeUuid, UUI } private StudyEntity insertDummyStudy(UUID networkUuid, UUID caseUuid) { - ShortCircuitParametersEntity defaultShortCircuitParametersEntity = ShortCircuitService.toEntity(ShortCircuitService.getDefaultShortCircuitParameters(), ShortCircuitPredefinedConfiguration.ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP); NonEvacuatedEnergyParametersEntity defaultNonEvacuatedEnergyParametersEntity = NonEvacuatedEnergyService.toEntity(NonEvacuatedEnergyService.getDefaultNonEvacuatedEnergyParametersInfos()); StudyEntity studyEntity = TestUtils.createDummyStudy(networkUuid, caseUuid, "", - UUID.randomUUID(), defaultShortCircuitParametersEntity, null, null, + UUID.randomUUID(), null, null, null, defaultNonEvacuatedEnergyParametersEntity); var study = studyRepository.save(studyEntity); networkModificationTreeService.createRoot(studyEntity, null); diff --git a/src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java b/src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java index 4a9aec36e..bc8df4ebd 100644 --- a/src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java +++ b/src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java @@ -26,7 +26,6 @@ import okhttp3.mockwebserver.RecordedRequest; import org.gridsuite.study.server.dto.LoadFlowParametersInfos; import org.gridsuite.study.server.dto.NodeReceiver; -import org.gridsuite.study.server.dto.ShortCircuitPredefinedConfiguration; import org.gridsuite.study.server.dto.sensianalysis.SensitivityAnalysisCsvFileInfos; import org.gridsuite.study.server.dto.sensianalysis.SensitivityFactorsIdsByGroup; import org.gridsuite.study.server.networkmodificationtree.dto.BuildStatus; @@ -34,13 +33,11 @@ import org.gridsuite.study.server.networkmodificationtree.dto.NetworkModificationNode; import org.gridsuite.study.server.networkmodificationtree.dto.RootNode; import org.gridsuite.study.server.notification.NotificationService; -import org.gridsuite.study.server.repository.ShortCircuitParametersEntity; import org.gridsuite.study.server.repository.StudyEntity; import org.gridsuite.study.server.repository.StudyRepository; import org.gridsuite.study.server.repository.networkmodificationtree.NetworkModificationNodeInfoRepository; import org.gridsuite.study.server.repository.nonevacuatedenergy.NonEvacuatedEnergyParametersEntity; import org.gridsuite.study.server.service.*; -import org.gridsuite.study.server.service.shortcircuit.ShortCircuitService; import org.gridsuite.study.server.utils.SendInput; import org.gridsuite.study.server.utils.TestUtils; import org.gridsuite.study.server.utils.elasticsearch.DisableElasticsearch; @@ -576,9 +573,8 @@ public void testSensitivityAnalysisFailedForNotification() throws Exception { } private StudyEntity insertDummyStudy(UUID networkUuid, UUID caseUuid) { - ShortCircuitParametersEntity defaultShortCircuitParametersEntity = ShortCircuitService.toEntity(ShortCircuitService.getDefaultShortCircuitParameters(), ShortCircuitPredefinedConfiguration.ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP); NonEvacuatedEnergyParametersEntity defaultNonEvacuatedEnergyParametersEntity = NonEvacuatedEnergyService.toEntity(NonEvacuatedEnergyService.getDefaultNonEvacuatedEnergyParametersInfos()); - StudyEntity studyEntity = TestUtils.createDummyStudy(networkUuid, caseUuid, "", UUID.randomUUID(), defaultShortCircuitParametersEntity, null, SENSITIVITY_ANALYSIS_PARAMETERS_UUID, + StudyEntity studyEntity = TestUtils.createDummyStudy(networkUuid, caseUuid, "", UUID.randomUUID(), null, null, SENSITIVITY_ANALYSIS_PARAMETERS_UUID, defaultNonEvacuatedEnergyParametersEntity); var study = studyRepository.save(studyEntity); networkModificationTreeService.createRoot(studyEntity, null); diff --git a/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java b/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java index 5fff2d40f..60b652c65 100644 --- a/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java +++ b/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java @@ -11,22 +11,17 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; import com.powsybl.commons.exceptions.UncheckedInterruptedException; -import com.powsybl.shortcircuit.InitialVoltageProfileMode; -import com.powsybl.shortcircuit.ShortCircuitParameters; -import com.powsybl.shortcircuit.StudyType; import lombok.SneakyThrows; import okhttp3.HttpUrl; import okhttp3.mockwebserver.Dispatcher; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; +import org.assertj.core.api.WithAssertions; import org.gridsuite.study.server.dto.ComputationType; import org.gridsuite.study.server.dto.NodeReceiver; -import org.gridsuite.study.server.dto.ShortCircuitParametersInfos; -import org.gridsuite.study.server.dto.ShortCircuitPredefinedConfiguration; import org.gridsuite.study.server.networkmodificationtree.dto.*; import org.gridsuite.study.server.notification.NotificationService; -import org.gridsuite.study.server.repository.ShortCircuitParametersEntity; import org.gridsuite.study.server.repository.StudyEntity; import org.gridsuite.study.server.repository.StudyRepository; import org.gridsuite.study.server.repository.networkmodificationtree.NetworkModificationNodeInfoRepository; @@ -53,6 +48,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.stream.binder.test.InputDestination; import org.springframework.cloud.stream.binder.test.OutputDestination; +import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.messaging.Message; import org.springframework.messaging.support.MessageBuilder; @@ -60,11 +56,7 @@ import org.springframework.test.web.servlet.MockMvc; import java.io.IOException; - -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.UUID; +import java.util.*; import static org.gridsuite.study.server.StudyConstants.HEADER_RECEIVER; import static org.gridsuite.study.server.StudyConstants.HEADER_USER_ID; @@ -82,7 +74,7 @@ @SpringBootTest @DisableElasticsearch @ContextConfigurationWithTestChannel -public class ShortCircuitTest { +public class ShortCircuitTest implements WithAssertions { private static final Logger LOGGER = LoggerFactory.getLogger(ShortCircuitTest.class); @@ -104,21 +96,19 @@ public class ShortCircuitTest { private static final String SHORT_CIRCUIT_ANALYSIS_OTHER_NODE_RESULT_UUID = "11131111-8594-4e55-8ef7-07ea965d24eb"; - private static final String SHORT_CIRCUIT_ANALYSIS_RESULT_JSON = "{\"version\":\"1.0\",\"faults\":[]"; + private static final String SHORT_CIRCUIT_ANALYSIS_PARAMETERS_UUID = "00000000-1111-2222-3333-444444444444"; - private static String FAULT_TYPES_JSON; + private static final String SHORT_CIRCUIT_ANALYSIS_RESULT_JSON = "{\"version\":\"1.0\",\"faults\":[]}"; private static final String CSV_HEADERS = "{csvHeaders}"; private static final byte[] SHORT_CIRCUIT_ANALYSIS_CSV_RESULT = {0x00, 0x11}; private static final String SHORT_CIRCUIT_ANALYSIS_STATUS_JSON = "{\"status\":\"COMPLETED\"}"; - private static final String VARIANT_ID = "variant_1"; + private static final String VARIANT_ID = "variant_1"; private static final String VARIANT_ID_2 = "variant_2"; - private static final String VARIANT_ID_3 = "variant_3"; - private static final String VARIANT_ID_4 = "variant_4"; private static final long TIMEOUT = 1000; @@ -176,20 +166,15 @@ public void setup() throws IOException { reportService.setReportServerBaseUri(baseUrl); String shortCircuitAnalysisResultUuidStr = objectMapper.writeValueAsString(SHORT_CIRCUIT_ANALYSIS_RESULT_UUID); - String shortCircuitAnalysisResultNotFoundUuidStr = objectMapper.writeValueAsString(SHORT_CIRCUIT_ANALYSIS_RESULT_UUID_NOT_FOUND); - String shortCircuitAnalysisErrorResultUuidStr = objectMapper.writeValueAsString(SHORT_CIRCUIT_ANALYSIS_ERROR_RESULT_UUID); - FAULT_TYPES_JSON = objectMapper.writeValueAsString(List.of("")); - final Dispatcher dispatcher = new Dispatcher() { @SneakyThrows @Override @NotNull public MockResponse dispatch(RecordedRequest request) { String path = Objects.requireNonNull(request.getPath()); - request.getBody(); if (path.matches("/v1/networks/" + NETWORK_UUID_STRING + "/run-and-save\\?receiver=.*&reportUuid=.*&reporterId=.*&busId=BUS_TEST_ID&variantId=" + VARIANT_ID_2)) { input.send(MessageBuilder.withPayload("") .setHeader("resultUuid", SHORT_CIRCUIT_ANALYSIS_RESULT_UUID) @@ -264,14 +249,20 @@ public MockResponse dispatch(RecordedRequest request) { return new MockResponse().setResponseCode(200) .addHeader("Content-Type", "application/json; charset=utf-8") .setBody("1"); + } else if ("POST".equalsIgnoreCase(request.getMethod()) && path.equals("/v1/parameters/default")) { + return new MockResponse().setResponseCode(200).setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).setBody("\"" + SHORT_CIRCUIT_ANALYSIS_PARAMETERS_UUID + "\""); + } else if ("GET".equalsIgnoreCase(request.getMethod()) && path.equals("/v1/parameters/" + SHORT_CIRCUIT_ANALYSIS_PARAMETERS_UUID)) { + return new MockResponse().setResponseCode(200).setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).setBody(TestUtils.resourceToString("/short-circuit-parameters.json")); + } else if ("PUT".equalsIgnoreCase(request.getMethod()) && path.equals("/v1/parameters/" + SHORT_CIRCUIT_ANALYSIS_PARAMETERS_UUID)) { + return new MockResponse().setResponseCode(200); } else { - LOGGER.error("Unhandled method+path: " + request.getMethod() + " " + request.getPath()); - return new MockResponse().setResponseCode(418).setBody("Unhandled method+path: " + request.getMethod() + " " + request.getPath()); + LOGGER.error("Unhandled method+path: {} {}", request.getMethod(), request.getPath()); + return new MockResponse().setResponseCode(418) + .setHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN_VALUE) + .setBody("Unhandled method+path: " + request.getMethod() + " " + request.getPath()); } } - }; - server.setDispatcher(dispatcher); } @@ -282,47 +273,16 @@ public void testShortCircuitAnalysisParameters() throws Exception { UUID studyNameUserIdUuid = studyEntity.getId(); //get default ShortCircuitParameters - mockMvc.perform(get("/v1/studies/{studyUuid}/short-circuit-analysis/parameters", studyNameUserIdUuid)).andExpectAll( - status().isOk(), - content().string(TestUtils.resourceToString("/short-circuit-parameters.json"))); + mockMvc.perform(get("/v1/studies/{studyUuid}/short-circuit-analysis/parameters", studyNameUserIdUuid)) + .andExpectAll(status().isOk(), content().string(TestUtils.resourceToString("/short-circuit-parameters.json"))); + assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.equals("/v1/parameters/default"))); + assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.equals("/v1/parameters/" + SHORT_CIRCUIT_ANALYSIS_PARAMETERS_UUID))); - // change some short circuit parameters - ShortCircuitParameters shortCircuitParametersWithIccMax = ShortCircuitService.newShortCircuitParameters(StudyType.TRANSIENT, 20, true, true, false, false, true, true, true, true, InitialVoltageProfileMode.NOMINAL, null); - ShortCircuitParametersInfos shortCircuitParametersWithIccMaxInfos = new ShortCircuitParametersInfos(); - shortCircuitParametersWithIccMaxInfos.setParameters(shortCircuitParametersWithIccMax); - shortCircuitParametersWithIccMaxInfos.setPredefinedParameters(ShortCircuitPredefinedConfiguration.ICC_MAX_WITH_CEI909); - - mockMvc.perform( - post("/v1/studies/{studyUuid}/short-circuit-analysis/parameters", studyNameUserIdUuid) - .header(HEADER_USER_ID, "testUserId") - .contentType(MediaType.APPLICATION_JSON) - .content(objectWriter.writeValueAsString(shortCircuitParametersWithIccMaxInfos))).andExpect( - status().isOk()); - - //getting set values - mockMvc.perform(get("/v1/studies/{studyUuid}/short-circuit-analysis/parameters", studyNameUserIdUuid)).andExpectAll( - status().isOk(), - content().string(TestUtils.resourceToString("/short-circuit-updated-parameters.json"))); - - // change some short circuit parameters - ShortCircuitParameters shortCircuitParametersWithIccMin = ShortCircuitService.newShortCircuitParameters(StudyType.TRANSIENT, 20, true, true, false, false, false, false, false, true, InitialVoltageProfileMode.NOMINAL, null); - ShortCircuitParametersInfos shortCircuitParametersWithIccMinInfos = new ShortCircuitParametersInfos(); - shortCircuitParametersWithIccMinInfos.setParameters(shortCircuitParametersWithIccMin); - - //change predefined params - shortCircuitParametersWithIccMinInfos.setPredefinedParameters(ShortCircuitPredefinedConfiguration.ICC_MIN_WITH_NOMINAL_VOLTAGE_MAP); - - mockMvc.perform( - post("/v1/studies/{studyUuid}/short-circuit-analysis/parameters", studyNameUserIdUuid) + mockMvc.perform(post("/v1/studies/{studyUuid}/short-circuit-analysis/parameters", studyNameUserIdUuid) .header(HEADER_USER_ID, "testUserId") - .contentType(MediaType.APPLICATION_JSON) - .content(objectWriter.writeValueAsString(shortCircuitParametersWithIccMinInfos))).andExpect( - status().isOk()); - - //getting set values - mockMvc.perform(get("/v1/studies/{studyUuid}/short-circuit-analysis/parameters", studyNameUserIdUuid)).andExpectAll( - status().isOk(), - content().string(TestUtils.resourceToString("/short-circuit-updated-predefined-parameters.json"))); + .content("{\"dumb\": \"json\"}").contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.equals("/v1/parameters/" + SHORT_CIRCUIT_ANALYSIS_PARAMETERS_UUID))); } @Test @@ -630,8 +590,7 @@ public void testOneBusShortCircuit() throws Exception { } @Test - @SneakyThrows - public void testResetUuidResultWhenSCFailed() { + public void testResetUuidResultWhenSCFailed() throws Exception { UUID resultUuid = UUID.randomUUID(); StudyEntity studyEntity = insertDummyStudy(UUID.randomUUID(), UUID.randomUUID()); RootNode rootNode = networkModificationTreeService.getStudyTree(studyEntity.getId()); @@ -647,8 +606,8 @@ public void testResetUuidResultWhenSCFailed() { doAnswer(invocation -> { input.send(MessageBuilder.withPayload("").setHeader(HEADER_RECEIVER, resultUuidJson).build(), shortCircuitAnalysisFailedDestination); return resultUuid; - }).when(studyService).runShortCircuit(any(), any(), any()); - studyService.runShortCircuit(studyEntity.getId(), modificationNode.getId(), ""); + }).when(studyService).runShortCircuit(any(), any(), any(), any()); + studyService.runShortCircuit(studyEntity.getId(), modificationNode.getId(), Optional.empty(), "user_1"); // Test reset uuid result in the database assertTrue(networkModificationTreeService.getComputationResultUuid(modificationNode.getId(), ComputationType.SHORT_CIRCUIT).isEmpty()); @@ -762,10 +721,9 @@ public void testInvalidateShortCircuitStatus() throws Exception { } private StudyEntity insertDummyStudy(UUID networkUuid, UUID caseUuid) { - ShortCircuitParametersEntity defaultShortCircuitParametersEntity = ShortCircuitService.toEntity(ShortCircuitService.getDefaultShortCircuitParameters(), ShortCircuitPredefinedConfiguration.ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP); NonEvacuatedEnergyParametersEntity defaultNonEvacuatedEnergyParametersEntity = NonEvacuatedEnergyService.toEntity(NonEvacuatedEnergyService.getDefaultNonEvacuatedEnergyParametersInfos()); StudyEntity studyEntity = TestUtils.createDummyStudy(networkUuid, caseUuid, "", - UUID.randomUUID(), defaultShortCircuitParametersEntity, null, null, + UUID.randomUUID(), null, null, null, defaultNonEvacuatedEnergyParametersEntity); var study = studyRepository.save(studyEntity); networkModificationTreeService.createRoot(studyEntity, null); diff --git a/src/test/java/org/gridsuite/study/server/SingleLineDiagramTest.java b/src/test/java/org/gridsuite/study/server/SingleLineDiagramTest.java index 8f43e8d49..b5ada9f84 100644 --- a/src/test/java/org/gridsuite/study/server/SingleLineDiagramTest.java +++ b/src/test/java/org/gridsuite/study/server/SingleLineDiagramTest.java @@ -28,16 +28,13 @@ import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; import org.gridsuite.study.server.dto.LoadFlowParametersInfos; -import org.gridsuite.study.server.dto.ShortCircuitPredefinedConfiguration; import org.gridsuite.study.server.dto.VoltageLevelInfos; import org.gridsuite.study.server.networkmodificationtree.dto.*; import org.gridsuite.study.server.notification.NotificationService; -import org.gridsuite.study.server.repository.ShortCircuitParametersEntity; import org.gridsuite.study.server.repository.StudyEntity; import org.gridsuite.study.server.repository.StudyRepository; import org.gridsuite.study.server.repository.nonevacuatedenergy.NonEvacuatedEnergyParametersEntity; import org.gridsuite.study.server.service.*; -import org.gridsuite.study.server.service.shortcircuit.ShortCircuitService; import org.gridsuite.study.server.utils.MatcherJson; import org.gridsuite.study.server.utils.TestUtils; import org.gridsuite.study.server.utils.WireMockUtils; @@ -544,10 +541,9 @@ public void testDiagramsVariantError() throws Exception { } private StudyEntity insertDummyStudy(UUID networkUuid, UUID caseUuid) { - ShortCircuitParametersEntity defaultShortCircuitParametersEntity = ShortCircuitService.toEntity(ShortCircuitService.getDefaultShortCircuitParameters(), ShortCircuitPredefinedConfiguration.ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP); NonEvacuatedEnergyParametersEntity defaultNonEvacuatedEnergyParametersEntity = NonEvacuatedEnergyService.toEntity(NonEvacuatedEnergyService.getDefaultNonEvacuatedEnergyParametersInfos()); StudyEntity studyEntity = TestUtils.createDummyStudy(networkUuid, caseUuid, "", - LOADFLOW_PARAMETERS_UUID, defaultShortCircuitParametersEntity, null, null, null, + LOADFLOW_PARAMETERS_UUID, null, null, null, null, defaultNonEvacuatedEnergyParametersEntity, false); var study = studyRepository.save(studyEntity); networkModificationTreeService.createRoot(studyEntity, null); diff --git a/src/test/java/org/gridsuite/study/server/StateEstimationTest.java b/src/test/java/org/gridsuite/study/server/StateEstimationTest.java index dbfabd1a6..99b327957 100644 --- a/src/test/java/org/gridsuite/study/server/StateEstimationTest.java +++ b/src/test/java/org/gridsuite/study/server/StateEstimationTest.java @@ -17,22 +17,15 @@ import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; -import org.gridsuite.study.server.dto.ShortCircuitPredefinedConfiguration; import org.gridsuite.study.server.networkmodificationtree.dto.InsertMode; import org.gridsuite.study.server.networkmodificationtree.dto.NetworkModificationNode; import org.gridsuite.study.server.networkmodificationtree.dto.RootNode; import org.gridsuite.study.server.notification.NotificationService; -import org.gridsuite.study.server.repository.ShortCircuitParametersEntity; import org.gridsuite.study.server.repository.StudyEntity; import org.gridsuite.study.server.repository.StudyRepository; import org.gridsuite.study.server.repository.networkmodificationtree.NetworkModificationNodeInfoRepository; import org.gridsuite.study.server.repository.nonevacuatedenergy.NonEvacuatedEnergyParametersEntity; -import org.gridsuite.study.server.service.NetworkModificationTreeService; -import org.gridsuite.study.server.service.NonEvacuatedEnergyService; -import org.gridsuite.study.server.service.ReportService; -import org.gridsuite.study.server.service.StateEstimationService; -import org.gridsuite.study.server.service.UserAdminService; -import org.gridsuite.study.server.service.shortcircuit.ShortCircuitService; +import org.gridsuite.study.server.service.*; import org.gridsuite.study.server.utils.TestUtils; import org.gridsuite.study.server.utils.elasticsearch.DisableElasticsearch; import org.jetbrains.annotations.NotNull; @@ -63,13 +56,8 @@ import static org.gridsuite.study.server.dto.ComputationType.STATE_ESTIMATION; import static org.gridsuite.study.server.notification.NotificationService.HEADER_UPDATE_TYPE; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; +import static org.junit.Assert.*; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -233,11 +221,10 @@ private void checkUpdateModelStatusMessagesReceived(UUID studyUuid, String updat } private StudyNodeIds createStudyAndNode(String variantId, String nodeName) throws Exception { - ShortCircuitParametersEntity defaultShortCircuitParametersEntity = ShortCircuitService.toEntity(ShortCircuitService.getDefaultShortCircuitParameters(), ShortCircuitPredefinedConfiguration.ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP); NonEvacuatedEnergyParametersEntity defaultNonEvacuatedEnergyParametersEntity = NonEvacuatedEnergyService.toEntity(NonEvacuatedEnergyService.getDefaultNonEvacuatedEnergyParametersInfos()); // create a study StudyEntity studyEntity = TestUtils.createDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_LOADFLOW_UUID, "", - LOADFLOW_PARAMETERS_UUID, defaultShortCircuitParametersEntity, null, null, + LOADFLOW_PARAMETERS_UUID, null, null, null, defaultNonEvacuatedEnergyParametersEntity); studyRepository.save(studyEntity); networkModificationTreeService.createRoot(studyEntity, null); diff --git a/src/test/java/org/gridsuite/study/server/StudyServiceTest.java b/src/test/java/org/gridsuite/study/server/StudyServiceTest.java index 48fac3ce1..f09509b1d 100644 --- a/src/test/java/org/gridsuite/study/server/StudyServiceTest.java +++ b/src/test/java/org/gridsuite/study/server/StudyServiceTest.java @@ -21,6 +21,7 @@ import org.gridsuite.study.server.service.LoadFlowService; import org.gridsuite.study.server.service.NetworkConversionService; import org.gridsuite.study.server.service.NetworkModificationTreeService; +import org.gridsuite.study.server.service.shortcircuit.ShortCircuitService; import org.gridsuite.study.server.utils.SendInput; import org.gridsuite.study.server.utils.TestUtils; import org.gridsuite.study.server.utils.WireMockUtils; @@ -99,6 +100,7 @@ public class StudyServiceTest { private static final String USER_ID_HEADER = "userId"; private static final String HEADER_UPDATE_TYPE = "updateType"; private static final UUID LOADFLOW_PARAMETERS_UUID = UUID.fromString("0c0f1efd-bd22-4a75-83d3-9e530245c7f4"); + private static final UUID SHORTCIRCUIT_PARAMETERS_UUID = UUID.fromString("00000000-bd22-4a75-83d3-9e530245c7f4"); @Autowired private StudyRepository studyRepository; @@ -112,6 +114,9 @@ public class StudyServiceTest { @MockBean private LoadFlowService loadFlowService; + @MockBean + private ShortCircuitService shortCircuitService; + @Before public void setup() throws IOException { wireMockServer = new WireMockServer(wireMockConfig().dynamicPort().extensions(new SendInput(input))); @@ -276,6 +281,7 @@ private UUID createStudy(String userId, UUID caseUuid, Map impor UUID disableCaseExpirationStubId = wireMockUtils.stubDisableCaseExpiration(caseUuid.toString()); when(loadFlowService.createDefaultLoadFlowParameters()).thenReturn(LOADFLOW_PARAMETERS_UUID); + when(shortCircuitService.createParameters(null)).thenReturn(SHORTCIRCUIT_PARAMETERS_UUID); MvcResult result = mockMvc.perform(post("/v1/studies/cases/{caseUuid}", caseUuid) .header("userId", userId) diff --git a/src/test/java/org/gridsuite/study/server/StudyTest.java b/src/test/java/org/gridsuite/study/server/StudyTest.java index 9ec15469b..714a5fdb0 100644 --- a/src/test/java/org/gridsuite/study/server/StudyTest.java +++ b/src/test/java/org/gridsuite/study/server/StudyTest.java @@ -41,11 +41,11 @@ import org.gridsuite.study.server.networkmodificationtree.dto.*; import org.gridsuite.study.server.networkmodificationtree.entities.NodeEntity; import org.gridsuite.study.server.notification.NotificationService; -import org.gridsuite.study.server.notification.dto.NetworkImpactsInfos; import org.gridsuite.study.server.repository.StudyCreationRequestRepository; import org.gridsuite.study.server.repository.StudyEntity; import org.gridsuite.study.server.repository.StudyRepository; import org.gridsuite.study.server.service.*; +import org.gridsuite.study.server.service.shortcircuit.ShortCircuitService; import org.gridsuite.study.server.utils.*; import org.gridsuite.study.server.utils.elasticsearch.DisableElasticsearch; import org.jetbrains.annotations.NotNull; @@ -108,21 +108,18 @@ * @author Abdelsalem Hedhili * @author Franck Lecuyer */ - @RunWith(SpringRunner.class) @AutoConfigureMockMvc @SpringBootTest @DisableElasticsearch @ContextConfigurationWithTestChannel public class StudyTest { - private static final Logger LOGGER = LoggerFactory.getLogger(StudyTest.class); @Autowired private MockMvc mockMvc; private static final String FIRST_VARIANT_ID = "first_variant_id"; - private static final long TIMEOUT = 1000; private static final String STUDIES_URL = "/v1/studies"; private static final String TEST_FILE_UCTE = "testCase.ucte"; @@ -151,8 +148,8 @@ public class StudyTest { private static final ReportNode ROOT_REPORT_TEST = ReportNode.newRootReportNode().withMessageTemplate(REPORT_UUID.toString(), REPORT_UUID.toString()).build(); private static final ReportNode REPORT_TEST = ReportNode.newRootReportNode().withMessageTemplate("test", "test").build(); private static final String VARIANT_ID = "variant_1"; - public static final String POST = "POST"; - public static final String DELETE = "DELETE"; + private static final String POST = "POST"; + private static final String DELETE = "DELETE"; private static final String VARIANT_ID_2 = "variant_2"; private static final String VARIANT_ID_3 = "variant_3"; private static final String MODIFICATION_UUID = "796719f5-bd31-48be-be46-ef7b96951e32"; @@ -222,6 +219,9 @@ public class StudyTest { @Autowired private LoadFlowService loadflowService; + @Autowired + private ShortCircuitService shortCircuitService; + @Autowired private StateEstimationService stateEstimationService; @@ -304,8 +304,7 @@ private void initMockBeans(Network network) { doNothing().when(networkStoreService).deleteNetwork(NETWORK_UUID); } - private void initMockBeansNetworkNotExisting(Network notExistingNetwork) { - + private void initMockBeansNetworkNotExisting() { when(networkStoreService.cloneNetwork(NOT_EXISTING_NETWORK_UUID, Collections.emptyList())).thenThrow(new PowsyblException("Network " + NOT_EXISTING_NETWORK_UUID + " not found")); when(networkStoreService.getNetwork(NOT_EXISTING_NETWORK_UUID)).thenThrow(new PowsyblException("Network " + NOT_EXISTING_NETWORK_UUID + " not found")); when(networkStoreService.getNetwork(NOT_EXISTING_NETWORK_UUID, PreloadingStrategy.COLLECTION)).thenThrow(new PowsyblException("Network " + NOT_EXISTING_NETWORK_UUID + " not found")); @@ -332,7 +331,7 @@ public void setup() throws IOException { Network notExistingNetwork = new XMLImporter().importData(dataSource, new NetworkFactoryImpl(), null); notExistingNetwork.getVariantManager().cloneVariant(VariantManagerConstants.INITIAL_VARIANT_ID, VARIANT_ID); notExistingNetwork.getVariantManager().setWorkingVariant(VariantManagerConstants.INITIAL_VARIANT_ID); - initMockBeansNetworkNotExisting(notExistingNetwork); + initMockBeansNetworkNotExisting(); server = new MockWebServer(); wireMockServer = new WireMockServer(wireMockConfig().dynamicPort().extensions(new SendInput(input))); @@ -355,6 +354,7 @@ public void setup() throws IOException { sensitivityAnalysisService.setSensitivityAnalysisServerBaseUri(baseUrl); voltageInitService.setVoltageInitServerBaseUri(baseUrl); loadflowService.setLoadFlowServerBaseUri(baseUrl); + shortCircuitService.setShortCircuitServerBaseUri(baseUrl); stateEstimationService.setStateEstimationServerServerBaseUri(baseUrl); String baseUrlWireMock = wireMockServer.baseUrl(); @@ -453,7 +453,7 @@ public MockResponse dispatch(RecordedRequest request) { countDownLatch.await(); sendCaseImportSucceededMessage(path, NETWORK_INFOS, "XIIDM"); } catch (Exception e) { - System.err.println(e); + LOGGER.error("Error while waiting", e); } }).start(); return new MockResponse().setResponseCode(200); @@ -475,7 +475,7 @@ public MockResponse dispatch(RecordedRequest request) { countDownLatch.await(); sendCaseImportSucceededMessage(path, NETWORK_INFOS, "XIIDM"); } catch (Exception e) { - System.err.println(e); + LOGGER.error("Error while waiting", e); } }).start(); return new MockResponse().setResponseCode(200); @@ -494,8 +494,6 @@ public MockResponse dispatch(RecordedRequest request) { } else { return new MockResponse().setResponseCode(200).addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).setBody(mapper.writeValueAsString(UUID.randomUUID())); } - } else if (path.matches("/v1/parameters/default") && POST.equals(request.getMethod())) { - return new MockResponse().setResponseCode(200).addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).setBody(mapper.writeValueAsString(UUID.randomUUID())); } else if (path.matches("/v1/parameters/.*") && DELETE.equals(request.getMethod())) { return new MockResponse().setResponseCode(200); } else if (path.matches("/v1/parameters/.*/provider")) { @@ -650,7 +648,7 @@ public MockResponse dispatch(RecordedRequest request) { case "/v1/networks/" + NETWORK_UUID_STRING + "/" + VARIANT_ID_3: return new MockResponse().setResponseCode(200); default: - LOGGER.error("Unhandled method+path: " + request.getMethod() + " " + request.getPath()); + LOGGER.error("Unhandled method+path: {} {}", request.getMethod(), request.getPath()); return new MockResponse().setResponseCode(418).setBody("Unhandled method+path: " + request.getMethod() + " " + request.getPath()); } } @@ -1055,7 +1053,7 @@ private UUID createStudy(String userId, UUID caseUuid, String parameterDuplicate assertStudyCreation(studyUuid, userId); // assert that all http requests have been sent to remote services - int nbRequest = 7; + int nbRequest = 8; if (parameterDuplicatedUuid != null && !parameterDuplicationSuccess) { nbRequest++; } @@ -1086,15 +1084,17 @@ protected UUID createStudyWithImportParameters(String userId, UUID caseUuid, Str assertStudyCreation(studyUuid, userId); // assert that all http requests have been sent to remote services - Set requests = TestUtils.getRequestsWithBodyDone(7, server); + Set requests = TestUtils.getRequestsWithBodyDone(8, server); assertTrue(requests.stream().anyMatch(r -> r.getPath().matches(String.format("/v1/cases/%s/exists", caseUuid)))); assertTrue(requests.stream().anyMatch(r -> r.getPath().matches("/v1/networks\\?caseUuid=" + caseUuid + "&variantId=" + FIRST_VARIANT_ID + "&reportUuid=.*"))); assertTrue(requests.stream().anyMatch(r -> r.getPath().matches(String.format("/v1/cases/%s/disableExpiration", caseUuid)))); assertTrue(requests.stream().anyMatch(r -> r.getPath().matches("/v1/parameters/default"))); - assertEquals(mapper.writeValueAsString(importParameters), - requests.stream().filter(r -> r.getPath().matches("/v1/networks\\?caseUuid=" + caseUuid + "&variantId=" + FIRST_VARIANT_ID + "&reportUuid=.*")) - .findFirst().orElseThrow().getBody()); + assertEquals(mapper.writeValueAsString(importParameters), requests.stream() + .filter(r -> r.getPath().matches("/v1/networks\\?caseUuid=" + caseUuid + "&variantId=" + FIRST_VARIANT_ID + "&reportUuid=.*")) + .findFirst() + .orElseThrow() + .getBody()); return studyUuid; } @@ -1112,7 +1112,7 @@ private UUID createStudyWithDuplicateCase(String userId, UUID caseUuid) throws E assertStudyCreation(studyUuid, userId); // assert that all http requests have been sent to remote services - var requests = TestUtils.getRequestsDone(8, server); + var requests = TestUtils.getRequestsDone(9, server); assertTrue(requests.contains(String.format("/v1/cases/%s/exists", caseUuid))); assertTrue(requests.contains(String.format("/v1/cases?duplicateFrom=%s&withExpiration=%s", caseUuid, true))); // note : it's a new case UUID @@ -1331,7 +1331,7 @@ public void testGetStudyCreationRequests() throws Exception { csbiListResponse = mapper.readValue(resultAsString, new TypeReference>() { }); // assert that all http requests have been sent to remote services - var requests = TestUtils.getRequestsDone(7, server); + var requests = TestUtils.getRequestsDone(8, server); assertTrue(requests.contains(String.format("/v1/cases/%s/exists", NEW_STUDY_CASE_UUID))); assertTrue(requests.stream().anyMatch(r -> r.matches("/v1/networks\\?caseUuid=" + NEW_STUDY_CASE_UUID + "&variantId=" + FIRST_VARIANT_ID + "&reportUuid=.*"))); assertTrue(requests.contains(String.format("/v1/cases/%s/disableExpiration", NEW_STUDY_CASE_UUID))); @@ -1372,21 +1372,6 @@ private void checkNodeBuildStatusUpdatedMessageReceived(UUID studyUuid, List messageStudyUpdate = output.receive(TIMEOUT, studyUpdateDestination); - NetworkImpactsInfos actualPayload = mapper.readValue(new String(messageStudyUpdate.getPayload()), new TypeReference() { - }); - assertThat(expectedPayload, new MatcherJson<>(mapper, actualPayload)); - MessageHeaders headersStudyUpdate = messageStudyUpdate.getHeaders(); - assertEquals(studyNameUserIdUuid, headersStudyUpdate.get(NotificationService.HEADER_STUDY_UUID)); - assertEquals(nodeUuid, headersStudyUpdate.get(NotificationService.HEADER_NODE)); - assertEquals(NotificationService.UPDATE_TYPE_STUDY, headersStudyUpdate.get(NotificationService.HEADER_UPDATE_TYPE)); - - checkNodeBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(nodeUuid)); - checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, nodeUuid); - } - private void checkEquipmentCreatingMessagesReceived(UUID studyNameUserIdUuid, UUID nodeUuid) { // assert that the broker message has been sent for updating study type Message messageStudyUpdate = output.receive(TIMEOUT, studyUpdateDestination); @@ -1415,10 +1400,6 @@ private void checkStudyMetadataUpdatedMessagesReceived() { assertEquals(NotificationService.UPDATE_TYPE_STUDY_METADATA_UPDATED, headersStudyUpdate.get(NotificationService.HEADER_UPDATE_TYPE)); } - private void checkEquipmentCreationMessagesReceived(UUID studyNameUserIdUuid, UUID nodeUuid, NetworkImpactsInfos expectedPayload) throws Exception { - checkEquipmentMessagesReceived(studyNameUserIdUuid, nodeUuid, expectedPayload); - } - @Test public void testCreateStudyWithDefaultLoadflow() throws Exception { createStudy("userId", CASE_UUID); @@ -1492,7 +1473,7 @@ private void testDuplicateStudy(UUID study1Uuid) throws Exception { checkElementUpdatedMessageSent(study1Uuid, userId); // duplicate the study - StudyEntity duplicatedStudy = duplicateStudy(study1Uuid, userId, "UCTE"); + StudyEntity duplicatedStudy = duplicateStudy(study1Uuid); assertNotEquals(study1Uuid, duplicatedStudy.getId()); //Test duplication from a non existing source study @@ -1546,7 +1527,7 @@ public void testDuplicateStudyWithErrorDuringCaseDuplication() throws Exception assertNull(studyRepository.findById(UUID.fromString(duplicatedStudyUuid)).orElse(null)); } - private StudyEntity duplicateStudy(UUID studyUuid, String userId, String caseFormat) throws Exception { + private StudyEntity duplicateStudy(UUID studyUuid) throws Exception { UUID stubUuid = wireMockUtils.stubDuplicateModificationGroup(); String response = mockMvc.perform(post(STUDIES_URL + "?duplicateFrom={studyUuid}", studyUuid) .header(USER_ID_HEADER, "userId")) @@ -1620,6 +1601,12 @@ private StudyEntity duplicateStudy(UUID studyUuid, String userId, String caseFor assertNotNull(duplicatedStudy.getLoadFlowParametersUuid()); numberOfRequests++; } + if (sourceStudy.getShortCircuitParametersUuid() == null) { + assertNull(duplicatedStudy.getShortCircuitParametersUuid()); + } else { + assertNotNull(duplicatedStudy.getShortCircuitParametersUuid()); + numberOfRequests++; + } requests = TestUtils.getRequestsWithBodyDone(numberOfRequests, server); assertEquals(1, requests.stream().filter(r -> r.getPath().matches("/v1/networks/" + duplicatedStudy.getNetworkUuid() + "/reindex-all")).count()); assertEquals(1, requests.stream().filter(r -> r.getPath().matches("/v1/cases\\?duplicateFrom=.*&withExpiration=false")).count()); @@ -1629,6 +1616,9 @@ private StudyEntity duplicateStudy(UUID studyUuid, String userId, String caseFor if (sourceStudy.getLoadFlowParametersUuid() != null) { assertEquals(1, requests.stream().filter(r -> r.getPath().matches("/v1/parameters\\?duplicateFrom=" + sourceStudy.getLoadFlowParametersUuid())).count()); } + if (sourceStudy.getShortCircuitParametersUuid() != null) { + assertEquals(1, requests.stream().filter(r -> r.getPath().matches("/v1/parameters\\?duplicateFrom=" + sourceStudy.getShortCircuitParametersUuid())).count()); + } if (sourceStudy.getSecurityAnalysisParametersUuid() != null) { assertEquals(1, requests.stream().filter(r -> r.getPath().matches("/v1/parameters\\?duplicateFrom=" + sourceStudy.getSecurityAnalysisParametersUuid())).count()); } diff --git a/src/test/java/org/gridsuite/study/server/VoltageInitTest.java b/src/test/java/org/gridsuite/study/server/VoltageInitTest.java index 891b3165f..ed6ebb894 100644 --- a/src/test/java/org/gridsuite/study/server/VoltageInitTest.java +++ b/src/test/java/org/gridsuite/study/server/VoltageInitTest.java @@ -23,7 +23,6 @@ import okhttp3.mockwebserver.RecordedRequest; import org.gridsuite.study.server.dto.NodeReceiver; import org.gridsuite.study.server.dto.impacts.SimpleElementImpact.SimpleImpactType; -import org.gridsuite.study.server.dto.ShortCircuitPredefinedConfiguration; import org.gridsuite.study.server.dto.modification.NetworkModificationResult; import org.gridsuite.study.server.dto.voltageinit.parameters.FilterEquipments; import org.gridsuite.study.server.dto.voltageinit.parameters.StudyVoltageInitParameters; @@ -33,7 +32,6 @@ import org.gridsuite.study.server.notification.NotificationService; import org.gridsuite.study.server.notification.dto.AlertLevel; import org.gridsuite.study.server.notification.dto.StudyAlert; -import org.gridsuite.study.server.repository.ShortCircuitParametersEntity; import org.gridsuite.study.server.repository.StudyEntity; import org.gridsuite.study.server.repository.StudyRepository; import org.gridsuite.study.server.repository.networkmodificationtree.NetworkModificationNodeInfoRepository; @@ -717,10 +715,9 @@ public void testNoResult() throws Exception { } private StudyEntity insertDummyStudy(UUID networkUuid, UUID caseUuid, UUID voltageInitParametersUuid, boolean applyModifications) { - ShortCircuitParametersEntity defaultShortCircuitParametersEntity = ShortCircuitService.toEntity(ShortCircuitService.getDefaultShortCircuitParameters(), ShortCircuitPredefinedConfiguration.ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP); NonEvacuatedEnergyParametersEntity defaultNonEvacuatedEnergyParametersEntity = NonEvacuatedEnergyService.toEntity(NonEvacuatedEnergyService.getDefaultNonEvacuatedEnergyParametersInfos()); StudyEntity studyEntity = TestUtils.createDummyStudy(networkUuid, caseUuid, "", - UUID.randomUUID(), defaultShortCircuitParametersEntity, voltageInitParametersUuid, null, null, + UUID.randomUUID(), null, voltageInitParametersUuid, null, null, defaultNonEvacuatedEnergyParametersEntity, applyModifications); var study = studyRepository.save(studyEntity); networkModificationTreeService.createRoot(studyEntity, null); diff --git a/src/test/java/org/gridsuite/study/server/repository/RepositoriesTest.java b/src/test/java/org/gridsuite/study/server/repository/RepositoriesTest.java index c0d016614..d8e3fee80 100644 --- a/src/test/java/org/gridsuite/study/server/repository/RepositoriesTest.java +++ b/src/test/java/org/gridsuite/study/server/repository/RepositoriesTest.java @@ -6,10 +6,6 @@ */ package org.gridsuite.study.server.repository; -import com.powsybl.shortcircuit.InitialVoltageProfileMode; -import com.powsybl.shortcircuit.StudyType; -import lombok.SneakyThrows; -import org.gridsuite.study.server.dto.ShortCircuitPredefinedConfiguration; import org.gridsuite.study.server.utils.elasticsearch.DisableElasticsearch; import org.junit.After; import org.junit.Test; @@ -19,20 +15,19 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; -import java.util.*; - -import static org.junit.Assert.*; +import java.util.Map; +import java.util.UUID; +import static org.assertj.core.api.Assertions.*; +import static org.junit.Assert.assertEquals; /** * @author Chamseddine Benhamed */ - @RunWith(SpringRunner.class) @SpringBootTest @DisableElasticsearch public class RepositoriesTest { - @Autowired StudyRepository studyRepository; @@ -52,110 +47,61 @@ public void tearDown() { @Test @Transactional public void testStudyRepository() { - Set countriesTemp = new HashSet<>(); - countriesTemp.add("FR"); - - ShortCircuitParametersEntity shortCircuitParametersEntity = new ShortCircuitParametersEntity(false, false, false, false, StudyType.TRANSIENT, 1, false, false, false, false, InitialVoltageProfileMode.NOMINAL, ShortCircuitPredefinedConfiguration.ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP); - - countriesTemp.add("IT"); + UUID shortCircuitParametersUuid1 = UUID.randomUUID(); + UUID shortCircuitParametersUuid2 = UUID.randomUUID(); + UUID shortCircuitParametersUuid3 = UUID.randomUUID(); - ShortCircuitParametersEntity shortCircuitParametersEntity2 = new ShortCircuitParametersEntity(true, true, false, true, StudyType.STEADY_STATE, 0, false, false, false, false, InitialVoltageProfileMode.NOMINAL, ShortCircuitPredefinedConfiguration.ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP); - - countriesTemp.add("DE"); - - ShortCircuitParametersEntity shortCircuitParametersEntity3 = new ShortCircuitParametersEntity(true, false, false, true, StudyType.SUB_TRANSIENT, 10, false, false, false, false, InitialVoltageProfileMode.NOMINAL, ShortCircuitPredefinedConfiguration.ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP); - - StudyEntity studyEntity1 = StudyEntity.builder() + StudyEntity studyEntity1 = studyRepository.save(StudyEntity.builder() .id(UUID.randomUUID()) .networkUuid(UUID.randomUUID()) .networkId("networkId") .caseFormat("caseFormat") .caseUuid(UUID.randomUUID()) - .shortCircuitParameters(shortCircuitParametersEntity) - .build(); + .shortCircuitParametersUuid(shortCircuitParametersUuid1) + .build()); - StudyEntity studyEntity2 = StudyEntity.builder() + StudyEntity studyEntity2 = studyRepository.save(StudyEntity.builder() .id(UUID.randomUUID()) .networkUuid(UUID.randomUUID()) .networkId("networkId2") .caseFormat("caseFormat2") .caseUuid(UUID.randomUUID()) - .shortCircuitParameters(shortCircuitParametersEntity2) - .build(); + .shortCircuitParametersUuid(shortCircuitParametersUuid2) + .build()); - StudyEntity studyEntity3 = StudyEntity.builder() + studyRepository.save(StudyEntity.builder() .id(UUID.randomUUID()) .networkUuid(UUID.randomUUID()) .networkId("networkId3") .caseFormat("caseFormat3") .caseUuid(UUID.randomUUID()) - .shortCircuitParameters(shortCircuitParametersEntity3) - .build(); - - studyRepository.save(studyEntity1); - studyRepository.save(studyEntity2); - studyRepository.save(studyEntity3); - - List findAllStudies = studyRepository.findAll(); - assertEquals(3, findAllStudies.size()); + .shortCircuitParametersUuid(shortCircuitParametersUuid3) + .build()); - StudyEntity savedStudyEntity1 = findAllStudies.stream().filter(e -> studyEntity1.getId() != null && studyEntity1.getId().equals(e.getId())).findFirst().orElse(null); - StudyEntity savedStudyEntity2 = findAllStudies.stream().filter(e -> studyEntity2.getId() != null && studyEntity2.getId().equals(e.getId())).findFirst().orElse(null); - - assertNotNull(savedStudyEntity1); - assertNotNull(savedStudyEntity2); + assertThat(studyEntity1).as("studyEntity1").extracting(StudyEntity::getId).isNotNull(); + assertThat(studyEntity2).as("studyEntity2").extracting(StudyEntity::getId).isNotNull(); + assertThat(studyRepository.findAll()).as("studyRepository").hasSize(3) + .anyMatch(se -> studyEntity1.getId().equals(se.getId())) + .anyMatch(se -> studyEntity2.getId().equals(se.getId())); // updates - savedStudyEntity1.setShortCircuitParameters(shortCircuitParametersEntity); - studyRepository.save(savedStudyEntity1); - - StudyEntity savedStudyEntity1Updated = studyRepository.findById(studyEntity1.getId()).get(); - assertNotNull(savedStudyEntity1Updated.getShortCircuitParameters()); - - studyRepository.save(savedStudyEntity1Updated); - savedStudyEntity1Updated = studyRepository.findById(studyEntity1.getId()).get(); - assertNotNull(savedStudyEntity1Updated); + final UUID newShortCircuitParametersUuid = UUID.randomUUID(); + studyEntity1.setShortCircuitParametersUuid(newShortCircuitParametersUuid); + studyRepository.save(studyEntity1); + assertThat(studyRepository.findById(studyEntity1.getId())).isPresent().get() + .extracting(StudyEntity::getShortCircuitParametersUuid).isNotNull().isEqualTo(newShortCircuitParametersUuid); } + @Transactional @Test public void testStudyCreationRequest() { UUID studyUuid = UUID.randomUUID(); StudyCreationRequestEntity studyCreationRequestEntity = new StudyCreationRequestEntity(studyUuid); studyCreationRequestRepository.save(studyCreationRequestEntity); - assertEquals(1, studyCreationRequestRepository.findAll().size()); - assertTrue(studyCreationRequestRepository.findById(studyUuid).isPresent()); - } - - @Test - @Transactional - public void testStudyDefaultShortCircuitParameters() { - - StudyEntity studyEntity1 = StudyEntity.builder() - .id(UUID.randomUUID()) - .networkUuid(UUID.randomUUID()) - .networkId("networkId") - .caseFormat("caseFormat") - .caseUuid(UUID.randomUUID()) - .shortCircuitParameters(null) // intentionally set to null - .build(); - - ShortCircuitParametersEntity shortCircuitParamFromEntity1 = studyEntity1.getShortCircuitParameters(); - assertNotNull(shortCircuitParamFromEntity1); - - assertEquals(20., shortCircuitParamFromEntity1.getMinVoltageDropProportionalThreshold(), 0.001); // 20 is the default value - assertEquals(20., studyEntity1.getShortCircuitParameters().getMinVoltageDropProportionalThreshold(), 0.001); - studyEntity1.getShortCircuitParameters().setMinVoltageDropProportionalThreshold(30.); - assertEquals(30., studyEntity1.getShortCircuitParameters().getMinVoltageDropProportionalThreshold(), 0.001); - - studyRepository.save(studyEntity1); - - StudyEntity savedStudyEntity1 = studyRepository.findAll().get(0); - assertNotNull(savedStudyEntity1.getShortCircuitParameters()); - assertEquals(30., savedStudyEntity1.getShortCircuitParameters().getMinVoltageDropProportionalThreshold(), 0.001); + assertThat(studyCreationRequestRepository.findAll()).singleElement().extracting(StudyCreationRequestEntity::getId).isEqualTo(studyUuid); } @Test - @SneakyThrows @Transactional public void testStudyImportParameters() { Map importParametersExpected = Map.of("param1", "changedValue1, changedValue2", "param2", "changedValue"); diff --git a/src/test/java/org/gridsuite/study/server/utils/TestUtils.java b/src/test/java/org/gridsuite/study/server/utils/TestUtils.java index e55299c77..6b1c19cd0 100644 --- a/src/test/java/org/gridsuite/study/server/utils/TestUtils.java +++ b/src/test/java/org/gridsuite/study/server/utils/TestUtils.java @@ -13,36 +13,28 @@ import com.powsybl.commons.exceptions.UncheckedInterruptedException; import com.powsybl.commons.report.ReportNode; import com.powsybl.commons.report.ReportNodeAdder; - import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; import okio.Buffer; -import org.gridsuite.study.server.dto.ShortCircuitPredefinedConfiguration; import org.gridsuite.study.server.networkmodificationtree.dto.BuildStatus; import org.gridsuite.study.server.networkmodificationtree.dto.NetworkModificationNode; import org.gridsuite.study.server.networkmodificationtree.dto.NodeBuildStatus; -import org.gridsuite.study.server.repository.ShortCircuitParametersEntity; import org.gridsuite.study.server.repository.StudyEntity; import org.gridsuite.study.server.repository.nonevacuatedenergy.NonEvacuatedEnergyParametersEntity; import org.gridsuite.study.server.repository.voltageinit.StudyVoltageInitParametersEntity; -import org.gridsuite.study.server.service.shortcircuit.ShortCircuitService; import org.junit.platform.commons.util.StringUtils; import org.springframework.cloud.stream.binder.test.OutputDestination; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; +import java.util.*; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import java.util.stream.IntStream; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -95,7 +87,7 @@ public static Set getRequestsDone(int n, MockWebServer server) throws Un public static StudyEntity createDummyStudy(UUID networkUuid, UUID caseUuid, String caseFormat, UUID loadFlowParametersUuid, - ShortCircuitParametersEntity shortCircuitParametersEntity, + UUID shortCircuitParametersUuid, UUID voltageInitParametersUuid, UUID securityAnalysisParametersUuid, UUID sensitivityParametersUuid, @@ -105,7 +97,7 @@ public static StudyEntity createDummyStudy(UUID networkUuid, UUID caseUuid, Stri .networkId("netId") .networkUuid(networkUuid) .loadFlowParametersUuid(loadFlowParametersUuid) - .shortCircuitParameters(shortCircuitParametersEntity) + .shortCircuitParametersUuid(shortCircuitParametersUuid) .voltageInitParametersUuid(voltageInitParametersUuid) .securityAnalysisParametersUuid(securityAnalysisParametersUuid) .sensitivityAnalysisParametersUuid(sensitivityParametersUuid) @@ -116,7 +108,7 @@ public static StudyEntity createDummyStudy(UUID networkUuid, UUID caseUuid, Stri public static StudyEntity createDummyStudy(UUID networkUuid, UUID caseUuid, String caseFormat, UUID loadFlowParametersUuid, - ShortCircuitParametersEntity shortCircuitParametersEntity, + UUID shortCircuitParametersUuid, UUID securityAnalysisParametersUuid, UUID sensitivityParametersUuid, NonEvacuatedEnergyParametersEntity nonEvacuatedEnergyParametersEntity) { @@ -124,7 +116,7 @@ public static StudyEntity createDummyStudy(UUID networkUuid, UUID caseUuid, Stri .networkId("netId") .networkUuid(networkUuid) .loadFlowParametersUuid(loadFlowParametersUuid) - .shortCircuitParameters(shortCircuitParametersEntity) + .shortCircuitParametersUuid(shortCircuitParametersUuid) .securityAnalysisParametersUuid(securityAnalysisParametersUuid) .sensitivityAnalysisParametersUuid(sensitivityParametersUuid) .nonEvacuatedEnergyParameters(nonEvacuatedEnergyParametersEntity) @@ -132,12 +124,11 @@ public static StudyEntity createDummyStudy(UUID networkUuid, UUID caseUuid, Stri } public static StudyEntity createDummyStudy(UUID networkUuid, UUID caseUuid, String caseName, String caseFormat) { - ShortCircuitParametersEntity defaultShortCircuitParametersEntity = ShortCircuitService.toEntity(ShortCircuitService.getDefaultShortCircuitParameters(), ShortCircuitPredefinedConfiguration.ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP); return StudyEntity.builder().id(UUID.randomUUID()).caseFormat(caseFormat).caseUuid(caseUuid) .caseName(caseName) .networkId("netId") .networkUuid(networkUuid) - .shortCircuitParameters(defaultShortCircuitParametersEntity) + .shortCircuitParametersUuid(UUID.randomUUID()) .build(); }