Node radio = null;
try {
radio = nodeService.byNodeId(radioId);
} catch (NodeNotFoundException e) {
LOG.error("Radio <{}> not found.", radioId);
throw new WebApplicationException(404);
}
if (radio == null) {
LOG.error("Radio <{}> not found.", radioId);
throw new WebApplicationException(404);
}
RegisterInputRequest rir;
try {
rir = objectMapper.readValue(body, RegisterInputRequest.class);
} catch(IOException e) {
LOG.error("Error while parsing JSON", e);
throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
}
Map<String, Object> inputData = Maps.newHashMap();
if (rir.inputId != null)
inputData.put("input_id", rir.inputId);
else
inputData.put("input_id", new ObjectId().toHexString());
inputData.put("title", rir.title);
inputData.put("type", rir.type);
inputData.put("creator_user_id", rir.creatorUserId);
inputData.put("configuration", rir.configuration);
inputData.put("created_at", Tools.iso8601());
inputData.put("radio_id", rir.radioId);
Input mongoInput = new InputImpl(inputData);
// Write to database.
String id;
try {
id = inputService.save(mongoInput);
} catch (ValidationException e) {
LOG.error("Validation error.", e);
throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
}
Map<String, Object> result = Maps.newHashMap();
result.put("persist_id", id);