Skip to content
This repository has been archived by the owner on Sep 23, 2023. It is now read-only.

Commit

Permalink
Corrected attachment name for zip downloads (#54)
Browse files Browse the repository at this point in the history
* corrected attachment name for zip downloads
  • Loading branch information
dinuta committed Jan 5, 2022
1 parent 105ab88 commit 4bbbb8e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
FROM azul/zulu-openjdk:11

ENV APP_DIR /app
ENV PORT 8443
ENV HTTPS_ENABLE=true
ENV SERVICE_PROTOCOL=https
ENV PORT 8080
ENV COMMAND_TIMEOUT 1200

RUN mkdir $APP_DIR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public ResponseEntity<ApiResponse> fileRead(@ApiParam(value = "Target file path
.sourceFileName(trimString(file.getName(), FILE_PATH_MAX_SIZE))
.sourceFilePath(trimString(file.getAbsolutePath(), FILE_PATH_MAX_SIZE))
.fileSize(resource.contentLength())
.dateTime(LocalDateTime.now().format(DateTimeConstants.PATTERN))
.build());
} catch (IOException e) {
throw new ApiException(ApiResponseCode.GET_FILE_FAILURE.getCode(),
Expand Down Expand Up @@ -129,6 +130,7 @@ public ResponseEntity<Resource> fileDownload(@ApiParam(value = "Target file path
.sourceFileName(trimString(file.getName(), FILE_PATH_MAX_SIZE))
.sourceFilePath(trimString(file.getAbsolutePath(), FILE_PATH_MAX_SIZE))
.fileSize(resource.contentLength())
.dateTime(LocalDateTime.now().format(DateTimeConstants.PATTERN))
.build());
} catch (IOException e) {
throw new ApiException(ApiResponseCode.GET_FILE_FAILURE.getCode(),
Expand Down Expand Up @@ -160,6 +162,7 @@ public ResponseEntity<ApiResponse> filePut(@ApiParam(value = "The content of the
.targetFilePath(trimString(file.getAbsolutePath(), FILE_PATH_MAX_SIZE))
.targetFolder(trimString(file.getParent(), FILE_PATH_MAX_SIZE))
.fileSize(content != null ? Long.valueOf(content.length) : 0L)
.dateTime(LocalDateTime.now().format(DateTimeConstants.PATTERN))
.build());
log.info(String.format("Stored file at '%s'", filePath));
} catch (IOException e) {
Expand Down Expand Up @@ -218,6 +221,7 @@ public ResponseEntity<ApiResponse> filesPut(@RequestPart("files") MultipartFile[
.targetFilePath(trimString(filePath, FILE_PATH_MAX_SIZE))
.fileSize(file.getSize())
.targetFolder(trimString(fPath, FILE_PATH_MAX_SIZE))
.dateTime(LocalDateTime.now().format(DateTimeConstants.PATTERN))
.build());
log.info(String.format("Stored file '%s' at '%s'", file.getName(), filePath));
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.estuaryoss.agent.component.ClientRequest;
import com.github.estuaryoss.agent.constants.ApiResponseCode;
import com.github.estuaryoss.agent.constants.ApiResponseMessage;
import com.github.estuaryoss.agent.constants.DefaultConstants;
import com.github.estuaryoss.agent.constants.FileTransferType;
import com.github.estuaryoss.agent.constants.*;
import com.github.estuaryoss.agent.entity.FileTransfer;
import com.github.estuaryoss.agent.exception.ApiException;
import com.github.estuaryoss.agent.service.DbService;
Expand All @@ -26,6 +24,7 @@
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;

import static com.github.estuaryoss.agent.constants.HeaderConstants.FOLDER_PATH;

Expand Down Expand Up @@ -84,14 +83,15 @@ public ResponseEntity<Resource> folderGet(@ApiParam(value = "Target folder path
.targetFileName(file.getName())
.targetFilePath(file.getAbsolutePath())
.fileSize(resource.contentLength())
.dateTime(LocalDateTime.now().format(DateTimeConstants.PATTERN))
.build());
} catch (IOException e) {
throw new ApiException(ApiResponseCode.FOLDER_ZIP_FAILURE.getCode(),
String.format(ApiResponseMessage.getMessage(ApiResponseCode.FOLDER_ZIP_FAILURE.getCode()), folderPath));
}

return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + sourceFolderPath.getName())
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + file.getName())
.contentType(MediaType.valueOf("application/zip"))
.contentLength(resource.contentLength())
.body(resource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ public class FileTransfer {

@Column(name = "FILE_SIZE")
private Long fileSize;

@Column(name = "DATE_TIME", columnDefinition = "TIMESTAMP")
private String dateTime;
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void whenSendingBackgroundCommandThenTheUserMustPollActiveAndFinishedEndp
assertThat(commandList.get(0).getOut().trim()).isEqualTo(stdOut);
assertThat(commandList.get(0).getErr()).isEqualTo("");
assertThat(commandList.get(0).getPid()).isGreaterThan(0);
assertThat(commandList.get(0).getDuration()).isGreaterThan(0);
assertThat(commandList.get(0).getDuration()).isGreaterThanOrEqualTo(0);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void whenCallingGetThenTheFolderIsRetrievedOkInZipFormat() throws IOExcep
assertThat(responseEntity.getStatusCode().value()).isEqualTo(HttpStatus.OK.value());
assertThat(body.contentLength()).isGreaterThan(0L);
//check also has the required name
assertThat(body.getFilename()).isEqualTo(folderNameToBeRetrieved);
assertThat(body.getFilename()).isEqualTo(folderNameToBeRetrieved + ".zip");
//audit transfer in DB
assertThat(fileTransferRepository.findAll().size()).isEqualTo(1);
}
Expand Down

0 comments on commit 4bbbb8e

Please sign in to comment.