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

Migrate security analysis endpoints to add rootNetworkUuid in path #650

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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
30 changes: 18 additions & 12 deletions src/main/java/org/gridsuite/study/server/StudyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -805,53 +805,57 @@ public ResponseEntity<byte[]> exportNetwork(
return ResponseEntity.ok().headers(header).contentType(MediaType.APPLICATION_OCTET_STREAM).body(exportNetworkInfos.getNetworkData());
}

@PostMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/security-analysis/run")
@PostMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/security-analysis/run")
@Operation(summary = "run security analysis on study")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The security analysis has started")})
public ResponseEntity<Void> runSecurityAnalysis(@Parameter(description = "studyUuid") @PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "rootNetworkUuid") @PathVariable("rootNetworkUuid") UUID rootNetworkUuid,
@Parameter(description = "nodeUuid") @PathVariable("nodeUuid") UUID nodeUuid,
@Parameter(description = "Contingency list names") @RequestParam(name = "contingencyListName", required = false) List<String> contingencyListNames,
@RequestHeader(HEADER_USER_ID) String userId) {
List<String> nonNullcontingencyListNames = contingencyListNames != null ? contingencyListNames : Collections.emptyList();
studyService.assertIsNodeNotReadOnly(nodeUuid);
studyService.runSecurityAnalysis(studyUuid, nonNullcontingencyListNames, nodeUuid, studyService.getStudyFirstRootNetworkUuid(studyUuid), userId);
studyService.runSecurityAnalysis(studyUuid, nonNullcontingencyListNames, nodeUuid, rootNetworkUuid, userId);
return ResponseEntity.ok().build();
}

@GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/security-analysis/result")
@GetMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/security-analysis/result")
@Operation(summary = "Get a security analysis result on study")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The security analysis result"),
@ApiResponse(responseCode = "204", description = "No security analysis has been done yet"),
@ApiResponse(responseCode = "404", description = "The security analysis has not been found")})
public ResponseEntity<String> getSecurityAnalysisResult(@Parameter(description = "study UUID") @PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "rootNetworkUuid") @PathVariable("rootNetworkUuid") UUID rootNetworkUuid,
@Parameter(description = "nodeUuid") @PathVariable("nodeUuid") UUID nodeUuid,
@Parameter(description = "result type") @RequestParam(name = "resultType") SecurityAnalysisResultType resultType,
@Parameter(description = "JSON array of filters") @RequestParam(name = "filters", required = false) String filters,
Pageable pageable) {
String result = rootNetworkNodeInfoService.getSecurityAnalysisResult(nodeUuid, studyService.getStudyFirstRootNetworkUuid(studyUuid), resultType, filters, pageable);
String result = rootNetworkNodeInfoService.getSecurityAnalysisResult(nodeUuid, rootNetworkUuid, resultType, filters, pageable);
return result != null ? ResponseEntity.ok().body(result) :
ResponseEntity.noContent().build();
}

@PostMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/security-analysis/result/csv")
@PostMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/security-analysis/result/csv")
@Operation(summary = "Get a security analysis result on study - CSV export")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The security analysis result csv export"),
@ApiResponse(responseCode = "204", description = "No security analysis has been done yet"),
@ApiResponse(responseCode = "404", description = "The security analysis has not been found")})
public byte[] getSecurityAnalysisResult(@Parameter(description = "study UUID") @PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "rootNetworkUuid") @PathVariable("rootNetworkUuid") UUID rootNetworkUuid,
@Parameter(description = "nodeUuid") @PathVariable("nodeUuid") UUID nodeUuid,
@Parameter(description = "result type") @RequestParam(name = "resultType") SecurityAnalysisResultType resultType,
@Parameter(description = "Csv translation (JSON)") @RequestBody String csvTranslations) {
return rootNetworkNodeInfoService.getSecurityAnalysisResultCsv(nodeUuid, studyService.getStudyFirstRootNetworkUuid(studyUuid), resultType, csvTranslations);
return rootNetworkNodeInfoService.getSecurityAnalysisResultCsv(nodeUuid, rootNetworkUuid, resultType, csvTranslations);
}

@GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/contingency-count")
@GetMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/contingency-count")
@Operation(summary = "Get contingency count for a list of contingency list on a study")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The contingency count")})
public ResponseEntity<Integer> getContingencyCount(@Parameter(description = "Study UUID") @PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "rootNetworkUuid") @PathVariable("rootNetworkUuid") UUID rootNetworkUuid,
@Parameter(description = "Node UUID") @PathVariable("nodeUuid") UUID nodeUuid,
@Parameter(description = "Contingency list names") @RequestParam(name = "contingencyListName", required = false) List<String> contingencyListNames) {
return ResponseEntity.ok().body(CollectionUtils.isEmpty(contingencyListNames) ? 0 : studyService.getContingencyCount(studyUuid, contingencyListNames, nodeUuid, studyService.getStudyFirstRootNetworkUuid(studyUuid)));
return ResponseEntity.ok().body(CollectionUtils.isEmpty(contingencyListNames) ? 0 : studyService.getContingencyCount(studyUuid, contingencyListNames, nodeUuid, rootNetworkUuid));
}

@GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/limit-violations")
Expand Down Expand Up @@ -1025,25 +1029,27 @@ public ResponseEntity<String> getNeworkAreaDiagram(
ResponseEntity.noContent().build();
}

@GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/security-analysis/status")
@GetMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/security-analysis/status")
@Operation(summary = "Get the security analysis status on study")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The security analysis status"),
@ApiResponse(responseCode = "204", description = "No security analysis has been done yet"),
@ApiResponse(responseCode = "404", description = "The security analysis status has not been found")})
public ResponseEntity<String> getSecurityAnalysisStatus(@Parameter(description = "Study UUID") @PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "rootNetworkUuid") @PathVariable("rootNetworkUuid") UUID rootNetworkUuid,
@Parameter(description = "nodeUuid") @PathVariable("nodeUuid") UUID nodeUuid) {
SecurityAnalysisStatus status = rootNetworkNodeInfoService.getSecurityAnalysisStatus(nodeUuid, studyService.getStudyFirstRootNetworkUuid(studyUuid));
SecurityAnalysisStatus status = rootNetworkNodeInfoService.getSecurityAnalysisStatus(nodeUuid, rootNetworkUuid);
return status != null ? ResponseEntity.ok().body(status.name()) :
ResponseEntity.noContent().build();
}

@PutMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/security-analysis/stop")
@PutMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/security-analysis/stop")
@Operation(summary = "stop security analysis on study")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The security analysis has been stopped")})
public ResponseEntity<Void> stopSecurityAnalysis(@Parameter(description = "Study uuid") @PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "rootNetworkUuid") @PathVariable("rootNetworkUuid") UUID rootNetworkUuid,
@Parameter(description = "nodeUuid") @PathVariable("nodeUuid") UUID nodeUuid,
@RequestHeader(HEADER_USER_ID) String userId) {
rootNetworkNodeInfoService.stopSecurityAnalysis(studyUuid, nodeUuid, studyService.getStudyFirstRootNetworkUuid(studyUuid), userId);
rootNetworkNodeInfoService.stopSecurityAnalysis(studyUuid, nodeUuid, rootNetworkUuid, userId);
return ResponseEntity.ok().build();
}

Expand Down
Loading
Loading