-
Notifications
You must be signed in to change notification settings - Fork 0
import shared composites #830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
4bb3526
f73bc65
b492fc1
7676ad7
a1c1e0b
0eb8f53
3cebb10
d298c15
9bdc3f5
6c450c8
25e2bc3
2707747
dc60c9c
2b99eff
b6a9a09
7e4e649
94f1332
919bf1e
edb9dcb
6a0b060
0365c18
8b7d22c
88c5a3d
e5c6c0f
14b4aa0
4de2680
06a5aa9
a722039
1c9beff
440e596
3cb0381
27b41f2
f3bb2ff
1291229
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) { } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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; | ||||||
|
|
@@ -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; | ||||||
|
|
||||||
|
|
@@ -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<>(); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why |
||||||
| for (UUID modificationUuid : modificationUuids) { | ||||||
| ModificationEntity modificationEntity = this.modificationRepository | ||||||
| .findById(modificationUuid) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isnt |
||||||
| .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
|
||||||
| // 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; | ||||||
|
|
@@ -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); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||||||
| } | ||||||
|
Mathieu-Deharbe marked this conversation as resolved.
|
||||||
| } | ||||||
| } | ||||||
| List<ModificationEntity> newEntities = saveModificationInfosNonTransactional(targetGroupUuid, newCompositeModifications); | ||||||
|
|
||||||
There was a problem hiding this comment.
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.