Skip to content

refactor computations parameters#996

Open
AbdelHedhili wants to merge 2 commits into
mainfrom
refactor_computations_parameters
Open

refactor computations parameters#996
AbdelHedhili wants to merge 2 commits into
mainfrom
refactor_computations_parameters

Conversation

@AbdelHedhili
Copy link
Copy Markdown
Contributor

No description provided.

Signed-off-by: Abdelsalem <abdelsalem.hedhili@rte-france.com>
@AbdelHedhili AbdelHedhili self-assigned this May 21, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

Review Change Stack

Warning

Rate limit exceeded

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

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ 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: c8d28a41-8745-4726-9ee2-5347b745bc7b

📥 Commits

Reviewing files that changed from the base of the PR and between 727e5c4 and d1f1fdf.

📒 Files selected for processing (1)
  • src/main/java/org/gridsuite/study/server/service/StudyService.java
📝 Walkthrough

Walkthrough

This PR consolidates computation parameter handling by introducing a unified ComputationParameters interface and ComputationParametersService that replace scattered per-type parameter management. A new ComputationsParameters DTO aggregates UUIDs for all ten computation types, and all computation services implement the interface with renamed methods to match a standard contract. StudyService and ConsumerService are refactored to delegate parameter operations to the new service, centralizing creation, duplication, deletion, and persistence logic.

Changes

Computation Parameter Consolidation

Layer / File(s) Summary
Core contract and parameter aggregation model
src/main/java/org/gridsuite/study/server/service/common/ComputationParameters.java, src/main/java/org/gridsuite/study/server/dto/computation/ComputationsParameters.java
New ComputationParameters interface defines duplicateParameters(UUID) and deleteParameters(UUID) contract; new ComputationsParameters record aggregates ten UUID fields for all computation parameter types and uses Lombok @Builder for instantiation.
ComputationParametersService orchestration
src/main/java/org/gridsuite/study/server/service/ComputationParametersService.java
New Spring service centralizes parameter management via internal ComputationParametersDefinition record mapping each computation type to UUID getters, services, default suppliers, and builder wiring; provides createDefaultComputationParameters(...) with user-profile fallback, duplicateParameters(...) for bulk duplication, deleteComputationsParameters(...) for bulk deletion, and two createOrUpdateParameters(...) overloads for flexible typed parameter persistence with error handling and user-profile duplication support.
Computation service interface implementations
src/main/java/org/gridsuite/study/server/service/LoadFlowService.java, src/main/java/org/gridsuite/study/server/service/SecurityAnalysisService.java, src/main/java/org/gridsuite/study/server/service/SensitivityAnalysisService.java, src/main/java/org/gridsuite/study/server/service/StateEstimationService.java, src/main/java/org/gridsuite/study/server/service/VoltageInitService.java, src/main/java/org/gridsuite/study/server/service/shortcircuit/ShortCircuitService.java, src/main/java/org/gridsuite/study/server/service/PccMinService.java, src/main/java/org/gridsuite/study/server/service/dynamicsimulation/DynamicSimulationService.java, src/main/java/org/gridsuite/study/server/service/dynamicsecurityanalysis/DynamicSecurityAnalysisService.java, src/main/java/org/gridsuite/study/server/service/dynamicmargincalculation/DynamicMarginCalculationService.java
All ten computation services now implement ComputationParameters interface; parameter-management methods renamed from type-specific names (e.g., duplicateLoadFlowParameters, deleteSecurityAnalysisParameters) to unified contract methods duplicateParameters(UUID) and deleteParameters(UUID), each annotated with @Override; method bodies/REST logic remain unchanged.
StudyService parameter handling refactoring
src/main/java/org/gridsuite/study/server/service/StudyService.java
Constructor now injects ComputationParametersService; study deletion builds ComputationsParameters from entity UUIDs and delegates to computationParametersService.deleteComputationsParameters(...); public insertStudy(...) signature updated to accept single ComputationsParameters instead of ten separate UUID parameters; duplication flow uses computationParametersService.duplicateParameters(sourceStudyEntity) to aggregate results; new generic helpers setComputationParameters(...) and emitComputationParametersChanged(...) centralize create/update, invalidation, and notification for all parameter setters (security, load flow, short circuit, voltage init, dynamic simulation/security/margin, sensitivity, state estimation); saveStudyThenCreateBasicTree(...) refactored to persist grouped computation UUIDs from aggregated ComputationsParameters; PCC Min operations delegated to pccMinService APIs; notification behavior in runShortCircuit(...) and runPccMin(...) adjusted.
ConsumerService parameter delegation
src/main/java/org/gridsuite/study/server/service/ConsumerService.java
Constructor signature simplified: removes individual injections of SecurityAnalysisService, SensitivityAnalysisService, DynamicSimulationService, DynamicSecurityAnalysisService, DynamicMarginCalculationService, StateEstimationService, PccMinService and introduces single ComputationParametersService dependency; insertStudy(...) refactored to generate ComputationsParameters via computationParametersService.createDefaultComputationParameters(...) and pass it to studyService.insertStudy(...); removes per-analysis default-parameter helper methods.

