@@ -18,4 +18,6 @@ public interface FileUploadService {
|
|||||||
void handleExpiredSession(FileUploadSession session);
|
void handleExpiredSession(FileUploadSession session);
|
||||||
|
|
||||||
void cancelUpload(String uploadId);
|
void cancelUpload(String uploadId);
|
||||||
|
|
||||||
|
void completeFileProcessingAsync(FileUploadSession session);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -232,37 +232,9 @@ public class FileUploadServiceImpl implements FileUploadService {
|
|||||||
return UploadProgressResponse.fromSession(session);
|
return UploadProgressResponse.fromSession(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateSession(FileUploadSession session) {
|
|
||||||
UploadStatus status = session.getStatus();
|
|
||||||
|
|
||||||
if (status == UploadStatus.FAILED) {
|
|
||||||
if (session.getRetryCount() >= maxRetryAttempts) {
|
|
||||||
throw new FileUploadException(
|
|
||||||
"Upload failed after maximum retry attempts");
|
|
||||||
}
|
|
||||||
session.setStatus(UploadStatus.UPLOADING);
|
|
||||||
session.setRetryCount(session.getRetryCount() + 1);
|
|
||||||
sessionRepository.save(session);
|
|
||||||
log.info("Retrying failed upload session: {}, attempt: {}",
|
|
||||||
session.getUploadId(), session.getRetryCount());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (status == UploadStatus.COMPLETED) {
|
|
||||||
throw new FileUploadException("Upload already completed");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (status == UploadStatus.CANCELLED) {
|
|
||||||
throw new FileUploadException("Upload was cancelled");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (status == UploadStatus.INITIATED) {
|
|
||||||
session.setStatus(UploadStatus.UPLOADING);
|
|
||||||
sessionRepository.save(session);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Async("fileUploadTaskExecutor")
|
@Async("fileUploadTaskExecutor")
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@Override
|
||||||
public void completeFileProcessingAsync(FileUploadSession session) {
|
public void completeFileProcessingAsync(FileUploadSession session) {
|
||||||
try {
|
try {
|
||||||
Path filePath = Paths.get(session.getFilePath());
|
Path filePath = Paths.get(session.getFilePath());
|
||||||
@@ -301,6 +273,35 @@ public class FileUploadServiceImpl implements FileUploadService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void validateSession(FileUploadSession session) {
|
||||||
|
UploadStatus status = session.getStatus();
|
||||||
|
|
||||||
|
if (status == UploadStatus.FAILED) {
|
||||||
|
if (session.getRetryCount() >= maxRetryAttempts) {
|
||||||
|
throw new FileUploadException(
|
||||||
|
"Upload failed after maximum retry attempts");
|
||||||
|
}
|
||||||
|
session.setStatus(UploadStatus.UPLOADING);
|
||||||
|
session.setRetryCount(session.getRetryCount() + 1);
|
||||||
|
sessionRepository.save(session);
|
||||||
|
log.info("Retrying failed upload session: {}, attempt: {}",
|
||||||
|
session.getUploadId(), session.getRetryCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status == UploadStatus.COMPLETED) {
|
||||||
|
throw new FileUploadException("Upload already completed");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status == UploadStatus.CANCELLED) {
|
||||||
|
throw new FileUploadException("Upload was cancelled");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status == UploadStatus.INITIATED) {
|
||||||
|
session.setStatus(UploadStatus.UPLOADING);
|
||||||
|
sessionRepository.save(session);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private UploadProgressResponse processChunk(FileUploadSession session, Integer chunkNumber, MultipartFile chunkFile) {
|
private UploadProgressResponse processChunk(FileUploadSession session, Integer chunkNumber, MultipartFile chunkFile) {
|
||||||
String chunkPath = null;
|
String chunkPath = null;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user