-
Notifications
You must be signed in to change notification settings - Fork 5
/
AddImageToEngineVerticle.java
60 lines (50 loc) · 1.81 KB
/
AddImageToEngineVerticle.java
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
package org.genericsystem.ir;
import java.nio.file.Paths;
import org.genericsystem.common.Root;
import org.genericsystem.cv.comparator.FillModelWithData;
import org.genericsystem.kernel.Engine;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.json.JsonObject;
/**
* The AddImageToEngineVerticle receives a message from the event bus when an image was classified. After saving the document in Generic System, a message is sent to the {@link DezonerVerticle}. A reference to an {@link Engine} must be given to be able to
* store the data in Generic System.
*
* @author Pierrik Lassalas
*/
public class AddImageToEngineVerticle extends ActionVerticle {
public static final String ACTION = "newImage";
private Root engine;
/**
* Default constructor. A reference to the engine must be provided.
*
* @param engine - the engine used to store the data
*/
public AddImageToEngineVerticle(Root engine) {
this.engine = engine;
}
@Override
public String getAction() {
return ACTION;
}
@Override
protected void handle(Future<Object> future, JsonObject task) {
String imagePath = task.getString(DistributedVerticle.FILENAME);
boolean result;
if (null != engine)
result = FillModelWithData.registerNewFile(engine, Paths.get(imagePath), DistributedVerticle.RESOURCES_FOLDER);
else
result = FillModelWithData.registerNewFile(Paths.get(imagePath));
if (result)
future.complete(imagePath);
else
future.fail("An error has occured while saving file " + imagePath);
}
@Override
protected void handleResult(AsyncResult<Object> res, JsonObject task) {
if (res.succeeded())
addTask((String) res.result(), DezonerVerticle.ACTION);
else
throw new IllegalStateException("An error has occurred while saving file " + task.getString(DistributedVerticle.FILENAME));
}
}