Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.gridsuite.study.server.dto.dynamicmapping.ModelInfos;
import org.gridsuite.study.server.dto.dynamicmargincalculation.DynamicMarginCalculationStatus;
import org.gridsuite.study.server.dto.dynamicsecurityanalysis.DynamicSecurityAnalysisStatus;
import org.gridsuite.study.server.dto.dynamicsimulation.DynamicSimulationParametersInfos;
import org.gridsuite.study.server.dto.dynamicsimulation.DynamicSimulationStatus;
import org.gridsuite.study.server.dto.dynamicsimulation.event.EventInfos;
import org.gridsuite.study.server.dto.elasticsearch.EquipmentInfos;
Expand Down Expand Up @@ -1836,8 +1835,10 @@
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "All models of dynamic simulation"),
@ApiResponse(responseCode = "204", description = "No dynamic simulation models"),
@ApiResponse(responseCode = "404", description = "The dynamic simulation models has not been found")})
public ResponseEntity<List<ModelInfos>> getDynamicSimulationModels(@Parameter(description = "study UUID") @PathVariable("studyUuid") UUID studyUuid) {
List<ModelInfos> models = studyService.getDynamicSimulationModels(studyUuid);
public ResponseEntity<List<ModelInfos>> getDynamicSimulationModels(
@Parameter(description = "study UUID") @PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "mapping") @RequestParam(name = "mapping", required = false) String mapping) {
List<ModelInfos> models = studyService.getDynamicSimulationModels(studyUuid, mapping);
return models != null ? ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(models) :
ResponseEntity.noContent().build();
}
Expand All @@ -1847,7 +1848,7 @@
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The dynamic simulation parameters are set")})
public ResponseEntity<Void> setDynamicSimulationParameters(
@PathVariable("studyUuid") UUID studyUuid,
@RequestBody(required = false) DynamicSimulationParametersInfos dsParameter,
@RequestBody(required = false) String dsParameter,
Comment thread
khouadrired marked this conversation as resolved.
@RequestHeader(HEADER_USER_ID) String userId) {
studyService.setDynamicSimulationParameters(studyUuid, dsParameter, userId);
return ResponseEntity.ok().build();
Comment on lines 1849 to 1854
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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Dynamic simulation parameter setter declarations/usages:"
rg -n -C2 '\bsetDynamicSimulationParameters\s*\(' --type java

echo
echo "Existing controller branches that map service results to HTTP 200/204:"
rg -n -C2 'ResponseEntity\.noContent\(\)\.build\(\)' src/main/java/org/gridsuite/study/server/controller/StudyController.java

Repository: gridsuite/study-server

Length of output: 15539


Fix inconsistent response codes for setDynamicSimulationParameters.

The service method returns a boolean, but this controller endpoint ignores it and always returns HTTP 200. All other parameter setters in this controller follow the pattern: return 204 No Content when the boolean is true, and 200 OK when false. Update this method to match that convention.

Affected pattern in other setters
// Line 980 (setVoltageInitParameters)
return studyService.setVoltageInitParameters(studyUuid, voltageInitParameters, userId) ? ResponseEntity.noContent().build() : ResponseEntity.ok().build();

// Line 1128 (setLoadFlowParameters)
return studyService.setLoadFlowParameters(studyUuid, lfParameter, userId) ? ResponseEntity.noContent().build() : ResponseEntity.ok().build();

// Line 2009-2011 (setDynamicSecurityAnalysisParameters)
return studyService.setDynamicSecurityAnalysisParameters(studyUuid, dsaParameter, userId) ?
        ResponseEntity.noContent().build() :
        ResponseEntity.ok().build();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/org/gridsuite/study/server/controller/StudyController.java`
around lines 1849 - 1854, The controller currently ignores the boolean result
from studyService.setDynamicSimulationParameters and always returns 200; update
StudyController.setDynamicSimulationParameters to use the returned boolean and
follow the pattern used by other setters (e.g., setVoltageInitParameters,
setLoadFlowParameters, setDynamicSecurityAnalysisParameters) so that when
studyService.setDynamicSimulationParameters(studyUuid, dsParameter, userId)
returns true the endpoint returns ResponseEntity.noContent().build() and when
false returns ResponseEntity.ok().build().

Comment thread
khouadrired marked this conversation as resolved.
Expand All @@ -1856,7 +1857,7 @@
@GetMapping(value = "/studies/{studyUuid}/dynamic-simulation/parameters")
@Operation(summary = "Get dynamic simulation parameters on study")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The dynamic simulation parameters")})
public ResponseEntity<DynamicSimulationParametersInfos> getDynamicSimulationParameters(
public ResponseEntity<String> getDynamicSimulationParameters(
Comment thread
khouadrired marked this conversation as resolved.
@PathVariable("studyUuid") UUID studyUuid) {
return ResponseEntity.ok().body(studyService.getDynamicSimulationParameters(studyUuid));
Comment on lines 1857 to 1862
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

Keep the parameter GET response explicitly JSON.

Once this endpoint returns a raw String instead of a DTO, the JSON response contract is no longer explicit. That can change how clients and generated API docs interpret the same payload.

💡 Suggested fix
-    `@GetMapping`(value = "/studies/{studyUuid}/dynamic-simulation/parameters")
+    `@GetMapping`(value = "/studies/{studyUuid}/dynamic-simulation/parameters", produces = MediaType.APPLICATION_JSON_VALUE)
     `@Operation`(summary = "Get dynamic simulation parameters on study")
     `@ApiResponses`(value = {`@ApiResponse`(responseCode = "200", description = "The dynamic simulation parameters")})
     public ResponseEntity<String> getDynamicSimulationParameters(
             `@PathVariable`("studyUuid") UUID studyUuid) {
-        return ResponseEntity.ok().body(studyService.getDynamicSimulationParameters(studyUuid));
+        return ResponseEntity.ok()
+                .contentType(MediaType.APPLICATION_JSON)
+                .body(studyService.getDynamicSimulationParameters(studyUuid));
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/org/gridsuite/study/server/controller/StudyController.java`
around lines 1857 - 1862, The GET endpoint returns a raw String which makes the
response contract ambiguous; update the mapping to explicitly declare JSON by
adding produces = MediaType.APPLICATION_JSON_VALUE to the `@GetMapping` on
getDynamicSimulationParameters and import org.springframework.http.MediaType,
ensuring the response Content-Type is application/json while still returning
studyService.getDynamicSimulationParameters(studyUuid) from the
getDynamicSimulationParameters method.

}
Expand Down Expand Up @@ -1934,11 +1935,10 @@
@Parameter(description = "rootNetworkUuid") @PathVariable("rootNetworkUuid") UUID rootNetworkUuid,
@Parameter(description = "nodeUuid") @PathVariable("nodeUuid") UUID nodeUuid,
@Parameter(description = "debug") @RequestParam(name = "debug", required = false, defaultValue = "false") boolean debug,
@RequestBody(required = false) DynamicSimulationParametersInfos parameters,
@RequestHeader(HEADER_USER_ID) String userId) {
studyService.assertIsNodeNotReadOnly(nodeUuid);
studyService.assertCanRunOnConstructionNode(studyUuid, nodeUuid, List.of(DYNAWO_PROVIDER), studyService::getDynamicSimulationProvider);
studyService.runDynamicSimulation(studyUuid, nodeUuid, rootNetworkUuid, parameters, userId, debug);
studyService.runDynamicSimulation(studyUuid, nodeUuid, rootNetworkUuid, userId, debug);
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).build();
}

