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.
CreateStaticFieldRequest csfr;
try {
csfr = objectMapper.readValue(body, CreateStaticFieldRequest.class);
} catch(IOException e) {
LOG.error("Error while parsing JSON", e);
throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
}
// Check if key is a valid message key.
if (!Message.validKey(csfr.key)) {
LOG.error("Invalid key: [{}]", csfr.key);
throw new WebApplicationException(Response.Status.BAD_REQUEST);
}
if (csfr.key == null || csfr.value == null || csfr.key.isEmpty() || csfr.value.isEmpty()) {
LOG.error("Missing parameters. Returning HTTP 400.");
throw new WebApplicationException(Response.Status.BAD_REQUEST);
}
if (Message.RESERVED_FIELDS.contains(csfr.key) && !Message.RESERVED_SETTABLE_FIELDS.contains(csfr.key)) {
LOG.error("Cannot add static field. Field [{}] is reserved.", csfr.key);
throw new WebApplicationException(Response.Status.BAD_REQUEST);
}
input.addStaticField(csfr.key, csfr.value);
Input mongoInput = inputService.find(input.getPersistId());
try {
inputService.addStaticField(mongoInput, csfr.key, csfr.value);
} catch (ValidationException e) {
LOG.error("Static field persist validation failed.", e);
throw new WebApplicationException(e, Response.Status.BAD_REQUEST);