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 */ /** Error message if the job failed */
private String error; private String error;
/** The file ID of the result file, if applicable (legacy single file support) */ /** List of result files for jobs that produce files */
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 */
private List<ResultFile> resultFiles; private List<ResultFile> resultFiles;
/** Time when the job was created */ /** Time when the job was created */
@ -68,20 +59,6 @@ public class JobResult {
.build(); .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 * 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 * @return true if this job has file results, false otherwise
*/ */
public boolean hasFiles() { 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 * @return List of result files
*/ */
@ -161,18 +138,6 @@ public class JobResult {
if (resultFiles != null && !resultFiles.isEmpty()) { if (resultFiles != null && !resultFiles.isEmpty()) {
return Collections.unmodifiableList(resultFiles); 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(); return Collections.emptyList();
} }

View File

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

View File

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