Skip to content

Commit

Permalink
Merge branch 'main' into remove_unused_modificationToExclude_clean
Browse files Browse the repository at this point in the history
  • Loading branch information
souissimai authored Oct 24, 2024
2 parents 5347fd1 + 909ded4 commit 5770c93
Show file tree
Hide file tree
Showing 123 changed files with 1,813 additions and 1,957 deletions.
65 changes: 21 additions & 44 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@
<properties>
<gridsuite-dependencies.version>34</gridsuite-dependencies.version>
<db-util.version>1.0.5</db-util.version>
<log4j2-mock-version>0.0.2</log4j2-mock-version>
<testcontainers.version>1.16.2</testcontainers.version>
<mockwebserver3.version>5.0.0-alpha.14</mockwebserver3.version>
<liquibase-hibernate-package>org.gridsuite.modification.server</liquibase-hibernate-package>
<!-- FIXME: powsybl-network-store modules'version is overloaded in the dependencies section.The overloads and this property below have to be removed at next powsybl-ws-dependencies.version upgrade -->
<powsybl-network-store.version>1.18.2</powsybl-network-store.version>
<powsybl-network-store.version>1.19.0</powsybl-network-store.version>
<sonar.coverage.exclusions>**/migration/**/*</sonar.coverage.exclusions>
<!-- FIXME: gridsuite-filter modules' version is overloaded in the dependencies section.
The overloads and this property below have to be removed at next gridsuite-dependencies.version upgrade -->
<filter.version>1.0.14</filter.version>
</properties>

