Skip to content
Open
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
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
<mockwebserver3.version>5.0.0-alpha.14</mockwebserver3.version>
<sonar.organization>gridsuite</sonar.organization>
<sonar.projectKey>org.gridsuite:security-analysis-server</sonar.projectKey>
<!-- FIXME: to be removed at next powsybl-ws-dependencies upgrade -->
<gridsuite-computation.version>2.3.0-SNAPSHOT</gridsuite-computation.version>
</properties>

<build>
Expand Down Expand Up @@ -175,6 +177,7 @@
<dependency>
<groupId>org.gridsuite</groupId>
<artifactId>gridsuite-computation</artifactId>
<version>${gridsuite-computation.version}</version>
</dependency>

<!-- Runtime dependencies -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.springframework.web.bind.annotation.*;

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

import static org.gridsuite.computation.service.NotificationService.HEADER_USER_ID;
Expand Down Expand Up @@ -270,6 +271,13 @@ public ResponseEntity<SecurityAnalysisStatus> getStatus(@Parameter(description =
return ResponseEntity.ok().body(result);
}

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

@PutMapping(value = "/results/invalidate-status", produces = APPLICATION_JSON_VALUE)
@Operation(summary = "Invalidate the security analysis status from the database")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The security analysis status has been invalidated")})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.stream.Collectors;

import static org.gridsuite.computation.error.ComputationBusinessErrorCode.INVALID_SORT_FORMAT;
import static org.gridsuite.computation.error.ComputationBusinessErrorCode.RESULT_NOT_FOUND;
Expand Down Expand Up @@ -299,6 +300,14 @@ public SecurityAnalysisStatus findStatus(UUID resultUuid) {
return securityAnalysisResult.get().getStatus();
}

@Override
@Transactional(readOnly = true)
public Map<UUID, SecurityAnalysisStatus> findStatuses(List<UUID> resultUuids) {
Objects.requireNonNull(resultUuids);
List<SecurityAnalysisResultEntity> saResultEntities = securityAnalysisResultRepository.findAllById(resultUuids);
return saResultEntities.stream().collect(Collectors.toMap(SecurityAnalysisResultEntity::getId, SecurityAnalysisResultEntity::getStatus));
}

private static Page<?> emptyPage(Pageable pageable) {
return new PageImpl<>(List.of(), pageable, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,40 @@ void testStatus() throws Exception {
assertEquals(SecurityAnalysisStatus.NOT_DONE, securityAnalysisStatus);
}

@Test
void testStatuses() throws Exception {
MvcResult mvcResult;
String resultAsString;

mvcResult = mockMvc.perform(post("/" + VERSION + "/networks/" + NETWORK_UUID + "/run-and-save?reportType=SecurityAnalysis&loadFlowParametersUuid=" + UUID.randomUUID())
.header(HEADER_USER_ID, USER_ID)
.contentType(MediaType.APPLICATION_JSON))
.andExpectAll(
status().isOk(),
content().contentType(MediaType.APPLICATION_JSON)
).andReturn();

resultAsString = mvcResult.getResponse().getContentAsString();
UUID resultUuid = mapper.readValue(resultAsString, UUID.class);
assertEquals(RESULT_UUID, resultUuid);

output.receive(TIMEOUT, "sa.result");

UUID unknownResultUuid = UUID.randomUUID();
mvcResult = mockMvc.perform(post("/" + VERSION + "/results/statuses")
.contentType(MediaType.APPLICATION_JSON)
.content(mapper.writeValueAsString(List.of(resultUuid, unknownResultUuid))))
.andExpectAll(
status().isOk(),
content().contentType(MediaType.APPLICATION_JSON)
).andReturn();

Map<UUID, SecurityAnalysisStatus> statuses = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { });
assertEquals(1, statuses.size());
assertEquals(SecurityAnalysisStatus.CONVERGED, statuses.get(resultUuid));
assertFalse(statuses.containsKey(unknownResultUuid));
}

@Test
void stopTest() throws Exception {
countDownLatch = new CountDownLatch(1);
Expand Down
Loading