Skip to content

Move Dynamic Simulation Params to Dynamic Simulation server#167

Open
thangqp wants to merge 3 commits intomainfrom
ds_move_params_to_computing_server
Open

Move Dynamic Simulation Params to Dynamic Simulation server#167
thangqp wants to merge 3 commits intomainfrom
ds_move_params_to_computing_server

Conversation

@thangqp
Copy link
Contributor

@thangqp thangqp commented Mar 18, 2026

PR Summary

  • DS Parameters is now persisted in the DS server instead of study server
  • Remove provider and mapping from run request's params

Signed-off-by: Thang PHAM <phamthang37@gmail.com>
Signed-off-by: Thang PHAM <phamthang37@gmail.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 20, 2026

📝 Walkthrough

Walkthrough

Parameters are persisted as new JPA entities and exposed via a full CRUD REST API; simulations now accept a parameters UUID plus a separate events list. Controller/service layers load parameters by UUID, serialize events into run context, and the DB schema and repositories were added/updated accordingly.

Changes

Cohort / File(s) Summary
Run API & Request Shape
src/main/java/org/gridsuite/ds/server/controller/DynamicSimulationController.java, src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java
Run endpoint signature changed to accept parametersUuid (UUID) and request body List<EventInfos>; removed mappingName/provider; events are read from/into the run context.
Parameters REST API
src/main/java/org/gridsuite/ds/server/controller/DynamicSimulationParametersController.java
Added CRUD endpoints for /v1/parameters (create, create default, duplicate, get, list, update, delete) and adjusted /values endpoint to use path /{uuid}/values.
DTO Changes
src/main/java/org/gridsuite/ds/server/dto/... (DynamicSimulationParametersInfos.java, curve/CurveInfos.java, network/NetworkInfos.java, solver DTOs, event/EventInfos.java)
Added id: UUID to several DTOs, switched solver representation from string/enum wrapper to DynawoSimulationParameters.SolverType, removed events from DynamicSimulationParametersInfos, and added/remove annotations/builders as noted. EventInfos hides several fields from JSON.
Solver API and Serialization
src/main/java/org/gridsuite/ds/server/dto/solver/...
Removed SolverTypeInfos enum; solver DTOs/interfaces now expose UUID getId() and SolverType getType(); XML solver serialization now uses getType().name().
New JPA Entities
src/main/java/org/gridsuite/ds/server/entities/parameters/... DynamicSimulationParametersEntity.java, curve/CurveEntity.java, network/NetworkParametersEntity.java, solver/...SolverParametersEntity.java
New entity model for dynamic simulation parameters with single-table inheritance for solvers, cascade relationships for solvers/network/curves, DTO<->entity sync methods, and merge-by-id semantics for child lists.
Repository Layer
src/main/java/org/gridsuite/ds/server/repository/DynamicSimulationParametersRepository.java, src/main/java/org/gridsuite/ds/server/repository/ResultRepository.java
New DynamicSimulationParametersRepository with findProviderById(UUID); ResultRepository updated to reference relocated ResultEntity.
Parameters Service
src/main/java/org/gridsuite/ds/server/service/parameters/... (ParameterUtils.java, ParametersService.java, impl/ParametersServiceImpl.java)
Refactored to create run contexts from parametersUuid + events; added CRUD service methods for parameters; ParameterUtils moved and renamed helpers; parameter value lookup now accepts parametersUuid.
Run/Result Contexts
src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java, DynamicSimulationResultContext.java
Run context now contains List<EventInfos> events; result context reads/writes events header using provided ObjectMapper.
DB Schema (Liquibase)
src/main/resources/db/changelog/... (changelog_20260318T185133Z.xml, db.changelog-master.yaml)
Added Liquibase changeset creating dynamic_simulation_parameters, network_parameters, solver_parameters, and curve tables with UUID PKs, constraints, indexes, and FKs.
Package Moves
src/main/java/org/gridsuite/ds/server/entities/... (AbstractManuallyAssignedIdentifierEntity.java, ResultEntity.java)
Moved some entity classes from org.gridsuite.ds.server.modelorg.gridsuite.ds.server.entities; updated imports/usages.
Tests & Test Utils
src/test/java/org/gridsuite/ds/server/... (DynamicSimulationParametersControllerTest.java, DynamicSimulationControllerTest.java, DynamicSimulationControllerIEEE14Test.java, DynamicSimulationParametersControllerIEEE14Test.java, ParameterTestUtils.java, others)
Added comprehensive integration tests for parameters CRUD; updated controller tests to use parametersUuid and event payloads; added ParameterTestUtils providing fixtures; adapted mocks and repository stubs.
Misc - Imports & References
various service/test files
Updated imports/references to use new DTO types, relocated entities, repository beans and adjusted method signatures across services and tests.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Controller
    participant Service
    participant Repository
    participant Database

    Client->>Controller: POST /v1/networks/{networkUuid}/run<br/>(parametersUuid, events)
    activate Controller
    Controller->>Service: createRunContext(networkUuid, variantId, receiver, reportContext, userId, parametersUuid, events, debug)
    activate Service
    Service->>Repository: findById(parametersUuid)
    activate Repository
    Repository->>Database: SELECT * FROM dynamic_simulation_parameters WHERE id=?
    Database-->>Repository: DynamicSimulationParametersEntity
    deactivate Repository
    Repository-->>Service: entity
    Service->>Service: entity.toDto() and set events on runContext
    Service-->>Controller: DynamicSimulationRunContext
    deactivate Service
    Controller->>Service: start simulation worker (uses runContext)
    Service->>Controller: result UUID
    Controller-->>Client: 200 OK (result UUID)
    deactivate Controller
