From fb204dac489332958223c3cfd77d5a9f27d1a54a Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Tue, 26 Dec 2023 09:33:19 +0100 Subject: [PATCH 01/20] Add loadflow parameters controller Signed-off-by: Ayoub LABIDI --- .../loadflow/server/LoadFlowController.java | 11 +- .../server/LoadFlowParametersController.java | 82 +++++++ .../parameters/LoadFlowParametersInfos.java | 39 ++++ .../LoadFlowParametersValues.java} | 6 +- .../LoadFlowSpecificParameterInfos.java | 24 +++ .../parameters/LoadFlowParametersEntity.java | 202 ++++++++++++++++++ .../LoadFlowSpecificParameterEntity.java | 64 ++++++ .../LoadFlowParametersRepository.java | 21 ++ .../server/service/LoadFlowResultContext.java | 7 +- .../server/service/LoadFlowRunContext.java | 6 +- .../parameters/LoadFlowParametersService.java | 57 +++++ .../changesets/changelog_20231225T122756Z.xml | 55 +++++ .../db/changelog/db.changelog-master.yaml | 4 + .../server/LoadFlowControllerTest.java | 4 +- 14 files changed, 567 insertions(+), 15 deletions(-) create mode 100644 src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java create mode 100644 src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersInfos.java rename src/main/java/org/gridsuite/loadflow/server/dto/{LoadFlowParametersInfos.java => parameters/LoadFlowParametersValues.java} (80%) create mode 100644 src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowSpecificParameterInfos.java create mode 100644 src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java create mode 100644 src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowSpecificParameterEntity.java create mode 100644 src/main/java/org/gridsuite/loadflow/server/repositories/parameters/LoadFlowParametersRepository.java create mode 100644 src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java create mode 100644 src/main/resources/db/changelog/changesets/changelog_20231225T122756Z.xml diff --git a/src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java b/src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java index 33082e22..8f0fbc00 100644 --- a/src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java +++ b/src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java @@ -12,11 +12,11 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; import org.gridsuite.loadflow.server.dto.LimitViolationInfos; -import org.gridsuite.loadflow.server.dto.LoadFlowParametersInfos; import org.gridsuite.loadflow.server.dto.LoadFlowResult; import org.gridsuite.loadflow.server.dto.LoadFlowStatus; import org.gridsuite.loadflow.server.service.LoadFlowRunContext; import org.gridsuite.loadflow.server.service.LoadFlowService; +import org.gridsuite.loadflow.server.service.parameters.LoadFlowParametersService; import org.gridsuite.loadflow.server.utils.ReportContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; @@ -42,6 +42,9 @@ public class LoadFlowController { @Autowired private LoadFlowService loadFlowService; + @Autowired + private LoadFlowParametersService parametersService; + @PostMapping(value = "/networks/{networkUuid}/run-and-save", produces = APPLICATION_JSON_VALUE) @Operation(summary = "Run a load flow on a network") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The load flow has been performed")}) @@ -53,8 +56,8 @@ public ResponseEntity run(@Parameter(description = "Network UUID") @PathVa @Parameter(description = "reporterId") @RequestParam(name = "reporterId", required = false) String reportName, @Parameter(description = "The type name for the report") @RequestParam(name = "reportType", required = false, defaultValue = "LoadFlow") String reportType, @Parameter(description = "The limit reduction") @RequestParam(name = "limitReduction", required = false, defaultValue = "0.8F") Float limitReduction, - @RequestHeader(HEADER_USER_ID) String userId, - @RequestBody(required = false) LoadFlowParametersInfos loadflowParams + @Parameter(description = "parametersUuid") @RequestParam(name = "parametersUuid", required = false) UUID parametersUuid, + @RequestHeader(HEADER_USER_ID) String userId ) { String providerToUse = provider != null ? provider : loadFlowService.getDefaultProvider(); LoadFlowRunContext loadFlowRunContext = LoadFlowRunContext.builder() @@ -62,7 +65,7 @@ public ResponseEntity run(@Parameter(description = "Network UUID") @PathVa .variantId(variantId) .receiver(receiver) .provider(providerToUse) - .parameters(loadflowParams) + .parameters(parametersService.getParametersValues(parametersUuid, providerToUse)) .reportContext(ReportContext.builder().reportId(reportId).reportName(reportName).reportType(reportType).build()) .userId(userId) .limitReduction(limitReduction) diff --git a/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java b/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java new file mode 100644 index 00000000..d80a9d89 --- /dev/null +++ b/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java @@ -0,0 +1,82 @@ +/** + * 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.loadflow.server; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; + +import org.gridsuite.loadflow.server.dto.parameters.LoadFlowParametersInfos; +import org.gridsuite.loadflow.server.service.parameters.LoadFlowParametersService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.UUID; + +/** + * @author Ayoub LABIDI + */ +@RestController +@RequestMapping(value = "/" + LoadFlowApi.API_VERSION + "/parameters") +@Tag(name = "Voltage init parameters") +public class LoadFlowParametersController { + + @Autowired + private LoadFlowParametersService parametersService; + + @PostMapping(value = "", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + @Operation(summary = "Create parameters") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "parameters were created")}) + public ResponseEntity createParameters( + @RequestBody LoadFlowParametersInfos parametersInfos) { + return ResponseEntity.ok().body(parametersService.createParameters(parametersInfos)); + } + + @GetMapping(value = "/{uuid}", produces = MediaType.APPLICATION_JSON_VALUE) + @Operation(summary = "Get parameters") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "parameters were returned"), + @ApiResponse(responseCode = "404", description = "parameters were not found")}) + public ResponseEntity getParameters( + @Parameter(description = "parameters UUID") @PathVariable("uuid") UUID parametersUuid) { + LoadFlowParametersInfos parameters = parametersService.getParameters(parametersUuid); + return parameters != null ? ResponseEntity.ok().body(parametersService.getParameters(parametersUuid)) + : ResponseEntity.notFound().build(); + } + + @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE) + @Operation(summary = "Get all parameters") + @ApiResponse(responseCode = "200", description = "The list of all parameters was returned") + public ResponseEntity> getAllParameters() { + return ResponseEntity.ok().body(parametersService.getAllParameters()); + } + + @PutMapping(value = "/{uuid}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + @Operation(summary = "Update parameters") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "parameters were updated")}) + public ResponseEntity updateParameters( + @Parameter(description = "parameters UUID") @PathVariable("uuid") UUID parametersUuid, + @RequestBody LoadFlowParametersInfos parametersInfos) { + parametersService.updateParameters(parametersUuid, parametersInfos); + return ResponseEntity.ok().build(); + } + + @DeleteMapping(value = "/{uuid}", produces = MediaType.APPLICATION_JSON_VALUE) + @Operation(summary = "Delete parameters") + @ApiResponse(responseCode = "200", description = "parameters were deleted") + public ResponseEntity deleteParameters( + @Parameter(description = "parameters UUID") @PathVariable("uuid") UUID parametersUuid) { + parametersService.deleteParameters(parametersUuid); + return ResponseEntity.ok().build(); + } +} diff --git a/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersInfos.java b/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersInfos.java new file mode 100644 index 00000000..19a23cd2 --- /dev/null +++ b/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersInfos.java @@ -0,0 +1,39 @@ +/** + 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.loadflow.server.dto.parameters; + +import com.powsybl.loadflow.LoadFlowParameters; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.Map; +import java.util.UUID; + +import org.gridsuite.loadflow.server.entities.parameters.LoadFlowParametersEntity; + +/** + * @author Ayoub LABIDI + */ +@Getter +@AllArgsConstructor +@Builder +@NoArgsConstructor +public class LoadFlowParametersInfos { + + private UUID uuid; + + private LoadFlowParameters commonParameters; + + private Map> specificParametersPerProvider; + + public LoadFlowParametersEntity toEntity() { + return new LoadFlowParametersEntity(this); + } +} diff --git a/src/main/java/org/gridsuite/loadflow/server/dto/LoadFlowParametersInfos.java b/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersValues.java similarity index 80% rename from src/main/java/org/gridsuite/loadflow/server/dto/LoadFlowParametersInfos.java rename to src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersValues.java index f8cf7237..a99e3c23 100644 --- a/src/main/java/org/gridsuite/loadflow/server/dto/LoadFlowParametersInfos.java +++ b/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersValues.java @@ -4,7 +4,7 @@ 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.loadflow.server.dto; +package org.gridsuite.loadflow.server.dto.parameters; import com.powsybl.loadflow.LoadFlowParameters; import lombok.AllArgsConstructor; @@ -15,13 +15,13 @@ import java.util.Map; /** - * @author David Braquart + * @author Ayoub LABIDI */ @Getter @NoArgsConstructor @AllArgsConstructor @Builder -public class LoadFlowParametersInfos { +public class LoadFlowParametersValues { private LoadFlowParameters commonParameters; diff --git a/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowSpecificParameterInfos.java b/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowSpecificParameterInfos.java new file mode 100644 index 00000000..3063f1e5 --- /dev/null +++ b/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowSpecificParameterInfos.java @@ -0,0 +1,24 @@ +/** + 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.loadflow.server.dto.parameters; + +import lombok.*; + +/** + * @author Ayoub LABIDI + */ +@Getter +@AllArgsConstructor +@Builder +public class LoadFlowSpecificParameterInfos { + + private String provider; + + private String name; + + private String value; +} diff --git a/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java new file mode 100644 index 00000000..4afce3b2 --- /dev/null +++ b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java @@ -0,0 +1,202 @@ +/** + * 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.loadflow.server.entities.parameters; + +import com.powsybl.iidm.network.Country; +import com.powsybl.loadflow.LoadFlowParameters; +import lombok.*; + +import jakarta.persistence.*; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Set; +import java.util.UUID; +import java.util.stream.Collectors; + +import org.gridsuite.loadflow.server.dto.parameters.LoadFlowParametersInfos; +import org.gridsuite.loadflow.server.dto.parameters.LoadFlowParametersValues; +import org.gridsuite.loadflow.server.dto.parameters.LoadFlowSpecificParameterInfos; + +/** + * @author Ayoub LABIDI + */ +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@Entity +@Table(name = "loadFlowParameters") +public class LoadFlowParametersEntity { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id") + private UUID id; + + @Column(name = "voltageInitMode") + @Enumerated(EnumType.STRING) + private LoadFlowParameters.VoltageInitMode voltageInitMode; + + @Column(name = "transformerVoltageControlOn", columnDefinition = "boolean default false") + private boolean transformerVoltageControlOn; + + @Column(name = "useReactiveLimits", columnDefinition = "boolean default true") + private boolean useReactiveLimits; + + @Column(name = "phaseShifterRegulationOn", columnDefinition = "boolean default false") + private boolean phaseShifterRegulationOn; + + @Column(name = "twtSplitShuntAdmittance", columnDefinition = "boolean default false") + private boolean twtSplitShuntAdmittance; + + @Column(name = "shuntCompensatorVoltageControlOn", columnDefinition = "boolean default false") + private boolean shuntCompensatorVoltageControlOn; + + @Column(name = "readSlackBus", columnDefinition = "boolean default true") + private boolean readSlackBus; + + @Column(name = "writeSlackBus", columnDefinition = "boolean default false") + private boolean writeSlackBus; + + @Column(name = "dc", columnDefinition = "boolean default false") + private boolean dc; + + @Column(name = "distributedSlack", columnDefinition = "boolean default true") + private boolean distributedSlack; + + @Column(name = "balanceType") + @Enumerated(EnumType.STRING) + private LoadFlowParameters.BalanceType balanceType; + + @Column(name = "dcUseTransformerRatio", columnDefinition = "boolean default true") + private boolean dcUseTransformerRatio; + + @Column(name = "countriesToBalance") + @ElementCollection + @CollectionTable(foreignKey = @ForeignKey(name = "loadFlowParametersEntity_countriesToBalance_fk1"), + indexes = {@Index(name = "loadFlowParametersEntity_countriesToBalance_idx1", + columnList = "load_flow_parameters_entity_id")}) + private Set countriesToBalance; + + @Column(name = "connectedComponentMode") + @Enumerated(EnumType.STRING) + private LoadFlowParameters.ConnectedComponentMode connectedComponentMode; + + @Column(name = "hvdcAcEmulation", columnDefinition = "boolean default true") + private boolean hvdcAcEmulation; + + @Column(name = "dcPowerFactor", columnDefinition = "double default 1.0") + private double dcPowerFactor; + + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "load_flow_parameters_id") + private List specificParameters; + + public LoadFlowParametersEntity(LoadFlowParametersInfos loadFlowParametersInfos) { + assignAttributes(loadFlowParametersInfos); + } + + public void update(LoadFlowParametersInfos loadFlowParametersInfos) { + assignAttributes(loadFlowParametersInfos); + } + + public void assignAttributes(LoadFlowParametersInfos loadFlowParametersInfos) { + LoadFlowParameters allCommonValues; + List allSpecificValues = new ArrayList<>(List.of()); + if (loadFlowParametersInfos == null) { + allCommonValues = LoadFlowParameters.load(); + } else { + allCommonValues = loadFlowParametersInfos.getCommonParameters(); + if (loadFlowParametersInfos.getSpecificParametersPerProvider() != null) { + loadFlowParametersInfos.getSpecificParametersPerProvider().forEach((provider, paramsMap) -> { + if (paramsMap != null) { + paramsMap.forEach((paramName, paramValue) -> { + if (paramValue != null) { + allSpecificValues.add(LoadFlowSpecificParameterInfos.builder() + .provider(provider) + .value(Objects.toString(paramValue)) + .name(paramName) + .build()); + } + } + ); + } + }); + } + } + voltageInitMode = allCommonValues.getVoltageInitMode(); + transformerVoltageControlOn = allCommonValues.isTransformerVoltageControlOn(); + useReactiveLimits = allCommonValues.isUseReactiveLimits(); + phaseShifterRegulationOn = allCommonValues.isPhaseShifterRegulationOn(); + twtSplitShuntAdmittance = allCommonValues.isTwtSplitShuntAdmittance(); + shuntCompensatorVoltageControlOn = allCommonValues.isShuntCompensatorVoltageControlOn(); + readSlackBus = allCommonValues.isReadSlackBus(); + writeSlackBus = allCommonValues.isWriteSlackBus(); + dc = allCommonValues.isDc(); + distributedSlack = allCommonValues.isDistributedSlack(); + balanceType = allCommonValues.getBalanceType(); + dcUseTransformerRatio = allCommonValues.isDcUseTransformerRatio(); + countriesToBalance = allCommonValues.getCountriesToBalance().stream().map(Country::toString).collect(Collectors.toSet()); + connectedComponentMode = allCommonValues.getConnectedComponentMode(); + hvdcAcEmulation = allCommonValues.isHvdcAcEmulation(); + dcPowerFactor = allCommonValues.getDcPowerFactor(); + List allSpecificValuesEntities = LoadFlowSpecificParameterEntity.toLoadFlowSpecificParameters(allSpecificValues); + if (specificParameters == null) { + specificParameters = allSpecificValuesEntities; + } else { + specificParameters.clear(); + if (!allSpecificValuesEntities.isEmpty()) { + specificParameters.addAll(allSpecificValuesEntities); + } + } + } + + public LoadFlowParameters toLoadFlowParameters() { + return LoadFlowParameters.load() + .setVoltageInitMode(this.getVoltageInitMode()) + .setTransformerVoltageControlOn(this.isTransformerVoltageControlOn()) + .setUseReactiveLimits(this.isUseReactiveLimits()) + .setPhaseShifterRegulationOn(this.isPhaseShifterRegulationOn()) + .setTwtSplitShuntAdmittance(this.isTwtSplitShuntAdmittance()) + .setShuntCompensatorVoltageControlOn(this.isShuntCompensatorVoltageControlOn()) + .setReadSlackBus(this.isReadSlackBus()) + .setWriteSlackBus(this.isWriteSlackBus()) + .setDc(this.isDc()) + .setDistributedSlack(this.isDistributedSlack()) + .setBalanceType(this.getBalanceType()) + .setDcUseTransformerRatio(this.isDcUseTransformerRatio()) + .setCountriesToBalance(this.getCountriesToBalance().stream().map(Country::valueOf).collect(Collectors.toSet())) + .setConnectedComponentMode(this.getConnectedComponentMode()) + .setHvdcAcEmulation(this.isHvdcAcEmulation()) + .setDcPowerFactor(this.getDcPowerFactor()); + } + + public LoadFlowParametersInfos toLoadFlowParametersInfos() { + return LoadFlowParametersInfos.builder() + .uuid(id) + .commonParameters(toLoadFlowParameters()) + .specificParametersPerProvider(specificParameters.stream() + .collect(Collectors.groupingBy(LoadFlowSpecificParameterEntity::getProvider, + Collectors.toMap(LoadFlowSpecificParameterEntity::getName, + LoadFlowSpecificParameterEntity::getValue)))) + .build(); + } + + public LoadFlowParametersValues toLoadFlowParametersValues(String provider) { + return LoadFlowParametersValues.builder() + .commonParameters(toLoadFlowParameters()) + .specificParameters(specificParameters.stream() + .filter(p -> p.getProvider().equalsIgnoreCase(provider)) + .collect(Collectors.toMap(LoadFlowSpecificParameterEntity::getName, + LoadFlowSpecificParameterEntity::getValue))) + .build(); + } +} diff --git a/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowSpecificParameterEntity.java b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowSpecificParameterEntity.java new file mode 100644 index 00000000..be752d02 --- /dev/null +++ b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowSpecificParameterEntity.java @@ -0,0 +1,64 @@ +/** + * 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.loadflow.server.entities.parameters; + +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + +import org.gridsuite.loadflow.server.dto.parameters.LoadFlowSpecificParameterInfos; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +/** + * @author Ayoub LABIDI + */ + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Entity +@Table(name = "loadFlowSpecificParameters") +public class LoadFlowSpecificParameterEntity { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id", nullable = false) + private UUID id; + + @Column(name = "provider") + private String provider; + + @Column(name = "name") + private String name; + + @Column(name = "value_") + private String value; + + public static List toLoadFlowSpecificParameters(List params) { + return params == null ? null + : params.stream() + .map(p -> new LoadFlowSpecificParameterEntity(null, p.getProvider(), p.getName(), p.getValue())) + .collect(Collectors.toList()); + } + + public LoadFlowSpecificParameterInfos toLoadFlowSpecificParameterInfos() { + return LoadFlowSpecificParameterInfos.builder() + .provider(getProvider()) + .name(getName()) + .value(getValue()) + .build(); + } +} diff --git a/src/main/java/org/gridsuite/loadflow/server/repositories/parameters/LoadFlowParametersRepository.java b/src/main/java/org/gridsuite/loadflow/server/repositories/parameters/LoadFlowParametersRepository.java new file mode 100644 index 00000000..0ac34823 --- /dev/null +++ b/src/main/java/org/gridsuite/loadflow/server/repositories/parameters/LoadFlowParametersRepository.java @@ -0,0 +1,21 @@ +/** + * 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.loadflow.server.repositories.parameters; + +import java.util.UUID; + +import org.gridsuite.loadflow.server.entities.parameters.LoadFlowParametersEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +/** + * @author Ayoub LABIDI + */ + +@Repository +public interface LoadFlowParametersRepository extends JpaRepository { +} diff --git a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowResultContext.java b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowResultContext.java index df3505a1..6e97f852 100644 --- a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowResultContext.java +++ b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowResultContext.java @@ -9,7 +9,8 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.Getter; -import org.gridsuite.loadflow.server.dto.LoadFlowParametersInfos; + +import org.gridsuite.loadflow.server.dto.parameters.LoadFlowParametersValues; import org.gridsuite.loadflow.server.utils.ReportContext; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; @@ -55,13 +56,13 @@ public static LoadFlowResultContext fromMessage(Message message, ObjectM String provider = (String) headers.get(HEADER_PROVIDER); String userId = (String) headers.get(HEADER_USER_ID); - LoadFlowParametersInfos parameters; + LoadFlowParametersValues parameters; try { // can't use the following line because jackson doesn't unwrap null in the rootname // -> '{"parameters": null}' throws instead returning null // MismatchedInputException: Cannot deserialize value of type `LoadFlowParametersInfos` from Null value (token `JsonToken.VALUE_NULL`) // parameters = objectMapper.reader().withRootName(MESSAGE_ROOT_NAME).readValue(message.getPayload(), LoadFlowParametersInfos.class); - parameters = objectMapper.treeToValue(objectMapper.readTree(message.getPayload()).get(MESSAGE_ROOT_NAME), LoadFlowParametersInfos.class); + parameters = objectMapper.treeToValue(objectMapper.readTree(message.getPayload()).get(MESSAGE_ROOT_NAME), LoadFlowParametersValues.class); } catch (JsonProcessingException e) { throw new UncheckedIOException(e); } diff --git a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowRunContext.java b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowRunContext.java index a0da409d..0d7e39cc 100644 --- a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowRunContext.java +++ b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowRunContext.java @@ -12,7 +12,7 @@ import com.powsybl.loadflow.LoadFlowProvider; import lombok.Builder; import lombok.Getter; -import org.gridsuite.loadflow.server.dto.LoadFlowParametersInfos; +import org.gridsuite.loadflow.server.dto.parameters.LoadFlowParametersValues; import org.gridsuite.loadflow.server.utils.ReportContext; import java.util.UUID; @@ -32,7 +32,7 @@ public class LoadFlowRunContext { private final String provider; - private final LoadFlowParametersInfos parameters; + private final LoadFlowParametersValues parameters; private final ReportContext reportContext; @@ -40,7 +40,7 @@ public class LoadFlowRunContext { private final Float limitReduction; - public static LoadFlowParameters buildParameters(LoadFlowParametersInfos parameters, String provider) { + public static LoadFlowParameters buildParameters(LoadFlowParametersValues parameters, String provider) { LoadFlowParameters params = parameters == null || parameters.getSpecificParameters() == null ? LoadFlowParameters.load() : parameters.getCommonParameters(); if (parameters == null || parameters.getSpecificParameters() == null || parameters.getSpecificParameters().isEmpty()) { diff --git a/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java b/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java new file mode 100644 index 00000000..b91bed5f --- /dev/null +++ b/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java @@ -0,0 +1,57 @@ +/** + * 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.loadflow.server.service.parameters; + +import java.util.List; +import java.util.UUID; + +import org.gridsuite.loadflow.server.dto.parameters.LoadFlowParametersInfos; +import org.gridsuite.loadflow.server.dto.parameters.LoadFlowParametersValues; +import org.gridsuite.loadflow.server.entities.parameters.LoadFlowParametersEntity; +import org.gridsuite.loadflow.server.repositories.parameters.LoadFlowParametersRepository; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + * @author Ayoub LABIDI + */ + +@Service +public class LoadFlowParametersService { + + private final LoadFlowParametersRepository loadFlowParametersRepository; + + public LoadFlowParametersService(LoadFlowParametersRepository loadFlowParametersRepository) { + this.loadFlowParametersRepository = loadFlowParametersRepository; + } + + public UUID createParameters(LoadFlowParametersInfos parametersInfos) { + return loadFlowParametersRepository.save(parametersInfos.toEntity()).toLoadFlowParametersInfos().getUuid(); + } + + public LoadFlowParametersInfos getParameters(UUID parametersUuid) { + return loadFlowParametersRepository.findById(parametersUuid).map(LoadFlowParametersEntity::toLoadFlowParametersInfos).orElse(null); + } + + public LoadFlowParametersValues getParametersValues(UUID parametersUuid, String provider) { + LoadFlowParametersEntity parametersEntity = loadFlowParametersRepository.findById(parametersUuid).orElse(null); + return parametersEntity != null ? parametersEntity.toLoadFlowParametersValues(provider) : null; + } + + public List getAllParameters() { + return loadFlowParametersRepository.findAll().stream().map(LoadFlowParametersEntity::toLoadFlowParametersInfos).toList(); + } + + @Transactional + public void updateParameters(UUID parametersUuid, LoadFlowParametersInfos parametersInfos) { + loadFlowParametersRepository.findById(parametersUuid).orElseThrow().update(parametersInfos); + } + + public void deleteParameters(UUID parametersUuid) { + loadFlowParametersRepository.deleteById(parametersUuid); + } +} diff --git a/src/main/resources/db/changelog/changesets/changelog_20231225T122756Z.xml b/src/main/resources/db/changelog/changesets/changelog_20231225T122756Z.xml new file mode 100644 index 00000000..a93b1589 --- /dev/null +++ b/src/main/resources/db/changelog/changesets/changelog_20231225T122756Z.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/db/changelog/db.changelog-master.yaml b/src/main/resources/db/changelog/db.changelog-master.yaml index 2fab3fa4..e867153b 100644 --- a/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/src/main/resources/db/changelog/db.changelog-master.yaml @@ -9,3 +9,7 @@ databaseChangeLog: - include: file: changesets/changelog_20231115T10528Z.xml relativeToChangelogFile: true + - include: + file: changesets/changelog_20231225T122756Z.xml + relativeToChangelogFile: true + diff --git a/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java b/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java index 9eaf4696..aa6b1c42 100644 --- a/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java +++ b/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java @@ -28,8 +28,8 @@ import org.apache.commons.collections4.CollectionUtils; import org.gridsuite.loadflow.server.dto.ComponentResult; import org.gridsuite.loadflow.server.dto.LimitViolationInfos; -import org.gridsuite.loadflow.server.dto.LoadFlowParametersInfos; import org.gridsuite.loadflow.server.dto.LoadFlowStatus; +import org.gridsuite.loadflow.server.dto.parameters.LoadFlowParametersValues; import org.gridsuite.loadflow.server.service.LoadFlowWorkerService; import org.gridsuite.loadflow.server.service.LoadFlowExecutionService; import org.gridsuite.loadflow.server.service.ReportService; @@ -263,7 +263,7 @@ public void testGetLimitViolations() throws Exception { LoadFlowParameters loadFlowParameters = LoadFlowParameters.load(); loadFlowParameters.setDc(true); - LoadFlowParametersInfos loadFlowParametersInfos = LoadFlowParametersInfos.builder() + LoadFlowParametersValues loadFlowParametersInfos = LoadFlowParametersValues.builder() .commonParameters(loadFlowParameters) .specificParameters(Collections.emptyMap()) .build(); From 193e1b9a7ff3d095e0781bee4b46d8330acce49a Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Tue, 26 Dec 2023 16:28:50 +0100 Subject: [PATCH 02/20] clean code Signed-off-by: Ayoub LABIDI --- .../server/LoadFlowParametersController.java | 2 +- .../parameters/LoadFlowParametersInfos.java | 2 +- .../LoadFlowSpecificParameterInfos.java | 24 ------------------- .../parameters/LoadFlowParametersEntity.java | 15 +++++------- .../LoadFlowSpecificParameterEntity.java | 21 +--------------- .../server/service/LoadFlowResultContext.java | 1 - ...56Z.xml => changelog_20231226T142800Z.xml} | 14 +++++------ .../db/changelog/db.changelog-master.yaml | 2 +- 8 files changed, 17 insertions(+), 64 deletions(-) delete mode 100644 src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowSpecificParameterInfos.java rename src/main/resources/db/changelog/changesets/{changelog_20231225T122756Z.xml => changelog_20231226T142800Z.xml} (90%) diff --git a/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java b/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java index d80a9d89..bf00c366 100644 --- a/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java +++ b/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java @@ -27,7 +27,7 @@ */ @RestController @RequestMapping(value = "/" + LoadFlowApi.API_VERSION + "/parameters") -@Tag(name = "Voltage init parameters") +@Tag(name = "LoadFlow parameters") public class LoadFlowParametersController { @Autowired diff --git a/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersInfos.java b/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersInfos.java index 19a23cd2..4223439c 100644 --- a/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersInfos.java +++ b/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersInfos.java @@ -31,7 +31,7 @@ public class LoadFlowParametersInfos { private LoadFlowParameters commonParameters; - private Map> specificParametersPerProvider; + private Map> specificParametersPerProvider; public LoadFlowParametersEntity toEntity() { return new LoadFlowParametersEntity(this); diff --git a/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowSpecificParameterInfos.java b/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowSpecificParameterInfos.java deleted file mode 100644 index 3063f1e5..00000000 --- a/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowSpecificParameterInfos.java +++ /dev/null @@ -1,24 +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.loadflow.server.dto.parameters; - -import lombok.*; - -/** - * @author Ayoub LABIDI - */ -@Getter -@AllArgsConstructor -@Builder -public class LoadFlowSpecificParameterInfos { - - private String provider; - - private String name; - - private String value; -} diff --git a/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java index 4afce3b2..d337b930 100644 --- a/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java +++ b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java @@ -15,14 +15,12 @@ import java.util.ArrayList; import java.util.List; -import java.util.Objects; import java.util.Set; import java.util.UUID; import java.util.stream.Collectors; import org.gridsuite.loadflow.server.dto.parameters.LoadFlowParametersInfos; import org.gridsuite.loadflow.server.dto.parameters.LoadFlowParametersValues; -import org.gridsuite.loadflow.server.dto.parameters.LoadFlowSpecificParameterInfos; /** * @author Ayoub LABIDI @@ -110,7 +108,7 @@ public void update(LoadFlowParametersInfos loadFlowParametersInfos) { public void assignAttributes(LoadFlowParametersInfos loadFlowParametersInfos) { LoadFlowParameters allCommonValues; - List allSpecificValues = new ArrayList<>(List.of()); + List allSpecificValuesEntities = new ArrayList<>(List.of()); if (loadFlowParametersInfos == null) { allCommonValues = LoadFlowParameters.load(); } else { @@ -120,11 +118,11 @@ public void assignAttributes(LoadFlowParametersInfos loadFlowParametersInfos) { if (paramsMap != null) { paramsMap.forEach((paramName, paramValue) -> { if (paramValue != null) { - allSpecificValues.add(LoadFlowSpecificParameterInfos.builder() - .provider(provider) - .value(Objects.toString(paramValue)) - .name(paramName) - .build()); + allSpecificValuesEntities.add(new LoadFlowSpecificParameterEntity( + null, + provider, + paramName, + paramValue)); } } ); @@ -148,7 +146,6 @@ public void assignAttributes(LoadFlowParametersInfos loadFlowParametersInfos) { connectedComponentMode = allCommonValues.getConnectedComponentMode(); hvdcAcEmulation = allCommonValues.isHvdcAcEmulation(); dcPowerFactor = allCommonValues.getDcPowerFactor(); - List allSpecificValuesEntities = LoadFlowSpecificParameterEntity.toLoadFlowSpecificParameters(allSpecificValues); if (specificParameters == null) { specificParameters = allSpecificValuesEntities; } else { diff --git a/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowSpecificParameterEntity.java b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowSpecificParameterEntity.java index be752d02..ba051448 100644 --- a/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowSpecificParameterEntity.java +++ b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowSpecificParameterEntity.java @@ -7,11 +7,7 @@ package org.gridsuite.loadflow.server.entities.parameters; -import java.util.List; import java.util.UUID; -import java.util.stream.Collectors; - -import org.gridsuite.loadflow.server.dto.parameters.LoadFlowSpecificParameterInfos; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -44,21 +40,6 @@ public class LoadFlowSpecificParameterEntity { @Column(name = "name") private String name; - @Column(name = "value_") + @Column(name = "value") private String value; - - public static List toLoadFlowSpecificParameters(List params) { - return params == null ? null - : params.stream() - .map(p -> new LoadFlowSpecificParameterEntity(null, p.getProvider(), p.getName(), p.getValue())) - .collect(Collectors.toList()); - } - - public LoadFlowSpecificParameterInfos toLoadFlowSpecificParameterInfos() { - return LoadFlowSpecificParameterInfos.builder() - .provider(getProvider()) - .name(getName()) - .value(getValue()) - .build(); - } } diff --git a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowResultContext.java b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowResultContext.java index 6e97f852..597c3a4e 100644 --- a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowResultContext.java +++ b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowResultContext.java @@ -9,7 +9,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.Getter; - import org.gridsuite.loadflow.server.dto.parameters.LoadFlowParametersValues; import org.gridsuite.loadflow.server.utils.ReportContext; import org.springframework.messaging.Message; diff --git a/src/main/resources/db/changelog/changesets/changelog_20231225T122756Z.xml b/src/main/resources/db/changelog/changesets/changelog_20231226T142800Z.xml similarity index 90% rename from src/main/resources/db/changelog/changesets/changelog_20231225T122756Z.xml rename to src/main/resources/db/changelog/changesets/changelog_20231226T142800Z.xml index a93b1589..cfa2e4a4 100644 --- a/src/main/resources/db/changelog/changesets/changelog_20231225T122756Z.xml +++ b/src/main/resources/db/changelog/changesets/changelog_20231226T142800Z.xml @@ -1,6 +1,6 @@ - + @@ -22,7 +22,7 @@ - + @@ -30,26 +30,26 @@ - + - + - + - + - + diff --git a/src/main/resources/db/changelog/db.changelog-master.yaml b/src/main/resources/db/changelog/db.changelog-master.yaml index e867153b..a6de2ee5 100644 --- a/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/src/main/resources/db/changelog/db.changelog-master.yaml @@ -10,6 +10,6 @@ databaseChangeLog: file: changesets/changelog_20231115T10528Z.xml relativeToChangelogFile: true - include: - file: changesets/changelog_20231225T122756Z.xml + file: changesets/changelog_20231226T142800Z.xml relativeToChangelogFile: true From 5eb78ef9af3b484fa415bd8549f132834ac034c9 Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Tue, 26 Dec 2023 17:26:36 +0100 Subject: [PATCH 03/20] Add duplication endpoint Signed-off-by: Ayoub LABIDI --- .../server/LoadFlowParametersController.java | 15 ++++++++++++--- .../dto/parameters/LoadFlowParametersValues.java | 2 +- .../parameters/LoadFlowParametersEntity.java | 4 ++++ .../parameters/LoadFlowParametersService.java | 7 +++++++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java b/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java index bf00c366..ca8d469e 100644 --- a/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java +++ b/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java @@ -33,7 +33,7 @@ public class LoadFlowParametersController { @Autowired private LoadFlowParametersService parametersService; - @PostMapping(value = "", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + @PostMapping(value = "", consumes = MediaType.APPLICATION_JSON_VALUE) @Operation(summary = "Create parameters") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "parameters were created")}) @@ -42,6 +42,15 @@ public ResponseEntity createParameters( return ResponseEntity.ok().body(parametersService.createParameters(parametersInfos)); } + @PostMapping(value = "") + @Operation(summary = "Duplicate parameters") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "parameters were duplicated")}) + public ResponseEntity createParameters( + @RequestParam("duplicateFrom") UUID sourceParametersUuid) { + return ResponseEntity.ok().body(parametersService.duplicateParameters(sourceParametersUuid)); + } + @GetMapping(value = "/{uuid}", produces = MediaType.APPLICATION_JSON_VALUE) @Operation(summary = "Get parameters") @ApiResponses(value = { @@ -61,7 +70,7 @@ public ResponseEntity> getAllParameters() { return ResponseEntity.ok().body(parametersService.getAllParameters()); } - @PutMapping(value = "/{uuid}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + @PutMapping(value = "/{uuid}", consumes = MediaType.APPLICATION_JSON_VALUE) @Operation(summary = "Update parameters") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "parameters were updated")}) public ResponseEntity updateParameters( @@ -71,7 +80,7 @@ public ResponseEntity updateParameters( return ResponseEntity.ok().build(); } - @DeleteMapping(value = "/{uuid}", produces = MediaType.APPLICATION_JSON_VALUE) + @DeleteMapping(value = "/{uuid}") @Operation(summary = "Delete parameters") @ApiResponse(responseCode = "200", description = "parameters were deleted") public ResponseEntity deleteParameters( diff --git a/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersValues.java b/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersValues.java index a99e3c23..43b34475 100644 --- a/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersValues.java +++ b/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersValues.java @@ -15,7 +15,7 @@ import java.util.Map; /** - * @author Ayoub LABIDI + * @author David Braquart */ @Getter @NoArgsConstructor diff --git a/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java index d337b930..06fca1f1 100644 --- a/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java +++ b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java @@ -196,4 +196,8 @@ public LoadFlowParametersValues toLoadFlowParametersValues(String provider) { LoadFlowSpecificParameterEntity::getValue))) .build(); } + + public LoadFlowParametersEntity copy() { + return toLoadFlowParametersInfos().toEntity(); + } } diff --git a/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java b/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java index b91bed5f..2c31efc9 100644 --- a/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java +++ b/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java @@ -54,4 +54,11 @@ public void updateParameters(UUID parametersUuid, LoadFlowParametersInfos parame public void deleteParameters(UUID parametersUuid) { loadFlowParametersRepository.deleteById(parametersUuid); } + + @Transactional + public UUID duplicateParameters(UUID sourceParametersUuid) { + LoadFlowParametersEntity sourceParameters = loadFlowParametersRepository.findById(sourceParametersUuid).orElseThrow(); + LoadFlowParametersEntity duplicatedParameters = sourceParameters.copy(); + return loadFlowParametersRepository.save(duplicatedParameters).toLoadFlowParametersInfos().getUuid(); + } } From c596fdb53657cdd51ccd9471cc527f1b3eed6a15 Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Tue, 2 Jan 2024 21:40:54 +0100 Subject: [PATCH 04/20] fix unit tests Signed-off-by: Ayoub LABIDI --- .../parameters/LoadFlowParametersEntity.java | 4 +- .../LoadFlowSpecificParameterEntity.java | 5 +- .../parameters/LoadFlowParametersService.java | 4 +- ...00Z.xml => changelog_20231228T155403Z.xml} | 21 ++- .../db/changelog/db.changelog-master.yaml | 2 +- .../server/LoadFlowControllerTest.java | 22 ++- .../server/LoadFlowParametersTest.java | 172 ++++++++++++++++++ .../loadflow/utils/assertions/Assertions.java | 21 +++ .../loadflow/utils/assertions/DTOAssert.java | 38 ++++ 9 files changed, 267 insertions(+), 22 deletions(-) rename src/main/resources/db/changelog/changesets/{changelog_20231226T142800Z.xml => changelog_20231228T155403Z.xml} (78%) create mode 100644 src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java create mode 100644 src/test/java/org/gridsuite/loadflow/utils/assertions/Assertions.java create mode 100644 src/test/java/org/gridsuite/loadflow/utils/assertions/DTOAssert.java diff --git a/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java index 06fca1f1..31904b13 100644 --- a/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java +++ b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java @@ -94,8 +94,8 @@ public class LoadFlowParametersEntity { @Column(name = "dcPowerFactor", columnDefinition = "double default 1.0") private double dcPowerFactor; - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "load_flow_parameters_id") + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) + @JoinColumn(name = "load_flow_parameters_entity_id", foreignKey = @ForeignKey(name = "loadFlowParametersEntity_specificParameters_fk")) private List specificParameters; public LoadFlowParametersEntity(LoadFlowParametersInfos loadFlowParametersInfos) { diff --git a/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowSpecificParameterEntity.java b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowSpecificParameterEntity.java index ba051448..2b17c066 100644 --- a/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowSpecificParameterEntity.java +++ b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowSpecificParameterEntity.java @@ -14,6 +14,7 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.Index; import jakarta.persistence.Table; import lombok.AllArgsConstructor; import lombok.Getter; @@ -27,7 +28,9 @@ @AllArgsConstructor @Getter @Entity -@Table(name = "loadFlowSpecificParameters") +@Table(name = "loadFlowSpecificParameters", indexes = { + @Index(name = "loadFlowParametersEntity_specificParameters_index", columnList = "load_flow_parameters_entity_id") +}) public class LoadFlowSpecificParameterEntity { @Id @GeneratedValue(strategy = GenerationType.AUTO) diff --git a/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java b/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java index 2c31efc9..0ad52f13 100644 --- a/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java +++ b/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java @@ -30,7 +30,7 @@ public LoadFlowParametersService(LoadFlowParametersRepository loadFlowParameters } public UUID createParameters(LoadFlowParametersInfos parametersInfos) { - return loadFlowParametersRepository.save(parametersInfos.toEntity()).toLoadFlowParametersInfos().getUuid(); + return loadFlowParametersRepository.save(parametersInfos.toEntity()).getId(); } public LoadFlowParametersInfos getParameters(UUID parametersUuid) { @@ -59,6 +59,6 @@ public void deleteParameters(UUID parametersUuid) { public UUID duplicateParameters(UUID sourceParametersUuid) { LoadFlowParametersEntity sourceParameters = loadFlowParametersRepository.findById(sourceParametersUuid).orElseThrow(); LoadFlowParametersEntity duplicatedParameters = sourceParameters.copy(); - return loadFlowParametersRepository.save(duplicatedParameters).toLoadFlowParametersInfos().getUuid(); + return loadFlowParametersRepository.save(duplicatedParameters).getId(); } } diff --git a/src/main/resources/db/changelog/changesets/changelog_20231226T142800Z.xml b/src/main/resources/db/changelog/changesets/changelog_20231228T155403Z.xml similarity index 78% rename from src/main/resources/db/changelog/changesets/changelog_20231226T142800Z.xml rename to src/main/resources/db/changelog/changesets/changelog_20231228T155403Z.xml index cfa2e4a4..b4420ea6 100644 --- a/src/main/resources/db/changelog/changesets/changelog_20231226T142800Z.xml +++ b/src/main/resources/db/changelog/changesets/changelog_20231228T155403Z.xml @@ -1,6 +1,6 @@ - + @@ -22,7 +22,7 @@ - + @@ -30,7 +30,7 @@ - + @@ -38,18 +38,23 @@ - + - + - - + + + + - + + + + diff --git a/src/main/resources/db/changelog/db.changelog-master.yaml b/src/main/resources/db/changelog/db.changelog-master.yaml index a6de2ee5..ec5a6123 100644 --- a/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/src/main/resources/db/changelog/db.changelog-master.yaml @@ -10,6 +10,6 @@ databaseChangeLog: file: changesets/changelog_20231115T10528Z.xml relativeToChangelogFile: true - include: - file: changesets/changelog_20231226T142800Z.xml + file: changesets/changelog_20231228T155403Z.xml relativeToChangelogFile: true diff --git a/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java b/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java index aa6b1c42..9485bf29 100644 --- a/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java +++ b/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java @@ -34,6 +34,7 @@ import org.gridsuite.loadflow.server.service.LoadFlowExecutionService; import org.gridsuite.loadflow.server.service.ReportService; import org.gridsuite.loadflow.server.service.UuidGeneratorService; +import org.gridsuite.loadflow.server.service.parameters.LoadFlowParametersService; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -45,6 +46,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.cloud.stream.binder.test.OutputDestination; import org.springframework.cloud.stream.binder.test.TestChannelBinderConfiguration; import org.springframework.http.MediaType; @@ -69,6 +71,7 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doReturn; 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; @@ -86,6 +89,7 @@ public class LoadFlowControllerTest { private static final UUID RESULT_UUID = UUID.fromString("0c8de370-3e6c-4d72-b292-d355a97e0d5d"); private static final UUID OTHER_RESULT_UUID = UUID.fromString("0c8de370-3e6c-4d72-b292-d355a97e0d5a"); private static final UUID REPORT_UUID = UUID.fromString("762b7298-8c0f-11ed-a1eb-0242ac120002"); + private static final UUID PARAMETERS_UUID = UUID.fromString("762b7298-8c0f-11ed-a1eb-0242ac120003"); private static final String VARIANT_1_ID = "variant_1"; private static final String VARIANT_2_ID = "variant_2"; @@ -123,6 +127,9 @@ private static final class LimitViolationsMock { @Autowired private LoadFlowExecutionService loadFlowExecutionService; + @SpyBean + private LoadFlowParametersService loadFlowParametersService; + @MockBean private UuidGeneratorService uuidGeneratorService; private final RestTemplateConfig restTemplateConfig = new RestTemplateConfig(); @@ -217,7 +224,7 @@ public void runTest() throws Exception { .thenReturn(CompletableFuture.completedFuture(LoadFlowResultMock.RESULT)); MvcResult result = mockMvc.perform(post( - "/" + VERSION + "/networks/{networkUuid}/run-and-save?reportType=LoadFlow&receiver=me&variantId=" + VARIANT_2_ID, NETWORK_UUID) + "/" + VERSION + "/networks/{networkUuid}/run-and-save?reportType=LoadFlow&receiver=me&variantId=" + VARIANT_2_ID + "¶metersUuid=" + PARAMETERS_UUID, NETWORK_UUID) .header(HEADER_USER_ID, "userId")) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) @@ -267,11 +274,10 @@ public void testGetLimitViolations() throws Exception { .commonParameters(loadFlowParameters) .specificParameters(Collections.emptyMap()) .build(); - String jsonLoadFlowParameters = mapper.writeValueAsString(loadFlowParametersInfos); + doReturn(loadFlowParametersInfos).when(loadFlowParametersService).getParametersValues(any(), any()); MvcResult result = mockMvc.perform(post( - "/" + VERSION + "/networks/{networkUuid}/run-and-save?reportType=LoadFlow&receiver=me&variantId=" + VARIANT_2_ID + "&limitReduction=0.7", NETWORK_UUID) - .content(jsonLoadFlowParameters).contentType(MediaType.APPLICATION_JSON) + "/" + VERSION + "/networks/{networkUuid}/run-and-save?reportType=LoadFlow&receiver=me&variantId=" + VARIANT_2_ID + "¶metersUuid=" + PARAMETERS_UUID + "&limitReduction=0.7", NETWORK_UUID) .header(HEADER_USER_ID, "userId")) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) @@ -304,7 +310,7 @@ public void testDeleteResults() throws Exception { .thenReturn(CompletableFuture.completedFuture(LoadFlowResultMock.RESULT)); MvcResult result = mockMvc.perform(post( - "/" + VERSION + "/networks/{networkUuid}/run-and-save?reportType=LoadFlow&receiver=me&variantId=" + VARIANT_2_ID, NETWORK_UUID) + "/" + VERSION + "/networks/{networkUuid}/run-and-save?reportType=LoadFlow&receiver=me&variantId=" + VARIANT_2_ID + "¶metersUuid=" + PARAMETERS_UUID, NETWORK_UUID) .header(HEADER_USER_ID, "userId")) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) @@ -342,7 +348,7 @@ public void stopTest() throws Exception { .thenReturn(CompletableFuture.completedFuture(LoadFlowResultMock.RESULT)); mockMvc.perform(post( - "/" + VERSION + "/networks/{networkUuid}/run-and-save?reportType=LoadFlow&receiver=me&variantId=" + VARIANT_2_ID, NETWORK_UUID) + "/" + VERSION + "/networks/{networkUuid}/run-and-save?reportType=LoadFlow&receiver=me&variantId=" + VARIANT_2_ID + "¶metersUuid=" + PARAMETERS_UUID, NETWORK_UUID) .header(HEADER_USER_ID, "userId")) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) @@ -393,7 +399,7 @@ public void runWithReportTest() { .thenReturn(CompletableFuture.completedFuture(LoadFlowResultMock.RESULT)); mockMvc.perform(post( - "/" + VERSION + "/networks/{networkUuid}/run-and-save?reportType=LoadFlow&reporterId=myReporter&receiver=me&reportUuid=" + REPORT_UUID + "&variantId=" + VARIANT_2_ID, NETWORK_UUID) + "/" + VERSION + "/networks/{networkUuid}/run-and-save?reportType=LoadFlow&reporterId=myReporter&receiver=me&reportUuid=" + REPORT_UUID + "&variantId=" + VARIANT_2_ID + "¶metersUuid=" + PARAMETERS_UUID, NETWORK_UUID) .header(HEADER_USER_ID, "user")) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) @@ -412,7 +418,7 @@ public void runWithDefaultVariant() { .thenReturn(CompletableFuture.completedFuture(LoadFlowResultMock.RESULT)); mockMvc.perform(post( - "/" + VERSION + "/networks/{networkUuid}/run-and-save?reporterId=myReporter&receiver=me&reportUuid=" + REPORT_UUID, NETWORK_UUID) + "/" + VERSION + "/networks/{networkUuid}/run-and-save?reporterId=myReporter&receiver=me&reportUuid=" + REPORT_UUID + "¶metersUuid=" + PARAMETERS_UUID, NETWORK_UUID) .header(HEADER_USER_ID, "user")) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) diff --git a/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java b/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java new file mode 100644 index 00000000..7cecfb32 --- /dev/null +++ b/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java @@ -0,0 +1,172 @@ +/** + * 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.loadflow.server; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.gridsuite.loadflow.utils.assertions.Assertions.*; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.gridsuite.loadflow.server.dto.parameters.LoadFlowParametersInfos; +import org.gridsuite.loadflow.server.entities.parameters.LoadFlowParametersEntity; +import org.gridsuite.loadflow.server.repositories.parameters.LoadFlowParametersRepository; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.http.MediaType; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.powsybl.loadflow.LoadFlowParameters; + +/** + * @author Ayoub LABIDI + */ +@RunWith(SpringRunner.class) +@SpringBootTest +@AutoConfigureMockMvc +@Transactional +public class LoadFlowParametersTest { + + private static final String URI_PARAMETERS_BASE = "/v1/parameters"; + + private static final String URI_PARAMETERS_GET_PUT = URI_PARAMETERS_BASE + "/"; + + @Autowired + protected MockMvc mockMvc; + + @Autowired + protected ObjectMapper mapper; + + @Autowired + private LoadFlowParametersRepository parametersRepository; + + @Before + public void setup() { + parametersRepository.deleteAll(); + } + + @After + public void tearOff() { + parametersRepository.deleteAll(); + } + + @Test + public void testCreate() throws Exception { + + LoadFlowParametersInfos parametersToCreate = buildParameters(); + String parametersToCreateJson = mapper.writeValueAsString(parametersToCreate); + + mockMvc.perform(post(URI_PARAMETERS_BASE).content(parametersToCreateJson).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()).andReturn(); + + LoadFlowParametersInfos createdParameters = parametersRepository.findAll().get(0).toLoadFlowParametersInfos(); + + assertThat(createdParameters).recursivelyEquals(parametersToCreate); + } + + @Test + public void testRead() throws Exception { + + LoadFlowParametersInfos parametersToRead = buildParameters(); + + UUID parametersUuid = saveAndRetunId(parametersToRead); + + MvcResult mvcResult = mockMvc.perform(get(URI_PARAMETERS_GET_PUT + parametersUuid)) + .andExpect(status().isOk()).andReturn(); + String resultAsString = mvcResult.getResponse().getContentAsString(); + LoadFlowParametersInfos receivedParameters = mapper.readValue(resultAsString, new TypeReference<>() { + }); + + assertThat(receivedParameters).recursivelyEquals(parametersToRead); + } + + @Test + public void testUpdate() throws Exception { + + LoadFlowParametersInfos parametersToUpdate = buildParameters(); + + UUID parametersUuid = saveAndRetunId(parametersToUpdate); + + parametersToUpdate = buildParametersUpdate(); + + String parametersToUpdateJson = mapper.writeValueAsString(parametersToUpdate); + + mockMvc.perform(put(URI_PARAMETERS_GET_PUT + parametersUuid).content(parametersToUpdateJson).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + + LoadFlowParametersInfos updatedParameters = parametersRepository.findById(parametersUuid).get().toLoadFlowParametersInfos(); + + assertThat(updatedParameters).recursivelyEquals(parametersToUpdate); + } + + @Test + public void testDelete() throws Exception { + + LoadFlowParametersInfos parametersToDelete = buildParameters(); + + UUID parametersUuid = saveAndRetunId(parametersToDelete); + + mockMvc.perform(delete(URI_PARAMETERS_GET_PUT + parametersUuid)).andExpect(status().isOk()).andReturn(); + + List storedParameters = parametersRepository.findAll(); + + assertTrue(storedParameters.isEmpty()); + } + + @Test + public void testGetAll() throws Exception { + LoadFlowParametersInfos parameters1 = buildParameters(); + + LoadFlowParametersInfos parameters2 = buildParametersUpdate(); + + saveAndRetunId(parameters1); + + saveAndRetunId(parameters2); + + MvcResult mvcResult = mockMvc.perform(get(URI_PARAMETERS_BASE)) + .andExpect(status().isOk()).andReturn(); + String resultAsString = mvcResult.getResponse().getContentAsString(); + List receivedParameters = mapper.readValue(resultAsString, new TypeReference<>() { + }); + + assertThat(receivedParameters).hasSize(2); + } + + /** Save parameters into the repository and return its UUID. */ + protected UUID saveAndRetunId(LoadFlowParametersInfos parametersInfos) { + parametersRepository.save(parametersInfos.toEntity()); + return parametersRepository.findAll().get(0).getId(); + } + + protected LoadFlowParametersInfos buildParameters() { + return LoadFlowParametersInfos.builder() + .commonParameters(LoadFlowParameters.load()) + .specificParametersPerProvider(Map.of()) + .build(); + } + + protected LoadFlowParametersInfos buildParametersUpdate() { + LoadFlowParameters loadFlowParameters = LoadFlowParameters.load(); + loadFlowParameters.setDc(true); + return LoadFlowParametersInfos.builder() + .commonParameters(loadFlowParameters) + .specificParametersPerProvider(Map.of()) + .build(); + } +} diff --git a/src/test/java/org/gridsuite/loadflow/utils/assertions/Assertions.java b/src/test/java/org/gridsuite/loadflow/utils/assertions/Assertions.java new file mode 100644 index 00000000..00163888 --- /dev/null +++ b/src/test/java/org/gridsuite/loadflow/utils/assertions/Assertions.java @@ -0,0 +1,21 @@ +/** + * 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.loadflow.utils.assertions; + +import org.assertj.core.util.CheckReturnValue; +import org.gridsuite.loadflow.server.dto.parameters.LoadFlowParametersInfos; + +/** + * @author Tristan Chuine + * {@link org.assertj.core.api.Assertions Assertions} completed with our custom assertions classes. + */ +public class Assertions extends org.assertj.core.api.Assertions { + @CheckReturnValue + public static DTOAssert assertThat(LoadFlowParametersInfos actual) { + return new DTOAssert<>(actual); + } +} diff --git a/src/test/java/org/gridsuite/loadflow/utils/assertions/DTOAssert.java b/src/test/java/org/gridsuite/loadflow/utils/assertions/DTOAssert.java new file mode 100644 index 00000000..f6f0e522 --- /dev/null +++ b/src/test/java/org/gridsuite/loadflow/utils/assertions/DTOAssert.java @@ -0,0 +1,38 @@ +/** + * 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.loadflow.utils.assertions; + +import org.assertj.core.api.AbstractAssert; +import org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration; + +import java.time.ZonedDateTime; +import java.util.Date; +import java.util.UUID; + +/** + * @author Tristan Chuine + * @author Slimane Amar + */ +public class DTOAssert extends AbstractAssert, T> { + public DTOAssert(T actual) { + super(actual, DTOAssert.class); + } + + public DTOAssert recursivelyEquals(T other) { + isNotNull(); + usingRecursiveComparison(this.getRecursiveConfiguration()).isEqualTo(other); + return myself; + } + + private RecursiveComparisonConfiguration getRecursiveConfiguration() { + return RecursiveComparisonConfiguration.builder() + .withIgnoreAllOverriddenEquals(true) // For equals test, need specific tests + .withIgnoredFieldsOfTypes(UUID.class, Date.class, ZonedDateTime.class) // For these types, need specific tests (uuid from db for example) + .withIgnoreCollectionOrder(true) // For collection order test, need specific tests + .build(); + } +} From 5081351fd2db1bdd0d9be837ff17d192be01b2a7 Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Tue, 2 Jan 2024 22:01:24 +0100 Subject: [PATCH 05/20] add unit tests Signed-off-by: Ayoub LABIDI --- .../loadflow/server/LoadFlowParametersTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java b/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java index 7cecfb32..35a3900f 100644 --- a/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java +++ b/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java @@ -129,6 +129,20 @@ public void testDelete() throws Exception { assertTrue(storedParameters.isEmpty()); } + @Test + public void testDuplicate() throws Exception { + LoadFlowParametersInfos parametersToDuplicate = buildParameters(); + + UUID parametersUuid = saveAndRetunId(parametersToDuplicate); + + mockMvc.perform(post(URI_PARAMETERS_BASE + "?duplicateFrom=" + parametersUuid)) + .andExpect(status().isOk()).andReturn(); + + List storedParameters = parametersRepository.findAll(); + + assertThat(storedParameters).hasSize(2); + } + @Test public void testGetAll() throws Exception { LoadFlowParametersInfos parameters1 = buildParameters(); From c44894cb34d4060afba87da111e4131101ea317f Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Tue, 2 Jan 2024 22:07:16 +0100 Subject: [PATCH 06/20] add unit tests Signed-off-by: Ayoub LABIDI --- .../gridsuite/loadflow/server/LoadFlowParametersTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java b/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java index 35a3900f..b9a0d539 100644 --- a/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java +++ b/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java @@ -143,6 +143,12 @@ public void testDuplicate() throws Exception { assertThat(storedParameters).hasSize(2); } + @Test + public void testGetWithInvalidId() throws Exception { + mockMvc.perform(get(URI_PARAMETERS_GET_PUT + UUID.randomUUID())) + .andExpect(status().isNotFound()).andReturn(); + } + @Test public void testGetAll() throws Exception { LoadFlowParametersInfos parameters1 = buildParameters(); From 323cf33039f096369840f63f08c085c722f262ee Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Mon, 8 Jan 2024 01:33:26 +0100 Subject: [PATCH 07/20] Fix run loadFlow with default params Signed-off-by: Ayoub LABIDI --- .../parameters/LoadFlowParametersService.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java b/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java index 0ad52f13..aecd7a88 100644 --- a/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java +++ b/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java @@ -7,6 +7,8 @@ package org.gridsuite.loadflow.server.service.parameters; import java.util.List; +import java.util.Map; +import java.util.Optional; import java.util.UUID; import org.gridsuite.loadflow.server.dto.parameters.LoadFlowParametersInfos; @@ -16,6 +18,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import com.powsybl.loadflow.LoadFlowParameters; + /** * @author Ayoub LABIDI */ @@ -38,8 +42,11 @@ public LoadFlowParametersInfos getParameters(UUID parametersUuid) { } public LoadFlowParametersValues getParametersValues(UUID parametersUuid, String provider) { - LoadFlowParametersEntity parametersEntity = loadFlowParametersRepository.findById(parametersUuid).orElse(null); - return parametersEntity != null ? parametersEntity.toLoadFlowParametersValues(provider) : null; + Optional parametersEntity = Optional.empty(); + if (parametersUuid != null) { + parametersEntity = loadFlowParametersRepository.findById(parametersUuid); + } + return parametersEntity.map(parameters -> parameters.toLoadFlowParametersValues(provider)).orElse(getDefaultLoadFlowParameters()); } public List getAllParameters() { @@ -61,4 +68,11 @@ public UUID duplicateParameters(UUID sourceParametersUuid) { LoadFlowParametersEntity duplicatedParameters = sourceParameters.copy(); return loadFlowParametersRepository.save(duplicatedParameters).getId(); } + + private LoadFlowParametersValues getDefaultLoadFlowParameters() { + return LoadFlowParametersValues.builder() + .commonParameters(LoadFlowParameters.load()) + .specificParameters(Map.of()) + .build(); + } } From 27b88c815c8526a0e7a8e0e57ebed18d04fcfc55 Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Wed, 10 Jan 2024 16:12:21 +0100 Subject: [PATCH 08/20] add create default params endpoint Signed-off-by: Ayoub LABIDI --- .../server/LoadFlowParametersController.java | 8 ++++++++ .../parameters/LoadFlowParametersService.java | 16 +++++++--------- .../loadflow/server/LoadFlowParametersTest.java | 15 +++++++++++++++ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java b/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java index ca8d469e..4519bfef 100644 --- a/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java +++ b/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java @@ -42,6 +42,14 @@ public ResponseEntity createParameters( return ResponseEntity.ok().body(parametersService.createParameters(parametersInfos)); } + @PostMapping(value = "/default") + @Operation(summary = "Create default parameters") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Default parameters were created")}) + public ResponseEntity createDefaultParameters() { + return ResponseEntity.ok().body(parametersService.createDefaultParameters()); + } + @PostMapping(value = "") @Operation(summary = "Duplicate parameters") @ApiResponses(value = { diff --git a/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java b/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java index aecd7a88..97a069c4 100644 --- a/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java +++ b/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java @@ -8,7 +8,6 @@ import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.UUID; import org.gridsuite.loadflow.server.dto.parameters.LoadFlowParametersInfos; @@ -42,11 +41,8 @@ public LoadFlowParametersInfos getParameters(UUID parametersUuid) { } public LoadFlowParametersValues getParametersValues(UUID parametersUuid, String provider) { - Optional parametersEntity = Optional.empty(); - if (parametersUuid != null) { - parametersEntity = loadFlowParametersRepository.findById(parametersUuid); - } - return parametersEntity.map(parameters -> parameters.toLoadFlowParametersValues(provider)).orElse(getDefaultLoadFlowParameters()); + LoadFlowParametersEntity parametersEntity = loadFlowParametersRepository.findById(parametersUuid).orElse(null); + return parametersEntity != null ? parametersEntity.toLoadFlowParametersValues(provider) : null; } public List getAllParameters() { @@ -69,10 +65,12 @@ public UUID duplicateParameters(UUID sourceParametersUuid) { return loadFlowParametersRepository.save(duplicatedParameters).getId(); } - private LoadFlowParametersValues getDefaultLoadFlowParameters() { - return LoadFlowParametersValues.builder() + public UUID createDefaultParameters() { + //default parameters + LoadFlowParametersInfos defaultParametersInfos = LoadFlowParametersInfos.builder() .commonParameters(LoadFlowParameters.load()) - .specificParameters(Map.of()) + .specificParametersPerProvider(Map.of()) .build(); + return createParameters(defaultParametersInfos); } } diff --git a/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java b/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java index b9a0d539..82b927f4 100644 --- a/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java +++ b/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java @@ -80,6 +80,21 @@ public void testCreate() throws Exception { assertThat(createdParameters).recursivelyEquals(parametersToCreate); } + @Test + public void testCreateWithDefaultValues() throws Exception { + LoadFlowParametersInfos defaultParameters = LoadFlowParametersInfos.builder() + .commonParameters(LoadFlowParameters.load()) + .specificParametersPerProvider(Map.of()) + .build(); + + mockMvc.perform(post(URI_PARAMETERS_BASE + "/default")) + .andExpect(status().isOk()).andReturn(); + + LoadFlowParametersInfos createdParameters = parametersRepository.findAll().get(0).toLoadFlowParametersInfos(); + + assertThat(createdParameters).recursivelyEquals(defaultParameters); + } + @Test public void testRead() throws Exception { From d08049db51b0eafe0195a61126380dd1ac6423b8 Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Wed, 10 Jan 2024 16:35:14 +0100 Subject: [PATCH 09/20] Requested changes Signed-off-by: Ayoub LABIDI --- .../loadflow/server/LoadFlowParametersController.java | 2 +- .../server/dto/parameters/LoadFlowParametersInfos.java | 2 +- .../server/entities/parameters/LoadFlowParametersEntity.java | 3 +-- .../entities/parameters/LoadFlowSpecificParameterEntity.java | 3 +-- .../parameters/LoadFlowParametersRepository.java | 2 +- .../server/service/parameters/LoadFlowParametersService.java | 2 +- .../gridsuite/loadflow/server/LoadFlowParametersTest.java | 2 +- .../org/gridsuite/loadflow/utils/assertions/Assertions.java | 4 ++-- .../org/gridsuite/loadflow/utils/assertions/DTOAssert.java | 5 ++--- 9 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java b/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java index 4519bfef..3ea66df8 100644 --- a/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java +++ b/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023, RTE (http://www.rte-france.com) + * Copyright (c) 2024, 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/. diff --git a/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersInfos.java b/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersInfos.java index 4223439c..3029fcda 100644 --- a/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersInfos.java +++ b/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersInfos.java @@ -1,5 +1,5 @@ /** - Copyright (c) 2023, RTE (http://www.rte-france.com) + Copyright (c) 2024, 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/. diff --git a/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java index 31904b13..9f036f4f 100644 --- a/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java +++ b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java @@ -1,10 +1,9 @@ /** - * Copyright (c) 2023, RTE (http://www.rte-france.com) + * Copyright (c) 2024, 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.loadflow.server.entities.parameters; import com.powsybl.iidm.network.Country; diff --git a/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowSpecificParameterEntity.java b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowSpecificParameterEntity.java index 2b17c066..68c387fb 100644 --- a/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowSpecificParameterEntity.java +++ b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowSpecificParameterEntity.java @@ -1,10 +1,9 @@ /** - * Copyright (c) 2023, RTE (http://www.rte-france.com) + * Copyright (c) 2024, 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.loadflow.server.entities.parameters; import java.util.UUID; diff --git a/src/main/java/org/gridsuite/loadflow/server/repositories/parameters/LoadFlowParametersRepository.java b/src/main/java/org/gridsuite/loadflow/server/repositories/parameters/LoadFlowParametersRepository.java index 0ac34823..b9a82ab2 100644 --- a/src/main/java/org/gridsuite/loadflow/server/repositories/parameters/LoadFlowParametersRepository.java +++ b/src/main/java/org/gridsuite/loadflow/server/repositories/parameters/LoadFlowParametersRepository.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023, RTE (http://www.rte-france.com) + * Copyright (c) 2024, 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/. diff --git a/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java b/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java index 97a069c4..fa8ad833 100644 --- a/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java +++ b/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023, RTE (http://www.rte-france.com) + * Copyright (c) 2024, 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/. diff --git a/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java b/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java index 82b927f4..9bfbf907 100644 --- a/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java +++ b/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023, RTE (http://www.rte-france.com) + * Copyright (c) 2024, 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/. diff --git a/src/test/java/org/gridsuite/loadflow/utils/assertions/Assertions.java b/src/test/java/org/gridsuite/loadflow/utils/assertions/Assertions.java index 00163888..66f4bc7b 100644 --- a/src/test/java/org/gridsuite/loadflow/utils/assertions/Assertions.java +++ b/src/test/java/org/gridsuite/loadflow/utils/assertions/Assertions.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023, RTE (http://www.rte-france.com) + * Copyright (c) 2024, 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/. @@ -10,7 +10,7 @@ import org.gridsuite.loadflow.server.dto.parameters.LoadFlowParametersInfos; /** - * @author Tristan Chuine + * @author Ayoub LABIDI * {@link org.assertj.core.api.Assertions Assertions} completed with our custom assertions classes. */ public class Assertions extends org.assertj.core.api.Assertions { diff --git a/src/test/java/org/gridsuite/loadflow/utils/assertions/DTOAssert.java b/src/test/java/org/gridsuite/loadflow/utils/assertions/DTOAssert.java index f6f0e522..98a7728d 100644 --- a/src/test/java/org/gridsuite/loadflow/utils/assertions/DTOAssert.java +++ b/src/test/java/org/gridsuite/loadflow/utils/assertions/DTOAssert.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023, RTE (http://www.rte-france.com) + * Copyright (c) 2024, 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/. @@ -14,8 +14,7 @@ import java.util.UUID; /** - * @author Tristan Chuine - * @author Slimane Amar + * @author Ayoub LABIDI */ public class DTOAssert extends AbstractAssert, T> { public DTOAssert(T actual) { From f112ae23d26e059c684fd5a9021f38219a7dee43 Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Mon, 15 Jan 2024 14:39:51 +0100 Subject: [PATCH 10/20] Requested change Signed-off-by: Ayoub LABIDI --- .../gridsuite/loadflow/server/LoadFlowParametersController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java b/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java index 3ea66df8..ef98a1a0 100644 --- a/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java +++ b/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java @@ -54,7 +54,7 @@ public ResponseEntity createDefaultParameters() { @Operation(summary = "Duplicate parameters") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "parameters were duplicated")}) - public ResponseEntity createParameters( + public ResponseEntity duplicateParameters( @RequestParam("duplicateFrom") UUID sourceParametersUuid) { return ResponseEntity.ok().body(parametersService.duplicateParameters(sourceParametersUuid)); } From 84fec28da0322e2fc4afe4cadae678f05bd1ecef Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Tue, 16 Jan 2024 10:31:20 +0100 Subject: [PATCH 11/20] Fix code smells Signed-off-by: Ayoub LABIDI --- .../loadflow/server/LoadFlowController.java | 11 ++++++----- .../server/LoadFlowParametersController.java | 8 +++++--- .../parameters/LoadFlowParametersEntity.java | 15 +++++++++++---- .../loadflow/server/service/ReportService.java | 2 -- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java b/src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java index 8f0fbc00..e2c0c46a 100644 --- a/src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java +++ b/src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java @@ -18,7 +18,6 @@ import org.gridsuite.loadflow.server.service.LoadFlowService; import org.gridsuite.loadflow.server.service.parameters.LoadFlowParametersService; import org.gridsuite.loadflow.server.utils.ReportContext; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -39,11 +38,13 @@ @Tag(name = "loadflow-server") public class LoadFlowController { - @Autowired - private LoadFlowService loadFlowService; + private final LoadFlowService loadFlowService; + private final LoadFlowParametersService parametersService; - @Autowired - private LoadFlowParametersService parametersService; + public LoadFlowController(LoadFlowService loadFlowService, LoadFlowParametersService parametersService) { + this.loadFlowService = loadFlowService; + this.parametersService = parametersService; + } @PostMapping(value = "/networks/{networkUuid}/run-and-save", produces = APPLICATION_JSON_VALUE) @Operation(summary = "Run a load flow on a network") diff --git a/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java b/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java index ef98a1a0..d2bb8a92 100644 --- a/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java +++ b/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java @@ -14,7 +14,6 @@ import org.gridsuite.loadflow.server.dto.parameters.LoadFlowParametersInfos; import org.gridsuite.loadflow.server.service.parameters.LoadFlowParametersService; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -30,8 +29,11 @@ @Tag(name = "LoadFlow parameters") public class LoadFlowParametersController { - @Autowired - private LoadFlowParametersService parametersService; + private final LoadFlowParametersService parametersService; + + public LoadFlowParametersController(LoadFlowParametersService parametersService) { + this.parametersService = parametersService; + } @PostMapping(value = "", consumes = MediaType.APPLICATION_JSON_VALUE) @Operation(summary = "Create parameters") diff --git a/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java index 9f036f4f..76e39a21 100644 --- a/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java +++ b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java @@ -116,19 +116,23 @@ public void assignAttributes(LoadFlowParametersInfos loadFlowParametersInfos) { loadFlowParametersInfos.getSpecificParametersPerProvider().forEach((provider, paramsMap) -> { if (paramsMap != null) { paramsMap.forEach((paramName, paramValue) -> { - if (paramValue != null) { - allSpecificValuesEntities.add(new LoadFlowSpecificParameterEntity( + if (paramValue != null) { + allSpecificValuesEntities.add(new LoadFlowSpecificParameterEntity( null, provider, paramName, paramValue)); - } } - ); + }); } }); } } + assignCommonValues(allCommonValues); + assignSpecificValues(allSpecificValuesEntities); + } + + private void assignCommonValues(LoadFlowParameters allCommonValues) { voltageInitMode = allCommonValues.getVoltageInitMode(); transformerVoltageControlOn = allCommonValues.isTransformerVoltageControlOn(); useReactiveLimits = allCommonValues.isUseReactiveLimits(); @@ -145,6 +149,9 @@ public void assignAttributes(LoadFlowParametersInfos loadFlowParametersInfos) { connectedComponentMode = allCommonValues.getConnectedComponentMode(); hvdcAcEmulation = allCommonValues.isHvdcAcEmulation(); dcPowerFactor = allCommonValues.getDcPowerFactor(); + } + + private void assignSpecificValues(List allSpecificValuesEntities) { if (specificParameters == null) { specificParameters = allSpecificValuesEntities; } else { diff --git a/src/main/java/org/gridsuite/loadflow/server/service/ReportService.java b/src/main/java/org/gridsuite/loadflow/server/service/ReportService.java index 96136a88..8eae7300 100644 --- a/src/main/java/org/gridsuite/loadflow/server/service/ReportService.java +++ b/src/main/java/org/gridsuite/loadflow/server/service/ReportService.java @@ -11,7 +11,6 @@ import com.powsybl.commons.PowsyblException; import com.powsybl.commons.reporter.Reporter; import com.powsybl.commons.reporter.ReporterModelJsonModule; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -40,7 +39,6 @@ public class ReportService { private ObjectMapper objectMapper; - @Autowired public ReportService(ObjectMapper objectMapper, @Value("${gridsuite.services.report-server.base-uri:http://report-server/}") String reportServerBaseUri, RestTemplate restTemplate) { From 6bf5b02534c1f2421da483a2fd57768a7d7eb02b Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Tue, 16 Jan 2024 16:48:14 +0100 Subject: [PATCH 12/20] Requested changes Signed-off-by: Ayoub LABIDI --- .../loadflow/server/LoadFlowController.java | 13 +---------- .../server/LoadFlowParametersController.java | 10 +++++---- .../server/service/LoadFlowService.java | 22 ++++++++++++++++--- .../parameters/LoadFlowParametersService.java | 22 +++++++++++-------- 4 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java b/src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java index e2c0c46a..a9d11621 100644 --- a/src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java +++ b/src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java @@ -60,18 +60,7 @@ public ResponseEntity run(@Parameter(description = "Network UUID") @PathVa @Parameter(description = "parametersUuid") @RequestParam(name = "parametersUuid", required = false) UUID parametersUuid, @RequestHeader(HEADER_USER_ID) String userId ) { - String providerToUse = provider != null ? provider : loadFlowService.getDefaultProvider(); - LoadFlowRunContext loadFlowRunContext = LoadFlowRunContext.builder() - .networkUuid(networkUuid) - .variantId(variantId) - .receiver(receiver) - .provider(providerToUse) - .parameters(parametersService.getParametersValues(parametersUuid, providerToUse)) - .reportContext(ReportContext.builder().reportId(reportId).reportName(reportName).reportType(reportType).build()) - .userId(userId) - .limitReduction(limitReduction) - .build(); - UUID resultUuid = loadFlowService.runAndSaveResult(loadFlowRunContext); + UUID resultUuid = loadFlowService.runAndSaveResult(networkUuid, variantId, provider, receiver, reportId, reportName, reportType, limitReduction, parametersUuid, userId); return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(resultUuid); } diff --git a/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java b/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java index d2bb8a92..8887519e 100644 --- a/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java +++ b/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java @@ -58,7 +58,9 @@ public ResponseEntity createDefaultParameters() { @ApiResponse(responseCode = "200", description = "parameters were duplicated")}) public ResponseEntity duplicateParameters( @RequestParam("duplicateFrom") UUID sourceParametersUuid) { - return ResponseEntity.ok().body(parametersService.duplicateParameters(sourceParametersUuid)); + return parametersService.duplicateParameters(sourceParametersUuid) + .map(duplicatedParametersUuid -> ResponseEntity.ok().body(duplicatedParametersUuid)) + .orElse(ResponseEntity.notFound().build()); } @GetMapping(value = "/{uuid}", produces = MediaType.APPLICATION_JSON_VALUE) @@ -68,9 +70,9 @@ public ResponseEntity duplicateParameters( @ApiResponse(responseCode = "404", description = "parameters were not found")}) public ResponseEntity getParameters( @Parameter(description = "parameters UUID") @PathVariable("uuid") UUID parametersUuid) { - LoadFlowParametersInfos parameters = parametersService.getParameters(parametersUuid); - return parameters != null ? ResponseEntity.ok().body(parametersService.getParameters(parametersUuid)) - : ResponseEntity.notFound().build(); + return parametersService.getParameters(parametersUuid) + .map(paramsInfos -> ResponseEntity.ok().body(paramsInfos)) + .orElse(ResponseEntity.notFound().build()); } @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE) diff --git a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowService.java b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowService.java index ca35a80e..1a40c716 100644 --- a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowService.java +++ b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowService.java @@ -21,6 +21,8 @@ import org.gridsuite.loadflow.server.entities.LimitViolationsEntity; import org.gridsuite.loadflow.server.entities.LoadFlowResultEntity; import org.gridsuite.loadflow.server.repositories.LoadFlowResultRepository; +import org.gridsuite.loadflow.server.service.parameters.LoadFlowParametersService; +import org.gridsuite.loadflow.server.utils.ReportContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -51,11 +53,14 @@ public class LoadFlowService { private UuidGeneratorService uuidGeneratorService; - public LoadFlowService(NotificationService notificationService, LoadFlowResultRepository resultRepository, ObjectMapper objectMapper, UuidGeneratorService uuidGeneratorService) { + private LoadFlowParametersService parametersService; + + public LoadFlowService(NotificationService notificationService, LoadFlowResultRepository resultRepository, ObjectMapper objectMapper, UuidGeneratorService uuidGeneratorService, LoadFlowParametersService parametersService) { this.notificationService = Objects.requireNonNull(notificationService); this.resultRepository = Objects.requireNonNull(resultRepository); this.objectMapper = Objects.requireNonNull(objectMapper); this.uuidGeneratorService = Objects.requireNonNull(uuidGeneratorService); + this.parametersService = Objects.requireNonNull(parametersService); } public static List getProviders() { @@ -83,8 +88,19 @@ public static Map> getSpecificLoadFlowParameters(String }).collect(Collectors.toMap(Pair::getLeft, Pair::getRight)); } - public UUID runAndSaveResult(LoadFlowRunContext runContext) { - Objects.requireNonNull(runContext); + public UUID runAndSaveResult(UUID networkUuid, String variantId, String provider, String receiver, UUID reportId, + String reportName, String reportType, Float limitReduction, UUID parametersUuid, String userId) { + String providerToUse = provider != null ? provider : getDefaultProvider(); + LoadFlowRunContext runContext = LoadFlowRunContext.builder() + .networkUuid(networkUuid) + .variantId(variantId) + .receiver(receiver) + .provider(providerToUse) + .parameters(parametersService.getParametersValues(parametersUuid, providerToUse).orElse(null)) + .reportContext(ReportContext.builder().reportId(reportId).reportName(reportName).reportType(reportType).build()) + .userId(userId) + .limitReduction(limitReduction) + .build(); UUID resultUuid = uuidGeneratorService.generate(); // update status to running status diff --git a/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java b/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java index fa8ad833..ce05cd69 100644 --- a/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java +++ b/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.UUID; import org.gridsuite.loadflow.server.dto.parameters.LoadFlowParametersInfos; @@ -36,13 +37,14 @@ public UUID createParameters(LoadFlowParametersInfos parametersInfos) { return loadFlowParametersRepository.save(parametersInfos.toEntity()).getId(); } - public LoadFlowParametersInfos getParameters(UUID parametersUuid) { - return loadFlowParametersRepository.findById(parametersUuid).map(LoadFlowParametersEntity::toLoadFlowParametersInfos).orElse(null); + public Optional getParameters(UUID parametersUuid) { + return loadFlowParametersRepository.findById(parametersUuid).map(LoadFlowParametersEntity::toLoadFlowParametersInfos); } - public LoadFlowParametersValues getParametersValues(UUID parametersUuid, String provider) { - LoadFlowParametersEntity parametersEntity = loadFlowParametersRepository.findById(parametersUuid).orElse(null); - return parametersEntity != null ? parametersEntity.toLoadFlowParametersValues(provider) : null; + public Optional getParametersValues(UUID parametersUuid, String provider) { + return loadFlowParametersRepository.findById(parametersUuid) + .map(entity -> Optional.of(entity.toLoadFlowParametersValues(provider))) + .orElse(Optional.empty()); } public List getAllParameters() { @@ -59,10 +61,12 @@ public void deleteParameters(UUID parametersUuid) { } @Transactional - public UUID duplicateParameters(UUID sourceParametersUuid) { - LoadFlowParametersEntity sourceParameters = loadFlowParametersRepository.findById(sourceParametersUuid).orElseThrow(); - LoadFlowParametersEntity duplicatedParameters = sourceParameters.copy(); - return loadFlowParametersRepository.save(duplicatedParameters).getId(); + public Optional duplicateParameters(UUID sourceParametersUuid) { + return loadFlowParametersRepository.findById(sourceParametersUuid) + .map(LoadFlowParametersEntity::copy) + .map(loadFlowParametersRepository::save) + .map(entity -> Optional.of(entity.getId())) + .orElse(Optional.empty()); } public UUID createDefaultParameters() { From 3fc08d94c7272e4d341cb136db0e23740d9a0b58 Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Tue, 16 Jan 2024 17:24:09 +0100 Subject: [PATCH 13/20] Fix checkStyle Signed-off-by: Ayoub LABIDI --- .../java/org/gridsuite/loadflow/server/LoadFlowController.java | 2 -- .../org/gridsuite/loadflow/server/LoadFlowControllerTest.java | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java b/src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java index a9d11621..43f19266 100644 --- a/src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java +++ b/src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java @@ -14,10 +14,8 @@ import org.gridsuite.loadflow.server.dto.LimitViolationInfos; import org.gridsuite.loadflow.server.dto.LoadFlowResult; import org.gridsuite.loadflow.server.dto.LoadFlowStatus; -import org.gridsuite.loadflow.server.service.LoadFlowRunContext; import org.gridsuite.loadflow.server.service.LoadFlowService; import org.gridsuite.loadflow.server.service.parameters.LoadFlowParametersService; -import org.gridsuite.loadflow.server.utils.ReportContext; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; diff --git a/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java b/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java index 9485bf29..dec4f923 100644 --- a/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java +++ b/src/test/java/org/gridsuite/loadflow/server/LoadFlowControllerTest.java @@ -274,7 +274,7 @@ public void testGetLimitViolations() throws Exception { .commonParameters(loadFlowParameters) .specificParameters(Collections.emptyMap()) .build(); - doReturn(loadFlowParametersInfos).when(loadFlowParametersService).getParametersValues(any(), any()); + doReturn(Optional.of(loadFlowParametersInfos)).when(loadFlowParametersService).getParametersValues(any(), any()); MvcResult result = mockMvc.perform(post( "/" + VERSION + "/networks/{networkUuid}/run-and-save?reportType=LoadFlow&receiver=me&variantId=" + VARIANT_2_ID + "¶metersUuid=" + PARAMETERS_UUID + "&limitReduction=0.7", NETWORK_UUID) From 228805d3adc48e75f5981054c8aa78e6e301b826 Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Wed, 17 Jan 2024 10:16:59 +0100 Subject: [PATCH 14/20] Fix code smells Signed-off-by: Ayoub LABIDI --- .../loadflow/server/LoadFlowController.java | 17 ++++++++++++----- .../server/service/LoadFlowRunContext.java | 7 +++++-- .../server/service/LoadFlowService.java | 19 +++++-------------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java b/src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java index 43f19266..d3fc74f0 100644 --- a/src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java +++ b/src/main/java/org/gridsuite/loadflow/server/LoadFlowController.java @@ -14,8 +14,9 @@ import org.gridsuite.loadflow.server.dto.LimitViolationInfos; import org.gridsuite.loadflow.server.dto.LoadFlowResult; import org.gridsuite.loadflow.server.dto.LoadFlowStatus; +import org.gridsuite.loadflow.server.service.LoadFlowRunContext; import org.gridsuite.loadflow.server.service.LoadFlowService; -import org.gridsuite.loadflow.server.service.parameters.LoadFlowParametersService; +import org.gridsuite.loadflow.server.utils.ReportContext; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -37,11 +38,9 @@ public class LoadFlowController { private final LoadFlowService loadFlowService; - private final LoadFlowParametersService parametersService; - public LoadFlowController(LoadFlowService loadFlowService, LoadFlowParametersService parametersService) { + public LoadFlowController(LoadFlowService loadFlowService) { this.loadFlowService = loadFlowService; - this.parametersService = parametersService; } @PostMapping(value = "/networks/{networkUuid}/run-and-save", produces = APPLICATION_JSON_VALUE) @@ -58,7 +57,15 @@ public ResponseEntity run(@Parameter(description = "Network UUID") @PathVa @Parameter(description = "parametersUuid") @RequestParam(name = "parametersUuid", required = false) UUID parametersUuid, @RequestHeader(HEADER_USER_ID) String userId ) { - UUID resultUuid = loadFlowService.runAndSaveResult(networkUuid, variantId, provider, receiver, reportId, reportName, reportType, limitReduction, parametersUuid, userId); + LoadFlowRunContext loadFlowRunContext = LoadFlowRunContext.builder() + .networkUuid(networkUuid) + .variantId(variantId) + .receiver(receiver) + .reportContext(ReportContext.builder().reportId(reportId).reportName(reportName).reportType(reportType).build()) + .userId(userId) + .limitReduction(limitReduction) + .build(); + UUID resultUuid = loadFlowService.runAndSaveResult(loadFlowRunContext, provider, parametersUuid); return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(resultUuid); } diff --git a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowRunContext.java b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowRunContext.java index 0d7e39cc..705a86e2 100644 --- a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowRunContext.java +++ b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowRunContext.java @@ -12,6 +12,8 @@ import com.powsybl.loadflow.LoadFlowProvider; import lombok.Builder; import lombok.Getter; +import lombok.Setter; + import org.gridsuite.loadflow.server.dto.parameters.LoadFlowParametersValues; import org.gridsuite.loadflow.server.utils.ReportContext; @@ -21,6 +23,7 @@ * @author Anis Touri */ @Getter +@Setter @Builder public class LoadFlowRunContext { @@ -30,9 +33,9 @@ public class LoadFlowRunContext { private final String receiver; - private final String provider; + private String provider; - private final LoadFlowParametersValues parameters; + private LoadFlowParametersValues parameters; private final ReportContext reportContext; diff --git a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowService.java b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowService.java index 1a40c716..a888b805 100644 --- a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowService.java +++ b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowService.java @@ -22,7 +22,6 @@ import org.gridsuite.loadflow.server.entities.LoadFlowResultEntity; import org.gridsuite.loadflow.server.repositories.LoadFlowResultRepository; import org.gridsuite.loadflow.server.service.parameters.LoadFlowParametersService; -import org.gridsuite.loadflow.server.utils.ReportContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -88,24 +87,16 @@ public static Map> getSpecificLoadFlowParameters(String }).collect(Collectors.toMap(Pair::getLeft, Pair::getRight)); } - public UUID runAndSaveResult(UUID networkUuid, String variantId, String provider, String receiver, UUID reportId, - String reportName, String reportType, Float limitReduction, UUID parametersUuid, String userId) { + public UUID runAndSaveResult(LoadFlowRunContext loadFlowRunContext, String provider, UUID parametersUuid) { String providerToUse = provider != null ? provider : getDefaultProvider(); - LoadFlowRunContext runContext = LoadFlowRunContext.builder() - .networkUuid(networkUuid) - .variantId(variantId) - .receiver(receiver) - .provider(providerToUse) - .parameters(parametersService.getParametersValues(parametersUuid, providerToUse).orElse(null)) - .reportContext(ReportContext.builder().reportId(reportId).reportName(reportName).reportType(reportType).build()) - .userId(userId) - .limitReduction(limitReduction) - .build(); + // set provider and parameters + loadFlowRunContext.setParameters(parametersService.getParametersValues(parametersUuid, providerToUse).orElse(null)); + loadFlowRunContext.setProvider(providerToUse); UUID resultUuid = uuidGeneratorService.generate(); // update status to running status setStatus(List.of(resultUuid), LoadFlowStatus.RUNNING); - notificationService.sendRunMessage(new LoadFlowResultContext(resultUuid, runContext).toMessage(objectMapper)); + notificationService.sendRunMessage(new LoadFlowResultContext(resultUuid, loadFlowRunContext).toMessage(objectMapper)); return resultUuid; } From b8d78de92255af2b3d793b8457fcd50440f14310 Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Wed, 17 Jan 2024 13:20:44 +0100 Subject: [PATCH 15/20] Requested changes Signed-off-by: Ayoub LABIDI --- .../service/parameters/LoadFlowParametersService.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java b/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java index ce05cd69..0e6bcb83 100644 --- a/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java +++ b/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java @@ -43,8 +43,7 @@ public Optional getParameters(UUID parametersUuid) { public Optional getParametersValues(UUID parametersUuid, String provider) { return loadFlowParametersRepository.findById(parametersUuid) - .map(entity -> Optional.of(entity.toLoadFlowParametersValues(provider))) - .orElse(Optional.empty()); + .map(entity -> entity.toLoadFlowParametersValues(provider)); } public List getAllParameters() { @@ -65,8 +64,7 @@ public Optional duplicateParameters(UUID sourceParametersUuid) { return loadFlowParametersRepository.findById(sourceParametersUuid) .map(LoadFlowParametersEntity::copy) .map(loadFlowParametersRepository::save) - .map(entity -> Optional.of(entity.getId())) - .orElse(Optional.empty()); + .map(entity -> entity.getId()); } public UUID createDefaultParameters() { From ded3688cca92413d8028e80fbbc936dab5b41414 Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Wed, 24 Jan 2024 16:30:44 +0100 Subject: [PATCH 16/20] rename columns and modify duplicate path Signed-off-by: Ayoub LABIDI --- .../server/LoadFlowParametersController.java | 4 ++-- .../parameters/LoadFlowParametersEntity.java | 2 +- .../LoadFlowSpecificParameterEntity.java | 4 ++-- ...03Z.xml => changelog_20240124T152518Z.xml} | 22 +++++++++---------- .../db/changelog/db.changelog-master.yaml | 2 +- .../server/LoadFlowParametersTest.java | 2 +- 6 files changed, 18 insertions(+), 18 deletions(-) rename src/main/resources/db/changelog/changesets/{changelog_20231228T155403Z.xml => changelog_20240124T152518Z.xml} (81%) diff --git a/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java b/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java index 8887519e..1228a7b3 100644 --- a/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java +++ b/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java @@ -52,12 +52,12 @@ public ResponseEntity createDefaultParameters() { return ResponseEntity.ok().body(parametersService.createDefaultParameters()); } - @PostMapping(value = "") + @PostMapping(value = "/{sourceParametersUuid}") @Operation(summary = "Duplicate parameters") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "parameters were duplicated")}) public ResponseEntity duplicateParameters( - @RequestParam("duplicateFrom") UUID sourceParametersUuid) { + @Parameter(description = "source parameters UUID") @PathVariable("sourceParametersUuid") UUID sourceParametersUuid) { return parametersService.duplicateParameters(sourceParametersUuid) .map(duplicatedParametersUuid -> ResponseEntity.ok().body(duplicatedParametersUuid)) .orElse(ResponseEntity.notFound().build()); diff --git a/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java index 76e39a21..ce3fe740 100644 --- a/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java +++ b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java @@ -94,7 +94,7 @@ public class LoadFlowParametersEntity { private double dcPowerFactor; @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "load_flow_parameters_entity_id", foreignKey = @ForeignKey(name = "loadFlowParametersEntity_specificParameters_fk")) + @JoinColumn(name = "load_flow_parameters_id", foreignKey = @ForeignKey(name = "loadFlowParametersEntity_specificParameters_fk")) private List specificParameters; public LoadFlowParametersEntity(LoadFlowParametersInfos loadFlowParametersInfos) { diff --git a/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowSpecificParameterEntity.java b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowSpecificParameterEntity.java index 68c387fb..3abbff68 100644 --- a/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowSpecificParameterEntity.java +++ b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowSpecificParameterEntity.java @@ -28,7 +28,7 @@ @Getter @Entity @Table(name = "loadFlowSpecificParameters", indexes = { - @Index(name = "loadFlowParametersEntity_specificParameters_index", columnList = "load_flow_parameters_entity_id") + @Index(name = "loadFlowParametersEntity_specificParameters_index", columnList = "load_flow_parameters_id") }) public class LoadFlowSpecificParameterEntity { @Id @@ -42,6 +42,6 @@ public class LoadFlowSpecificParameterEntity { @Column(name = "name") private String name; - @Column(name = "value") + @Column(name = "value_") private String value; } diff --git a/src/main/resources/db/changelog/changesets/changelog_20231228T155403Z.xml b/src/main/resources/db/changelog/changesets/changelog_20240124T152518Z.xml similarity index 81% rename from src/main/resources/db/changelog/changesets/changelog_20231228T155403Z.xml rename to src/main/resources/db/changelog/changesets/changelog_20240124T152518Z.xml index b4420ea6..d45a8452 100644 --- a/src/main/resources/db/changelog/changesets/changelog_20231228T155403Z.xml +++ b/src/main/resources/db/changelog/changesets/changelog_20240124T152518Z.xml @@ -1,6 +1,6 @@ - + @@ -22,7 +22,7 @@ - + @@ -30,31 +30,31 @@ - + - - + + - + - + - + - + - - + + diff --git a/src/main/resources/db/changelog/db.changelog-master.yaml b/src/main/resources/db/changelog/db.changelog-master.yaml index ec5a6123..8865bea6 100644 --- a/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/src/main/resources/db/changelog/db.changelog-master.yaml @@ -10,6 +10,6 @@ databaseChangeLog: file: changesets/changelog_20231115T10528Z.xml relativeToChangelogFile: true - include: - file: changesets/changelog_20231228T155403Z.xml + file: changesets/changelog_20240124T152518Z.xml relativeToChangelogFile: true diff --git a/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java b/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java index 9bfbf907..15d359e3 100644 --- a/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java +++ b/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java @@ -150,7 +150,7 @@ public void testDuplicate() throws Exception { UUID parametersUuid = saveAndRetunId(parametersToDuplicate); - mockMvc.perform(post(URI_PARAMETERS_BASE + "?duplicateFrom=" + parametersUuid)) + mockMvc.perform(post(URI_PARAMETERS_BASE + "/" + parametersUuid)) .andExpect(status().isOk()).andReturn(); List storedParameters = parametersRepository.findAll(); From 806bf1e6f66ae25ed4f4f17efbaf2df3f1eae83d Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Fri, 26 Jan 2024 10:02:50 +0100 Subject: [PATCH 17/20] Requested changes Signed-off-by: Ayoub LABIDI --- .../server/LoadFlowParametersController.java | 29 +++++--------- .../parameters/LoadFlowParametersService.java | 2 +- .../server/LoadFlowParametersTest.java | 40 +++++++------------ 3 files changed, 26 insertions(+), 45 deletions(-) diff --git a/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java b/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java index 1228a7b3..1002fc1b 100644 --- a/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java +++ b/src/main/java/org/gridsuite/loadflow/server/LoadFlowParametersController.java @@ -9,7 +9,6 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; import org.gridsuite.loadflow.server.dto.parameters.LoadFlowParametersInfos; @@ -37,42 +36,34 @@ public LoadFlowParametersController(LoadFlowParametersService parametersService) @PostMapping(value = "", consumes = MediaType.APPLICATION_JSON_VALUE) @Operation(summary = "Create parameters") - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "parameters were created")}) + @ApiResponse(responseCode = "200", description = "parameters were created") public ResponseEntity createParameters( @RequestBody LoadFlowParametersInfos parametersInfos) { - return ResponseEntity.ok().body(parametersService.createParameters(parametersInfos)); + return ResponseEntity.ok(parametersService.createParameters(parametersInfos)); } @PostMapping(value = "/default") @Operation(summary = "Create default parameters") - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Default parameters were created")}) + @ApiResponse(responseCode = "200", description = "Default parameters were created") public ResponseEntity createDefaultParameters() { - return ResponseEntity.ok().body(parametersService.createDefaultParameters()); + return ResponseEntity.ok(parametersService.createDefaultParameters()); } @PostMapping(value = "/{sourceParametersUuid}") @Operation(summary = "Duplicate parameters") - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "parameters were duplicated")}) + @ApiResponse(responseCode = "200", description = "parameters were duplicated") public ResponseEntity duplicateParameters( @Parameter(description = "source parameters UUID") @PathVariable("sourceParametersUuid") UUID sourceParametersUuid) { - return parametersService.duplicateParameters(sourceParametersUuid) - .map(duplicatedParametersUuid -> ResponseEntity.ok().body(duplicatedParametersUuid)) - .orElse(ResponseEntity.notFound().build()); + return ResponseEntity.of(parametersService.duplicateParameters(sourceParametersUuid)); } @GetMapping(value = "/{uuid}", produces = MediaType.APPLICATION_JSON_VALUE) @Operation(summary = "Get parameters") - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "parameters were returned"), - @ApiResponse(responseCode = "404", description = "parameters were not found")}) + @ApiResponse(responseCode = "200", description = "parameters were returned") + @ApiResponse(responseCode = "404", description = "parameters were not found") public ResponseEntity getParameters( @Parameter(description = "parameters UUID") @PathVariable("uuid") UUID parametersUuid) { - return parametersService.getParameters(parametersUuid) - .map(paramsInfos -> ResponseEntity.ok().body(paramsInfos)) - .orElse(ResponseEntity.notFound().build()); + return ResponseEntity.of(parametersService.getParameters(parametersUuid)); } @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE) @@ -84,7 +75,7 @@ public ResponseEntity> getAllParameters() { @PutMapping(value = "/{uuid}", consumes = MediaType.APPLICATION_JSON_VALUE) @Operation(summary = "Update parameters") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "parameters were updated")}) + @ApiResponse(responseCode = "200", description = "parameters were updated") public ResponseEntity updateParameters( @Parameter(description = "parameters UUID") @PathVariable("uuid") UUID parametersUuid, @RequestBody LoadFlowParametersInfos parametersInfos) { diff --git a/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java b/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java index 0e6bcb83..d6543947 100644 --- a/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java +++ b/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java @@ -64,7 +64,7 @@ public Optional duplicateParameters(UUID sourceParametersUuid) { return loadFlowParametersRepository.findById(sourceParametersUuid) .map(LoadFlowParametersEntity::copy) .map(loadFlowParametersRepository::save) - .map(entity -> entity.getId()); + .map(LoadFlowParametersEntity::getId); } public UUID createDefaultParameters() { diff --git a/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java b/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java index 15d359e3..0ae14011 100644 --- a/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java +++ b/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java @@ -6,7 +6,6 @@ */ package org.gridsuite.loadflow.server; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.gridsuite.loadflow.utils.assertions.Assertions.*; import java.util.List; import java.util.Map; @@ -15,14 +14,11 @@ import org.gridsuite.loadflow.server.dto.parameters.LoadFlowParametersInfos; import org.gridsuite.loadflow.server.entities.parameters.LoadFlowParametersEntity; import org.gridsuite.loadflow.server.repositories.parameters.LoadFlowParametersRepository; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.AfterEach; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; import org.springframework.transaction.annotation.Transactional; @@ -37,11 +33,10 @@ /** * @author Ayoub LABIDI */ -@RunWith(SpringRunner.class) @SpringBootTest @AutoConfigureMockMvc @Transactional -public class LoadFlowParametersTest { +class LoadFlowParametersTest { private static final String URI_PARAMETERS_BASE = "/v1/parameters"; @@ -54,20 +49,15 @@ public class LoadFlowParametersTest { protected ObjectMapper mapper; @Autowired - private LoadFlowParametersRepository parametersRepository; + LoadFlowParametersRepository parametersRepository; - @Before - public void setup() { - parametersRepository.deleteAll(); - } - - @After - public void tearOff() { + @AfterEach + public void clean() { parametersRepository.deleteAll(); } @Test - public void testCreate() throws Exception { + void testCreate() throws Exception { LoadFlowParametersInfos parametersToCreate = buildParameters(); String parametersToCreateJson = mapper.writeValueAsString(parametersToCreate); @@ -81,7 +71,7 @@ public void testCreate() throws Exception { } @Test - public void testCreateWithDefaultValues() throws Exception { + void testCreateWithDefaultValues() throws Exception { LoadFlowParametersInfos defaultParameters = LoadFlowParametersInfos.builder() .commonParameters(LoadFlowParameters.load()) .specificParametersPerProvider(Map.of()) @@ -96,7 +86,7 @@ public void testCreateWithDefaultValues() throws Exception { } @Test - public void testRead() throws Exception { + void testRead() throws Exception { LoadFlowParametersInfos parametersToRead = buildParameters(); @@ -112,7 +102,7 @@ public void testRead() throws Exception { } @Test - public void testUpdate() throws Exception { + void testUpdate() throws Exception { LoadFlowParametersInfos parametersToUpdate = buildParameters(); @@ -131,7 +121,7 @@ public void testUpdate() throws Exception { } @Test - public void testDelete() throws Exception { + void testDelete() throws Exception { LoadFlowParametersInfos parametersToDelete = buildParameters(); @@ -141,11 +131,11 @@ public void testDelete() throws Exception { List storedParameters = parametersRepository.findAll(); - assertTrue(storedParameters.isEmpty()); + assertThat(storedParameters).isEmpty(); } @Test - public void testDuplicate() throws Exception { + void testDuplicate() throws Exception { LoadFlowParametersInfos parametersToDuplicate = buildParameters(); UUID parametersUuid = saveAndRetunId(parametersToDuplicate); @@ -159,13 +149,13 @@ public void testDuplicate() throws Exception { } @Test - public void testGetWithInvalidId() throws Exception { + void testGetWithInvalidId() throws Exception { mockMvc.perform(get(URI_PARAMETERS_GET_PUT + UUID.randomUUID())) .andExpect(status().isNotFound()).andReturn(); } @Test - public void testGetAll() throws Exception { + void testGetAll() throws Exception { LoadFlowParametersInfos parameters1 = buildParameters(); LoadFlowParametersInfos parameters2 = buildParametersUpdate(); From f317f1e70366149931b242f062a12876041d1fde Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Fri, 26 Jan 2024 11:57:05 +0100 Subject: [PATCH 18/20] Requested changes Signed-off-by: Ayoub LABIDI --- .../parameters/LoadFlowParametersInfos.java | 18 ++----- .../parameters/LoadFlowParametersValues.java | 16 ++---- .../parameters/LoadFlowParametersEntity.java | 54 +++++++++---------- .../server/service/LoadFlowRunContext.java | 8 +-- .../changesets/changelog_20240124T152518Z.xml | 48 ++++++++++++----- .../server/LoadFlowParametersTest.java | 4 +- 6 files changed, 77 insertions(+), 71 deletions(-) diff --git a/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersInfos.java b/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersInfos.java index 3029fcda..2ac0842c 100644 --- a/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersInfos.java +++ b/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersInfos.java @@ -8,10 +8,7 @@ import com.powsybl.loadflow.LoadFlowParameters; -import lombok.AllArgsConstructor; import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; import java.util.Map; import java.util.UUID; @@ -21,18 +18,11 @@ /** * @author Ayoub LABIDI */ -@Getter -@AllArgsConstructor @Builder -@NoArgsConstructor -public class LoadFlowParametersInfos { - - private UUID uuid; - - private LoadFlowParameters commonParameters; - - private Map> specificParametersPerProvider; - +public record LoadFlowParametersInfos( + UUID uuid, + LoadFlowParameters commonParameters, + Map> specificParametersPerProvider) { public LoadFlowParametersEntity toEntity() { return new LoadFlowParametersEntity(this); } diff --git a/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersValues.java b/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersValues.java index 43b34475..d60967b9 100644 --- a/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersValues.java +++ b/src/main/java/org/gridsuite/loadflow/server/dto/parameters/LoadFlowParametersValues.java @@ -7,23 +7,15 @@ package org.gridsuite.loadflow.server.dto.parameters; import com.powsybl.loadflow.LoadFlowParameters; -import lombok.AllArgsConstructor; import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; import java.util.Map; /** * @author David Braquart */ -@Getter -@NoArgsConstructor -@AllArgsConstructor @Builder -public class LoadFlowParametersValues { - - private LoadFlowParameters commonParameters; - - private Map specificParameters; -} +public record LoadFlowParametersValues( + LoadFlowParameters commonParameters, + Map specificParameters +) { } diff --git a/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java index ce3fe740..a5d9b2f0 100644 --- a/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java +++ b/src/main/java/org/gridsuite/loadflow/server/entities/parameters/LoadFlowParametersEntity.java @@ -42,39 +42,39 @@ public class LoadFlowParametersEntity { @Enumerated(EnumType.STRING) private LoadFlowParameters.VoltageInitMode voltageInitMode; - @Column(name = "transformerVoltageControlOn", columnDefinition = "boolean default false") - private boolean transformerVoltageControlOn; + @Column(name = "transformerVoltageControlOn", columnDefinition = "boolean default false", nullable = false) + private boolean transformerVoltageControlOn = false; - @Column(name = "useReactiveLimits", columnDefinition = "boolean default true") - private boolean useReactiveLimits; + @Column(name = "useReactiveLimits", columnDefinition = "boolean default true", nullable = false) + private boolean useReactiveLimits = true; - @Column(name = "phaseShifterRegulationOn", columnDefinition = "boolean default false") - private boolean phaseShifterRegulationOn; + @Column(name = "phaseShifterRegulationOn", columnDefinition = "boolean default false", nullable = false) + private boolean phaseShifterRegulationOn = false; - @Column(name = "twtSplitShuntAdmittance", columnDefinition = "boolean default false") - private boolean twtSplitShuntAdmittance; + @Column(name = "twtSplitShuntAdmittance", columnDefinition = "boolean default false", nullable = false) + private boolean twtSplitShuntAdmittance = false; - @Column(name = "shuntCompensatorVoltageControlOn", columnDefinition = "boolean default false") - private boolean shuntCompensatorVoltageControlOn; + @Column(name = "shuntCompensatorVoltageControlOn", columnDefinition = "boolean default false", nullable = false) + private boolean shuntCompensatorVoltageControlOn = false; - @Column(name = "readSlackBus", columnDefinition = "boolean default true") - private boolean readSlackBus; + @Column(name = "readSlackBus", columnDefinition = "boolean default true", nullable = false) + private boolean readSlackBus = true; - @Column(name = "writeSlackBus", columnDefinition = "boolean default false") - private boolean writeSlackBus; + @Column(name = "writeSlackBus", columnDefinition = "boolean default false", nullable = false) + private boolean writeSlackBus = false; - @Column(name = "dc", columnDefinition = "boolean default false") - private boolean dc; + @Column(name = "dc", columnDefinition = "boolean default false", nullable = false) + private boolean dc = false; - @Column(name = "distributedSlack", columnDefinition = "boolean default true") - private boolean distributedSlack; + @Column(name = "distributedSlack", columnDefinition = "boolean default true", nullable = false) + private boolean distributedSlack = true; @Column(name = "balanceType") @Enumerated(EnumType.STRING) private LoadFlowParameters.BalanceType balanceType; - @Column(name = "dcUseTransformerRatio", columnDefinition = "boolean default true") - private boolean dcUseTransformerRatio; + @Column(name = "dcUseTransformerRatio", columnDefinition = "boolean default true", nullable = false) + private boolean dcUseTransformerRatio = true; @Column(name = "countriesToBalance") @ElementCollection @@ -87,11 +87,11 @@ public class LoadFlowParametersEntity { @Enumerated(EnumType.STRING) private LoadFlowParameters.ConnectedComponentMode connectedComponentMode; - @Column(name = "hvdcAcEmulation", columnDefinition = "boolean default true") - private boolean hvdcAcEmulation; + @Column(name = "hvdcAcEmulation", columnDefinition = "boolean default true", nullable = false) + private boolean hvdcAcEmulation = true; - @Column(name = "dcPowerFactor", columnDefinition = "double default 1.0") - private double dcPowerFactor; + @Column(name = "dcPowerFactor", columnDefinition = "double default 1.0", nullable = false) + private double dcPowerFactor = 1.0; @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) @JoinColumn(name = "load_flow_parameters_id", foreignKey = @ForeignKey(name = "loadFlowParametersEntity_specificParameters_fk")) @@ -111,9 +111,9 @@ public void assignAttributes(LoadFlowParametersInfos loadFlowParametersInfos) { if (loadFlowParametersInfos == null) { allCommonValues = LoadFlowParameters.load(); } else { - allCommonValues = loadFlowParametersInfos.getCommonParameters(); - if (loadFlowParametersInfos.getSpecificParametersPerProvider() != null) { - loadFlowParametersInfos.getSpecificParametersPerProvider().forEach((provider, paramsMap) -> { + allCommonValues = loadFlowParametersInfos.commonParameters(); + if (loadFlowParametersInfos.specificParametersPerProvider() != null) { + loadFlowParametersInfos.specificParametersPerProvider().forEach((provider, paramsMap) -> { if (paramsMap != null) { paramsMap.forEach((paramName, paramValue) -> { if (paramValue != null) { diff --git a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowRunContext.java b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowRunContext.java index 705a86e2..b8b5ab5a 100644 --- a/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowRunContext.java +++ b/src/main/java/org/gridsuite/loadflow/server/service/LoadFlowRunContext.java @@ -44,15 +44,15 @@ public class LoadFlowRunContext { private final Float limitReduction; public static LoadFlowParameters buildParameters(LoadFlowParametersValues parameters, String provider) { - LoadFlowParameters params = parameters == null || parameters.getSpecificParameters() == null ? - LoadFlowParameters.load() : parameters.getCommonParameters(); - if (parameters == null || parameters.getSpecificParameters() == null || parameters.getSpecificParameters().isEmpty()) { + LoadFlowParameters params = parameters == null || parameters.specificParameters() == null ? + LoadFlowParameters.load() : parameters.commonParameters(); + if (parameters == null || parameters.specificParameters() == null || parameters.specificParameters().isEmpty()) { return params; // no specific LF params } LoadFlowProvider lfProvider = LoadFlowProvider.findAll().stream() .filter(p -> p.getName().equals(provider)) .findFirst().orElseThrow(() -> new PowsyblException("LoadFLow provider not found " + provider)); - Extension extension = lfProvider.loadSpecificParameters(parameters.getSpecificParameters()) + Extension extension = lfProvider.loadSpecificParameters(parameters.specificParameters()) .orElseThrow(() -> new PowsyblException("Cannot add specific loadflow parameters with provider " + provider)); params.addExtension((Class) extension.getClass(), extension); return params; diff --git a/src/main/resources/db/changelog/changesets/changelog_20240124T152518Z.xml b/src/main/resources/db/changelog/changesets/changelog_20240124T152518Z.xml index d45a8452..f1dcc9c8 100644 --- a/src/main/resources/db/changelog/changesets/changelog_20240124T152518Z.xml +++ b/src/main/resources/db/changelog/changesets/changelog_20240124T152518Z.xml @@ -7,19 +7,43 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + diff --git a/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java b/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java index 0ae14011..d715a882 100644 --- a/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java +++ b/src/test/java/org/gridsuite/loadflow/server/LoadFlowParametersTest.java @@ -43,10 +43,10 @@ class LoadFlowParametersTest { private static final String URI_PARAMETERS_GET_PUT = URI_PARAMETERS_BASE + "/"; @Autowired - protected MockMvc mockMvc; + MockMvc mockMvc; @Autowired - protected ObjectMapper mapper; + ObjectMapper mapper; @Autowired LoadFlowParametersRepository parametersRepository; From ade497b7f76a332786866ab1f2f85f74dfea9172 Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Fri, 26 Jan 2024 13:30:17 +0100 Subject: [PATCH 19/20] fix liquibase checksum Signed-off-by: Ayoub LABIDI --- ...T152518Z.xml => changelog_20240126T122251Z.xml} | 14 +++++++------- .../db/changelog/db.changelog-master.yaml | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) rename src/main/resources/db/changelog/changesets/{changelog_20240124T152518Z.xml => changelog_20240126T122251Z.xml} (91%) diff --git a/src/main/resources/db/changelog/changesets/changelog_20240124T152518Z.xml b/src/main/resources/db/changelog/changesets/changelog_20240126T122251Z.xml similarity index 91% rename from src/main/resources/db/changelog/changesets/changelog_20240124T152518Z.xml rename to src/main/resources/db/changelog/changesets/changelog_20240126T122251Z.xml index f1dcc9c8..f6533d1e 100644 --- a/src/main/resources/db/changelog/changesets/changelog_20240124T152518Z.xml +++ b/src/main/resources/db/changelog/changesets/changelog_20240126T122251Z.xml @@ -1,6 +1,6 @@ - + @@ -46,7 +46,7 @@ - + @@ -54,7 +54,7 @@ - + @@ -65,20 +65,20 @@ - + - + - + - + diff --git a/src/main/resources/db/changelog/db.changelog-master.yaml b/src/main/resources/db/changelog/db.changelog-master.yaml index 8865bea6..949e7781 100644 --- a/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/src/main/resources/db/changelog/db.changelog-master.yaml @@ -10,6 +10,6 @@ databaseChangeLog: file: changesets/changelog_20231115T10528Z.xml relativeToChangelogFile: true - include: - file: changesets/changelog_20240124T152518Z.xml + file: changesets/changelog_20240126T122251Z.xml relativeToChangelogFile: true From 51e5df03aa1a96967328bcda7480153fd5b90bbb Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Fri, 26 Jan 2024 16:08:29 +0100 Subject: [PATCH 20/20] Remove whitespace Signed-off-by: Ayoub LABIDI --- .../server/service/parameters/LoadFlowParametersService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java b/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java index d6543947..6b550806 100644 --- a/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java +++ b/src/main/java/org/gridsuite/loadflow/server/service/parameters/LoadFlowParametersService.java @@ -23,7 +23,6 @@ /** * @author Ayoub LABIDI */ - @Service public class LoadFlowParametersService {