<build>
Expand Down Expand Up @@ -86,6 +89,13 @@
<dependencyManagement>
<dependencies>
<!-- overrides of imports -->
<dependency><!-- To remove when integrate in next release of gridsuite-dependencies or powsybl-ws-dependencies -->
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp-bom</artifactId>
<version>${mockwebserver3.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-network-store-client</artifactId>
Expand Down Expand Up @@ -116,26 +126,19 @@

<!-- project specific dependencies -->
<dependency>
<groupId>de.dentrassi.elasticsearch</groupId>
<artifactId>log4j2-mock</artifactId>
<version>${log4j2-mock-version}</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>elasticsearch</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
<groupId>com.vladmihalcea</groupId>
<artifactId>db-util</artifactId>
<version>${db-util.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>

<!-- Compilation dependencies -->

<dependency>
<groupId>org.gridsuite</groupId>
<artifactId>gridsuite-filter</artifactId>
<version>${filter.version}</version>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
Expand Down Expand Up @@ -210,7 +213,6 @@
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
Expand All @@ -219,71 +221,46 @@
</dependency>

<!-- Test dependencies -->

<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-config-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-guava</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.vladmihalcea</groupId>
<artifactId>db-util</artifactId>
<version>${db-util.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>elasticsearch</artifactId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>de.dentrassi.elasticsearch</groupId>
<artifactId>log4j2-mock</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<groupId>org.testcontainers</groupId>
<artifactId>elasticsearch</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<artifactId>mockwebserver3-junit5</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-test-binder</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,11 @@ public ResponseEntity<Void> stashNetworkModifications(
@Parameter(description = "Group UUID") @RequestParam("groupUuid") UUID groupUuid,
@Parameter(description = "stash or unstash network modifications") @RequestParam(name = "stashed", defaultValue = "true") Boolean stashed) {
if (Boolean.TRUE.equals(stashed)) {
networkModificationService.stashNetworkModifications(networkModificationUuids);
networkModificationService.stashNetworkModifications(groupUuid, networkModificationUuids);
networkModificationService.reorderNetworkModifications(groupUuid, Boolean.FALSE);
} else {
networkModificationService.restoreNetworkModifications(networkModificationUuids);
networkModificationService.restoreNetworkModifications(groupUuid, networkModificationUuids);
networkModificationService.reorderNetworkModifications(groupUuid, Boolean.TRUE);
}
return ResponseEntity.ok().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
* 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.modification.server.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

/**
Expand All @@ -21,8 +19,7 @@
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Data
@Schema(description = "Generator reactive capability curve point creation")
public class ReactiveCapabilityCurveModificationInfos {
@Schema(description = "Minimum reactive power ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
import org.gridsuite.modification.server.modifications.ModificationUtils;

import static org.gridsuite.modification.server.NetworkModificationException.Type.MODIFY_BATTERY_ERROR;
import static org.gridsuite.modification.server.modifications.BatteryModification.modifyBatteryActiveLimitsAttributes;
import static org.gridsuite.modification.server.modifications.BatteryModification.modifyBatterySetpointsAttributes;
import static org.gridsuite.modification.server.modifications.BatteryModification.*;

/**
* @author Seddik Yengui <Seddik.yengui at rte-france.com>
Expand All @@ -44,6 +43,7 @@ public static String getReferenceValue(Battery battery, String batteryField) {

public static void setNewValue(Battery battery, String batteryField, @NotNull String newValue) {
BatteryField field = BatteryField.valueOf(batteryField);
String errorMessage = String.format(ERROR_MESSAGE, battery.getId());
final AttributeModification<Double> attributeModification = new AttributeModification<>(Double.parseDouble(newValue), OperationType.SET);
switch (field) {
case MINIMUM_ACTIVE_POWER ->
Expand All @@ -53,7 +53,7 @@ public static void setNewValue(Battery battery, String batteryField, @NotNull St
case ACTIVE_POWER_SET_POINT -> {
ModificationUtils.getInstance().checkActivePowerZeroOrBetweenMinAndMaxActivePower(
attributeModification, null, null, battery.getMinP(),
battery.getMaxP(), battery.getTargetP(), MODIFY_BATTERY_ERROR, "Battery '" + battery.getId() + "' : "
battery.getMaxP(), battery.getTargetP(), MODIFY_BATTERY_ERROR, errorMessage
);
modifyBatterySetpointsAttributes(attributeModification, null, null, null, battery, null);
}
Expand All @@ -64,7 +64,8 @@ public static void setNewValue(Battery battery, String batteryField, @NotNull St
ActivePowerControlAdder<Battery> activePowerControlAdder = battery.newExtension(ActivePowerControlAdder.class);
ModificationUtils.getInstance().modifyActivePowerControlAttributes(
activePowerControl, activePowerControlAdder, null,
new AttributeModification<>(Float.parseFloat(newValue), OperationType.SET), null, null);
new AttributeModification<>(Float.parseFloat(newValue), OperationType.SET), null,
null, MODIFY_BATTERY_ERROR, errorMessage);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public static String getReferenceValue(Generator generator, String generatorFiel

public static void setNewValue(Generator generator, String generatorField, @NotNull String newValue) {
GeneratorField field = GeneratorField.valueOf(generatorField);
String errorMessage = String.format(ERROR_MESSAGE, generator.getId());
switch (field) {
case MAXIMUM_ACTIVE_POWER -> modifyGeneratorActiveLimitsAttributes(
new AttributeModification<>(Double.parseDouble(newValue), OperationType.SET),
Expand All @@ -75,7 +76,7 @@ public static void setNewValue(Generator generator, String generatorField, @NotN
ModificationUtils.getInstance().checkActivePowerZeroOrBetweenMinAndMaxActivePower(
new AttributeModification<>(Double.parseDouble(newValue), OperationType.SET),
null, null, generator.getMinP(), generator.getMaxP(), generator.getTargetP(),
MODIFY_GENERATOR_ERROR, "Generator '" + generator.getId() + "' : "
MODIFY_GENERATOR_ERROR, errorMessage
);
generator.setTargetP(Double.parseDouble(newValue));
}
Expand All @@ -98,7 +99,8 @@ public static void setNewValue(Generator generator, String generatorField, @NotN
ActivePowerControl<Generator> activePowerControl = generator.getExtension(ActivePowerControl.class);
ActivePowerControlAdder<Generator> activePowerControlAdder = generator.newExtension(ActivePowerControlAdder.class);
ModificationUtils.getInstance().modifyActivePowerControlAttributes(activePowerControl, activePowerControlAdder, null,
new AttributeModification<>(Float.parseFloat(newValue), OperationType.SET), null, null);
new AttributeModification<>(Float.parseFloat(newValue), OperationType.SET), null, null,
MODIFY_GENERATOR_ERROR, errorMessage);
}
case TRANSIENT_REACTANCE -> modifyGeneratorShortCircuitAttributes(
new AttributeModification<>(Double.parseDouble(newValue), OperationType.SET),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ModificationGroupEntity extends AbstractManuallyAssignedIdentifierE
mappedBy = "group",
cascade = CascadeType.ALL
)
@OrderColumn
@OrderBy("modificationsOrder asc")
private List<ModificationEntity> modifications = new ArrayList<>();

public ModificationGroupEntity(UUID uuid) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package org.gridsuite.modification.server.migration;

import liquibase.change.custom.CustomSqlChange;
import liquibase.database.Database;
import liquibase.database.jvm.JdbcConnection;
import liquibase.exception.CustomChangeException;
import liquibase.exception.DatabaseException;
import liquibase.exception.SetupException;
import liquibase.exception.ValidationErrors;
import liquibase.resource.ResourceAccessor;
import liquibase.statement.SqlStatement;
import liquibase.statement.core.UpdateStatement;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.stream.IntStream;

/**
* @author Etienne Lesot <etienne.lesot at rte-france.com>
*/
public class ModificationOrderMigration implements CustomSqlChange {

private static final Logger LOGGER = LoggerFactory.getLogger(ModificationOrderMigration.class);

@Override
public SqlStatement[] generateStatements(Database database) throws CustomChangeException {
JdbcConnection connection = (JdbcConnection) database.getConnection();
List<SqlStatement> statements = new ArrayList<>();
try (PreparedStatement stmt = connection.prepareStatement("select distinct group_id from modification where group_id is not null")) {
ResultSet groupIds = stmt.executeQuery();
while (groupIds.next()) {
UUID groupId = UUID.fromString(groupIds.getString(1));
reorderNetworkModifications(groupId, true, connection, statements, database);
reorderNetworkModifications(groupId, false, connection, statements, database);
}
} catch (SQLException | DatabaseException e) {
throw new CustomChangeException(e);
}
return statements.toArray(new SqlStatement[0]);
}

private void reorderNetworkModifications(UUID groupId, boolean stashed, JdbcConnection connection, List<SqlStatement> statements, Database database) throws CustomChangeException {
List<UUID> entities = findAllByGroupId(groupId, stashed, connection);
List<Pair<UUID, Integer>> entitiesToUpdate = new ArrayList<>();
if (!entities.isEmpty()) {
if (Boolean.TRUE.equals(stashed)) {
IntStream.range(1, entities.size() + 1)
.forEach(i -> entitiesToUpdate.add(Pair.of(entities.get(i - 1), -i)));
} else {
IntStream.range(0, entities.size())
.forEach(i -> entitiesToUpdate.add(Pair.of(entities.get(i), i)));
}
}
createMigrationRequests(entitiesToUpdate, statements, database);
}

private List<UUID> findAllByGroupId(UUID groupId, boolean stashed, JdbcConnection connection) throws CustomChangeException {
try (PreparedStatement stmt = connection.prepareStatement("SELECT id FROM modification m WHERE m.group_id = ? AND m.stashed = ? order by modifications_order")) {
stmt.setObject(1, groupId);
stmt.setBoolean(2, stashed);
ResultSet resultSet = stmt.executeQuery();
List<UUID> entities = new ArrayList<>();
while (resultSet.next()) {
entities.add(UUID.fromString(resultSet.getString(1)));
}
return entities;
} catch (SQLException | DatabaseException e) {
throw new CustomChangeException(e);
}
}

private void createMigrationRequests(List<Pair<UUID, Integer>> entities, List<SqlStatement> statements, Database database) {
entities.forEach(pair -> statements.add(new UpdateStatement(database.getDefaultCatalogName(), database.getDefaultSchemaName(), "modification")
.addNewColumnValue("modifications_order", pair.getValue())
.setWhereClause(String.format("id='%s'", pair.getKey()))));
}

@Override
public String getConfirmationMessage() {
return "modification order was successfully updated";
}

@Override
public void setUp() throws SetupException {
LOGGER.info("Set up migration for modification order");
}

@Override
public void setFileOpener(ResourceAccessor resourceAccessor) {
LOGGER.info("Set file opener for modification order");
}

@Override
public ValidationErrors validate(Database database) {
return new ValidationErrors();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.util.List;

import static org.gridsuite.modification.server.NetworkModificationException.Type.BATTERY_ALREADY_EXISTS;
import static org.gridsuite.modification.server.NetworkModificationException.Type.CREATE_BATTERY_ERROR;
import static org.gridsuite.modification.server.modifications.BatteryModification.ERROR_MESSAGE;
import static org.gridsuite.modification.server.modifications.ModificationUtils.*;

/**
Expand Down Expand Up @@ -49,6 +51,9 @@ public void check(Network network) throws NetworkModificationException {
modificationInfos.getErrorType(),
modificationInfos.getEquipmentId(),
"Battery");

ModificationUtils.getInstance().checkActivePowerControl(modificationInfos.getParticipate(),
modificationInfos.getDroop(), CREATE_BATTERY_ERROR, String.format(ERROR_MESSAGE, modificationInfos.getEquipmentId()));
}

@Override
Expand Down
Loading

0 comments on commit 5770c93

Please sign in to comment.