Skip to content

Add a modification reference as a new modification type#187

Open
SlimaneAmar wants to merge 9 commits into
mainfrom
shared-modification
Open

Add a modification reference as a new modification type#187
SlimaneAmar wants to merge 9 commits into
mainfrom
shared-modification

Conversation

@SlimaneAmar

Copy link
Copy Markdown
Contributor

PR Summary

@coderabbitai

This comment was marked as low quality.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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/dto/ModificationReferenceInfos.java`:
- Around line 55-63: ModificationReferenceInfos must validate its required
payloads before delegating: add non-null checks for referenceInfos and
referenceType in the DTO (e.g., at the start of toModification() and
createSubReportNode()) and throw a clear runtime exception
(IllegalStateException or Objects.requireNonNull with message) instead of
silently mapping null referenceType to DIRECTORY; then use the validated
referenceType to select the template (Type.SAMPLE ->
"network.modification.sample.reference.apply", otherwise
"network.modification.directory.reference.apply") and proceed to construct the
ModificationReference and ReportNode as before.

In
`@src/main/java/org/gridsuite/modification/modifications/ModificationReference.java`:
- Around line 24-25: ModificationReference is delegating to other modifications
but never stores the application context services, so filterService and
loadFlowService remain null; update ModificationReference's
initApplicationContext(...) to assign the passed IFilterService and
ILoadFlowService to the protected fields (filterService, loadFlowService) and
ensure any delegation path (the code that forwards to the wrapped/delegated
modification around the current forwarding at ~line 40) calls the delegated
modification's initApplicationContext(...) with the same services so the
delegate receives the captured context.
- Around line 45-46: The getName method in class ModificationReference returns
the misspelled string "ModificationRefence"; update the return value in the
getName() method to the correct "ModificationReference" so the method signature
and returned name match the class and other references.

In `@src/main/java/org/gridsuite/modification/ModificationType.java`:
- Line 14: The TabularBaseInfos formatting falls back to "equipments of unknown
type" for the newly added enum value ModificationType.MODIFICATION_REFERENCE;
update the equipment-type mapping in
src/main/java/org/gridsuite/modification/dto/tabular/TabularBaseInfos (the
method that maps ModificationType to display labels) to add a case for
MODIFICATION_REFERENCE and return the appropriate user-facing label (consistent
with other mappings) instead of the default unknown-type string so the new enum
renders correctly in tabular views.

In
`@src/test/java/org/gridsuite/modification/modifications/ModificationReferenceTest.java`:
- Around line 57-58: The testCreationModificationMessage currently calls
assertNotNull with ModificationType.MODIFICATION_REFERENCE.name() and
modificationInfos.getMessageType(), which doesn’t verify the actual value;
replace that assertion with
assertEquals(ModificationType.MODIFICATION_REFERENCE.name(),
modificationInfos.getMessageType()) in the testCreationModificationMessage
method so the test asserts the message type is exactly 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: 14c0c97c-6d2a-46d6-a9b5-17df814d1948

📥 Commits

Reviewing files that changed from the base of the PR and between c5f1721 and 466e7a2.

📒 Files selected for processing (5)
  • src/main/java/org/gridsuite/modification/ModificationType.java
  • src/main/java/org/gridsuite/modification/dto/ModificationInfos.java
  • src/main/java/org/gridsuite/modification/dto/ModificationReferenceInfos.java
  • src/main/java/org/gridsuite/modification/modifications/ModificationReference.java
  • src/test/java/org/gridsuite/modification/modifications/ModificationReferenceTest.java

Comment thread src/main/java/org/gridsuite/modification/modifications/ModificationReference.java Outdated
Comment thread src/main/java/org/gridsuite/modification/ModificationType.java
@SlimaneAmar SlimaneAmar force-pushed the shared-modification branch 3 times, most recently from 5b58389 to 244a439 Compare April 29, 2026 08:22
@SlimaneAmar SlimaneAmar force-pushed the shared-modification branch from 244a439 to c19317b Compare April 29, 2026 09:34

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
src/main/java/org/gridsuite/modification/dto/ModificationReferenceInfos.java (1)

62-64: ⚠️ Potential issue | 🟠 Major

Avoid silent fallback to DIRECTORY when report template type is invalid/unvalidated.

Line 63 maps any non-SAMPLE value (including null) to DIRECTORY. Please validate first (or call check()), then use an exhaustive switch to prevent accidental misreporting.

Proposed fix
 `@Override`
 public ReportNode createSubReportNode(ReportNode reportNode) {
-    return reportNode.newReportNode().withMessageTemplate(referenceType == Type.SAMPLE ? "network.modification.sample.reference.apply" : "network.modification.directory.reference.apply").add();
+    check();
+    String template = switch (referenceType) {
+        case SAMPLE -> "network.modification.sample.reference.apply";
+        case DIRECTORY -> "network.modification.directory.reference.apply";
+    };
+    return reportNode.newReportNode().withMessageTemplate(template).add();
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/org/gridsuite/modification/dto/ModificationReferenceInfos.java`
around lines 62 - 64, createSubReportNode silently treats any non-SAMPLE
referenceType (including null) as DIRECTORY; first validate referenceType (call
or inline the existing check() or throw IllegalStateException on null/invalid)
and then replace the ternary with an exhaustive switch on referenceType (switch
over Type enum with cases SAMPLE and DIRECTORY and a default that throws) to
avoid accidental fallback/misreporting; update createSubReportNode to perform
validation before constructing the ReportNode and to use the switch so unknown
values fail fast.
🧹 Nitpick comments (1)
src/main/java/org/gridsuite/modification/dto/ModificationReferenceInfos.java (1)

