Skip to content

Use the modification applicability per root network tag - #1053

Open
flomillot wants to merge 6 commits into
mainfrom
florent/GRD-4941-modification-applicability
Open

Use the modification applicability per root network tag#1053
flomillot wants to merge 6 commits into
mainfrom
florent/GRD-4941-modification-applicability

Conversation

@flomillot

@flomillot flomillot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Depends on gridsuite/network-modification-server#867.

The applicabilities per root network are now held by the modifications themselves, keyed by root network tag, so study-server stops storing them:

  • RootNetworkNodeInfoEntity.modificationsUuidsToExclude and everything that maintained it are removed: the copy on paste, the transfer on cut, the tag matching when a node or a study is duplicated, and the purge when modifications are deleted. A modification now keeps its applicability wherever it goes.
  • The application context and BuildInfos carry the tag of the root network instead of the excluded modification uuids.
  • GET /studies/{studyUuid}/nodes/{nodeUuid}/excluded-network-modifications is replaced by GET /studies/{studyUuid}/nodes/{nodeUuid}/network-modifications/applicability, which relays the applicability per tag of every modification of the node.
  • Changing the applicability of a shared modification requires the write permission on the shared element, since it is held by that element and used by every study referencing it.
  • PUT /studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/network-modifications takes an applicable query parameter instead of activated: it sets the applicability on one root network, not the global activation flag. The parameter also discriminates that mapping, so Handle the modification applicability per root network tag commons-ui#1281 must go with it.

The applicabilities stored so far are not migrated: every modification goes back to applicable on every root network. Only production database will be migrated.

Signed-off-by: Florent MILLOT <75525996+flomillot@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 334da10d-3691-4f63-8b0c-885d01ef7926

📥 Commits

Reviewing files that changed from the base of the PR and between 62e3fe0 and ed85ed2.

📒 Files selected for processing (1)
  • src/test/java/org/gridsuite/study/server/rootnetworks/RootNetworkApplicabilityTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/test/java/org/gridsuite/study/server/rootnetworks/RootNetworkApplicabilityTest.java

📝 Walkthrough

Walkthrough

The change replaces study-side excluded-modification storage with root-network-tag applicability. It updates duplication, build, application-context, authorization, and voltage-init flows, and adds integration coverage for applicability behavior.

Changes

Root-network applicability migration

