Skip to content

Commit 9992f9e

Browse files
Merge pull request #64 from sergeylukichev/mavenized
mavenized version
2 parents 6b47d58 + 566f206 commit 9992f9e

27 files changed

Lines changed: 731 additions & 22 deletions

ImageProcessor2/.gitignore

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,10 @@
1-
/target/
2-
!.mvn/wrapper/maven-wrapper.jar
3-
4-
### STS ###
5-
.apt_generated
6-
.classpath
7-
.factorypath
1+
/bin/
2+
/out
3+
*.iml
4+
.idea
85
.project
9-
.settings
10-
.springBeans
11-
.sts4-cache
12-
13-
### IntelliJ IDEA ###
6+
.classpath
7+
/target/
148
.idea
159
*.iws
16-
*.iml
17-
*.ipr
18-
19-
### NetBeans ###
20-
/nbproject/private/
21-
/build/
22-
/nbbuild/
23-
/dist/
24-
/nbdist/
25-
/.nb-gradle/
10+
*.ipr

ImageProcessor2/pom.xml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>de.telran</groupId>
8+
<artifactId>ImageProcessor3</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
12+
<dependencies>
13+
<dependency>
14+
<groupId>junit</groupId>
15+
<artifactId>junit</artifactId>
16+
<version>4.12</version>
17+
<scope>test</scope>
18+
</dependency>
19+
20+
<dependency>
21+
<groupId>org.mockito</groupId>
22+
<artifactId>mockito-core</artifactId>
23+
<version>3.3.3</version>
24+
<scope>test</scope>
25+
</dependency>
26+
</dependencies>
27+
28+
<build>
29+
<plugins>
30+
<plugin>
31+
<groupId>org.apache.maven.plugins</groupId>
32+
<artifactId>maven-compiler-plugin</artifactId>
33+
<configuration>
34+
<source>1.8</source>
35+
<target>1.8</target>
36+
</configuration>
37+
</plugin>
38+
</plugins>
39+
</build>
40+
</project>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package de.telran.processor;
2+
3+
import de.telran.processor.entity.DownloadedImage;
4+
import de.telran.processor.entity.ImageDescriptor;
5+
import de.telran.processor.factory.ImageActionFactory;
6+
import de.telran.processor.service.*;
7+
8+
import java.util.List;
9+
import java.util.stream.Collectors;
10+
11+
public class ImageProcessor {
12+
13+
private FileService fileService;
14+
private DownloadService downloadService;
15+
private ImageService imageService;
16+
17+
public static void main(String[] args) throws Exception {
18+
19+
String csvFile = args[0];
20+
21+
FileService fs = new FileService(new FileConfigService(), new FileNameGenertorService());
22+
DownloadService ds = new DownloadService(new ImageReadingService());
23+
ImageService is = new ImageService(new ImageActionFactory(new ActionsConfigService()));
24+
ImageProcessor processor = new ImageProcessor(fs, ds, is);
25+
processor.process(csvFile);
26+
27+
}
28+
29+
public ImageProcessor(FileService fileService,
30+
DownloadService downloadService,
31+
ImageService imageService) {
32+
this.fileService = fileService;
33+
this.downloadService = downloadService;
34+
this.imageService = imageService;
35+
}
36+
37+
public void process(String fileName){
38+
//main logic is here
39+
40+
//reading CSV file to get image data like urls and actions
41+
List<ImageDescriptor> imageDescriptors = fileService.readImageDescriptors(fileName);
42+
43+
//download images
44+
List<DownloadedImage> downloadedImages = downloadService.downloadImages(imageDescriptors);
45+
46+
//filter successfully downloaded images
47+
List<DownloadedImage> successfullyDownloadedImages = downloadedImages
48+
.stream()
49+
.filter(DownloadedImage::isSuccessful)
50+
.collect(Collectors.toList());
51+
52+
53+
//apply action to every downloaded image
54+
List<DownloadedImage> processedImages = successfullyDownloadedImages
55+
.stream()
56+
.map(di -> imageService.processImage(di))
57+
.collect(Collectors.toList());
58+
59+
60+
//save transformed images to disk
61+
processedImages
62+
.stream()
63+
.filter(di -> !di.isSuccessful())
64+
.forEach(f -> fileService.saveImageAsFile(f));
65+
66+
//where do we save an image? - use some config service - FileConfigService
67+
68+
//generate a file name. how?
69+
//file naming strategy: 1. action_name+random_number.jpg -> which target format to use?
70+
// 2. use a file name from original URL.
71+
//lukaroundimg/beelitz2017/1a.jpg -> lukaroundimg_beelitz2017_1a_TRULALA.jpg
72+
//lukaroundimg/beelitz2017/1a.jpg -> lukaroundimg_beelitz2017_1a_GRAYSCALE.jpg
73+
//lukaroundimg_beelitz2017_1a.jpg -> lukaroundimg_beelitz2017_1a02.jpg
74+
75+
}
76+
77+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package de.telran.processor.action;
2+
3+
import java.awt.image.BufferedImage;
4+
5+
public class DefaultImageAction implements ImageAction {
6+
7+
@Override
8+
public String getName() {
9+
return "DEFAULT";
10+
}
11+
12+
@Override
13+
public BufferedImage doAction(BufferedImage image) throws Exception {
14+
System.out.println("default action - not supported");
15+
return image;
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package de.telran.processor.action;
2+
3+
import java.awt.image.BufferedImage;
4+
5+
public class GrayscaleImageAction implements ImageAction {
6+
@Override
7+
public String getName() {
8+
return "GRAYSCALE";
9+
}
10+
11+
@Override
12+
public BufferedImage doAction(BufferedImage image) throws Exception {
13+
System.out.println("Grayscaling an image");
14+
//tranformation
15+
return image;
16+
}
17+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package de.telran.processor.action;
2+
3+
import java.awt.image.BufferedImage;
4+
5+
public interface ImageAction {
6+
String getName();
7+
BufferedImage doAction(BufferedImage image) throws Exception;
8+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package de.telran.processor.action;
2+
3+
import java.awt.image.BufferedImage;
4+
5+
public class NewImageAction implements ImageAction {
6+
@Override
7+
public String getName() {
8+
return "NEW ACTION";
9+
}
10+
11+
@Override
12+
public BufferedImage doAction(BufferedImage image) throws Exception {
13+
System.out.println("executing new action");
14+
return image;
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package de.telran.processor.action;
2+
3+
import java.awt.image.BufferedImage;
4+
5+
public class PreviewImageAction implements ImageAction {
6+
@Override
7+
public String getName() {
8+
return "PREVIEW";
9+
}
10+
11+
@Override
12+
public BufferedImage doAction(BufferedImage image) throws Exception {
13+
System.out.println("Generating a preview");
14+
return image;
15+
}
16+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package de.telran.processor.entity;
2+
3+
import java.awt.image.BufferedImage;
4+
5+
public class DownloadedImage {
6+
private BufferedImage image;
7+
private boolean isSuccessful;
8+
private ImageDescriptor descriptor;
9+
10+
public DownloadedImage(BufferedImage image, boolean isSuccessful, ImageDescriptor descriptor) {
11+
this.image = image;
12+
this.isSuccessful = isSuccessful;
13+
this.descriptor = descriptor;
14+
}
15+
16+
public BufferedImage getImage() {
17+
return image;
18+
}
19+
20+
public boolean isSuccessful() {
21+
return isSuccessful;
22+
}
23+
24+
public ImageDescriptor getDescriptor() {
25+
return descriptor;
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package de.telran.processor.entity;
2+
3+
public class ImageDescriptor {
4+
private String imageURL;
5+
private String actionName;
6+
7+
public ImageDescriptor(String imageURL, String actionName) {
8+
this.imageURL = imageURL;
9+
this.actionName = actionName;
10+
}
11+
12+
public String getImageURL() {
13+
return imageURL;
14+
}
15+
16+
public String getActionName() {
17+
return actionName;
18+
}
19+
20+
@Override
21+
public String toString() {
22+
return "ImageDescriptor{" +
23+
"imageURL='" + imageURL + '\'' +
24+
", actionName='" + actionName + '\'' +
25+
'}';
26+
}
27+
}

0 commit comments

Comments
 (0)