| @@ 330-354 (lines=25) @@ | ||
| 327 | .map(output -> output.getId()) |
|
| 328 | .collect(Collectors.toList()))); |
|
| 329 | } |
|
| 330 | if (exerciseRequestDTO.getFiles() != null) { |
|
| 331 | exerciseFilePreviewRepository.deleteAll(existedExercise.getExerciseFiles()); |
|
| 332 | List<ExerciseFile> exerciseFiles = |
|
| 333 | exerciseRequestDTO.getFiles().stream() |
|
| 334 | .map( |
|
| 335 | file -> { |
|
| 336 | final MapBindingResult errors = |
|
| 337 | new MapBindingResult( |
|
| 338 | new HashMap<>(), String.class.getName()); |
|
| 339 | if (file.getData_url() == null) { |
|
| 340 | throw new UnauthorizedException("Invalid data_url"); |
|
| 341 | } |
|
| 342 | dataurlValidator.validate(file.getData_url(), errors); |
|
| 343 | if (errors.hasErrors()) { |
|
| 344 | throw new UnauthorizedException( |
|
| 345 | errors.getAllErrors() |
|
| 346 | .get(0) |
|
| 347 | .getDefaultMessage()); |
|
| 348 | } |
|
| 349 | return new ExerciseFile() |
|
| 350 | .setFile_name(file.getFile_name()) |
|
| 351 | .setFile_size(file.getFile_size()) |
|
| 352 | .setFile_type(file.getFile_type()) |
|
| 353 | .setData_url(file.getData_url()); |
|
| 354 | }) |
|
| 355 | .collect(Collectors.toList()); |
|
| 356 | List<ExerciseFile> savedExerciseFiles = exerciseFileRepository.saveAll(exerciseFiles); |
|
| 357 | existedExercise.setExerciseFiles( |
|
| @@ 229-252 (lines=24) @@ | ||
| 226 | .map(output -> output.getId()) |
|
| 227 | .collect(Collectors.toList()))); |
|
| 228 | } |
|
| 229 | if (exerciseRequestDTO.getFiles() != null) { |
|
| 230 | List<ExerciseFile> exerciseFiles = |
|
| 231 | exerciseRequestDTO.getFiles().stream() |
|
| 232 | .map( |
|
| 233 | file -> { |
|
| 234 | final MapBindingResult errors = |
|
| 235 | new MapBindingResult( |
|
| 236 | new HashMap<>(), String.class.getName()); |
|
| 237 | if (file.getData_url() == null) { |
|
| 238 | throw new UnauthorizedException("Invalid data_url"); |
|
| 239 | } |
|
| 240 | dataurlValidator.validate(file.getData_url(), errors); |
|
| 241 | if (errors.hasErrors()) { |
|
| 242 | throw new UnauthorizedException( |
|
| 243 | errors.getAllErrors() |
|
| 244 | .get(0) |
|
| 245 | .getDefaultMessage()); |
|
| 246 | } |
|
| 247 | return new ExerciseFile() |
|
| 248 | .setFile_name(file.getFile_name()) |
|
| 249 | .setFile_size(file.getFile_size()) |
|
| 250 | .setFile_type(file.getFile_type()) |
|
| 251 | .setData_url(file.getData_url()); |
|
| 252 | }) |
|
| 253 | .collect(Collectors.toList()); |
|
| 254 | List<ExerciseFile> savedExerciseFiles = exerciseFileRepository.saveAll(exerciseFiles); |
|
| 255 | exercise.setExerciseFiles( |
|