IMPROVE input validation
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user