remove "legacy"

This commit is contained in:
Anthony Stirling 2025-07-10 14:30:22 +01:00
parent 2c9537f786
commit 98b4763c96
3 changed files with 24 additions and 62 deletions

View File

@ -27,16 +27,7 @@ public class JobResult {
/** Error message if the job failed */
private String error;
/** The file ID of the result file, if applicable (legacy single file support) */
private String fileId;
/** Original file name, if applicable (legacy single file support) */
private String originalFileName;
/** MIME type of the result, if applicable (legacy single file support) */
private String contentType;
/** List of result files for jobs that produce multiple files */
/** List of result files for jobs that produce files */
private List<ResultFile> resultFiles;
/** Time when the job was created */
@ -68,20 +59,6 @@ public class JobResult {
.build();
}
/**
* Mark this job as complete with a file result
*
* @param fileId The file ID of the result
* @param originalFileName The original file name
* @param contentType The content type of the file
*/
public void completeWithFile(String fileId, String originalFileName, String contentType) {
this.complete = true;
this.fileId = fileId;
this.originalFileName = originalFileName;
this.contentType = contentType;
this.completedAt = LocalDateTime.now();
}
/**
* Mark this job as complete with a general result
@ -140,7 +117,7 @@ public class JobResult {
* @return true if this job has file results, false otherwise
*/
public boolean hasFiles() {
return (resultFiles != null && !resultFiles.isEmpty()) || fileId != null;
return resultFiles != null && !resultFiles.isEmpty();
}
/**
@ -153,7 +130,7 @@ public class JobResult {
}
/**
* Get all result files (includes legacy single file converted to ResultFile)
* Get all result files
*
* @return List of result files
*/
@ -161,18 +138,6 @@ public class JobResult {
if (resultFiles != null && !resultFiles.isEmpty()) {
return Collections.unmodifiableList(resultFiles);
}
// Legacy single file support
if (fileId != null) {
ResultFile legacyFile = ResultFile.builder()
.fileId(fileId)
.fileName(originalFileName)
.contentType(contentType)
.fileSize(0) // Size not tracked in legacy format
.build();
return List.of(legacyFile);
}
return Collections.emptyList();
}

View File

@ -107,9 +107,15 @@ public class TaskManager {
}
}
// Fallback to legacy single file or non-ZIP file
jobResult.completeWithFile(fileId, originalFileName, contentType);
log.debug("Set file result for job ID: {} with file ID: {}", jobId, fileId);
// Handle as single file using new ResultFile approach
try {
long fileSize = fileStorage.getFileSize(fileId);
jobResult.completeWithSingleFile(fileId, originalFileName, contentType, fileSize);
log.debug("Set single file result for job ID: {} with file ID: {}", jobId, fileId);
} catch (Exception e) {
log.warn("Failed to get file size for job {}: {}. Using size 0.", jobId, e.getMessage());
jobResult.completeWithSingleFile(fileId, originalFileName, contentType, 0);
}
}
/**
@ -144,7 +150,7 @@ public class TaskManager {
public void setComplete(String jobId) {
JobResult jobResult = getOrCreateJobResult(jobId);
if (jobResult.getResult() == null
&& jobResult.getFileId() == null
&& !jobResult.hasFiles()
&& jobResult.getError() == null) {
// If no result or error has been set, mark it as complete with an empty result
jobResult.completeWithResult("Task completed successfully");
@ -226,7 +232,7 @@ public class TaskManager {
failedJobs++;
} else {
successfulJobs++;
if (result.getFileId() != null) {
if (result.hasFiles()) {
fileResultJobs++;
}
}
@ -411,18 +417,9 @@ public class TaskManager {
* Clean up files associated with a job result
*/
private void cleanupJobFiles(JobResult result, String jobId) {
// Clean up legacy single file
if (result.getFileId() != null) {
try {
fileStorage.deleteFile(result.getFileId());
} catch (Exception e) {
log.warn("Failed to delete legacy file for job {}: {}", jobId, e.getMessage());
}
}
// Clean up multiple files
if (result.getResultFiles() != null) {
for (ResultFile resultFile : result.getResultFiles()) {
// Clean up all result files
if (result.hasFiles()) {
for (ResultFile resultFile : result.getAllResultFiles()) {
try {
fileStorage.deleteFile(resultFile.getFileId());
} catch (Exception e) {

View File

@ -91,17 +91,17 @@ public class JobController {
));
}
// Handle single file (legacy support)
if (result.getFileId() != null) {
// Handle single file (download directly)
if (result.hasFiles() && !result.hasMultipleFiles()) {
try {
byte[] fileContent = fileStorage.retrieveBytes(result.getFileId());
List<ResultFile> files = result.getAllResultFiles();
ResultFile singleFile = files.get(0);
byte[] fileContent = fileStorage.retrieveBytes(singleFile.getFileId());
return ResponseEntity.ok()
.header("Content-Type", result.getContentType())
.header("Content-Type", singleFile.getContentType())
.header(
"Content-Disposition",
"form-data; name=\"attachment\"; filename=\""
+ result.getOriginalFileName()
+ "\"")
"attachment; filename=\"" + singleFile.getFileName() + "\"")
.body(fileContent);
} catch (Exception e) {
log.error("Error retrieving file for job {}: {}", jobId, e.getMessage(), e);