Add a modification reference as a new modification type#807
Add a modification reference as a new modification type#807SlimaneAmar wants to merge 6 commits into
Conversation
This comment was marked as low quality.
This comment was marked as low quality.
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@src/main/java/org/gridsuite/modification/server/entities/ModificationReferenceEntity.java`:
- Around line 59-64: Validate and guard against nulls for referenceType,
referenceId and referenceInfos before dereferencing in the
conversion/constructor that sets this.referenceType and this.referenceId and
calls modificationReferenceInfos.getReferenceInfos(); specifically check
modificationReferenceInfos, modificationReferenceInfos.getReferenceType(),
modificationReferenceInfos.getReferenceId(), and
modificationReferenceInfos.getReferenceInfos() (and its
getMessageType()/getMapMessageValues()) and either throw a clear
IllegalArgumentException or handle missing values gracefully; only call
setMessageType(...) and new ObjectMapper().writeValueAsString(...) when
referenceInfos is non-null, and include a descriptive error message mentioning
ModificationReferenceEntity/ modificationReferenceInfos to aid debugging.
In
`@src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java`:
- Around line 489-499: The loadModificationReference method calls
modificationRepository.getReferenceById(...) and passes its result directly to
toModificationsInfosOptimized, which can NPE if the repository returns null;
update loadModificationReference to guard the reference result (from
modificationRepository.getReferenceById) before conversion: retrieve the
reference into a local variable, check for null (or empty) and either pass an
empty/nullable-safe value to toModificationsInfosOptimized or set referenceInfos
to an appropriate default, keeping the existing fields (uuid, activated,
description, date, stashed, referenceId, referenceType) intact; references to
modify: loadModificationReference, modificationRepository.getReferenceById, and
toModificationsInfosOptimized.
In `@src/main/resources/db/changelog/changesets/changelog_20260424T113143Z.xml`:
- Around line 4-13: Make the schema enforce that references are present by
adding NOT NULL constraints on modification_reference.reference_id and
modification_reference.reference_type and a check constraint that both are set
together; update the Liquibase changeset that defines table
modification_reference (and/or add a new changeSet) to run addNotNullConstraint
for columns reference_id and reference_type and add a logical checkConstraint
(e.g., "reference_id IS NOT NULL AND reference_type IS NOT NULL") on
modification_reference; optionally, if there is a single concrete target type,
add the corresponding addForeignKeyConstraint from
modification_reference.reference_id to that target table, otherwise leave
polymorphic FK logic to application code.
In
`@src/test/java/org/gridsuite/modification/server/modifications/ModificationReferenceTest.java`:
- Around line 49-51: buildModificationUpdate() currently just returns
buildModification(), so the update tests reuse the creation payload; change
buildModificationUpdate() to produce a distinct ModificationInfos instance
(e.g., clone the object returned by buildModification() then mutate one or more
fields such as name, version, description, or attributes) so the update path
exercises a changed payload, and update any assertions in the test to verify the
modified fields differ (use the ModificationInfos constructor/setters or a
builder to make the change).
- Around line 64-70: The tests testCreationModificationMessage and
testUpdateModificationMessage currently misuse assertNotNull by passing the
constant ModificationType.COMPOSITE_MODIFICATION.name() as the first parameter
and modificationInfos.getMessageType() as the message, so they always pass;
replace those assertNotNull calls with
assertEquals(ModificationType.COMPOSITE_MODIFICATION.name(),
modificationInfos.getMessageType()) in both methods to assert the actual message
type equals the expected value.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 459859bb-1f68-43e6-8758-552f6600df57
📒 Files selected for processing (8)
src/main/java/org/gridsuite/modification/server/entities/EntityRegistry.javasrc/main/java/org/gridsuite/modification/server/entities/ModificationReferenceEntity.javasrc/main/java/org/gridsuite/modification/server/modifications/ModificationTypeWithPreloadingStrategy.javasrc/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.javasrc/main/resources/db/changelog/changesets/changelog_20260424T113143Z.xmlsrc/main/resources/db/changelog/db.changelog-master.yamlsrc/test/java/org/gridsuite/modification/server/ModificationControllerTest.javasrc/test/java/org/gridsuite/modification/server/modifications/ModificationReferenceTest.java
…ion-server into shared-modification
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@src/main/java/org/gridsuite/modification/server/entities/ModificationReferenceEntity.java`:
- Around line 60-63: The update method in ModificationReferenceEntity currently
casts modificationInfos to ModificationReferenceInfos without checking its
runtime type, which can throw ClassCastException; modify
ModificationReferenceEntity.update to first verify modificationInfos is an
instance of ModificationReferenceInfos (using instanceof or equivalent), then
call assignAttributes((ModificationReferenceInfos) modificationInfos) only when
the check passes, and if not, throw a controlled domain error (e.g.,
IllegalArgumentException or your project's DomainException) with a clear message
indicating the expected DTO type; keep the call to
super.update(modificationInfos) as appropriate and reference the update and
assignAttributes methods and the ModificationInfos/ModificationReferenceInfos
types when making the change.
In
`@src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java`:
- Around line 490-506: loadModificationReference(...) calls
toModificationsInfosOptimized(referencedEntity) with no cycle detection which
can cause stack overflow on self/cyclic references; modify
toModificationsInfosOptimized to accept a recursion guard (e.g., a Set of
visited modification IDs or a max-depth param) and check/mark
referencedEntity.getId() before recursing, returning a safe placeholder or
skipping recursive expansion when a cycle is detected; update
loadModificationReference (and the other call sites at the other reference
handling locations) to create/pass the visited set (add the current modification
id before the call) so cycles are detected and prevented.
- Line 30: Remove the unused import of DirectoryService from the top of
NetworkModificationRepository: delete the line importing
org.gridsuite.modification.server.service.DirectoryService (or alternatively
reference DirectoryService where needed); ensure no other code in class
NetworkModificationRepository references DirectoryService so Checkstyle
UnusedImports no longer fails.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: dd6ef7cf-1a81-42c7-bb29-11488c9bb807
📒 Files selected for processing (4)
src/main/java/org/gridsuite/modification/server/entities/ModificationReferenceEntity.javasrc/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.javasrc/main/resources/db/changelog/changesets/changelog_20260424T113143Z.xmlsrc/test/java/org/gridsuite/modification/server/modifications/ModificationReferenceTest.java
✅ Files skipped from review due to trivial changes (1)
- src/main/resources/db/changelog/changesets/changelog_20260424T113143Z.xml
Mathieu-Deharbe
left a comment
There was a problem hiding this comment.
Read but not executed yet. I don't want to mess with my database until this is completely finished.
| @Column(name = "referenceId") | ||
| UUID referenceId; | ||
|
|
||
| @Column(name = "referenceType") | ||
| String referenceType; |
There was a problem hiding this comment.
Those will be turned into reference_id and reference_type in the database won't they ? If yes, why not directly :
| @Column(name = "referenceId") | |
| UUID referenceId; | |
| @Column(name = "referenceType") | |
| String referenceType; | |
| @Column(name = "reference_id") | |
| UUID referenceId; | |
| @Column(name = "reference_type") | |
| String referenceType; |
The reference would be more precise, easier to track.
| .messageType(modificationEntity.getMessageType()) | ||
| .messageValues(modificationEntity.getMessageValues()) |
There was a problem hiding this comment.
I am not sure of how the update will happen when the referenced modification is changed so I may be wrong. But just in case shouldn't we use the message type and message values of the referencedEntity here ?
Isn't it how we want this modification reference to be displayed in the front ?
| .referenceType(ModificationReferenceInfos.Type.SAMPLE) | ||
| .referenceId(loadModificationInfo.getUuid()) | ||
| .referenceInfos(loadModificationInfo) | ||
| .stashed(false) |
There was a problem hiding this comment.
? :
| .stashed(false) |
(false by default)
…ion-server into shared-modification
PR Summary