Suggested reviewers

  • Meklo
  • SlimaneAmar
  • khouadrired
🚥 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 No description was provided by the author, making it impossible to assess whether it relates to the changeset. Add a pull request description explaining the motivation, approach, and impact of the computations parameters refactoring.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main refactoring: consolidating computation parameters handling through a new ComputationsParameters DTO and ComputationParametersService.
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

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: 2

🤖 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/java/org/gridsuite/study/server/service/ComputationParametersService.java`:
- Around line 210-211: The call to userAdminService.getUserProfile when
computing UserProfileInfos can throw and currently will abort the method instead
of falling back; wrap the lookup in a try-catch around the invocation of
userAdminService.getUserProfile and on any exception set userProfileInfos to
null (and optionally log the exception) so profileParameterId computed from
profileParameterGetter remains null and the existing default/create-update
fallback path using parameters continues to execute; update the block where
UserProfileInfos, userAdminService.getUserProfile, profileParameterGetter and
profileParameterId are used to implement this safe-lookup behavior.

In `@src/main/java/org/gridsuite/study/server/service/StudyService.java`:
- Around line 2831-2845: The call to setComputationParameters for dynamic
simulation parameters must also invalidate downstream Dynamic Margin Calculation
(DMC) results and emit its status update; modify the invocation that currently
passes List.of(this::invalidateDynamicSimulationStatusOnAllNodes,
this::invalidateDynamicSecurityAnalysisStatusOnAllNodes) and the two
notification types (NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS,
NotificationService.UPDATE_TYPE_DYNAMIC_SECURITY_ANALYSIS_STATUS) to also
include the DMC invalidation callback (e.g.,
this::invalidateDynamicMarginCalculationStatusOnAllNodes) and the DMC
notification constant (e.g.,
NotificationService.UPDATE_TYPE_DYNAMIC_MARGIN_CALCULATION_STATUS); apply the
same change to the other setComputationParameters call that handles dynamic
security analysis parameters so both parameter setters clear and notify Dynamic
Margin Calculation status via the appropriate invalidate method and notification
type.
🪄 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: 79fabab0-4687-4ad6-875f-6aa3f15ebd47

📥 Commits

Reviewing files that changed from the base of the PR and between b07c75b and 727e5c4.

📒 Files selected for processing (15)
  • src/main/java/org/gridsuite/study/server/dto/computation/ComputationsParameters.java
  • src/main/java/org/gridsuite/study/server/service/ComputationParametersService.java
  • src/main/java/org/gridsuite/study/server/service/ConsumerService.java
  • src/main/java/org/gridsuite/study/server/service/LoadFlowService.java
  • src/main/java/org/gridsuite/study/server/service/PccMinService.java
  • src/main/java/org/gridsuite/study/server/service/SecurityAnalysisService.java
  • src/main/java/org/gridsuite/study/server/service/SensitivityAnalysisService.java
  • src/main/java/org/gridsuite/study/server/service/StateEstimationService.java
  • src/main/java/org/gridsuite/study/server/service/StudyService.java
  • src/main/java/org/gridsuite/study/server/service/VoltageInitService.java
  • src/main/java/org/gridsuite/study/server/service/common/ComputationParameters.java
  • src/main/java/org/gridsuite/study/server/service/dynamicmargincalculation/DynamicMarginCalculationService.java
  • src/main/java/org/gridsuite/study/server/service/dynamicsecurityanalysis/DynamicSecurityAnalysisService.java
  • src/main/java/org/gridsuite/study/server/service/dynamicsimulation/DynamicSimulationService.java
  • src/main/java/org/gridsuite/study/server/service/shortcircuit/ShortCircuitService.java

Comment on lines +210 to +211
UserProfileInfos userProfileInfos = parameters == null ? userAdminService.getUserProfile(userId) : null;
UUID profileParameterId = userProfileInfos == null ? null : profileParameterGetter.apply(userProfileInfos);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Handle user-profile lookup failures before fallback.

Line 210 calls an external service (userAdminService.getUserProfile) without a guard. If it throws, the method exits instead of falling back to default/create-update behavior.

💡 Proposed fix
-        UserProfileInfos userProfileInfos = parameters == null ? userAdminService.getUserProfile(userId) : null;
+        UserProfileInfos userProfileInfos = null;
+        if (parameters == null) {
+            try {
+                userProfileInfos = userAdminService.getUserProfile(userId);
+            } catch (Exception e) {
+                userProfileIssue = true;
+                LOGGER.error("Could not retrieve user/profile '{}'. Using default parameters", userId, e);
+            }
+        }
         UUID profileParameterId = userProfileInfos == null ? null : profileParameterGetter.apply(userProfileInfos);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
UserProfileInfos userProfileInfos = parameters == null ? userAdminService.getUserProfile(userId) : null;
UUID profileParameterId = userProfileInfos == null ? null : profileParameterGetter.apply(userProfileInfos);
UserProfileInfos userProfileInfos = null;
if (parameters == null) {
try {
userProfileInfos = userAdminService.getUserProfile(userId);
} catch (Exception e) {
userProfileIssue = true;
LOGGER.error("Could not retrieve user/profile '{}'. Using default parameters", userId, e);
}
}
UUID profileParameterId = userProfileInfos == null ? null : profileParameterGetter.apply(userProfileInfos);
🤖 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/ComputationParametersService.java`
around lines 210 - 211, The call to userAdminService.getUserProfile when
computing UserProfileInfos can throw and currently will abort the method instead
of falling back; wrap the lookup in a try-catch around the invocation of
userAdminService.getUserProfile and on any exception set userProfileInfos to
null (and optionally log the exception) so profileParameterId computed from
profileParameterGetter remains null and the existing default/create-update
fallback path using parameters continues to execute; update the block where
UserProfileInfos, userAdminService.getUserProfile, profileParameterGetter and
profileParameterId are used to implement this safe-lookup behavior.

