Skip to content

Commit

Permalink
Fix reactive threshold value when creating default parameters
Browse files Browse the repository at this point in the history
Fix pb when updating with null parameters

Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
  • Loading branch information
FranckLecuyer committed Dec 18, 2024
1 parent cb03a70 commit 1d01ed7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
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

0 comments on commit 1d01ed7

Please sign in to comment.