Map<String, String[]> form = request().body().asFormUrlEncoded();
Extractor.Type extractorType = Extractor.Type.valueOf(form.get("extractor_type")[0].toUpperCase());
Extractor extractor;
try {
Node node = nodeService.loadNode(nodeId);
try {
extractor = extractorFactory.forCreate(
Extractor.CursorStrategy.valueOf(form.get("cut_or_copy")[0].toUpperCase()),
form.get("title")[0],
form.get("source_field")[0],
form.get("target_field")[0],
extractorType,
currentUser(),
Extractor.ConditionType.valueOf(form.get("condition_type")[0].toUpperCase()),
form.get("condition_value")[0]
);
} catch (NullPointerException e) {
Logger.error("Cannot build extractor configuration.", e);
return badRequest();
}
extractor.loadConfigFromForm(extractorType, form);
extractor.loadConvertersFromForm(form);
extractor.create(node, node.getInput(inputId));
} catch (IOException e) {
return status(500, views.html.errors.error.render(ApiClient.ERROR_MSG_IO, e, request()));
} catch (APIException e) {
String message = "Could not create extractor! We expected HTTP 200, but got a HTTP " + e.getHttpCode() + ".";
return status(500, views.html.errors.error.render(message, e, request()));