Loading
sequenceDiagram
    participant Client
    participant Controller
    participant Service
    participant Repository
    participant Database

    Client->>Controller: POST /v1/parameters (DynamicSimulationParametersInfos)
    activate Controller
    Controller->>Service: createParameters(parametersInfos)
    activate Service
    Service->>Repository: save(new DynamicSimulationParametersEntity)
    activate Repository
    Repository->>Database: INSERT dynamic_simulation_parameters (+ solver/network/curve via cascade)
    Database-->>Repository: persisted entity with id
    deactivate Repository
    Repository-->>Service: persisted entity
    Service-->>Controller: UUID
    Controller-->>Client: 200 OK (UUID)
    deactivate Controller
Loading
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 2.70% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main architectural change: moving DS parameters persistence from the study server to the DS server.
Description check ✅ Passed The description is directly related to the changeset, mentioning the two key changes: parameter persistence relocation and removal of provider/mapping from requests.

✏️ 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.

Tip

You can customize the tone of the review comments and chat replies.

Configure the tone_instructions setting to customize the tone of the review comments and chat replies. For example, you can set the tone to Act like a strict teacher, Act like a pirate and more.

Copy link

@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: 4

🧹 Nitpick comments (3)
src/main/java/org/gridsuite/ds/server/dto/curve/CurveInfos.java (1)

11-11: Consider using explicit imports instead of wildcard import.

Using lombok.*; works but explicit imports (@NoArgsConstructor, @AllArgsConstructor, @Getter, @Setter, @Builder) improve readability and make dependencies clearer at a glance.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/org/gridsuite/ds/server/dto/curve/CurveInfos.java` at line 11,
Replace the wildcard lombok import in CurveInfos with explicit annotation
imports to improve readability and clarity: remove "import lombok.*;" and add
specific imports for the annotations used on the class (e.g., NoArgsConstructor,
AllArgsConstructor, Getter, Setter, Builder) so the class declaration
(CurveInfos) references those named imports instead of a wildcard.
src/main/java/org/gridsuite/ds/server/dto/DynamicSimulationParametersInfos.java (1)

24-31: Consider adding @Builder.Default for collection fields.

With @Builder on a class that has List fields (solvers, curves), these fields will be null by default when using the builder unless explicitly set. If an empty list is the preferred default, consider using @Builder.Default:

`@Builder.Default`
private List<SolverInfos> solvers = new ArrayList<>();
`@Builder.Default`
private List<CurveInfos> curves = new ArrayList<>();

This prevents potential NullPointerException when iterating over these collections if not set during construction.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/gridsuite/ds/server/dto/DynamicSimulationParametersInfos.java`
around lines 24 - 31, DynamicSimulationParametersInfos has List fields (solvers,
curves) that will be null when using Lombok `@Builder`; update those fields to use
`@Builder.Default` and initialize them to empty lists (e.g., add `@Builder.Default`
private List<SolverInfos> solvers = new ArrayList<>(); and similarly for curves)
so instances created via the builder have non-null empty collections and avoid
NullPointerException when iterating.
src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationResultContext.java (1)

77-84: Consider making the events header optional to align with defensive coding patterns.

The code using events (getEventModel() at line 113) explicitly handles empty/null cases by returning Collections.emptyList(). However, getNonNullHeader() will throw an exception if HEADER_EVENTS is missing. To match the defensive pattern used elsewhere in the codebase (e.g., getCurveModel() at line 126) and improve robustness for edge cases:

Suggested change
- String eventsJson = getNonNullHeader(headers, HEADER_EVENTS);
- List<EventInfos> events;
- try {
-     events = objectMapper.readValue(eventsJson, new TypeReference<>() { });
- } catch (JsonProcessingException e) {
-     throw new UncheckedIOException(e);
- }
+ String eventsJson = (String) headers.get(HEADER_EVENTS);
+ List<EventInfos> events = Collections.emptyList();
+ if (eventsJson != null && !eventsJson.isEmpty()) {
+     try {
+         events = objectMapper.readValue(eventsJson, new TypeReference<>() { });
+     } catch (JsonProcessingException e) {
+         throw new UncheckedIOException(e);
+     }
+ }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationResultContext.java`
around lines 77 - 84, The events header should be treated as optional: replace
the call to getNonNullHeader(headers, HEADER_EVENTS) with a nullable header
lookup (e.g., getHeader or a null-safe utility) and only call
objectMapper.readValue when the header value is non-null/non-empty; if missing
or blank, set runContext.setEvents(Collections.emptyList()) so getEventModel()
can continue to return an empty list. Keep references to HEADER_EVENTS,
objectMapper.readValue(..., new TypeReference<>() { }), and
runContext.setEvents(...) when implementing this null-safe flow.
🤖 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/ds/server/entities/parameters/DynamicSimulationParametersEntity.java`:
- Around line 103-110: The code currently assumes non-null child IDs belong to
this aggregate before calling existingEntity.update(...); modify the loop that
iterates solverInfosList to first check
solversByIdMap.containsKey(solverInfos.getId()) when solverInfos.getId() != null
and if not present throw or return a controlled 4xx/domain-specific exception
(e.g., InvalidChildReferenceException) instead of dereferencing null or silently
overwriting; apply the same membership validation pattern for the analogous
loops handling networks and curves (use their maps and corresponding Entity
classes and update(...) calls) so any unknown child UUIDs are rejected before
calling update.

