diff --git a/src/main/java/com/ddf/vodsystem/entities/Job.java b/src/main/java/com/ddf/vodsystem/entities/Job.java index 560ebee..402ca58 100644 --- a/src/main/java/com/ddf/vodsystem/entities/Job.java +++ b/src/main/java/com/ddf/vodsystem/entities/Job.java @@ -18,7 +18,7 @@ public class Job { private ClipConfig clipConfig; // job status - private JobStatus status = JobStatus.PENDING; + private JobStatus status = JobStatus.NOT_READY; private Float progress = 0.0f; public Job(String uuid, File inputFile, File outputFile) { diff --git a/src/main/java/com/ddf/vodsystem/services/DownloadService.java b/src/main/java/com/ddf/vodsystem/services/DownloadService.java index 26a47c7..8d35875 100644 --- a/src/main/java/com/ddf/vodsystem/services/DownloadService.java +++ b/src/main/java/com/ddf/vodsystem/services/DownloadService.java @@ -22,7 +22,7 @@ public class DownloadService { } public Resource downloadInput(String uuid) { - Job job = jobService.get(uuid); + Job job = jobService.getJob(uuid); if (job == null) { throw new JobNotFound("Job doesn't exist"); @@ -33,7 +33,7 @@ public class DownloadService { } public Resource downloadOutput(String uuid) { - Job job = jobService.get(uuid); + Job job = jobService.getJob(uuid); if (job == null) { throw new JobNotFound("Job doesn't exist"); diff --git a/src/main/java/com/ddf/vodsystem/services/EditService.java b/src/main/java/com/ddf/vodsystem/services/EditService.java index ce16448..94c00b0 100644 --- a/src/main/java/com/ddf/vodsystem/services/EditService.java +++ b/src/main/java/com/ddf/vodsystem/services/EditService.java @@ -3,7 +3,6 @@ package com.ddf.vodsystem.services; import com.ddf.vodsystem.entities.ClipConfig; import com.ddf.vodsystem.entities.Job; import com.ddf.vodsystem.entities.JobStatus; -import com.ddf.vodsystem.exceptions.JobNotFound; import org.springframework.stereotype.Service; @Service @@ -15,16 +14,8 @@ public class EditService { } public void edit(String uuid, ClipConfig clipConfig) { - Job job = jobService.get(uuid); - - if (clipConfig.getStartPoint() != null && clipConfig.getStartPoint() < 0) { - throw new IllegalArgumentException("Start point cannot be negative"); - } - - if (clipConfig.getFileSize() != null && clipConfig.getFileSize() < 100) { - throw new IllegalArgumentException("File size cannot be less than 100kb"); - } - + Job job = jobService.getJob(uuid); + validateClipConfig(clipConfig); job.setClipConfig(clipConfig); } @@ -33,11 +24,7 @@ public class EditService { } public float getProgress(String uuid) { - Job job = jobService.get(uuid); - - if (job == null) { - throw new JobNotFound(uuid); - } + Job job = jobService.getJob(uuid); if (job.getStatus() == JobStatus.FINISHED) { return 1f; @@ -45,4 +32,26 @@ public class EditService { return job.getProgress(); } + + private void validateClipConfig(ClipConfig clipConfig) { + Float start = clipConfig.getStartPoint(); + Float end = clipConfig.getEndPoint(); + Float fileSize = clipConfig.getFileSize(); + + if (start != null && start < 0) { + throw new IllegalArgumentException("Start point cannot be negative"); + } + + if (end != null && end < 0) { + throw new IllegalArgumentException("End point cannot be negative"); + } + + if (start != null && end != null && end <= start) { + throw new IllegalArgumentException("End point must be greater than start point"); + } + + if (fileSize != null && fileSize < 100) { + throw new IllegalArgumentException("File size cannot be less than 100kb"); + } + } } diff --git a/src/main/java/com/ddf/vodsystem/services/JobService.java b/src/main/java/com/ddf/vodsystem/services/JobService.java index 9e71362..0c7debc 100644 --- a/src/main/java/com/ddf/vodsystem/services/JobService.java +++ b/src/main/java/com/ddf/vodsystem/services/JobService.java @@ -2,6 +2,7 @@ package com.ddf.vodsystem.services; import com.ddf.vodsystem.entities.Job; import com.ddf.vodsystem.entities.JobStatus; +import com.ddf.vodsystem.exceptions.JobNotFound; import jakarta.annotation.PostConstruct; import org.springframework.stereotype.Service; @@ -28,17 +29,19 @@ public class JobService { jobs.put(job.getUuid(), job); } - public Job get(String uuid) { - return jobs.get(uuid); - } - - public void jobReady(String uuid) { + public Job getJob(String uuid) { Job job = jobs.get(uuid); if (job == null) { - throw new RuntimeException("Job not found"); + throw new JobNotFound("Job not found"); } + return job; + } + + public void jobReady(String uuid) { + Job job = getJob(uuid); + logger.info("Job ready: {}", job.getUuid()); job.setStatus(JobStatus.PENDING); jobQueue.add(job); diff --git a/src/main/java/com/ddf/vodsystem/services/UploadService.java b/src/main/java/com/ddf/vodsystem/services/UploadService.java index 12e1399..3447d25 100644 --- a/src/main/java/com/ddf/vodsystem/services/UploadService.java +++ b/src/main/java/com/ddf/vodsystem/services/UploadService.java @@ -25,9 +25,9 @@ public class UploadService { private static final Logger logger = LoggerFactory.getLogger(UploadService.class); @Value("${temp.vod.storage}") - private String INPUT_DIR; + private String inputDir; @Value("${temp.vod.output}") - private String OUTPUT_DIR; + private String outputDir; private final JobService jobService; @@ -42,10 +42,10 @@ public class UploadService { String extension = getFileExtension(file.getOriginalFilename()); String filename = uuid + (extension.isEmpty() ? "" : "." + extension); - Path inputPath = Paths.get(INPUT_DIR, filename); + Path inputPath = Paths.get(inputDir, filename); File inputFile = inputPath.toFile(); - Path outputPath = Paths.get(OUTPUT_DIR, filename); + Path outputPath = Paths.get(outputDir, filename); File outputFile = outputPath.toFile(); moveToFile(file, inputFile); @@ -87,17 +87,17 @@ public class UploadService { private void createDirectories() throws IOException { // Create INPUT_DIR if it doesn't exist - Path inputDirPath = Paths.get(INPUT_DIR); + Path inputDirPath = Paths.get(inputDir); if (Files.notExists(inputDirPath)) { Files.createDirectories(inputDirPath); - System.out.println("Created directory: " + INPUT_DIR); + logger.info("Created directory: {}", inputDir); } // Create OUTPUT_DIR if it doesn't exist - Path outputDirPath = Paths.get(OUTPUT_DIR); + Path outputDirPath = Paths.get(outputDir); if (Files.notExists(outputDirPath)) { Files.createDirectories(outputDirPath); - System.out.println("Created directory: " + OUTPUT_DIR); + logger.info("Created directory: {}", outputDir); } }