Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move shortcircuit parameters #569

Merged
merged 5 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions src/main/java/org/gridsuite/study/server/StudyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <abdelsalem.hedhili at rte-france.com>
Expand Down Expand Up @@ -628,18 +629,14 @@ public ResponseEntity<Void> 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<Void> runShortCircuit(
@PathVariable("studyUuid") UUID studyUuid,
@PathVariable("nodeUuid") UUID nodeUuid,
@RequestParam(value = "busId", required = false) String busId,
@RequestParam(value = "busId", required = false) Optional<String> 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();
}

Expand Down Expand Up @@ -914,22 +911,21 @@ public ResponseEntity<String> 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<Void> 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<ShortCircuitParametersInfos> getShortCircuitParameters(
@PathVariable("studyUuid") UUID studyUuid) {
@ApiResponse(responseCode = "200", description = "The short-circuit analysis parameters return by shortcircuit-server")
public ResponseEntity<String> getShortCircuitParameters(@PathVariable("studyUuid") UUID studyUuid) {
return ResponseEntity.ok().body(studyService.getShortCircuitParametersInfo(studyUuid));
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/gridsuite/study/server/StudyException.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

/**
* @author AJELLAL Ali <ali.ajellal@rte-france.com>
* @deprecated for delete
*/
@Deprecated(forRemoval = true, since = "1.7.0")
public enum ShortCircuitPredefinedConfiguration {
ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP,
ICC_MAX_WITH_CEI909,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,25 @@

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 <abdelsalem.hedhili at rte-france.com>
* @deprecated to remove when the data is migrated into the shortcircuit-server
*/
@Deprecated(forRemoval = true, since = "1.7.0")
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Getter
@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,7 +20,6 @@
* @author Abdelsalem Hedhili <abdelsalem.hedhili at rte-france.com>
* @author Chamseddine Benhamed <chamseddine.benhamed at rte-france.com>
*/

@NoArgsConstructor
@AllArgsConstructor
@Getter
Expand Down Expand Up @@ -102,6 +98,10 @@ public class StudyEntity extends AbstractManuallyAssignedIdentifierEntity<UUID>
))
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",
Expand All @@ -110,6 +110,9 @@ public class StudyEntity extends AbstractManuallyAssignedIdentifierEntity<UUID>
))
private ShortCircuitParametersEntity shortCircuitParameters;

@Column(name = "shortCircuitParametersUuid")
private UUID shortCircuitParametersUuid;

@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
@JoinColumn(name = "dynamicSimulationParametersEntity_id",
referencedColumnName = "id",
Expand Down Expand Up @@ -180,13 +183,6 @@ public class StudyEntity extends AbstractManuallyAssignedIdentifierEntity<UUID>
))
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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,
Expand All @@ -75,6 +75,7 @@ public ConsumerService(ObjectMapper objectMapper,
SecurityAnalysisService securityAnalysisService,
CaseService caseService,
LoadFlowService loadFlowService,
ShortCircuitService shortCircuitService,
UserAdminService userAdminService,
NetworkModificationTreeService networkModificationTreeService,
SensitivityAnalysisService sensitivityAnalysisService,
Expand All @@ -89,6 +90,7 @@ public ConsumerService(ObjectMapper objectMapper,
this.networkModificationTreeService = networkModificationTreeService;
this.sensitivityAnalysisService = sensitivityAnalysisService;
this.studyRepository = studyRepository;
this.shortCircuitService = shortCircuitService;
}

@Bean
Expand Down Expand Up @@ -183,10 +185,9 @@ public Consumer<Message<String>> 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;
}

Expand All @@ -198,23 +199,21 @@ public Consumer<Message<String>> 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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -499,15 +516,6 @@ public Consumer<Message<String>> 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<Message<String>> consumeStateEstimationResult() {
return message -> consumeCalculationResult(message, STATE_ESTIMATION);
Expand Down
Loading
Loading