LOG.error("Missing inputId. Returning HTTP 400.");
throw new WebApplicationException(400);
}
checkPermission(RestPermissions.INPUTS_EDIT, inputId);
MessageInput input = inputs.getRunningInput(inputId);
if (input == null) {
LOG.error("Input <{}> not found.", inputId);
throw new WebApplicationException(404);
}
// Build extractor.
CreateExtractorRequest cer;
try {
cer = objectMapper.readValue(body, CreateExtractorRequest.class);
} catch (IOException e) {
LOG.error("Error while parsing JSON", e);
throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
}
if (cer.sourceField.isEmpty() || cer.targetField.isEmpty()) {
LOG.error("Missing parameters. Returning HTTP 400.");
throw new WebApplicationException(Response.Status.BAD_REQUEST);
}
String id = new com.eaio.uuid.UUID().toString();
Extractor extractor;
try {
extractor = extractorFactory.factory(
id,
cer.title,
cer.order,
Extractor.CursorStrategy.valueOf(cer.cutOrCopy.toUpperCase()),
Extractor.Type.valueOf(cer.extractorType.toUpperCase()),
cer.sourceField,
cer.targetField,
cer.extractorConfig,
getCurrentUser().getName(),
loadConverters(cer.converters),
Extractor.ConditionType.valueOf(cer.conditionType.toUpperCase()),
cer.conditionValue
);
} catch (ExtractorFactory.NoSuchExtractorException e) {
LOG.error("No such extractor type.", e);
throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
} catch (Extractor.ReservedFieldException e) {
LOG.error("Cannot create extractor. Field is reserved.", e);
throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
} catch (ConfigurationException e) {
LOG.error("Cannot create extractor. Missing configuration.", e);
throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
}
Input mongoInput = inputService.find(input.getPersistId());
try {
inputService.addExtractor(mongoInput, extractor);
} catch (ValidationException e) {
LOG.error("Extractor persist validation failed.", e);
throw new WebApplicationException(e, Response.Status.BAD_REQUEST);