Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add pagination for one bus short circuit analysis #451

Closed
wants to merge 3 commits into from
Closed
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
11 changes: 6 additions & 5 deletions src/main/java/org/gridsuite/study/server/StudyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -640,17 +640,18 @@ public ResponseEntity<String> getShortCircuitResult(@Parameter(description = "st
ResponseEntity.noContent().build();
}

@GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/shortcircuit/results/fault_results/paged")
@Operation(summary = "Get a fault results page for the short circuit analysis result on study")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The short circuit analysis result fault results page"),
@GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/shortcircuit/results/paged")
@Operation(summary = "Get a short circuit analysis results page on study")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The short circuit analysis results page"),
@ApiResponse(responseCode = "204", description = "No short circuit analysis has been done yet"),
@ApiResponse(responseCode = "404", description = "The short circuit analysis has not been found")})
public ResponseEntity<String> getShortCircuitAnalysisFaultResultsPage(@Parameter(description = "study UUID") @PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "nodeUuid") @PathVariable("nodeUuid") UUID nodeUuid,
@Parameter(description = "Full or only those with limit violations or none fault results") @RequestParam(name = "mode", required = false, defaultValue = "WITH_LIMIT_VIOLATIONS") String mode,
@Parameter(description = "type") @RequestParam(value = "type", required = false, defaultValue = "ALL_BUSES") ShortcircuitAnalysisType type,
Pageable pageable) {
String faultResultsPage = shortCircuitService.getShortCircuitAnalysisFaultResultsPage(nodeUuid, mode, pageable);
return faultResultsPage != null ? ResponseEntity.ok().body(faultResultsPage) :
String resultsPage = shortCircuitService.getShortCircuitAnalysisResultsPage(nodeUuid, mode, type, pageable);
return resultsPage != null ? ResponseEntity.ok().body(resultsPage) :
ResponseEntity.noContent().build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ private String getShortCircuitAnalysisResultResourcePath(UUID nodeUuid, Shortcir
return UriComponentsBuilder.fromPath(DELIMITER + SHORT_CIRCUIT_API_VERSION + "/results" + "/{resultUuid}").buildAndExpand(resultUuidOpt.get()).toUriString();
}

private String getShortCircuitAnalysisFaultResultsResourcePath(UUID nodeUuid) {
String resultPath = getShortCircuitAnalysisResultResourcePath(nodeUuid, ShortcircuitAnalysisType.ALL_BUSES);
private String getShortCircuitAnalysisResultsPageResourcePath(UUID nodeUuid, ShortcircuitAnalysisType type) {
String resultPath = getShortCircuitAnalysisResultResourcePath(nodeUuid, type);
if (resultPath == null) {
return null;
}
return UriComponentsBuilder.fromPath(resultPath + "/fault_results/paged").toUriString();
return UriComponentsBuilder.fromPath(resultPath + "/paged").toUriString();
}

public String getShortCircuitAnalysisResult(UUID nodeUuid, String mode, ShortcircuitAnalysisType type) {
Expand All @@ -135,18 +135,18 @@ public String getShortCircuitAnalysisResult(UUID nodeUuid, String mode, Shortcir
return getShortCircuitAnalysisResource(resultPath + params);
}

public String getShortCircuitAnalysisFaultResultsPage(UUID nodeUuid, String mode, Pageable pageable) {
public String getShortCircuitAnalysisResultsPage(UUID nodeUuid, String mode, ShortcircuitAnalysisType type, Pageable pageable) {
StringBuilder paramsBuilder = new StringBuilder();
paramsBuilder.append("?mode=" + mode + "&page=" + pageable.getPageNumber() + "&size=" + pageable.getPageSize());
paramsBuilder.append("?mode=" + mode + "&type=" + type + "&page=" + pageable.getPageNumber() + "&size=" + pageable.getPageSize());

for (Sort.Order order : pageable.getSort()) {
paramsBuilder.append("&sort=" + order.getProperty() + "," + order.getDirection());
}
String faultResultsPath = getShortCircuitAnalysisFaultResultsResourcePath(nodeUuid);
if (faultResultsPath == null) {
String resultsPath = getShortCircuitAnalysisResultsPageResourcePath(nodeUuid, type);
if (resultsPath == null) {
return null;
}
return getShortCircuitAnalysisResource(faultResultsPath + paramsBuilder);
return getShortCircuitAnalysisResource(resultsPath + paramsBuilder);
}

public String getShortCircuitAnalysisStatus(UUID nodeUuid, ShortcircuitAnalysisType type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public MockResponse dispatch(RecordedRequest request) {
} else if (path.matches("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "\\?mode=FULL")) {
return new MockResponse().setResponseCode(200).setBody(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON)
.addHeader("Content-Type", "application/json; charset=utf-8");
} else if (path.matches("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/fault_results/paged" + "\\?mode=WITH_LIMIT_VIOLATIONS&page=0&size=20&sort=id,DESC")) {
} else if (path.matches("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/paged" + "\\?mode=WITH_LIMIT_VIOLATIONS&type=ALL_BUSES&page=0&size=20&sort=id,DESC")) {
return new MockResponse().setResponseCode(200).setBody(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON)
.addHeader("Content-Type", "application/json; charset=utf-8");
} else if (path.matches("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/status")) {
Expand Down Expand Up @@ -409,14 +409,14 @@ public void testPagedShortCircuit() throws Exception {
assertEquals(uuidResponse, UUID.fromString(SHORT_CIRCUIT_ANALYSIS_RESULT_UUID));

// get short circuit result with pagination
mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/shortcircuit/results/fault_results/paged?page=0&size=20&sort=id,DESC", studyNameUserIdUuid, modificationNode1Uuid)).andExpectAll(
mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/shortcircuit/results/paged?page=0&size=20&sort=id,DESC", studyNameUserIdUuid, modificationNode1Uuid)).andExpectAll(
status().isOk(),
content().string(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON));

assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/fault_results/paged\\?mode=WITH_LIMIT_VIOLATIONS&page=0&size=20&sort=id,DESC")));
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/paged\\?mode=WITH_LIMIT_VIOLATIONS&type=ALL_BUSES&page=0&size=20&sort=id,DESC")));

// get short circuit result with pagination but with unknown node
mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/shortcircuit/results/fault_results/paged?page=0&size=20", studyNameUserIdUuid, unknownModificationNodeUuid)).andExpect(
mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/shortcircuit/results/paged?page=0&size=20", studyNameUserIdUuid, unknownModificationNodeUuid)).andExpect(
status().isNoContent());

assertTrue(TestUtils.getRequestsDone(0, server).isEmpty());
Expand Down
Loading