Comment on lines +2831 to +2845
return setComputationParameters(
studyUuid,
dsParameter,
userId,
StudyEntity::getDynamicSimulationParametersUuid,
StudyEntity::setDynamicSimulationParametersUuid,
UserProfileInfos::getDynamicSimulationParameterId,
dynamicSimulationService,
dynamicSimulationService::createParameters,
dynamicSimulationService::updateParameters,
DYNAMIC_SIMULATION,
List.of(this::invalidateDynamicSimulationStatusOnAllNodes, this::invalidateDynamicSecurityAnalysisStatusOnAllNodes),
NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS,
NotificationService.UPDATE_TYPE_DYNAMIC_SECURITY_ANALYSIS_STATUS
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Invalidate dynamic margin calculation when its upstream dynamic parameters change.

handleDynamicMarginCalculationRequest(...) reads both the dynamic simulation and dynamic security analysis parameter UUIDs, but neither setter invalidates existing dynamic margin calculation results or emits its status update. After either parameter changes, stale DMC results can still appear valid in the UI.

Proposed fix
     public boolean setDynamicSimulationParameters(UUID studyUuid, String dsParameter, String userId) {
         return setComputationParameters(
                 studyUuid,
                 dsParameter,
                 userId,
                 StudyEntity::getDynamicSimulationParametersUuid,
                 StudyEntity::setDynamicSimulationParametersUuid,
                 UserProfileInfos::getDynamicSimulationParameterId,
                 dynamicSimulationService,
                 dynamicSimulationService::createParameters,
                 dynamicSimulationService::updateParameters,
                 DYNAMIC_SIMULATION,
-                List.of(this::invalidateDynamicSimulationStatusOnAllNodes, this::invalidateDynamicSecurityAnalysisStatusOnAllNodes),
+                List.of(
+                        this::invalidateDynamicSimulationStatusOnAllNodes,
+                        this::invalidateDynamicSecurityAnalysisStatusOnAllNodes,
+                        this::invalidateDynamicMarginCalculationStatusOnAllNodes
+                ),
                 NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS,
-                NotificationService.UPDATE_TYPE_DYNAMIC_SECURITY_ANALYSIS_STATUS
+                NotificationService.UPDATE_TYPE_DYNAMIC_SECURITY_ANALYSIS_STATUS,
+                NotificationService.UPDATE_TYPE_DYNAMIC_MARGIN_CALCULATION_STATUS
         );
     }
     public boolean setDynamicSecurityAnalysisParameters(UUID studyUuid, String dsaParameter, String userId) {
         return setComputationParameters(
                 studyUuid,
                 dsaParameter,
                 userId,
                 StudyEntity::getDynamicSecurityAnalysisParametersUuid,
                 StudyEntity::setDynamicSecurityAnalysisParametersUuid,
                 UserProfileInfos::getDynamicSecurityAnalysisParameterId,
                 dynamicSecurityAnalysisService,
                 dynamicSecurityAnalysisService::createParameters,
                 dynamicSecurityAnalysisService::updateParameters,
                 DYNAMIC_SECURITY_ANALYSIS,
-                List.of(this::invalidateDynamicSecurityAnalysisStatusOnAllNodes),
-                NotificationService.UPDATE_TYPE_DYNAMIC_SECURITY_ANALYSIS_STATUS
+                List.of(
+                        this::invalidateDynamicSecurityAnalysisStatusOnAllNodes,
+                        this::invalidateDynamicMarginCalculationStatusOnAllNodes
+                ),
+                NotificationService.UPDATE_TYPE_DYNAMIC_SECURITY_ANALYSIS_STATUS,
+                NotificationService.UPDATE_TYPE_DYNAMIC_MARGIN_CALCULATION_STATUS
         );
     }

Also applies to: 2959-2972

🤖 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 2831 - 2845, The call to setComputationParameters for dynamic simulation
parameters must also invalidate downstream Dynamic Margin Calculation (DMC)
results and emit its status update; modify the invocation that currently passes
List.of(this::invalidateDynamicSimulationStatusOnAllNodes,
this::invalidateDynamicSecurityAnalysisStatusOnAllNodes) and the two
notification types (NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS,
NotificationService.UPDATE_TYPE_DYNAMIC_SECURITY_ANALYSIS_STATUS) to also
include the DMC invalidation callback (e.g.,
this::invalidateDynamicMarginCalculationStatusOnAllNodes) and the DMC
notification constant (e.g.,
NotificationService.UPDATE_TYPE_DYNAMIC_MARGIN_CALCULATION_STATUS); apply the
same change to the other setComputationParameters call that handles dynamic
security analysis parameters so both parameter setters clear and notify Dynamic
Margin Calculation status via the appropriate invalidate method and notification
type.

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