In
`@src/main/java/org/gridsuite/ds/server/entities/parameters/solver/SolverParametersEntity.java`:
- Around line 143-145: The update(SolverInfos) in SolverParametersEntity casts
to AbstractSolverInfos and calls assignAttributes(AbstractSolverInfos), causing
wrong overload resolution and losing solver-specific fields; fix by removing the
cast and implementing proper per-subclass dispatch: either make
update(SolverInfos) abstract in SolverParametersEntity and implement
update(SolverInfos) in IdaSolverParametersEntity and SimSolverParametersEntity
to call assignAttributes(IdaSolverInfos) and assignAttributes(SimSolverInfos)
respectively, or override update(SolverInfos) in both subclasses so they cast to
their concrete SolverInfos type and call their specific assignAttributes
overloads (e.g., assignAttributes(IdaSolverInfos),
assignAttributes(SimSolverInfos)) to ensure subtype fields like order, initStep,
minStep, maxStep, relAccuracy, hMin, hMax, kReduceStep are updated.

In
`@src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java`:
- Around line 330-334: getParametersValues (and the other overloaded variant
near the 378-386 region) returns parameter values for a persisted parameters
record but does not guard against a null mapping created by
createDefaultParameters; this causes value generation to fail. Fix by either (A)
in getParametersValues(DynamicSimulationParametersInfos, Network) and the other
values-entrypoint check parametersInfos.getMapping() and if null throw the
existing MAPPING_NOT_PROVIDED error used in createRunContext, or (B) change
createDefaultParameters to assign a valid default mapping when persisting the
record so downstream calls to getParametersValues/doGetParameters always see a
non-null mapping. Use the existing MAPPING_NOT_PROVIDED symbol and the
doGetParameters/createDefaultParameters/getParametersValues function names to
locate the spots to change.
- Around line 139-146: Validate the selected solver and the solvers list before
attempting to serialize: in ParametersServiceImpl where you compute inputSolver
from inputParameters.getSolvers().stream() and use inputParameters.getSolver(),
first check that inputParameters.getSolvers() is non-null and non-empty and that
inputParameters.getSolver() (the selected solver id/type) is present; if any
check fails, fail fast by throwing a clear exception (e.g.,
IllegalArgumentException or a domain-specific exception) rather than continuing
to serialize or dereference nulls, so avoid proceeding to
ByteArrayOutputStream/XmlSerializableParameter.writeParameter/ParametersXml.load/dynawoSimulationParameters.setSolverType/setSolverParameters
when inputSolver is null or inputs are invalid.

---

Nitpick comments:
In `@src/main/java/org/gridsuite/ds/server/dto/curve/CurveInfos.java`:
- Line 11: Replace the wildcard lombok import in CurveInfos with explicit
annotation imports to improve readability and clarity: remove "import lombok.*;"
and add specific imports for the annotations used on the class (e.g.,
NoArgsConstructor, AllArgsConstructor, Getter, Setter, Builder) so the class
declaration (CurveInfos) references those named imports instead of a wildcard.

In
`@src/main/java/org/gridsuite/ds/server/dto/DynamicSimulationParametersInfos.java`:
- Around line 24-31: DynamicSimulationParametersInfos has List fields (solvers,
curves) that will be null when using Lombok `@Builder`; update those fields to use
`@Builder.Default` and initialize them to empty lists (e.g., add `@Builder.Default`
private List<SolverInfos> solvers = new ArrayList<>(); and similarly for curves)
so instances created via the builder have non-null empty collections and avoid
NullPointerException when iterating.

In
`@src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationResultContext.java`:
- Around line 77-84: The events header should be treated as optional: replace
the call to getNonNullHeader(headers, HEADER_EVENTS) with a nullable header
lookup (e.g., getHeader or a null-safe utility) and only call
objectMapper.readValue when the header value is non-null/non-empty; if missing
or blank, set runContext.setEvents(Collections.emptyList()) so getEventModel()
can continue to return an empty list. Keep references to HEADER_EVENTS,
objectMapper.readValue(..., new TypeReference<>() { }), and
runContext.setEvents(...) when implementing this null-safe flow.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7be6a3d3-17de-4013-819d-af6f65614370

📥 Commits

Reviewing files that changed from the base of the PR and between 074241a and 5176c3e.

📒 Files selected for processing (37)
  • src/main/java/org/gridsuite/ds/server/controller/DynamicSimulationController.java
  • src/main/java/org/gridsuite/ds/server/controller/DynamicSimulationParametersController.java
  • src/main/java/org/gridsuite/ds/server/dto/DynamicSimulationParametersInfos.java
  • src/main/java/org/gridsuite/ds/server/dto/curve/CurveInfos.java
  • src/main/java/org/gridsuite/ds/server/dto/network/NetworkInfos.java
  • src/main/java/org/gridsuite/ds/server/dto/solver/AbstractSolverInfos.java
  • src/main/java/org/gridsuite/ds/server/dto/solver/IdaSolverInfos.java
  • src/main/java/org/gridsuite/ds/server/dto/solver/SimSolverInfos.java
  • src/main/java/org/gridsuite/ds/server/dto/solver/SolverInfos.java
  • src/main/java/org/gridsuite/ds/server/dto/solver/SolverTypeInfos.java
  • src/main/java/org/gridsuite/ds/server/entities/AbstractManuallyAssignedIdentifierEntity.java
  • src/main/java/org/gridsuite/ds/server/entities/ResultEntity.java
  • src/main/java/org/gridsuite/ds/server/entities/parameters/DynamicSimulationParametersEntity.java
  • src/main/java/org/gridsuite/ds/server/entities/parameters/curve/CurveEntity.java
  • src/main/java/org/gridsuite/ds/server/entities/parameters/network/NetworkParametersEntity.java
  • src/main/java/org/gridsuite/ds/server/entities/parameters/solver/IdaSolverParametersEntity.java
  • src/main/java/org/gridsuite/ds/server/entities/parameters/solver/SimSolverParametersEntity.java
  • src/main/java/org/gridsuite/ds/server/entities/parameters/solver/SolverParametersEntity.java
  • src/main/java/org/gridsuite/ds/server/repository/DynamicSimulationParametersRepository.java
  • src/main/java/org/gridsuite/ds/server/repository/ResultRepository.java
  • src/main/java/org/gridsuite/ds/server/service/DynamicSimulationResultService.java
  • src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java
  • src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationResultContext.java
  • src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java
  • src/main/java/org/gridsuite/ds/server/service/parameters/ParameterUtils.java
  • src/main/java/org/gridsuite/ds/server/service/parameters/ParametersService.java
  • src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java
  • src/main/resources/db/changelog/changesets/changelog_20260318T185133Z.xml
  • src/main/resources/db/changelog/db.changelog-master.yaml
  • src/test/java/org/gridsuite/ds/server/controller/AbstractDynamicSimulationControllerTest.java
  • src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerIEEE14Test.java
  • src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java
  • src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationParametersControllerIEEE14Test.java
  • src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationParametersControllerTest.java
  • src/test/java/org/gridsuite/ds/server/controller/utils/ParameterTestUtils.java
  • src/test/java/org/gridsuite/ds/server/dto/XmlSerializableParameterTest.java
  • src/test/java/org/gridsuite/ds/server/service/DynamicSimulationResultServiceTest.java
