@PathParam("id") Integer labelId,
@QueryParam("name") String labelName,
String requestJSONContent)
{
Mailbox mailbox = new Mailbox(user, domain);
Label label;
if (requestJSONContent.isEmpty())
{
// if request body is empty, use path param
label = new Label();
label.setName(labelName);
}
else
{
// deserialize request body to Label
try {
ObjectMapper mapper = new ObjectMapper();
label = mapper.readValue(requestJSONContent, Label.class);
} catch (Exception e) {
logger.info("Malformed JSON request: {}", e.getMessage());
throw new BadRequestException("Malformed JSON request");
}
if (label.getName() == null && labelName != null) {
label.setName(labelName);
}
}
label.setId(labelId);
try {
labelDAO.update(mailbox, label);
} catch (IllegalLabelException ile) {
throw new BadRequestException(ile.getMessage());