-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathImageProcessor.java
More file actions
73 lines (51 loc) · 2.53 KB
/
ImageProcessor.java
File metadata and controls
73 lines (51 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package de.telran;
import de.telran.entity.ActionableImage;
import de.telran.entity.ImageDescriptor;
import de.telran.factory.ImageActionFactory;
import de.telran.service.DownloadService;
import de.telran.service.FileService;
import de.telran.service.ImageDescriptorService;
import de.telran.service.ImageService;
import java.awt.image.BufferedImage;
import java.util.List;
import java.util.stream.Collectors;
public class ImageProcessor {
private ImageDescriptorService imageDescriptorService;
private DownloadService downloadService;
private ImageService imageService;
private FileService fileService;
public ImageProcessor(ImageDescriptorService imageDescriptorService,
DownloadService downloadService,
ImageService imageService,
FileService fileService) {
this.imageDescriptorService = imageDescriptorService;
this.downloadService = downloadService;
this.imageService = imageService;
this.fileService = fileService;
}
public void doProcessing(String fileName) {
List<ImageDescriptor> imageDescriptors = imageDescriptorService.getImageDescriptors(fileName);
List<ActionableImage> actionableImages = imageDescriptors
.stream()
.map(i -> new ActionableImage(null, false, i.getImageUrlName(), i.getActionName()))
.collect(Collectors.toList());
List<ActionableImage> downloadedImages = downloadService.downloadImages(actionableImages);
List<ActionableImage> successfullyDownloadedImages = downloadedImages.stream()
.filter(ActionableImage::isSuccessfull)
.collect(Collectors.toList());
List<ActionableImage> processedImages = successfullyDownloadedImages
.stream()
.map(i -> imageService.processImage(i))
.collect(Collectors.toList());
processedImages.forEach(i -> fileService.saveImageAsFile(i));
}
public static void main(String[] args) {
String fileName = args[0];
FileService fileService = new FileService();
ImageDescriptorService imageDescriptorService = new ImageDescriptorService(fileService);
DownloadService downloadService = new DownloadService();
ImageService imageService = new ImageService(new ImageActionFactory());
ImageProcessor processor = new ImageProcessor(imageDescriptorService, downloadService, imageService, fileService);
processor.doProcessing(fileName);
}
}