Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
<antlr4.version>4.10.1</antlr4.version>
<sonar.organization>gridsuite</sonar.organization>
<sonar.projectKey>org.gridsuite:loadflow-server</sonar.projectKey>
<!-- FIXME: to be removed at next powsybl-ws-dependencies upgrade -->
<gridsuite-computation.version>2.3.0-SNAPSHOT</gridsuite-computation.version>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't forget to delete it

</properties>

<build>
Expand Down Expand Up @@ -126,6 +128,7 @@
<dependency>
<groupId>org.gridsuite</groupId>
<artifactId>gridsuite-computation</artifactId>
<version>${gridsuite-computation.version}</version>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ public ResponseEntity<LoadFlowStatus> getStatus(@Parameter(description = "Result
return ResponseEntity.ok().body(loadFlowService.getStatus(resultUuid));
}

@PostMapping(value = "/results/statuses", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
@Operation(summary = "Get loadflow statuses from the database")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The loadflow statuses")})
public ResponseEntity<Map<UUID, LoadFlowStatus>> getStatuses(@Parameter(description = "Result uuids") @RequestBody List<UUID> resultUuids) {
return ResponseEntity.ok().body(loadFlowService.getStatuses(resultUuids));
}

@PutMapping(value = "/results/invalidate-status", produces = APPLICATION_JSON_VALUE)
@Operation(summary = "Invalidate the loadflow status from the database")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The loadflow status has been invalidated")})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.UUID;

/**
Expand All @@ -19,6 +20,8 @@
public interface GlobalStatusRepository extends JpaRepository<GlobalStatusEntity, UUID> {
GlobalStatusEntity findByResultUuid(UUID resultUuid);

List<GlobalStatusEntity> findByResultUuidIn(List<UUID> resultUuids);

void deleteByResultUuid(UUID resultUuid);

}
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ public LoadFlowStatus findStatus(UUID resultUuid) {
return globalEntity != null ? globalEntity.getStatus() : null;
}

@Override
@Transactional(readOnly = true)
public Map<UUID, LoadFlowStatus> findStatuses(List<UUID> resultUuids) {
Objects.requireNonNull(resultUuids);
List<GlobalStatusEntity> globalEntities = globalStatusRepository.findByResultUuidIn(resultUuids);
return globalEntities.stream().collect(Collectors.toMap(GlobalStatusEntity::getResultUuid, GlobalStatusEntity::getStatus));
}
Comment on lines +236 to 240

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check GlobalStatusEntity field annotations for nullability constraints
rg -n -A2 'status' --type=java src/main/java/org/gridsuite/loadflow/server/entities/GlobalStatusEntity.java

Repository: gridsuite/loadflow-server

Length of output: 210


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== LoadFlowResultService excerpt =="
sed -n '220,245p' src/main/java/org/gridsuite/loadflow/server/service/LoadFlowResultService.java | cat -n

echo
echo "== GlobalStatusEntity file =="
sed -n '1,120p' src/main/java/org/gridsuite/loadflow/server/entities/GlobalStatusEntity.java | cat -n

echo
echo "== Search for status nullability / schema constraints =="
rg -n --hidden --glob '!target/**' --glob '!build/**' --glob '!dist/**' \
  '`@Column`\\(|nullable\\s*=\\s*false|status.*not null|not null.*status|GlobalStatusEntity' \
  src main resources .

Repository: gridsuite/loadflow-server

Length of output: 2975


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Search for globalStatus schema/migrations =="
rg -n --hidden --glob '!target/**' --glob '!build/**' --glob '!dist/**' \
  'globalStatus|global_status|status' \
  src/main/resources src/main/java

echo
echo "== Search for migration files =="
fd -a -t f '.*(sql|xml|yml|yaml)$' src/main/resources db . | sed -n '1,200p'

Repository: gridsuite/loadflow-server

Length of output: 11245


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '1,40p' src/main/resources/db/changelog/changesets/changelog_20230606T161304Z.xml | cat -n

Repository: gridsuite/loadflow-server

Length of output: 3073


Handle nullable status in findStatuses

global_status.status is nullable in both the entity and the Liquibase DDL, so Collectors.toMap(...) can throw if any row has a null status. findStatus() already returns null in that case; make findStatuses() use a null-tolerant collector or filter nulls first.

🤖 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/loadflow/server/service/LoadFlowResultService.java`
around lines 236 - 240, `LoadFlowResultService.findStatuses` currently uses
`Collectors.toMap` on `GlobalStatusEntity::getStatus`, which can fail when a row
has a null status. Update this method to match `findStatus()` behavior by making
the collection null-tolerant, either by filtering out null statuses before
collecting or by mapping them safely so `null` values do not break the result
map.


public List<ComponentResultEntity> findComponentResults(UUID resultUuid, List<ResourceFilterDTO> resourceFilters, Sort sort) {
Objects.requireNonNull(resultUuid);
Specification<ComponentResultEntity> specification = componentResultSpecificationBuilder.buildSpecification(resultUuid, resourceFilters);
Expand Down
Loading