model.addAttribute("errorMessage", "Invalid thought ID.");
model.addAttribute("thoughs", dataService.getAllThought());
return "home";
}
Thought thought = dataService.getThought(id);
if (thought == null) {
model.addAttribute("errorMessage", String.format("Nothing to update. Thought with ID %s not found.", id));
model.addAttribute("thoughs", dataService.getAllThought());
return "home";
}
if (isEmpty(contentType) || isEmpty(name) || isEmpty(userThought)) {
model.addAttribute("errorMessage", "Name, your thoughts and a picture are required.");
return show("write");
}
String encodedIcon = null;
if (image != null) {
encodedIcon = Base64.encodeBase64String(image);
}
if (isEmpty(encodedIcon) && thought.getThumbnail() == null) {
model.addAttribute("errorMessage", "Name, your thoughts and a picture are required.");
return show("write");
}
Person owner = thought.getOwner();
if (!owner.getName().equals(name)) {
owner.setName(name);
dataService.updatePerson(owner);
}
thought.setThought(new Text(userThought));
thought.setOwner(owner);
if (StringUtils.isNotEmpty(encodedIcon)) {
thought.setThumbnail(new Text(String.format("data:%s;base64,%s", contentType, encodedIcon)));
}
dataService.updateThought(thought);
model.addAttribute("successMessage", "Thought updated successfully.");