67-69: Prefer immutable empty map for no-value payloads.

new HashMap<>() allocates a mutable object each call; Map.of() is cheaper and expresses intent better.

Proposed refactor
 `@Override`
 public Map<String, String> getMapMessageValues() {
-    return new HashMap<>();
+    return Map.of();
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/org/gridsuite/modification/dto/ModificationReferenceInfos.java`
around lines 67 - 69, The getMapMessageValues method in class
ModificationReferenceInfos currently returns a newly allocated mutable HashMap
on each call; replace that with an immutable empty map (e.g., return Map.of())
to avoid unnecessary allocations and make the intent explicit—update the body of
ModificationReferenceInfos.getMapMessageValues() to return an immutable empty
map instance instead of new HashMap<>().
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In
`@src/main/java/org/gridsuite/modification/dto/ModificationReferenceInfos.java`:
- Around line 62-64: createSubReportNode silently treats any non-SAMPLE
referenceType (including null) as DIRECTORY; first validate referenceType (call
or inline the existing check() or throw IllegalStateException on null/invalid)
and then replace the ternary with an exhaustive switch on referenceType (switch
over Type enum with cases SAMPLE and DIRECTORY and a default that throws) to
avoid accidental fallback/misreporting; update createSubReportNode to perform
validation before constructing the ReportNode and to use the switch so unknown
values fail fast.

---

Nitpick comments:
In
`@src/main/java/org/gridsuite/modification/dto/ModificationReferenceInfos.java`:
- Around line 67-69: The getMapMessageValues method in class
ModificationReferenceInfos currently returns a newly allocated mutable HashMap
on each call; replace that with an immutable empty map (e.g., return Map.of())
to avoid unnecessary allocations and make the intent explicit—update the body of
ModificationReferenceInfos.getMapMessageValues() to return an immutable empty
map instance instead of new HashMap<>().

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d9d1c774-8a13-4bc0-b6a7-2b38aec5cb1d

📥 Commits

Reviewing files that changed from the base of the PR and between 244a439 and c19317b.

📒 Files selected for processing (9)
  • src/main/java/org/gridsuite/modification/ModificationType.java
  • src/main/java/org/gridsuite/modification/dto/ModificationInfos.java
  • src/main/java/org/gridsuite/modification/dto/ModificationReferenceInfos.java
  • src/main/java/org/gridsuite/modification/modifications/ModificationReference.java
  • src/test/java/org/gridsuite/modification/modifications/AbstractNetworkModificationTest.java
  • src/test/java/org/gridsuite/modification/modifications/CreateVoltageLevelSectionTest.java
  • src/test/java/org/gridsuite/modification/modifications/LccCreationInNodeBreakerTest.java
  • src/test/java/org/gridsuite/modification/modifications/ModificationReferenceTest.java
  • src/test/java/org/gridsuite/modification/modifications/VoltageLevelTopologyModificationTest.java
✅ Files skipped from review due to trivial changes (5)
  • src/main/java/org/gridsuite/modification/ModificationType.java
  • src/test/java/org/gridsuite/modification/modifications/VoltageLevelTopologyModificationTest.java
  • src/test/java/org/gridsuite/modification/modifications/LccCreationInNodeBreakerTest.java
  • src/test/java/org/gridsuite/modification/modifications/CreateVoltageLevelSectionTest.java
  • src/main/java/org/gridsuite/modification/modifications/ModificationReference.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/test/java/org/gridsuite/modification/modifications/ModificationReferenceTest.java

@Mathieu-Deharbe Mathieu-Deharbe self-assigned this Apr 29, 2026

@Mathieu-Deharbe Mathieu-Deharbe left a comment

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 only reported my test results in gridsuite/directory-server#247

So just a few questions and discussions about naming.

Comment thread src/main/java/org/gridsuite/modification/dto/ModificationReferenceInfos.java Outdated
Comment on lines +27 to +29
/**
* @author Slimane Amar <slimane.amar at rte-france.com>
*/

@Mathieu-Deharbe Mathieu-Deharbe Apr 29, 2026

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.

It would be useful to precise somewhere what can be referenced. The jira precises only composites but it looks like anything can be referenced (of course if really any modification can and will be referenced, no need to precise anything, but should a modification reference be referenced by another modification reference ?)

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.

?


@Override
public Map<String, String> getMapMessageValues() {
return 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 are you overriding an already empty super function ? If I am reading right assignAttributes from ModificationReferenceEntity, this should never be used right ?

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.

We force the value as empty.
Because the default value may change later for ordinary modifications

.referenceType(ModificationReferenceInfos.Type.SAMPLE)
.referenceId(UUID.randomUUID())
.referenceInfos(modificationInfo)
.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.

It is a default value :

Suggested change
.stashed(false)

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.

It's like the other tests

@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/resources/org/gridsuite/modification/reports_fr.properties`:
- Line 28: Replace the English values for the two localization keys with the
provided French translations: update network.modification.basic.reference.apply
to "Modification par référence basique" and update
network.modification.directory.reference.apply to "Modifications par référence
de répertoire"; ensure you edit these values in
src/main/resources/org/gridsuite/modification/reports_fr.properties so the keys
remain unchanged and only the right-hand-side strings are replaced.
🪄 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: 4449069f-aa71-488a-825e-08e6a17483b6

📥 Commits

Reviewing files that changed from the base of the PR and between 4d8185e and 802f5c8.

📒 Files selected for processing (5)
  • src/main/java/org/gridsuite/modification/dto/ModificationReferenceInfos.java
  • src/main/java/org/gridsuite/modification/modifications/ModificationReference.java
  • src/main/resources/org/gridsuite/modification/reports.properties
  • src/main/resources/org/gridsuite/modification/reports_fr.properties
  • src/test/java/org/gridsuite/modification/modifications/ModificationReferenceTest.java
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/main/java/org/gridsuite/modification/modifications/ModificationReference.java
  • src/main/java/org/gridsuite/modification/dto/ModificationReferenceInfos.java
  • src/test/java/org/gridsuite/modification/modifications/ModificationReferenceTest.java

Comment thread src/main/resources/org/gridsuite/modification/reports_fr.properties
@sonarqubecloud

Copy link
Copy Markdown

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