-
Notifications
You must be signed in to change notification settings - Fork 5
/
OcrPersistenceVerticle.java
54 lines (44 loc) · 1.38 KB
/
OcrPersistenceVerticle.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
package org.genericsystem.ir;
import org.genericsystem.common.Root;
import org.genericsystem.cv.comparator.FillModelWithData;
import org.genericsystem.kernel.Cache;
import org.genericsystem.kernel.Engine;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.json.JsonObject;
/**
* The OcrPersistenceVerticle persists the informations from the OCR into Generic System.
*
* @author Pierrik Lassalas
*/
public class OcrPersistenceVerticle extends ActionVerticle {
public static final String ACTION = "ocrPersist";
private Root engine;
private Cache cache;
/**
* Default constructor. A reference to an {@link Engine} must be provided to be able to save the results.
*
* @param engine - the engine used to store the data
*/
public OcrPersistenceVerticle(Root engine) {
this.engine = engine;
this.cache = (Cache) engine.newCache();
}
@Override
public String getAction() {
return ACTION;
}
@Override
protected void handle(Future<Object> future, JsonObject task) {
JsonObject data = task.getJsonObject(DistributedVerticle.JSON_OBJECT);
cache.safeConsum(unused -> {
FillModelWithData.saveOcrDataInModel(engine, data);
});
future.complete();
}
@Override
protected void handleResult(AsyncResult<Object> res, JsonObject task) {
if (res.failed())
throw new IllegalStateException("Exception in OcrPersistenceVerticle.", res.cause());
}
}