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

Fix reactive threshold value when creating default parameters #86

Merged
merged 1 commit into from
Dec 18, 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
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public ResponseEntity<List<VoltageInitParametersInfos>> getAllParameters() {
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "parameters were updated")})
public ResponseEntity<Void> updateParameters(
@Parameter(description = "parameters UUID") @PathVariable("uuid") UUID parametersUuid,
@RequestBody VoltageInitParametersInfos parametersInfos) {
@RequestBody(required = false) VoltageInitParametersInfos parametersInfos) {
parametersService.updateParameters(parametersUuid, parametersInfos);
return ResponseEntity.ok().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ public VoltageInitParametersService(VoltageInitParametersRepository voltageInitP
}

public UUID createParameters(VoltageInitParametersInfos parametersInfos) {
return voltageInitParametersRepository.save(parametersInfos != null
? parametersInfos.toEntity()
: new VoltageInitParametersEntity()).getId();
if (parametersInfos != null) {
return voltageInitParametersRepository.save(parametersInfos.toEntity()).getId();
} else {
return voltageInitParametersRepository.save(new VoltageInitParametersEntity(getDefaultParametersInfos())).getId();
}
}

public Optional<UUID> duplicateParameters(UUID sourceParametersId) {
Expand Down Expand Up @@ -94,13 +96,23 @@ public List<VoltageInitParametersInfos> getAllParameters() {

@Transactional
public void updateParameters(UUID parametersUuid, VoltageInitParametersInfos parametersInfos) {
voltageInitParametersRepository.findById(parametersUuid).orElseThrow().update(parametersInfos);
VoltageInitParametersEntity entity = voltageInitParametersRepository.findById(parametersUuid).orElseThrow();
//if the parameters is null it means it's a reset to defaultValues
if (parametersInfos == null) {
entity.update(getDefaultParametersInfos());
} else {
entity.update(parametersInfos);
}
}

public void deleteParameters(UUID parametersUuid) {
voltageInitParametersRepository.deleteById(parametersUuid);
}

private VoltageInitParametersInfos getDefaultParametersInfos() {
return VoltageInitParametersInfos.builder().reactiveSlacksThreshold(DEFAULT_REACTIVE_SLACKS_THRESHOLD).build();
}

private Map<String, VoltageLimitEntity> resolveVoltageLevelLimits(VoltageInitRunContext context, List<VoltageLimitEntity> voltageLimits) {
Map<String, VoltageLimitEntity> voltageLevelLimits = new HashMap<>();
//each voltage level is associated to a voltage limit setting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.List;
import java.util.UUID;

import static org.gridsuite.voltageinit.server.service.parameters.VoltageInitParametersService.DEFAULT_REACTIVE_SLACKS_THRESHOLD;
import static org.gridsuite.voltageinit.utils.assertions.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down Expand Up @@ -82,12 +83,12 @@ void testCreateDefault() throws Exception {
mockMvc.perform(post(URI_PARAMETERS_BASE)).andExpect(status().isOk()).andReturn();
VoltageInitParametersInfos createdParameters = parametersRepository.findAll().get(0).toVoltageInitParametersInfos();
assertNotNull(createdParameters);
assertNull(createdParameters.getVoltageLimitsDefault());
assertTrue(createdParameters.getVoltageLimitsDefault().isEmpty());
assertNull(createdParameters.getVariableShuntCompensators());
assertNull(createdParameters.getVariableTwoWindingsTransformers());
assertNull(createdParameters.getConstantQGenerators());
assertNull(createdParameters.getVoltageLimitsModification());
assertEquals(0., createdParameters.getReactiveSlacksThreshold());
assertTrue(createdParameters.getVoltageLimitsModification().isEmpty());
assertEquals(DEFAULT_REACTIVE_SLACKS_THRESHOLD, createdParameters.getReactiveSlacksThreshold());
assertEquals(0., createdParameters.getShuntCompensatorActivationThreshold());
assertFalse(createdParameters.isUpdateBusVoltage());
}
Expand Down
Loading