Layer / File(s) Summary
Applicability contracts and service flow
src/main/java/org/gridsuite/study/server/controller/StudyController.java, src/main/java/org/gridsuite/study/server/dto/*, src/main/java/org/gridsuite/study/server/service/*, src/main/java/org/gridsuite/study/server/networkmodificationtree/*, src/main/java/org/gridsuite/study/server/StudyConstants.java
Applicability uses root-network tags. The service sends and retrieves applicability mappings. Exclusion persistence and management methods are removed. Shared modification updates require write permission.
Duplication and build integration
src/main/java/org/gridsuite/study/server/controller/StudyController.java, src/main/java/org/gridsuite/study/server/service/StudyService.java, src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java, src/test/java/org/gridsuite/study/server/VoltageInitTest.java
Modification duplication no longer requires an origin node or copies exclusion mappings. Build information and application contexts carry root-network tags. Voltage-init deactivates modifications through tag-based applicability updates.
Applicability and duplication test updates
src/test/java/org/gridsuite/study/server/NetworkModificationTest.java, src/test/java/org/gridsuite/study/server/studycontroller/StudyControllerRebuildNodeTest.java, src/test/java/org/gridsuite/study/server/rootnetworks/RootNetworkApplicabilityTest.java
Tests verify applicability forwarding, shared-modification authorization, tag propagation, simplified duplication, and applicability controller delegation.

Sequence Diagram(s)

sequenceDiagram
  participant StudyController
  participant StudyService
  participant DirectoryService
  participant NetworkModificationService
  participant NetworkModificationServer
  StudyController->>StudyService: request applicability update
  StudyService->>DirectoryService: check WRITE permission
  StudyService->>NetworkModificationService: update modification UUIDs and rootNetworkTag
  NetworkModificationService->>NetworkModificationServer: PUT applicability state
Loading

Suggested reviewers: meklo

Mergeability Score: ⚪ Minimal · up to ed85e

The PR changes how modification applicability is stored and exposed, with no actionable merge-blocking risk currently identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.02% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change to use modification applicability per root-network tag.
Description check ✅ Passed The description directly explains the applicability model, endpoint changes, permission requirements, migration status, and dependencies.
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.

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

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

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

🧹 Nitpick comments (1)
src/test/java/org/gridsuite/study/server/VoltageInitTest.java (1)

422-423: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Tighten the applicability request assertion.

At Lines [422]-[423], the dispatcher accepts any query string and any request body for the applicability endpoint.

At Lines [894]-[900], allMatch only checks that the five requests belong to an allowlist. It does not require an applicability request.

At Lines [908]-[914], Mockito verifies the client method arguments before serialization, not the wire payload. Capture the RecordedRequest and assert exactly one PUT contains the second root-network tag, VOLTAGE_INIT_MODIFICATION_UUID, and false.

Also applies to: 894-900, 908-914

🤖 Prompt for 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.

In `@src/test/java/org/gridsuite/study/server/VoltageInitTest.java` around lines
422 - 423, In VoltageInitTest, tighten the mock dispatcher branch for
/v1/network-modifications/root-network-applicability so it validates the PUT
request body instead of accepting any query or payload. Update the request
assertions around the allMatch verification to require exactly one applicability
PUT, capture its RecordedRequest, and assert the serialized payload contains the
second root-network tag, VOLTAGE_INIT_MODIFICATION_UUID, and false; retain the
existing checks for the other requests.
🤖 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.

Nitpick comments:
In `@src/test/java/org/gridsuite/study/server/VoltageInitTest.java`:
- Around line 422-423: In VoltageInitTest, tighten the mock dispatcher branch
for /v1/network-modifications/root-network-applicability so it validates the PUT
request body instead of accepting any query or payload. Update the request
assertions around the allMatch verification to require exactly one applicability
PUT, capture its RecordedRequest, and assert the serialized payload contains the
second root-network tag, VOLTAGE_INIT_MODIFICATION_UUID, and false; retain the
existing checks for the other requests.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: aeb0b844-b27d-4001-8c96-1807a95ddf5d

📥 Commits

Reviewing files that changed from the base of the PR and between f8dd235 and a2ba643.

📒 Files selected for processing (15)
  • src/main/java/org/gridsuite/study/server/controller/StudyController.java
  • src/main/java/org/gridsuite/study/server/dto/BuildInfos.java
  • src/main/java/org/gridsuite/study/server/dto/modification/ModificationApplicationContext.java
  • src/main/java/org/gridsuite/study/server/networkmodificationtree/dto/ExcludedNetworkModifications.java
  • src/main/java/org/gridsuite/study/server/networkmodificationtree/entities/RootNetworkNodeInfoEntity.java
  • src/main/java/org/gridsuite/study/server/repository/rootnetwork/RootNetworkNodeInfoRepository.java
  • src/main/java/org/gridsuite/study/server/service/NetworkModificationService.java
  • src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java
  • src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java
  • src/main/java/org/gridsuite/study/server/service/RootNetworkService.java
  • src/main/java/org/gridsuite/study/server/service/StudyService.java
  • src/test/java/org/gridsuite/study/server/NetworkModificationTest.java
  • src/test/java/org/gridsuite/study/server/VoltageInitTest.java
  • src/test/java/org/gridsuite/study/server/rootnetworks/ModificationToExcludeTest.java
  • src/test/java/org/gridsuite/study/server/rootnetworks/RootNetworkApplicabilityTest.java
💤 Files with no reviewable changes (3)
  • src/main/java/org/gridsuite/study/server/networkmodificationtree/dto/ExcludedNetworkModifications.java
  • src/main/java/org/gridsuite/study/server/networkmodificationtree/entities/RootNetworkNodeInfoEntity.java
  • src/test/java/org/gridsuite/study/server/rootnetworks/ModificationToExcludeTest.java

The network modification server names it after the applicability it carries,
not after the modification wide activation flag.

Signed-off-by: Florent MILLOT <florent.millot_externe@rte-france.com>
The endpoint sets the applicability of modifications on one root network, not
their global activation flag, so activated was ambiguous. The value now keeps
the same name from the front-end call down to the network modification server.

Also name the two root network tags of RootNetworkApplicabilityTest after their
rank rather than their position.

Signed-off-by: Florent MILLOT <florent.millot_externe@rte-france.com>

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/main/java/org/gridsuite/study/server/service/StudyService.java (2)

1869-1881: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Validate root-network ownership before resolving the tag.

The controller validates nodeUuid, but the shown path does not validate that rootNetworkUuid belongs to studyUuid. This service only checks node ownership at Line 1874. rootNetworkService.getRootNetworkTag(rootNetworkUuid) can therefore resolve a root network from another study before updateRootNetworkApplicability changes its applicability. Call rootNetworkService.assertIsRootNetworkInStudy(studyUuid, rootNetworkUuid) or assertIsRootNetworkAndNodeInStudy(...) before this update.

🤖 Prompt for 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.

In `@src/main/java/org/gridsuite/study/server/service/StudyService.java` around
lines 1869 - 1881, In updateNetworkModificationsApplicabilityInRootNetwork,
validate that rootNetworkUuid belongs to studyUuid before resolving its tag or
updating applicability. Add
rootNetworkService.assertIsRootNetworkInStudy(studyUuid, rootNetworkUuid), or
the combined assertIsRootNetworkAndNodeInStudy equivalent, before
getRootNetworkTag and updateRootNetworkApplicability.

2617-2619: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Make non-target applicability updates atomic or recoverable.

updateRootNetworkApplicability sends one remote request per root-network tag. If a later request fails, earlier changes remain, the local transaction cannot roll them back, and resetModificationsGroupUuid is not called. Use a batch endpoint or a safe compensation/retry workflow. Add a mid-loop failure test.

🤖 Prompt for 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.

In `@src/main/java/org/gridsuite/study/server/service/StudyService.java` around
lines 2617 - 2619, Make the root-network applicability updates in the flow
containing createdModificationUuids and rootNetworkTagsToDeactivate atomic or
recoverable: replace the per-tag updateRootNetworkApplicability calls with a
batch operation, or add compensation/retry handling that restores earlier
successful updates and ensures resetModificationsGroupUuid is invoked on
failure. Add a test that simulates a failure during the loop and verifies no
partial state remains.
🤖 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.

Outside diff comments:
In `@src/main/java/org/gridsuite/study/server/service/StudyService.java`:
- Around line 1869-1881: In
updateNetworkModificationsApplicabilityInRootNetwork, validate that
rootNetworkUuid belongs to studyUuid before resolving its tag or updating
applicability. Add rootNetworkService.assertIsRootNetworkInStudy(studyUuid,
rootNetworkUuid), or the combined assertIsRootNetworkAndNodeInStudy equivalent,
before getRootNetworkTag and updateRootNetworkApplicability.
- Around line 2617-2619: Make the root-network applicability updates in the flow
containing createdModificationUuids and rootNetworkTagsToDeactivate atomic or
recoverable: replace the per-tag updateRootNetworkApplicability calls with a
batch operation, or add compensation/retry handling that restores earlier
successful updates and ensures resetModificationsGroupUuid is invoked on
failure. Add a test that simulates a failure during the loop and verifies no
partial state remains.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0845892e-6f4c-443d-875b-10264d25a9d4

📥 Commits

Reviewing files that changed from the base of the PR and between 44a8817 and a5e1c49.

📒 Files selected for processing (6)
  • src/main/java/org/gridsuite/study/server/controller/StudyController.java
  • src/main/java/org/gridsuite/study/server/service/RebuildNodeService.java
  • src/main/java/org/gridsuite/study/server/service/StudyService.java
  • src/test/java/org/gridsuite/study/server/NetworkModificationTest.java
  • src/test/java/org/gridsuite/study/server/rootnetworks/RootNetworkApplicabilityTest.java
  • src/test/java/org/gridsuite/study/server/studycontroller/StudyControllerRebuildNodeTest.java
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/test/java/org/gridsuite/study/server/NetworkModificationTest.java
  • src/test/java/org/gridsuite/study/server/rootnetworks/RootNetworkApplicabilityTest.java
  • src/main/java/org/gridsuite/study/server/controller/StudyController.java

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/main/java/org/gridsuite/study/server/service/StudyService.java (2)

1877-1890: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Validate rootNetworkUuid against studyUuid before updating applicability.

The controller checks only the node. The service reads the root-network tag without checking ownership. Call assertIsRootNetworkAndNodeInStudy(studyUuid, rootNetworkUuid, nodeUuid) at the start of this service method, before side effects.

🤖 Prompt for 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.

In `@src/main/java/org/gridsuite/study/server/service/StudyService.java` around
lines 1877 - 1890, At the start of
updateNetworkModificationsApplicabilityInRootNetwork, call
assertIsRootNetworkAndNodeInStudy(studyUuid, rootNetworkUuid, nodeUuid) before
retrieving children, verifying modifications, or emitting notifications.
Preserve the existing applicability update flow after this validation.

945-946: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Preserve the battery DC power-factor parameter.

Line [945] initializes the battery map with QUERY_PARAM_DC_POWERFACTOR. Line [964] replaces that map with a new map containing only QUERY_PARAM_LOAD_REGULATING_TERMINALS. Battery map-data requests therefore lose the DC power factor.

Add the regulating-terminal parameter to the existing mutable battery map, or define both parameters in one map.

Proposed fix
-        optionalParameters.put(String.valueOf(ElementType.BATTERY),
-                Map.of(
-                        InfoTypeParameters.QUERY_PARAM_LOAD_REGULATING_TERMINALS,
-                        String.valueOf(studyEntity.getSpreadsheetParameters().isSpreadsheetLoadBatteryRegulatingTerminal())));
+        optionalParameters.get(String.valueOf(ElementType.BATTERY)).put(
+                InfoTypeParameters.QUERY_PARAM_LOAD_REGULATING_TERMINALS,
+                String.valueOf(studyEntity.getSpreadsheetParameters().isSpreadsheetLoadBatteryRegulatingTerminal()));

Also applies to: 964-967

🤖 Prompt for 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.

In `@src/main/java/org/gridsuite/study/server/service/StudyService.java` around
lines 945 - 946, Update the battery parameter map initialization and subsequent
handling so the existing QUERY_PARAM_DC_POWERFACTOR entry is preserved while
adding QUERY_PARAM_LOAD_REGULATING_TERMINALS to the same map. Do not replace the
battery map with a new map containing only the regulating-terminal parameter;
ensure battery map-data requests include both parameters.
🤖 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.

Outside diff comments:
In `@src/main/java/org/gridsuite/study/server/service/StudyService.java`:
- Around line 1877-1890: At the start of
updateNetworkModificationsApplicabilityInRootNetwork, call
assertIsRootNetworkAndNodeInStudy(studyUuid, rootNetworkUuid, nodeUuid) before
retrieving children, verifying modifications, or emitting notifications.
Preserve the existing applicability update flow after this validation.
- Around line 945-946: Update the battery parameter map initialization and
subsequent handling so the existing QUERY_PARAM_DC_POWERFACTOR entry is
preserved while adding QUERY_PARAM_LOAD_REGULATING_TERMINALS to the same map. Do
not replace the battery map with a new map containing only the
regulating-terminal parameter; ensure battery map-data requests include both
parameters.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c1575af4-32e0-4336-90be-a13a4fd8fc70

📥 Commits

Reviewing files that changed from the base of the PR and between a5e1c49 and 62e3fe0.

📒 Files selected for processing (2)
  • src/main/java/org/gridsuite/study/server/service/NetworkModificationService.java
  • src/main/java/org/gridsuite/study/server/service/StudyService.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/org/gridsuite/study/server/service/NetworkModificationService.java

Static import the Mockito methods and keep a single throwing invocation in
the assertThrows lambda.

Signed-off-by: Florent MILLOT <florent.millot_externe@rte-france.com>
@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.

1 participant