Skip to content

Commit 227fc11

Browse files
author
Robin Duda
committed
Website improvements, parsing off event loop, status info.
1 parent b3232be commit 227fc11

19 files changed

+2140
-1820
lines changed

configuration.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
{
2-
"web_port": 8080,
3-
"elastic_port": 9200,
4-
"elastic_host": "localhost"
1+
{
2+
"web_port": 0,
3+
"elastic_port": 9200,
4+
"elastic_host": "localhost"
55
}

pom.xml

+94-94
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,95 @@
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-
<properties>
8-
<project.version.sourceEncoding>UTF-8</project.version.sourceEncoding>
9-
</properties>
10-
11-
<groupId>com.codingchili</groupId>
12-
<artifactId>excelastic</artifactId>
13-
<version>1.0.2</version>
14-
<build>
15-
<plugins>
16-
<plugin>
17-
<groupId>org.apache.maven.plugins</groupId>
18-
<artifactId>maven-compiler-plugin</artifactId>
19-
<version>3.5.1</version>
20-
<configuration>
21-
<source>1.8</source>
22-
<target>1.8</target>
23-
</configuration>
24-
</plugin>
25-
<plugin>
26-
<groupId>org.apache.maven.plugins</groupId>
27-
<artifactId>maven-shade-plugin</artifactId>
28-
<version>1.6</version>
29-
<executions>
30-
<execution>
31-
<phase>package</phase>
32-
<goals>
33-
<goal>shade</goal>
34-
</goals>
35-
<configuration>
36-
<outputFile>${project.artifactId}-${project.version}.jar</outputFile>
37-
<transformers>
38-
<transformer
39-
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
40-
<mainClass>com.codingchili.Launcher</mainClass>
41-
</transformer>
42-
</transformers>
43-
</configuration>
44-
</execution>
45-
</executions>
46-
</plugin>
47-
</plugins>
48-
</build>
49-
<dependencies>
50-
<dependency>
51-
<groupId>junit</groupId>
52-
<artifactId>junit</artifactId>
53-
<version>4.12</version>
54-
<scope>test</scope>
55-
</dependency>
56-
57-
<dependency>
58-
<groupId>io.vertx</groupId>
59-
<artifactId>vertx-core</artifactId>
60-
<version>3.4.1</version>
61-
</dependency>
62-
63-
<dependency>
64-
<groupId>io.vertx</groupId>
65-
<artifactId>vertx-unit</artifactId>
66-
<version>3.4.1</version>
67-
</dependency>
68-
69-
<dependency>
70-
<groupId>io.vertx</groupId>
71-
<artifactId>vertx-web</artifactId>
72-
<version>3.4.1</version>
73-
</dependency>
74-
75-
<dependency>
76-
<groupId>io.vertx</groupId>
77-
<artifactId>vertx-web-templ-jade</artifactId>
78-
<version>3.4.1</version>
79-
</dependency>
80-
81-
<dependency>
82-
<groupId>org.apache.poi</groupId>
83-
<artifactId>poi</artifactId>
84-
<version>3.13</version>
85-
</dependency>
86-
87-
<dependency>
88-
<groupId>org.apache.poi</groupId>
89-
<artifactId>poi-ooxml</artifactId>
90-
<version>3.13</version>
91-
</dependency>
92-
93-
</dependencies>
94-
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+
<properties>
8+
<project.version.sourceEncoding>UTF-8</project.version.sourceEncoding>
9+
</properties>
10+
11+
<groupId>com.codingchili</groupId>
12+
<artifactId>excelastic</artifactId>
13+
<version>1.0.2</version>
14+
<build>
15+
<plugins>
16+
<plugin>
17+
<groupId>org.apache.maven.plugins</groupId>
18+
<artifactId>maven-compiler-plugin</artifactId>
19+
<version>3.5.1</version>
20+
<configuration>
21+
<source>1.8</source>
22+
<target>1.8</target>
23+
</configuration>
24+
</plugin>
25+
<plugin>
26+
<groupId>org.apache.maven.plugins</groupId>
27+
<artifactId>maven-shade-plugin</artifactId>
28+
<version>1.6</version>
29+
<executions>
30+
<execution>
31+
<phase>package</phase>
32+
<goals>
33+
<goal>shade</goal>
34+
</goals>
35+
<configuration>
36+
<outputFile>${project.artifactId}-${project.version}.jar</outputFile>
37+
<transformers>
38+
<transformer
39+
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
40+
<mainClass>com.codingchili.ApplicationLauncher</mainClass>
41+
</transformer>
42+
</transformers>
43+
</configuration>
44+
</execution>
45+
</executions>
46+
</plugin>
47+
</plugins>
48+
</build>
49+
<dependencies>
50+
<dependency>
51+
<groupId>junit</groupId>
52+
<artifactId>junit</artifactId>
53+
<version>4.12</version>
54+
<scope>test</scope>
55+
</dependency>
56+
57+
<dependency>
58+
<groupId>io.vertx</groupId>
59+
<artifactId>vertx-core</artifactId>
60+
<version>3.4.1</version>
61+
</dependency>
62+
63+
<dependency>
64+
<groupId>io.vertx</groupId>
65+
<artifactId>vertx-unit</artifactId>
66+
<version>3.4.1</version>
67+
</dependency>
68+
69+
<dependency>
70+
<groupId>io.vertx</groupId>
71+
<artifactId>vertx-web</artifactId>
72+
<version>3.4.1</version>
73+
</dependency>
74+
75+
<dependency>
76+
<groupId>io.vertx</groupId>
77+
<artifactId>vertx-web-templ-jade</artifactId>
78+
<version>3.4.1</version>
79+
</dependency>
80+
81+
<dependency>
82+
<groupId>org.apache.poi</groupId>
83+
<artifactId>poi</artifactId>
84+
<version>3.13</version>
85+
</dependency>
86+
87+
<dependency>
88+
<groupId>org.apache.poi</groupId>
89+
<artifactId>poi-ooxml</artifactId>
90+
<version>3.13</version>
91+
</dependency>
92+
93+
</dependencies>
94+
9595
</project>
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,90 @@
1-
package com.codingchili;
2-
3-
import java.util.Optional;
4-
import java.util.logging.Level;
5-
import java.util.logging.Logger;
6-
7-
import com.codingchili.Controller.Website;
8-
import com.codingchili.Model.Configuration;
9-
import com.codingchili.Model.ElasticWriter;
10-
import com.codingchili.Model.FileParser;
11-
import com.codingchili.Model.ParserException;
12-
13-
import io.vertx.core.*;
14-
15-
/**
16-
* @author Robin Duda
17-
*
18-
* Launcher class to bootstrap the application.
19-
*/
20-
public class Launcher {
21-
private static final Logger logger = Logger.getLogger(Launcher.class.getName());
22-
private static final String COMMAND_IMPORT = "import";
23-
private Vertx vertx = Vertx.vertx();
24-
25-
public static void main(String[] args) {
26-
new Launcher(args);
27-
}
28-
29-
public Launcher(String[] args) {
30-
logger.info("Starting application..");
31-
Future<Void> future = Future.future();
32-
33-
future.setHandler(done -> {
34-
if (done.succeeded()) {
35-
logger.info("Successfully started application");
36-
getImportFileName(args).ifPresent(this::importFile);
37-
} else {
38-
logger.log(Level.SEVERE, "Failed to start application", done.cause());
39-
}
40-
});
41-
42-
start(future);
43-
}
44-
45-
private void importFile(String fileName) {
46-
logger.info(String.format("Loading file %s from filesystem..", fileName));
47-
vertx.fileSystem().readFile(fileName, file -> {
48-
if (file.succeeded()) {
49-
logger.info("Parsing XLSX file to JSON..");
50-
try {
51-
FileParser parser = new FileParser(file.result().getBytes(), 1);
52-
logger.info("File parsed, starting import to elasticsearch..");
53-
vertx.eventBus().send(Configuration.INDEXING_ELASTICSEARCH, parser.toImportableObject());
54-
} catch (ParserException e) {
55-
logger.log(Level.SEVERE, String.format("Failed to import file %s", fileName));
56-
}
57-
} else {
58-
logger.log(Level.SEVERE, String.format("Failed to load file %s", fileName), file.cause());
59-
}
60-
});
61-
}
62-
63-
private static Optional<String> getImportFileName(String[] args) {
64-
for (int i = 0; i < args.length; i++) {
65-
switch (args[i]) {
66-
case COMMAND_IMPORT:
67-
return Optional.of(args[++i]);
68-
}
69-
}
70-
return Optional.empty();
71-
}
72-
73-
public void start(Future<Void> start) {
74-
Future<String> writer = Future.future();
75-
Future<String> website = Future.future();
76-
vertx.deployVerticle(new ElasticWriter(), writer.completer());
77-
vertx.deployVerticle(new Website(), website.completer());
78-
79-
CompositeFuture.all(writer, website).setHandler(done -> {
80-
if (done.succeeded()) {
81-
start.complete();
82-
} else {
83-
start.fail(done.cause());
84-
}
85-
});
86-
}
87-
}
1+
package com.codingchili;
2+
3+
import java.util.logging.Level;
4+
import java.util.logging.Logger;
5+
6+
import com.codingchili.Controller.Website;
7+
import com.codingchili.Model.Configuration;
8+
import com.codingchili.Model.ElasticWriter;
9+
import com.codingchili.Model.FileParser;
10+
import com.codingchili.Model.ParserException;
11+
12+
import io.vertx.core.*;
13+
14+
/**
15+
* @author Robin Duda
16+
*
17+
* ApplicationLauncher class to bootstrap the application.
18+
*/
19+
public class ApplicationLauncher {
20+
private static final Logger logger = Logger.getLogger(ApplicationLauncher.class.getName());
21+
public static String version = "1.1.0";
22+
private Vertx vertx = Vertx.vertx();
23+
private String[] args;
24+
25+
public static void main(String[] args) {
26+
new ApplicationLauncher(args);
27+
}
28+
29+
public ApplicationLauncher(String[] args) {
30+
this.args = args;
31+
32+
logger.info(String.format("Starting excelastic %s..", version));
33+
Future<Void> future = Future.future();
34+
35+
future.setHandler(done -> {
36+
if (done.succeeded()) {
37+
logger.info("Successfully started application");
38+
39+
if (args.length == 3) {
40+
importFile(getFileName(), getIndexName());
41+
}
42+
} else {
43+
logger.log(Level.SEVERE, "Failed to start application", done.cause());
44+
vertx.close();
45+
}
46+
});
47+
start(future);
48+
}
49+
50+
private String getFileName() {
51+
return args[1];
52+
}
53+
54+
private String getIndexName() {
55+
return args[2];
56+
}
57+
58+
private void importFile(String fileName, String indexName) {
59+
logger.info(String.format("Loading file %s from filesystem..", fileName));
60+
vertx.fileSystem().readFile(fileName, file -> {
61+
if (file.succeeded()) {
62+
logger.info("Parsing XLSX file to JSON..");
63+
try {
64+
FileParser parser = new FileParser(file.result().getBytes(), 1, fileName);
65+
logger.info("File parsed, starting import to elasticsearch..");
66+
vertx.eventBus().send(Configuration.INDEXING_ELASTICSEARCH, parser.toImportable(indexName));
67+
} catch (ParserException e) {
68+
logger.log(Level.SEVERE, String.format("Failed to import file %s", fileName));
69+
}
70+
} else {
71+
logger.log(Level.SEVERE, String.format("Failed to load file %s", fileName), file.cause());
72+
}
73+
});
74+
}
75+
76+
public void start(Future<Void> start) {
77+
Future<String> writer = Future.future();
78+
Future<String> website = Future.future();
79+
vertx.deployVerticle(new ElasticWriter(), writer.completer());
80+
vertx.deployVerticle(new Website(), website.completer());
81+
82+
CompositeFuture.all(writer, website).setHandler(done -> {
83+
if (done.succeeded()) {
84+
start.complete();
85+
} else {
86+
start.fail(done.cause());
87+
}
88+
});
89+
}
90+
}

0 commit comments

Comments
 (0)