Skip to content

Add a modification reference as a new modification type#807

Open
SlimaneAmar wants to merge 5 commits intomainfrom
shared-modification
Open

Add a modification reference as a new modification type#807
SlimaneAmar wants to merge 5 commits intomainfrom
shared-modification

Conversation

@SlimaneAmar
Copy link
Copy Markdown
Contributor

PR Summary

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 28, 2026

Warning

Rate limit exceeded

@SlimaneAmar has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 47 minutes and 15 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 00273a9e-72bd-40de-82e6-616a85ceea3f

📥 Commits

Reviewing files that changed from the base of the PR and between 7676ad7 and a1c1e0b.

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

Walkthrough

Adds a new ModificationReference feature: a JPA entity for modification references, registry & modification-type mappings, repository conversion logic to resolve referenced modifications, DB changelog to persist references, and integration tests including COPY behavior.

Changes

Cohort / File(s) Summary
Entity Layer
src/main/java/org/gridsuite/modification/server/entities/ModificationReferenceEntity.java, src/main/java/org/gridsuite/modification/server/entities/EntityRegistry.java
New ModificationReferenceEntity extending ModificationEntity with referenceId, referenceType, transient referenceInfos, conversion/update methods; EntityRegistry mapped ModificationReferenceInfosModificationReferenceEntity.
Modification Type Configuration
src/main/java/org/gridsuite/modification/server/modifications/ModificationTypeWithPreloadingStrategy.java
Added enum constant mapping ModificationType.MODIFICATION_REFERENCEPreloadingStrategy.COLLECTION.
Repository Layer
src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java
Added optimized conversion for ModificationReferenceEntity that resolves referenced modification via modificationRepository.getReferenceById(...), builds ModificationReferenceInfos including resolved referenceInfos, and updated import list/dispatching.
Database Schema
src/main/resources/db/changelog/changesets/changelog_20260424T113143Z.xml, src/main/resources/db/changelog/db.changelog-master.yaml
Creates modification_reference table (id, reference_id, reference_type) and FK to modification.id; includes new changeset in master changelog.
Integration Tests
src/test/java/org/gridsuite/modification/server/modifications/ModificationReferenceTest.java, src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java
Adds tests for modification reference creation/update/deletion and for COPY action duplicating references across groups.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Controller as Controller
    participant Repo as NetworkModificationRepository
    participant RefRepo as ModificationRepository
    participant DB as Database

    Client->>Controller: request (e.g., GET/COPY involving a reference)
    Controller->>Repo: load modification(s)
    Repo->>DB: query modification_reference (if entity is a reference)
    DB-->>Repo: modification_reference row
    Repo->>RefRepo: getReferenceById(referenceId)
    RefRepo->>DB: query referenced modification
    DB-->>RefRepo: referenced modification row
    RefRepo-->>Repo: referenced ModificationEntity / DTO (optimized conversion)
    Repo-->>Controller: assembled ModificationReferenceInfos (includes referenceInfos)
    Controller-->>Client: response with resolved reference payload
Loading

Suggested reviewers

  • Mathieu-Deharbe
  • Meklo
  • etiennehomer
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description contains only a placeholder template with no actual content describing the changeset. Provide a meaningful description explaining what the modification reference feature does, why it was added, and how it works within the system.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: introducing a new modification type called 'modification reference' to the system.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 47 minutes and 15 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6af09c1 and f73bc65.

📒 Files selected for processing (8)
  • src/main/java/org/gridsuite/modification/server/entities/EntityRegistry.java
  • src/main/java/org/gridsuite/modification/server/entities/ModificationReferenceEntity.java
  • src/main/java/org/gridsuite/modification/server/modifications/ModificationTypeWithPreloadingStrategy.java
  • src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java
  • src/main/resources/db/changelog/changesets/changelog_20260424T113143Z.xml
  • src/main/resources/db/changelog/db.changelog-master.yaml
  • src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java
  • src/test/java/org/gridsuite/modification/server/modifications/ModificationReferenceTest.java

@Mathieu-Deharbe Mathieu-Deharbe self-assigned this Apr 29, 2026
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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between f73bc65 and 7676ad7.

📒 Files selected for processing (4)
  • src/main/java/org/gridsuite/modification/server/entities/ModificationReferenceEntity.java
  • src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java
  • src/main/resources/db/changelog/changesets/changelog_20260424T113143Z.xml
  • src/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

Copy link
Copy Markdown
Contributor

@Mathieu-Deharbe Mathieu-Deharbe left a comment

Choose a reason for hiding this comment

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

Read but not executed yet. I don't want to mess with my database until this is completely finished.

Comment on lines +27 to +31
@Column(name = "referenceId")
UUID referenceId;

@Column(name = "referenceType")
String referenceType;
Copy link
Copy Markdown
Contributor

@Mathieu-Deharbe Mathieu-Deharbe Apr 29, 2026

Choose a reason for hiding this comment

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

Those will be turned into reference_id and reference_type in the database won't they ? If yes, why not directly :

Suggested change
@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.

Comment on lines +496 to +497
.messageType(modificationEntity.getMessageType())
.messageValues(modificationEntity.getMessageValues())
Copy link
Copy Markdown
Contributor

@Mathieu-Deharbe Mathieu-Deharbe Apr 29, 2026

Choose a reason for hiding this comment

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

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)
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
.stashed(false)

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