use of com.codingchili.Model.FileParser.INDEX in project parser-excel-elasticsearch by codingchili.
the class Website method setRouterAPI.
/**
* Adds the upload route to the given router
*
* @param router the upload route is added to the given router
*/
private void setRouterAPI(Router router) {
router.route("/api/upload").handler(context -> {
Iterator<FileUpload> iterator = context.fileUploads().iterator();
if (iterator.hasNext()) {
MultiMap params = context.request().params();
logger.info("Receiving uploaded file with request id " + params.get(UPLOAD_ID));
FileUpload upload = context.fileUploads().iterator().next();
vertx.fileSystem().readFile(upload.uploadedFileName(), file -> {
parse(file.result(), params, upload.fileName(), Future.<Integer>future().setHandler(result -> {
if (result.succeeded()) {
String index = context.request().params().get(INDEX);
logger.info(String.format("Imported file '%s' successfully into '%s'.", upload.fileName(), index));
context.put(INDEX, index);
context.put(FILE, upload.fileName());
context.put(IMPORTED, result.result());
context.reroute(DONE);
} else {
context.put(MESSAGE, traceToText(result.cause()));
logger.log(Level.SEVERE, String.format("Failed to parse file '%s'.", upload.fileName()), result.cause());
context.reroute(ERROR);
}
}));
});
} else {
context.put(MESSAGE, NO_FILE_WAS_UPLOADED);
context.reroute(ERROR);
}
});
}
Aggregations