💤 Files with no reviewable changes (1)
  • src/main/java/org/gridsuite/ds/server/dto/solver/SolverTypeInfos.java

Comment on lines +103 to +110
Map<UUID, SolverParametersEntity> solversByIdMap = solvers.stream().collect(Collectors.toMap(SolverParametersEntity::getId, solverEntity -> solverEntity));

// merge existing and add new solvers
List<SolverParametersEntity> mergedSolvers = new ArrayList<>();
for (SolverInfos solverInfos : solverInfosList) {
if (solverInfos.getId() != null) {
SolverParametersEntity existingEntity = solversByIdMap.get(solverInfos.getId());
existingEntity.update(solverInfos);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Reject unknown child UUIDs before updating nested entities.

Line 109, Line 129, and Line 148 assume every non-null child id already belongs to this aggregate. A stale/foreign solver, network, or curve id will either dereference null or overwrite the current network instead of returning a controlled 4xx/domain error. Please validate child membership before calling update(...), and reject unknown nested ids explicitly.

Also applies to: 128-131, 142-149

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/gridsuite/ds/server/entities/parameters/DynamicSimulationParametersEntity.java`
around lines 103 - 110, The code currently assumes non-null child IDs belong to
this aggregate before calling existingEntity.update(...); modify the loop that
iterates solverInfosList to first check
solversByIdMap.containsKey(solverInfos.getId()) when solverInfos.getId() != null
and if not present throw or return a controlled 4xx/domain-specific exception
(e.g., InvalidChildReferenceException) instead of dereferencing null or silently
overwriting; apply the same membership validation pattern for the analogous
loops handling networks and curves (use their maps and corresponding Entity
classes and update(...) calls) so any unknown child UUIDs are rejected before
calling update.

Comment on lines 139 to 146
// solver from input parameter
SolverInfos inputSolver = inputParameters.getSolvers().stream().filter(elem -> elem.getId().equals(inputParameters.getSolverId())).findFirst().orElse(null);
SolverInfos inputSolver = inputParameters.getSolvers().stream().filter(elem -> elem.getType() == inputParameters.getSolver()).findFirst().orElse(null);
if (inputSolver != null) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
XmlSerializableParameter.writeParameter(os, XmlSerializableParameter.PARAMETER_SET, inputSolver);
ParametersSet solverParameters = ParametersXml.load(new ByteArrayInputStream(os.toByteArray()), inputSolver.getId());
dynawoSimulationParameters.setSolverType(inputSolver.getType().toSolverType());
ParametersSet solverParameters = ParametersXml.load(new ByteArrayInputStream(os.toByteArray()), inputSolver.getType().name());
dynawoSimulationParameters.setSolverType(inputSolver.getType());
dynawoSimulationParameters.setSolverParameters(solverParameters);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Fail fast when the selected solver is missing.

Line 140 assumes inputParameters.getSolvers() is non-null and contains the solver referenced by inputParameters.getSolver(). With the new CRUD API, persisted rows can violate that assumption, which makes this either NPE or serializes Dynawo parameters without any solver block. Please validate solver, solvers, and the selected entry before continuing.

💡 Proposed guard
-            SolverInfos inputSolver = inputParameters.getSolvers().stream().filter(elem -> elem.getType() == inputParameters.getSolver()).findFirst().orElse(null);
-            if (inputSolver != null) {
+            List<SolverInfos> configuredSolvers = Optional.ofNullable(inputParameters.getSolvers())
+                    .orElseThrow(() -> new IllegalArgumentException("No solver definitions configured"));
+            SolverInfos inputSolver = configuredSolvers.stream()
+                    .filter(elem -> elem.getType() == inputParameters.getSolver())
+                    .findFirst()
+                    .orElseThrow(() -> new IllegalArgumentException("Selected solver is missing from solvers list"));
+            {
                 ByteArrayOutputStream os = new ByteArrayOutputStream();
                 XmlSerializableParameter.writeParameter(os, XmlSerializableParameter.PARAMETER_SET, inputSolver);
                 ParametersSet solverParameters = ParametersXml.load(new ByteArrayInputStream(os.toByteArray()), inputSolver.getType().name());
                 dynawoSimulationParameters.setSolverType(inputSolver.getType());
                 dynawoSimulationParameters.setSolverParameters(solverParameters);
             }
📝 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
// solver from input parameter
SolverInfos inputSolver = inputParameters.getSolvers().stream().filter(elem -> elem.getId().equals(inputParameters.getSolverId())).findFirst().orElse(null);
SolverInfos inputSolver = inputParameters.getSolvers().stream().filter(elem -> elem.getType() == inputParameters.getSolver()).findFirst().orElse(null);
if (inputSolver != null) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
XmlSerializableParameter.writeParameter(os, XmlSerializableParameter.PARAMETER_SET, inputSolver);
ParametersSet solverParameters = ParametersXml.load(new ByteArrayInputStream(os.toByteArray()), inputSolver.getId());
dynawoSimulationParameters.setSolverType(inputSolver.getType().toSolverType());
ParametersSet solverParameters = ParametersXml.load(new ByteArrayInputStream(os.toByteArray()), inputSolver.getType().name());
dynawoSimulationParameters.setSolverType(inputSolver.getType());
dynawoSimulationParameters.setSolverParameters(solverParameters);
// solver from input parameter
List<SolverInfos> configuredSolvers = Optional.ofNullable(inputParameters.getSolvers())
.orElseThrow(() -> new IllegalArgumentException("No solver definitions configured"));
SolverInfos inputSolver = configuredSolvers.stream()
.filter(elem -> elem.getType() == inputParameters.getSolver())
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Selected solver is missing from solvers list"));
{
ByteArrayOutputStream os = new ByteArrayOutputStream();
XmlSerializableParameter.writeParameter(os, XmlSerializableParameter.PARAMETER_SET, inputSolver);
ParametersSet solverParameters = ParametersXml.load(new ByteArrayInputStream(os.toByteArray()), inputSolver.getType().name());
dynawoSimulationParameters.setSolverType(inputSolver.getType());
dynawoSimulationParameters.setSolverParameters(solverParameters);
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java`
around lines 139 - 146, Validate the selected solver and the solvers list before
attempting to serialize: in ParametersServiceImpl where you compute inputSolver
from inputParameters.getSolvers().stream() and use inputParameters.getSolver(),
first check that inputParameters.getSolvers() is non-null and non-empty and that
inputParameters.getSolver() (the selected solver id/type) is present; if any
check fails, fail fast by throwing a clear exception (e.g.,
IllegalArgumentException or a domain-specific exception) rather than continuing
to serialize or dereference nulls, so avoid proceeding to
ByteArrayOutputStream/XmlSerializableParameter.writeParameter/ParametersXml.load/dynawoSimulationParameters.setSolverType/setSolverParameters
when inputSolver is null or inputs are invalid.

Comment on lines +330 to 334
public DynamicSimulationParametersValues getParametersValues(UUID parametersUuid, UUID networkUuid, String variantId) {
Network network = getNetwork(networkUuid, variantId);
DynamicSimulationParametersInfos parametersInfos = doGetParameters(parametersUuid);

return getParametersValues(parametersInfos, network);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

/default now produces parameter sets that /values cannot resolve.

createDefaultParameters() persists defaults without a mapping, but the new UUID-based /values path routes those records into value generation anyway. A freshly created default parameters set can therefore fail as soon as the client calls /v1/parameters/{uuid}/values, because the downstream mapping export/load path still expects a non-null mapping. Please either reject missing mappings here with the same MAPPING_NOT_PROVIDED error used in createRunContext, or assign a default mapping when creating the record.

Also applies to: 378-386

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java`
around lines 330 - 334, getParametersValues (and the other overloaded variant
near the 378-386 region) returns parameter values for a persisted parameters
record but does not guard against a null mapping created by
createDefaultParameters; this causes value generation to fail. Fix by either (A)
in getParametersValues(DynamicSimulationParametersInfos, Network) and the other
values-entrypoint check parametersInfos.getMapping() and if null throw the
existing MAPPING_NOT_PROVIDED error used in createRunContext, or (B) change
createDefaultParameters to assign a valid default mapping when persisting the
record so downstream calls to getParametersValues/doGetParameters always see a
non-null mapping. Use the existing MAPPING_NOT_PROVIDED symbol and the
doGetParameters/createDefaultParameters/getParametersValues function names to
locate the spots to change.

Signed-off-by: Thang PHAM <phamthang37@gmail.com>
@sonarqubecloud
Copy link

Copy link

@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: 6

🤖 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/ds/server/dto/event/EventInfos.java`:
- Around line 30-32: The EventInfos class currently marks the UUID field
`private UUID id` with both `@JsonProperty`("uuid") and `@JsonIgnore` which cancels
serialization/deserialization; update the annotations on `id` in EventInfos to
allow round-tripping (either remove `@JsonIgnore` or replace the annotation with
`@JsonProperty`(value = "uuid", access = JsonProperty.Access.READ_WRITE)) so
DynamicSimulationResultContext can serialize and deserialize the `uuid` field
correctly.

In
`@src/main/java/org/gridsuite/ds/server/entities/parameters/solver/IdaSolverParametersEntity.java`:
- Around line 61-63: The update(SolverInfos) method currently performs an
unchecked cast to IdaSolverInfos via assignAttributes((IdaSolverInfos)
solverInfos); guard this by checking the runtime type of solverInfos (e.g., if
(!(solverInfos instanceof IdaSolverInfos)) ) and throw a clear, controlled
validation exception (IllegalArgumentException or your domain
ValidationException) with a descriptive message; otherwise cast safely
(IdaSolverInfos ida = (IdaSolverInfos) solverInfos) and call
assignAttributes(ida). Ensure the exception type and message align with existing
validation/error handling in the service so callers receive a proper 4xx
response rather than a 500.

In
`@src/main/java/org/gridsuite/ds/server/entities/parameters/solver/SolverParametersEntity.java`:
- Around line 175-181: Add a null guard at the start of
SolverParametersEntity.fromDto(SolverInfos) to fail fast when solverInfos is
null: check if solverInfos == null and throw an IllegalArgumentException with a
clear message (e.g. "solverInfos must not be null") before the existing
instanceof branches (so the method either handles IdaSolverInfos/SimSolverInfos
or immediately rejects null).
- Around line 113-118: The assignAttributes method currently sets the entity's
type from the incoming DTO (type = solverInfos.getType()), but for a
discriminator-backed hierarchy the type must come from the concrete entity
class; change assignAttributes in SolverParametersEntity to stop copying
solverInfos.getType() and instead assign type from a protected/abstract
getSolverType() called on this instance (e.g., type = getSolverType()), then
implement getSolverType() in each concrete subclass (IdaSolverParametersEntity,
SimSolverParametersEntity) to return their correct SolverType; ensure no other
code paths overwrite type from the DTO.

In
`@src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationResultContext.java`:
- Around line 77-85: The code calls headers.get(HEADER_EVENTS) into eventsJson
and immediately does eventsJson.toString(), which will NPE if the header is
missing; update the block in DynamicSimulationResultContext to first check if
headers.get(HEADER_EVENTS) (HEADER_EVENTS / eventsJson) is null and in that case
set events to Collections.emptyList() (or call a getNonNullHeader helper) before
calling objectMapper.readValue; otherwise parse using
objectMapper.readValue(eventsJson.toString(), new TypeReference<>() { }) and
keep the existing JsonProcessingException -> UncheckedIOException handling, then
call runContext.setEvents(events).
- Around line 91-99: The getSpecificMsgHeaders method currently serializes
getRunContext().getEvents() directly which can be null; change it to normalize
null to an empty list before serialization (e.g., assign a local events variable
= getRunContext().getEvents() != null ? getRunContext().getEvents() :
Collections.emptyList()) and then call objectMapper.writeValueAsString on that
normalized list so HEADER_EVENTS always contains "[]" instead of null after
deserialization; update references in getSpecificMsgHeaders accordingly (method:
getSpecificMsgHeaders, call site: getRunContext().getEvents(), header key:
HEADER_EVENTS).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 64cb943c-6d7e-49a9-9999-b9874ec3a23c

📥 Commits

Reviewing files that changed from the base of the PR and between 5176c3e and c362a1e.

📒 Files selected for processing (5)
  • src/main/java/org/gridsuite/ds/server/dto/event/EventInfos.java
  • src/main/java/org/gridsuite/ds/server/entities/parameters/solver/IdaSolverParametersEntity.java
  • src/main/java/org/gridsuite/ds/server/entities/parameters/solver/SimSolverParametersEntity.java
  • src/main/java/org/gridsuite/ds/server/entities/parameters/solver/SolverParametersEntity.java
  • src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationResultContext.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/org/gridsuite/ds/server/entities/parameters/solver/SimSolverParametersEntity.java

Comment on lines 30 to 32
@JsonProperty("uuid")
@JsonIgnore
private UUID id;
Copy link

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:

# Locate the files mentioned in the review
find . -type f -name "EventInfos.java" | head -5
find . -type f -name "DynamicSimulationResultContext.java" | head -5

Repository: gridsuite/dynamic-simulation-server

Length of output: 237


🏁 Script executed:

# Check repository structure
git ls-files | grep -E "(EventInfos|DynamicSimulationResultContext)" | head -20

Repository: gridsuite/dynamic-simulation-server

Length of output: 233


🏁 Script executed:

# Read EventInfos.java to verify the annotation state
cat -n ./src/main/java/org/gridsuite/ds/server/dto/event/EventInfos.java | head -50

Repository: gridsuite/dynamic-simulation-server

Length of output: 1467


🏁 Script executed:

# Read DynamicSimulationResultContext.java around lines 81 and 94
cat -n ./src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationResultContext.java | sed -n '70,105p'

Repository: gridsuite/dynamic-simulation-server

Length of output: 1530


🏁 Script executed:

# Check for ObjectMapper configuration or custom setup
rg -A 5 -B 5 "objectMapper" ./src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationResultContext.java | head -40

Repository: gridsuite/dynamic-simulation-server

Length of output: 1712


🏁 Script executed:

# Search for any custom Jackson configuration in the codebase
find ./src -type f -name "*.java" | xargs grep -l "JsonIgnore\|JsonProperty" | head -10

Repository: gridsuite/dynamic-simulation-server

Length of output: 596


🏁 Script executed:

# Search for ObjectMapper bean configuration or Jackson setup
find ./src -type f -name "*.java" | xargs grep -l "ObjectMapper" | xargs grep -l "Bean\|Configuration\|@Configuration" | head -10

Repository: gridsuite/dynamic-simulation-server

Length of output: 963


🏁 Script executed:

# Look for Jackson configuration or feature disabling
rg "ObjectMapper|Jackson|@Bean" ./src --type java -B 2 -A 5 | grep -A 7 -B 2 "ObjectMapper" | head -50

Repository: gridsuite/dynamic-simulation-server

Length of output: 5462


🏁 Script executed:

# Check if there's Jackson configuration in the main config
cat -n ./src/main/java/org/gridsuite/ds/server/config/RestTemplateConfig.java | head -100

Repository: gridsuite/dynamic-simulation-server

Length of output: 3510


🏁 Script executed:

# Verify Jackson annotation behavior is standard - check if there are any custom configurations
rg "setSerializationInclusion|disable|enable|JsonProperty|JsonIgnore" ./src/main/java --type java -B 2 -A 2 | head -60

Repository: gridsuite/dynamic-simulation-server

Length of output: 6052


@JsonIgnore suppresses both serialization and deserialization, completely neutralizing @JsonProperty("uuid").

At lines 30-31, the conflicting annotations cause the uuid field to be dropped during the serialization/deserialization cycle in DynamicSimulationResultContext (lines 81 and 94), preventing round-tripping of event data.

Remove @JsonIgnore if the uuid field should be serialized, or use @JsonProperty(value = "uuid", access = JsonProperty.Access.READ_WRITE) to be explicit about allowing both directions.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/org/gridsuite/ds/server/dto/event/EventInfos.java` around lines
30 - 32, The EventInfos class currently marks the UUID field `private UUID id`
with both `@JsonProperty`("uuid") and `@JsonIgnore` which cancels
serialization/deserialization; update the annotations on `id` in EventInfos to
allow round-tripping (either remove `@JsonIgnore` or replace the annotation with
`@JsonProperty`(value = "uuid", access = JsonProperty.Access.READ_WRITE)) so
DynamicSimulationResultContext can serialize and deserialize the `uuid` field
correctly.

Comment on lines +61 to +63
public void update(SolverInfos solverInfos) {
assignAttributes((IdaSolverInfos) solverInfos);
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Guard update() against wrong subtype to avoid runtime ClassCastException.

Line 62 performs an unchecked cast. If a mismatched SolverInfos reaches this entity, this will fail with a 500 instead of a controlled validation error.

Proposed fix
 `@Override`
 public void update(SolverInfos solverInfos) {
-    assignAttributes((IdaSolverInfos) solverInfos);
+    if (!(solverInfos instanceof IdaSolverInfos idaSolverInfos)) {
+        throw new IllegalArgumentException(
+            "Expected IdaSolverInfos but got " +
+            (solverInfos == null ? "null" : solverInfos.getClass().getSimpleName())
+        );
+    }
+    assignAttributes(idaSolverInfos);
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/gridsuite/ds/server/entities/parameters/solver/IdaSolverParametersEntity.java`
around lines 61 - 63, The update(SolverInfos) method currently performs an
unchecked cast to IdaSolverInfos via assignAttributes((IdaSolverInfos)
solverInfos); guard this by checking the runtime type of solverInfos (e.g., if
(!(solverInfos instanceof IdaSolverInfos)) ) and throw a clear, controlled
validation exception (IllegalArgumentException or your domain
ValidationException) with a descriptive message; otherwise cast safely
(IdaSolverInfos ida = (IdaSolverInfos) solverInfos) and call
assignAttributes(ida). Ensure the exception type and message align with existing
validation/error handling in the service so callers receive a proper 4xx
response rather than a 500.

Comment on lines +113 to +118
protected void assignAttributes(AbstractSolverInfos solverInfos) {
if (id == null) {
id = UUID.randomUUID();
}
type = solverInfos.getType();
fNormTolAlg = solverInfos.getFNormTolAlg();
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Do not source entity type from client DTO in base assignment.

Line 117 copies type from input. For a discriminator-backed hierarchy, this should be derived from the concrete entity subtype, not request payload, otherwise in-memory DTO round-trips can report inconsistent solver types.

Suggested direction
 protected void assignAttributes(AbstractSolverInfos solverInfos) {
     if (id == null) {
         id = UUID.randomUUID();
     }
-    type = solverInfos.getType();
+    type = getSolverType();
     fNormTolAlg = solverInfos.getFNormTolAlg();
     ...
 }
+
+protected abstract SolverType getSolverType();

Then implement getSolverType() in each subtype (IdaSolverParametersEntity, SimSolverParametersEntity).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/gridsuite/ds/server/entities/parameters/solver/SolverParametersEntity.java`
around lines 113 - 118, The assignAttributes method currently sets the entity's
type from the incoming DTO (type = solverInfos.getType()), but for a
discriminator-backed hierarchy the type must come from the concrete entity
class; change assignAttributes in SolverParametersEntity to stop copying
solverInfos.getType() and instead assign type from a protected/abstract
getSolverType() called on this instance (e.g., type = getSolverType()), then
implement getSolverType() in each concrete subclass (IdaSolverParametersEntity,
SimSolverParametersEntity) to return their correct SolverType; ensure no other
code paths overwrite type from the DTO.

Comment on lines +175 to +181
public static SolverParametersEntity fromDto(SolverInfos solverInfos) {
if (solverInfos instanceof IdaSolverInfos idaInfos) {
return new IdaSolverParametersEntity(idaInfos);
} else if (solverInfos instanceof SimSolverInfos simInfos) {
return new SimSolverParametersEntity(simInfos);
}
throw new IllegalArgumentException("Unknown solver type: " + solverInfos.getType());
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Add an explicit null guard in fromDto(...).

A null input currently triggers a less clear NPE path. Fail fast with a clear IllegalArgumentException.

Proposed fix
 public static SolverParametersEntity fromDto(SolverInfos solverInfos) {
+    if (solverInfos == null) {
+        throw new IllegalArgumentException("solverInfos must not be null");
+    }
     if (solverInfos instanceof IdaSolverInfos idaInfos) {
         return new IdaSolverParametersEntity(idaInfos);
     } else if (solverInfos instanceof SimSolverInfos simInfos) {
         return new SimSolverParametersEntity(simInfos);
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/gridsuite/ds/server/entities/parameters/solver/SolverParametersEntity.java`
around lines 175 - 181, Add a null guard at the start of
SolverParametersEntity.fromDto(SolverInfos) to fail fast when solverInfos is
null: check if solverInfos == null and throw an IllegalArgumentException with a
clear message (e.g. "solverInfos must not be null") before the existing
instanceof branches (so the method either handles IdaSolverInfos/SimSolverInfos
or immediately rejects null).

Comment on lines +77 to +85
// using Object then toString() to avoid casting exception since rabbitmq uses LongString instead of String
Object eventsJson = headers.get(HEADER_EVENTS);
List<EventInfos> events;
try {
events = objectMapper.readValue(eventsJson.toString(), new TypeReference<>() { });
} catch (JsonProcessingException e) {
throw new UncheckedIOException(e);
}
runContext.setEvents(events);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Guard against missing events header to avoid runtime NPE.

At Line 81, eventsJson.toString() will throw if Line 78 returns null (missing header / backward-compat message). Handle absent header explicitly and default to an empty list (or fail fast with getNonNullHeader).

Proposed null-safe parsing
         // using Object then toString() to avoid casting exception since rabbitmq uses LongString instead of String
         Object eventsJson = headers.get(HEADER_EVENTS);
-        List<EventInfos> events;
-        try {
-            events = objectMapper.readValue(eventsJson.toString(), new TypeReference<>() { });
-        } catch (JsonProcessingException e) {
-            throw new UncheckedIOException(e);
-        }
+        List<EventInfos> events = List.of();
+        if (eventsJson != null) {
+            try {
+                events = objectMapper.readValue(eventsJson.toString(), new TypeReference<>() { });
+                if (events == null) {
+                    events = List.of();
+                }
+            } catch (JsonProcessingException e) {
+                throw new UncheckedIOException(e);
+            }
+        }
         runContext.setEvents(events);
📝 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
// using Object then toString() to avoid casting exception since rabbitmq uses LongString instead of String
Object eventsJson = headers.get(HEADER_EVENTS);
List<EventInfos> events;
try {
events = objectMapper.readValue(eventsJson.toString(), new TypeReference<>() { });
} catch (JsonProcessingException e) {
throw new UncheckedIOException(e);
}
runContext.setEvents(events);
// using Object then toString() to avoid casting exception since rabbitmq uses LongString instead of String
Object eventsJson = headers.get(HEADER_EVENTS);
List<EventInfos> events = List.of();
if (eventsJson != null) {
try {
events = objectMapper.readValue(eventsJson.toString(), new TypeReference<>() { });
if (events == null) {
events = List.of();
}
} catch (JsonProcessingException e) {
throw new UncheckedIOException(e);
}
}
runContext.setEvents(events);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationResultContext.java`
around lines 77 - 85, The code calls headers.get(HEADER_EVENTS) into eventsJson
and immediately does eventsJson.toString(), which will NPE if the header is
missing; update the block in DynamicSimulationResultContext to first check if
headers.get(HEADER_EVENTS) (HEADER_EVENTS / eventsJson) is null and in that case
set events to Collections.emptyList() (or call a getNonNullHeader helper) before
calling objectMapper.readValue; otherwise parse using
objectMapper.readValue(eventsJson.toString(), new TypeReference<>() { }) and
keep the existing JsonProcessingException -> UncheckedIOException handling, then
call runContext.setEvents(events).

Comment on lines +91 to +99
public Map<String, String> getSpecificMsgHeaders(ObjectMapper objectMapper) {
String eventsJson;
try {
eventsJson = objectMapper.writeValueAsString(getRunContext().getEvents());
} catch (JsonProcessingException e) {
throw new UncheckedIOException(e);
}
return Map.of(HEADER_MAPPING, getRunContext().getMapping(),
HEADER_EVENTS, eventsJson);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Normalize null events before serializing headers.

At Line 94, serializing a null events list propagates a non-list payload and weakens invariants downstream. Serialize [] instead to keep runContext.getEvents() consistently non-null after deserialization.

Proposed normalization
     public Map<String, String> getSpecificMsgHeaders(ObjectMapper objectMapper) {
         String eventsJson;
         try {
-            eventsJson = objectMapper.writeValueAsString(getRunContext().getEvents());
+            eventsJson = objectMapper.writeValueAsString(
+                    Objects.requireNonNullElseGet(getRunContext().getEvents(), List::of)
+            );
         } catch (JsonProcessingException e) {
             throw new UncheckedIOException(e);
         }
         return Map.of(HEADER_MAPPING, getRunContext().getMapping(),
                 HEADER_EVENTS, eventsJson);
📝 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
public Map<String, String> getSpecificMsgHeaders(ObjectMapper objectMapper) {
String eventsJson;
try {
eventsJson = objectMapper.writeValueAsString(getRunContext().getEvents());
} catch (JsonProcessingException e) {
throw new UncheckedIOException(e);
}
return Map.of(HEADER_MAPPING, getRunContext().getMapping(),
HEADER_EVENTS, eventsJson);
public Map<String, String> getSpecificMsgHeaders(ObjectMapper objectMapper) {
String eventsJson;
try {
eventsJson = objectMapper.writeValueAsString(
Objects.requireNonNullElseGet(getRunContext().getEvents(), List::of)
);
} catch (JsonProcessingException e) {
throw new UncheckedIOException(e);
}
return Map.of(HEADER_MAPPING, getRunContext().getMapping(),
HEADER_EVENTS, eventsJson);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationResultContext.java`
around lines 91 - 99, The getSpecificMsgHeaders method currently serializes
getRunContext().getEvents() directly which can be null; change it to normalize
null to an empty list before serialization (e.g., assign a local events variable
= getRunContext().getEvents() != null ? getRunContext().getEvents() :
Collections.emptyList()) and then call objectMapper.writeValueAsString on that
normalized list so HEADER_EVENTS always contains "[]" instead of null after
deserialization; update references in getSpecificMsgHeaders accordingly (method:
getSpecificMsgHeaders, call site: getRunContext().getEvents(), header key:
HEADER_EVENTS).

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