Expand Down Expand Up @@ -2079,7 +2079,7 @@
@Parameter(description = "root network id") @PathVariable("rootNetworkUuid") UUID rootNetworkUuid,
@Parameter(description = "nodeUuid") @PathVariable("nodeUuid") UUID nodeUuid,
@Parameter(description = "debug") @RequestParam(name = "debug", required = false, defaultValue = "false") boolean debug,
@RequestHeader(HEADER_USER_ID) String userId) throws JsonProcessingException {

Check warning on line 2082 in src/main/java/org/gridsuite/study/server/controller/StudyController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the declaration of thrown exception 'com.fasterxml.jackson.core.JsonProcessingException', as it cannot be thrown from method's body.

See more on https://sonarcloud.io/project/issues?id=org.gridsuite%3Astudy-server&issues=AZ0MdK1BZVYF3I7QP0FA&open=AZ0MdK1BZVYF3I7QP0FA&pullRequest=969
studyService.assertIsNodeNotReadOnly(nodeUuid);
studyService.assertCanRunOnConstructionNode(studyUuid, nodeUuid, List.of(DYNAWO_PROVIDER), studyService::getDynamicMarginCalculationProvider);
studyService.runDynamicMarginCalculation(studyUuid, nodeUuid, rootNetworkUuid, userId, debug);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class UserProfileInfos {

private UUID pccMinParameterId;

// note: this parameter is not managed by user-admin-server yet
private UUID dynamicSimulationParameterId;

// note: this parameter is not managed by user-admin-server yet
private UUID dynamicSecurityAnalysisParameterId;

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading