Skip to content

Commit

Permalink
Springboot 3.3.3 migration (#520)
Browse files Browse the repository at this point in the history
Signed-off-by: Seddik Yengui <[email protected]>
  • Loading branch information
YenguiSeddik authored Sep 18, 2024
1 parent 433fad1 commit f001cf8
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 29 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-parent-ws</artifactId>
<version>19</version>
<version>20</version>
<relativePath/>
</parent>

Expand Down Expand Up @@ -44,7 +44,7 @@
</developers>

<properties>
<gridsuite-dependencies.version>31</gridsuite-dependencies.version>
<gridsuite-dependencies.version>33</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>
Expand Down Expand Up @@ -287,7 +287,7 @@
</dependency>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<artifactId>wiremock-jetty12</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.modification.server.repositories;

import org.gridsuite.modification.server.entities.equipment.creation.GeneratorCreationEntity;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.UUID;

/**
* @author Seddik Yengui <seddik.yengui_externe at rte-france.com>
*/

public interface GeneratorCreationRepository extends JpaRepository<GeneratorCreationEntity, UUID> {
@EntityGraph(attributePaths = {"reactiveCapabilityCurvePoints"}, type = EntityGraph.EntityGraphType.LOAD)
List<GeneratorCreationEntity> findAllReactiveCapabilityCurvePointsByIdIn(List<UUID> ids);

@EntityGraph(attributePaths = {"properties"}, type = EntityGraph.EntityGraphType.LOAD)
List<GeneratorCreationEntity> findAllPropertiesByIdIn(List<UUID> ids);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@
package org.gridsuite.modification.server.repositories;

import org.gridsuite.modification.server.entities.ModificationEntity;
import org.gridsuite.modification.server.entities.TabularCreationEntity;
import org.gridsuite.modification.server.entities.equipment.creation.GeneratorCreationEntity;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;

/**
Expand All @@ -41,17 +36,14 @@ public interface ModificationRepository extends JpaRepository<ModificationEntity
@Query(value = "SELECT cast(modifications_id AS VARCHAR) FROM tabular_modification_modifications WHERE tabular_modification_entity_id = :uuid ORDER BY modifications_order", nativeQuery = true)
List<UUID> findSubModificationIdsByTabularModificationIdOrderByModificationsOrder(UUID uuid);

@Query(value = "SELECT cast(creations_id AS VARCHAR) FROM tabular_creation_creations WHERE tabular_creation_entity_id = :uuid ORDER BY creations_order", nativeQuery = true)
List<UUID> findSubModificationIdsByTabularCreationIdOrderByModificationsOrder(UUID uuid);

@Query(value = "SELECT cast(modifications_id AS VARCHAR) FROM tabular_modification_modifications WHERE tabular_modification_entity_id = :uuid", nativeQuery = true)
List<UUID> findSubModificationIdsByTabularModificationId(UUID uuid);

@Query(value = "SELECT cast(modification_id AS VARCHAR) FROM composite_modification_sub_modifications WHERE id = :uuid ORDER BY modifications_order", nativeQuery = true)
List<UUID> findModificationIdsByCompositeModificationId(UUID uuid);

@EntityGraph(attributePaths = {"creations", "creations.reactiveCapabilityCurvePoints"}, type = EntityGraph.EntityGraphType.LOAD)
Optional<TabularCreationEntity> findTabularCreationWithReactiveCapabilityCurvePointsById(UUID id);

@EntityGraph(attributePaths = {"reactiveCapabilityCurvePoints"}, type = EntityGraph.EntityGraphType.LOAD)
Set<GeneratorCreationEntity> findAllCreationsWithReactiveCapabilityCurvePointsByIdIn(List<UUID> ids);

Integer countByGroupIdAndStashed(UUID groupId, boolean stashed);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
import lombok.NonNull;
import org.gridsuite.modification.server.ModificationType;
import org.gridsuite.modification.server.NetworkModificationException;
import org.gridsuite.modification.server.dto.CompositeModificationInfos;
import org.gridsuite.modification.server.dto.ModificationInfos;
import org.gridsuite.modification.server.dto.ModificationMetadata;
import org.gridsuite.modification.server.dto.TabularModificationInfos;
import org.gridsuite.modification.server.dto.*;
import org.gridsuite.modification.server.entities.*;
import org.gridsuite.modification.server.entities.equipment.creation.GeneratorCreationEntity;
import org.gridsuite.modification.server.entities.equipment.modification.GeneratorModificationEntity;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -38,12 +36,18 @@ public class NetworkModificationRepository {

private final GeneratorModificationRepository generatorModificationRepository;

private final GeneratorCreationRepository generatorCreationRepository;

private static final String MODIFICATION_NOT_FOUND_MESSAGE = "Modification (%s) not found";

public NetworkModificationRepository(ModificationGroupRepository modificationGroupRepository, ModificationRepository modificationRepository, GeneratorModificationRepository generatorModificationRepository) {
public NetworkModificationRepository(ModificationGroupRepository modificationGroupRepository,
ModificationRepository modificationRepository,
GeneratorModificationRepository generatorModificationRepository,
GeneratorCreationRepository generatorCreationRepository) {
this.modificationGroupRepository = modificationGroupRepository;
this.modificationRepository = modificationRepository;
this.generatorModificationRepository = generatorModificationRepository;
this.generatorCreationRepository = generatorCreationRepository;
}

@Transactional // To have the 2 delete in the same transaction (atomic)
Expand Down Expand Up @@ -251,26 +255,41 @@ public TabularModificationInfos loadTabularModificationSubEntities(ModificationE
return tabularModificationEntity.toModificationInfos();
}

public TabularCreationEntity loadTabularCreationSubEntities(ModificationEntity modificationEntity) {
public TabularCreationInfos loadTabularCreationSubEntities(ModificationEntity modificationEntity) {
TabularCreationEntity tabularCreationEntity = (TabularCreationEntity) modificationEntity;
switch (tabularCreationEntity.getCreationType()) {
case GENERATOR_CREATION:
tabularCreationEntity = modificationRepository.findTabularCreationWithReactiveCapabilityCurvePointsById(modificationEntity.getId()).orElseThrow(() ->
new NetworkModificationException(MODIFICATION_NOT_FOUND, String.format(MODIFICATION_NOT_FOUND_MESSAGE, modificationEntity.getId()))
);
modificationRepository.findAllCreationsWithReactiveCapabilityCurvePointsByIdIn(tabularCreationEntity.getCreations().stream().map(ModificationEntity::getId).toList());
break;
List<UUID> subModificationsUuids = modificationRepository.findSubModificationIdsByTabularCreationIdOrderByModificationsOrder(modificationEntity.getId());
Map<UUID, GeneratorCreationEntity> generatorCreations = generatorCreationRepository.findAllReactiveCapabilityCurvePointsByIdIn(subModificationsUuids)
.stream()
.collect(Collectors.toMap(
ModificationEntity::getId,
Function.identity()
));
generatorCreationRepository.findAllPropertiesByIdIn(subModificationsUuids);
List<GeneratorCreationEntity> orderedGeneratorCreation = subModificationsUuids
.stream()
.map(generatorCreations::get)
.toList();
return TabularCreationInfos.builder()
.uuid(tabularCreationEntity.getId())
.date(tabularCreationEntity.getDate())
.stashed(tabularCreationEntity.getStashed())
.activated(tabularCreationEntity.getActivated())
.creationType(tabularCreationEntity.getCreationType())
.creations(orderedGeneratorCreation.stream().map(GeneratorCreationEntity::toModificationInfos).map(m -> (ModificationInfos) m).toList())
.build();
default:
break;
}
return tabularCreationEntity;
return tabularCreationEntity.toModificationInfos();
}

public ModificationInfos getModificationInfos(ModificationEntity modificationEntity) {
if (modificationEntity instanceof TabularModificationEntity) {
return loadTabularModificationSubEntities(modificationEntity);
} else if (modificationEntity instanceof TabularCreationEntity) {
return loadTabularCreationSubEntities(modificationEntity).toModificationInfos();
return loadTabularCreationSubEntities(modificationEntity);
}
return modificationEntity.toModificationInfos();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public void testCheckSqlRequestsCount() throws Exception {
status().isOk(), content().contentType(MediaType.APPLICATION_JSON))
.andReturn();
// We check that the request count is not dependent on the number of sub creations of the tabular creation (the JPA N+1 problem is correctly solved)
assertSelectCount(9);
assertSelectCount(4);

List<ModificationInfos> creations = List.of(
GeneratorCreationInfos.builder()
Expand Down Expand Up @@ -216,7 +216,7 @@ public void testCheckSqlRequestsCount() throws Exception {
mockMvc.perform(get("/v1/groups/{groupUuid}/network-modifications", getGroupId()))
.andExpect(status().isOk());
// We check that the request count is not dependent on the number of sub creations of the tabular creation (the JPA N+1 problem is correctly solved)
assertSelectCount(13);
assertSelectCount(8);
}

@Test
Expand Down

0 comments on commit f001cf8

Please sign in to comment.