Skip to content

use modifications_order for the composites#804

Open
Mathieu-Deharbe wants to merge 17 commits intomainfrom
use-modifications_order-for-coposites
Open

use modifications_order for the composites#804
Mathieu-Deharbe wants to merge 17 commits intomainfrom
use-modifications_order-for-coposites

Conversation

@Mathieu-Deharbe
Copy link
Copy Markdown
Contributor

@Mathieu-Deharbe Mathieu-Deharbe commented Apr 23, 2026

PR Summary

  • replaces the OrderColumn annotation used for the modifications contained inside a composite, with the modificationOrder ot ModificatoinEntity.
  • removed removeOrphan because now modifications may be "orphan" when removed from composite and put into groups. They shoudn't be deleted in this case.
  • few renaming and reorganisations along the way to make more readable what confused me (and remove some useless actions)

Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
@coderabbitai

This comment was marked as off-topic.

coderabbitai[bot]

This comment was marked as off-topic.

@Mathieu-Deharbe Mathieu-Deharbe marked this pull request as draft April 23, 2026 13:35
Mathieu-Deharbe and others added 9 commits April 24, 2026 15:19
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
…omposites to groups

Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
@Mathieu-Deharbe Mathieu-Deharbe marked this pull request as ready for review April 28, 2026 09:22
@Mathieu-Deharbe Mathieu-Deharbe self-assigned this Apr 28, 2026
Mathieu-Deharbe and others added 2 commits April 28, 2026 11:36
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
coderabbitai[bot]

This comment was marked as resolved.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java (1)

668-680: Consider using flatMap for conciseness (optional).

The forEach loop building a list could be simplified, though the current approach is readable and maintains clear per-composite ordering.

♻️ Optional refactor using flatMap
 private List<ModificationInfos> getModificationsInfosInsideCompositesNonTransactional(`@NonNull` List<UUID> compositeUuids) {
-    List<ModificationInfos> entities = new ArrayList<>();
-    compositeUuids.forEach(uuid -> {
-        List<UUID> foundEntities = modificationRepository.findModificationIdsByCompositeModificationId(uuid);
-        List<ModificationInfos> orderedModifications = foundEntities
-                .stream()
-                .map(this::getModificationInfo)
-                .toList();
-        entities.addAll(orderedModifications);
-    }
-    );
-    return entities;
+    return compositeUuids.stream()
+            .flatMap(uuid -> modificationRepository.findModificationIdsByCompositeModificationId(uuid).stream())
+            .map(this::getModificationInfo)
+            .toList();
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java`
around lines 668 - 680, Replace the manual forEach accumulation in
getModificationsInfosInsideCompositesNonTransactional with a single stream
pipeline using flatMap to keep code concise while preserving per-composite
ordering: stream compositeUuids, flatMap each uuid to
modificationRepository.findModificationIdsByCompositeModificationId(uuid).stream(),
map each id with this::getModificationInfo, and collect to a
List<ModificationInfos>; ensure you still return the collected list and keep
method signature unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java`:
- Around line 668-680: Replace the manual forEach accumulation in
getModificationsInfosInsideCompositesNonTransactional with a single stream
pipeline using flatMap to keep code concise while preserving per-composite
ordering: stream compositeUuids, flatMap each uuid to
modificationRepository.findModificationIdsByCompositeModificationId(uuid).stream(),
map each id with this::getModificationInfo, and collect to a
List<ModificationInfos>; ensure you still return the collected list and keep
method signature unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1c4d95d0-eb3c-4711-b7c2-178d4c1ee334

📥 Commits

Reviewing files that changed from the base of the PR and between 4437ed0 and ddf31ce.

📒 Files selected for processing (1)
  • src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java

Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
Copy link
Copy Markdown
Contributor

@Meklo Meklo left a comment

Choose a reason for hiding this comment

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

LGTM, just minor remark

private String name;

@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@OneToMany(cascade = CascadeType.ALL)
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.

Could oprhanRemoval be kept as a security ?

Copy link
Copy Markdown
Contributor Author

@Mathieu-Deharbe Mathieu-Deharbe Apr 30, 2026

Choose a reason for hiding this comment

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

Since I do everything with entity lists without copying it like it was done before, JPA considers an entity to be orphan when I remove it from the list of movedEntities and automatically delete it. (while I just moved it to rootNode/group, but technically it is no longer referenced by any composite)

I could probably keep Orphan Removal by making a copy of the entity table, but it would lose a bit in performance and it would be less "JPA entity pure".

I’m not sure what is best and if there is another way.

@sonarqubecloud
Copy link
Copy Markdown

.filter(Objects::nonNull)
.filter(m -> !m.getStashed())
.collect(Collectors.toList());
movedEntities.forEach(movedEntity -> movedEntity.setGroup(group));
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.

I've noticed you've removed movedEntities.forEach(movedEntity -> movedEntity.setGroup(group)); but kept movedMods.forEach(entity -> entity.setGroup(null)); above line 979 is it deliberated ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Well seen.
I did this because movedEntities.forEach(movedEntity -> movedEntity.setGroup(group)); is already done in the following group.setModifications(rootMods); so it shouldn't be needed.

On the other hand when the group is set to null, we have to do it manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants