Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
Signed-off-by: maissa SOUISSI <[email protected]>
  • Loading branch information
souissimai committed Jul 17, 2024
1 parent 7438f1d commit 6b5761c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/powsybl/caseserver/CaseController.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@ public ResponseEntity<byte[]> downloadCase(@PathVariable("caseUuid") UUID caseUu
public ResponseEntity<byte[]> exportCase(
@PathVariable UUID caseUuid,
@RequestParam String format,
@RequestParam(value = "fileName", required = false) String fileName,
@RequestBody(required = false) Map<String, Object> formatParameters) throws IOException {
LOGGER.debug("exportCase request received with parameter caseUuid = {}", caseUuid);
return caseService.exportCase(caseUuid, format, formatParameters).map(networkInfos -> {
return caseService.exportCase(caseUuid, format, fileName, formatParameters).map(networkInfos -> {
var headers = new HttpHeaders();
headers.setContentDisposition(
ContentDisposition.builder("attachment")
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/powsybl/caseserver/CaseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ Optional<byte[]> getCaseBytes(UUID caseUuid) {
return Optional.empty();
}

public Optional<ExportCaseInfos> exportCase(UUID caseUuid, String format, Map<String, Object> formatParameters) throws IOException {
public Optional<ExportCaseInfos> exportCase(UUID caseUuid, String format, String fileName, Map<String, Object> formatParameters) throws IOException {
if (!Exporter.getFormats().contains(format)) {
throw CaseException.createUnsupportedFormat(format);
}
Expand All @@ -426,17 +426,17 @@ public Optional<ExportCaseInfos> exportCase(UUID caseUuid, String format, Map<St
network.write(format, exportProperties, memDataSource);

var listNames = memDataSource.listNames(".*");
String networkName = DataSourceUtil.getBaseName(getCaseName(caseUuid));
String fileOrNetworkName = fileName != null ? fileName : DataSourceUtil.getBaseName(getCaseName(caseUuid));
byte[] networkData;
if (listNames.size() == 1) {
String extension = listNames.iterator().next();
networkName += extension;
fileOrNetworkName += extension;
networkData = memDataSource.getData(extension);
} else {
networkName += ".zip";
fileOrNetworkName += ".zip";
networkData = createZipFile(listNames, memDataSource);
}
return Optional.of(new ExportCaseInfos(networkName, networkData));
return Optional.of(new ExportCaseInfos(fileOrNetworkName, networkData));
} else {
return Optional.empty();
}
Expand Down

0 comments on commit 6b5761c

Please sign in to comment.