Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4bb3526
Add a modification reference as a new modification type
Apr 28, 2026
f73bc65
Merge branch 'main' of https://github.com/gridsuite/network-modificat…
Apr 28, 2026
b492fc1
Sonar issues
Apr 29, 2026
7676ad7
Merge branch 'main' of https://github.com/gridsuite/network-modificat…
Apr 29, 2026
a1c1e0b
Sonar issues
Apr 29, 2026
0eb8f53
Merge branch 'main' of https://github.com/gridsuite/network-modificat…
May 13, 2026
3cebb10
Merge branch 'main' of https://github.com/gridsuite/network-modificat…
May 21, 2026
d298c15
Merge branch 'main' into shared-modification
Mathieu-Deharbe Jun 3, 2026
9bdc3f5
import shared composites
Mathieu-Deharbe Jun 5, 2026
6c450c8
import shared composites
Mathieu-Deharbe Jun 5, 2026
25e2bc3
eslint
Mathieu-Deharbe Jun 9, 2026
2707747
Merge branch 'main' of https://github.com/gridsuite/network-modificat…
Jun 11, 2026
dc60c9c
Merge branch 'shared-modification' into import-shared-composite
Mathieu-Deharbe Jun 11, 2026
2b99eff
Update reference type
Jun 12, 2026
b6a9a09
Merge branch 'shared-modification' into import-shared-composite
Mathieu-Deharbe Jun 12, 2026
7e4e649
clean
Mathieu-Deharbe Jun 12, 2026
94f1332
Fix get modification reference for applying
Jun 12, 2026
919bf1e
Merge branch 'shared-modification' into import-shared-composite
Mathieu-Deharbe Jun 12, 2026
edb9dcb
returns references to be updated after stash and unstash
Mathieu-Deharbe Jun 12, 2026
6a0b060
Merge branch 'main' into import-shared-composite
Mathieu-Deharbe Jun 16, 2026
0365c18
specific endpoint to return references
Mathieu-Deharbe Jun 16, 2026
8b7d22c
Merge branch 'main' into import-shared-composite
Mathieu-Deharbe Jun 17, 2026
88c5a3d
getAllReferencesDataFromGroup
Mathieu-Deharbe Jun 17, 2026
e5c6c0f
corrects previous Tus
Mathieu-Deharbe Jun 17, 2026
14b4aa0
cleans imports
Mathieu-Deharbe Jun 17, 2026
4de2680
testGetReferencesData
Mathieu-Deharbe Jun 17, 2026
06a5aa9
testGetAllReferencesDataFromGroup
Mathieu-Deharbe Jun 17, 2026
a722039
testInsertSharedComposite
Mathieu-Deharbe Jun 17, 2026
1c9beff
format
Mathieu-Deharbe Jun 17, 2026
440e596
Merge branch 'main' into import-shared-composite
Mathieu-Deharbe Jun 19, 2026
3cb0381
updates TODOs
Mathieu-Deharbe Jun 19, 2026
27b41f2
cleans useless returns
Mathieu-Deharbe Jun 19, 2026
f3bb2ff
Merge branch 'main' into import-shared-composite
Mathieu-Deharbe Jul 7, 2026
1291229
new sonar locks
Mathieu-Deharbe Jul 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.gridsuite.modification.dto.ModificationInfos;
import org.gridsuite.modification.server.dto.CompositesToBeInserted;
import org.gridsuite.modification.server.dto.ModificationApplicationContext;
import org.gridsuite.modification.server.dto.NetworkModificationsResult;
import org.gridsuite.modification.server.service.NetworkModificationService;
Expand Down Expand Up @@ -50,7 +51,7 @@ public CompositeController(NetworkModificationService networkModificationService
public CompletableFuture<ResponseEntity<NetworkModificationsResult>> insertCompositeModifications(
@Parameter(description = "updated group UUID, where modifications are inserted") @PathVariable("groupUuid") UUID targetGroupUuid,
@Parameter(description = "Insertion method", required = true) @RequestParam(value = "action") CompositeModificationAction action,
@RequestBody Pair<List<Pair<UUID, String>>, List<ModificationApplicationContext>> modificationContextInfos) {
@RequestBody Pair<List<CompositesToBeInserted>, List<ModificationApplicationContext>> modificationContextInfos) {
return switch (action) {
case SPLIT -> networkModificationService.splitCompositeModifications(
targetGroupUuid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,39 @@
return ResponseEntity.ok().build();
}

/**
* filters out the netmods which are not references and returns the references data as :
* referenced element uuid -> container of the reference (uuid of the composite if there is one, null if it is at the root level)
*/
Comment on lines +247 to +250

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why using the word data as we just return a map ?
What is a reference ?
For me the names and comments are not really clear. It's hard to understand what does the endpoints by reading them.

@GetMapping(value = "/references", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "fetch references data of the network modifications")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The references data were returned")})
public ResponseEntity<Map<UUID, UUID>> getReferencesData(
@Parameter(description = "Network modification UUIDs") @RequestParam("uuids") List<UUID> networkModificationUuids) {
Map<UUID, UUID> referencesData = networkModificationService.getReferencesData(networkModificationUuids);
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON)
.body(referencesData);
}

/**
* filters out the netmods which are not references and returns the references data as :
* referenced element uuid -> container of the reference (uuid of the composite if there is one, null if it is at the root level)
*/
@GetMapping(value = "/groups/{groupUuid}/references", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Fetches references data of all the network modifications in a group, including in the composites' submodifications")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The references data were returned")})
public ResponseEntity<Map<UUID, UUID>> getAllReferencesDataFromGroup(
@Parameter(description = "Group UUID") @PathVariable("groupUuid") UUID groupUuid) {
// TODO GRD-4785 : for now shared modification are only at the root level and can't be inside composites,

Check warning on line 270 in src/main/java/org/gridsuite/modification/server/NetworkModificationController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this TODO comment.

See more on https://sonarcloud.io/project/issues?id=org.gridsuite%3Anetwork-modification-server&issues=AZ7V31E0s07k0bCoLhbp&open=AZ7V31E0s07k0bCoLhbp&pullRequest=830
// but when it will be the case a specific function will have to be done in order to fetch recursively all the references inside the composites and only return uuids
List<UUID> netModUuids = networkModificationService.getNetworkModifications(groupUuid, true, false, false)
.stream().map(ModificationInfos::getUuid)
.toList();
Map<UUID, UUID> referencesData = networkModificationService.getReferencesData(netModUuids);
Comment thread
Mathieu-Deharbe marked this conversation as resolved.
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON)
.body(referencesData);
}

@PutMapping(value = "/network-modifications", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Updates the metadata of network modifications")
@ApiResponse(responseCode = "200", description = "The metadata of the network modifications has been successfully updated")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
Copyright (c) 2026, 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.dto;

import java.util.UUID;

/**
* @author Mathieu Deharbe <mathieu.deharbe at rte-france.com>
*/
public record CompositesToBeInserted(UUID id, String name, boolean isShared) { }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you update or extend ModificationMetadata instead ?

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.gridsuite.modification.dto.tabular.TabularBaseInfos;
import org.gridsuite.modification.dto.tabular.TabularCreationInfos;
import org.gridsuite.modification.dto.tabular.TabularModificationInfos;
import org.gridsuite.modification.server.dto.CompositesToBeInserted;
import org.gridsuite.modification.server.dto.ModificationMetadata;
import org.gridsuite.modification.server.elasticsearch.ModificationApplicationInfosService;
import org.gridsuite.modification.server.entities.CompositeModificationEntity;
Expand All @@ -29,7 +30,6 @@
import org.gridsuite.modification.server.entities.tabular.TabularPropertyEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.util.Pair;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -710,6 +710,26 @@
return getModificationEntityStream(groupUuid).filter(m -> !m.getStashed()).map(this::toModificationsInfosOptimized).toList();
}

/**
* @return elementUuid of the shared modification -> Uuid of the composite containing the reference, null if the composite is at the root level
*/
@Transactional
public Map<UUID, UUID> getReferencesData(@NonNull List<UUID> modificationUuids) {
Map<UUID, UUID> referencesToBeDeleted = new HashMap<>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why referencesToBeDeleted, and not just references ?

for (UUID modificationUuid : modificationUuids) {
ModificationEntity modificationEntity = this.modificationRepository
.findById(modificationUuid)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isnt findAllById better in terms of performance ?

.orElseThrow(() -> new NetworkModificationException(MODIFICATION_NOT_FOUND, String.format(MODIFICATION_NOT_FOUND_MESSAGE, modificationUuid)));
if (Boolean.FALSE.equals(modificationEntity.getStashed()) && modificationEntity instanceof ModificationReferenceEntity modificationReference) {
// TODO GRD-4785 : for now shared modification are only at the root level and can't be inside composites, so the composite uuid is set to null

Check warning on line 724 in src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this TODO comment.

See more on https://sonarcloud.io/project/issues?id=org.gridsuite%3Anetwork-modification-server&issues=AZ7V31Cas07k0bCoLhbn&open=AZ7V31Cas07k0bCoLhbn&pullRequest=830
// but when it will be the case a specific function will have to be done in order to fetch the composite containing the modificationReference (if there is one)
referencesToBeDeleted.putIfAbsent(modificationReference.getReferenceId(), null);
}
}

return referencesToBeDeleted;
}

@Transactional
public void stashNetworkModifications(@NonNull List<UUID> modificationUuids, int stashedModificationCount) {
int stashModificationOrder = -stashedModificationCount - 1;
Expand Down Expand Up @@ -937,20 +957,35 @@
@Transactional
public List<ModificationInfos> insertCompositeModifications(
@NonNull UUID targetGroupUuid,
@NonNull List<Pair<UUID, String>> compositesUuidName) {
List<UUID> compositeUuids = compositesUuidName.stream().map(Pair::getFirst).toList();
@NonNull List<CompositesToBeInserted> compositesToBeInserted) {
List<UUID> compositeUuids = compositesToBeInserted.stream().map(CompositesToBeInserted::id).toList();
List<ModificationInfos> newCompositeModifications = new ArrayList<>();
List<ModificationInfos> modificationInfos = getModificationsInfosNonTransactional(compositeUuids);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
List<ModificationInfos> modificationInfos = getModificationsInfosNonTransactional(compositeUuids);
List<ModificationInfos> compositeModificationInfos = getModificationsInfosNonTransactional(compositeUuids);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we load them here instead of one by one inside the loop ? Is it just for performance ? Because it's not really clear as we use a filter after to get the one we want.

If it's for performance, are we really going to insert hundreds of composite modifications in the same time ?

// apply the new composite name to the corresponding composite modifications
for (Pair<UUID, String> compositeUuidName : compositesUuidName) {
CompositeModificationInfos newCompositeModification = (CompositeModificationInfos) modificationInfos.stream()
.filter(modif -> modif.getUuid().equals(compositeUuidName.getFirst()))
.findFirst().orElse(null);
if (newCompositeModification != null) {
newCompositeModification.setName(compositeUuidName.getSecond());
newCompositeModifications.add(newCompositeModification);
for (CompositesToBeInserted compositeToBeInserted : compositesToBeInserted) {
if (compositeToBeInserted.isShared()) {
CompositeModificationInfos referencedCompositeModification = (CompositeModificationInfos) modificationInfos.stream()
.filter(modif -> modif.getUuid().equals(compositeToBeInserted.id()))
.findFirst().orElse(null);
if (referencedCompositeModification != null) {
referencedCompositeModification.setName(compositeToBeInserted.name());
ModificationReferenceInfos newModificationReference = ModificationReferenceInfos.builder()
.referenceId(compositeToBeInserted.id())
.referenceType(ModificationReferenceInfos.Type.BASIC)
.referenceInfos(referencedCompositeModification)
.build();
Comment on lines +971 to +975

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only difference between shared and non-shared modification, right ? So why don't we put the condition here ?

newCompositeModifications.add(newModificationReference);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it on purpose to not logging error here ?

}
} else {
LOGGER.error("Could not find composite modification with uuid {} to apply its name {}", compositeUuidName.getFirst(), compositeUuidName.getSecond());
// apply the new composite name to the corresponding composite modifications

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there with a S at the end of modification ?

CompositeModificationInfos newCompositeModification = (CompositeModificationInfos) modificationInfos.stream()
.filter(modif -> modif.getUuid().equals(compositeToBeInserted.id()))
.findFirst().orElse(null);
Comment on lines +980 to +982

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated code

if (newCompositeModification != null) {
newCompositeModification.setName(compositeToBeInserted.name());
newCompositeModifications.add(newCompositeModification);
} else {
LOGGER.error("Could not find composite modification with uuid {} to apply its name {}", compositeToBeInserted.id(), compositeToBeInserted.name());
}
Comment thread
Mathieu-Deharbe marked this conversation as resolved.
}
}
List<ModificationEntity> newEntities = saveModificationInfosNonTransactional(targetGroupUuid, newCompositeModifications);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.gridsuite.modification.dto.ModificationInfos;
import org.gridsuite.modification.server.NetworkModificationServerException;
import org.gridsuite.modification.server.dto.*;
import org.gridsuite.modification.server.dto.CompositesToBeInserted;
import org.gridsuite.modification.server.dto.elasticsearch.ModificationApplicationInfos;
import org.gridsuite.modification.server.elasticsearch.EquipmentInfosService;
import org.gridsuite.modification.server.elasticsearch.ModificationApplicationInfosService;
Expand Down Expand Up @@ -269,6 +270,11 @@ public void updateNetworkModificationMetadata(@NonNull List<UUID> modificationUu
networkModificationRepository.updateNetworkModificationMetadata(modificationUuids, metadata);
}

@Transactional
public Map<UUID, UUID> getReferencesData(@NonNull List<UUID> modificationUuids) {
return networkModificationRepository.getReferencesData(modificationUuids);
}

@Transactional
public void stashNetworkModifications(UUID groupUuid, @NonNull List<UUID> modificationUuids) {
for (UUID modificationUuid : modificationUuids) {
Expand Down Expand Up @@ -487,8 +493,8 @@ public CompletableFuture<NetworkModificationsResult> duplicateModifications(@Non
*/
public CompletableFuture<NetworkModificationsResult> splitCompositeModifications(
@NonNull UUID targetGroupUuid,
@NonNull Pair<List<Pair<UUID, String>>, List<ModificationApplicationContext>> modificationContextInfos) {
List<UUID> compositesUuids = modificationContextInfos.getFirst().stream().map(Pair::getFirst).toList();
@NonNull Pair<List<CompositesToBeInserted>, List<ModificationApplicationContext>> modificationContextInfos) {
List<UUID> compositesUuids = modificationContextInfos.getFirst().stream().map(CompositesToBeInserted::id).toList();
List<ModificationInfos> modifications = networkModificationRepository.extractModificationsFromCompositesAndSave(targetGroupUuid, compositesUuids);
List<UUID> ids = modifications.stream().map(ModificationInfos::getUuid).toList();
return applyModifications(targetGroupUuid, modifications, modificationContextInfos.getSecond()).thenApply(result ->
Expand All @@ -497,7 +503,7 @@ public CompletableFuture<NetworkModificationsResult> splitCompositeModifications

public CompletableFuture<NetworkModificationsResult> insertCompositeModifications(
@NonNull UUID targetGroupUuid,
@NonNull Pair<List<Pair<UUID, String>>, List<ModificationApplicationContext>> modificationContextInfos) {
@NonNull Pair<List<CompositesToBeInserted>, List<ModificationApplicationContext>> modificationContextInfos) {
List<ModificationInfos> modifications = networkModificationRepository.insertCompositeModifications(
targetGroupUuid, modificationContextInfos.getFirst());
List<UUID> ids = modifications.stream().map(ModificationInfos::getUuid).toList();
Expand Down
Loading
Loading