use of org.springframework.transaction.UnexpectedRollbackException in project vboard by voyages-sncf-technologies.
the class CommentsController method removeComment.
@RequestMapping(value = "", method = RequestMethod.DELETE)
@ResponseBody
@Valid
public Comment removeComment(@RequestParam(value = "id") String id) {
Comment comment;
try {
comment = this.commentDAO.findById(id);
if (comment != null) {
// Check if the user can update this comment (or throw an exception)
permission.ensureUserHasRightsToAlterPin(comment.getAuthor());
this.commentDAO.delete(comment);
String pinId = comment.getPinId();
Pin pin = this.pinDAO.findByPinId(pinId);
if (pin != null) {
pin.decreaseCommentsNumber();
this.pinDAO.save(pin);
}
// Decrease the number of comments for the given pin in elasticsearch
this.elsClient.removeComment(pinId);
this.logger.debug("deleteComment: id={}", id);
// Update the stats
this.gamification.updateStats(permission.getSessionUserWithSyncFromDB());
} else {
throw new VBoardException("Comment does not exist or already deleted");
}
} catch (UnexpectedRollbackException e) {
throw new VBoardException(e.getMessage(), e.getMostSpecificCause());
}
return comment;
}
use of org.springframework.transaction.UnexpectedRollbackException in project vboard by voyages-sncf-technologies.
the class MessagesController method hideMessage.
@RequestMapping(value = "/remove", method = RequestMethod.POST)
@ResponseBody
@Valid
public Message hideMessage() {
permission.ensureCurrentUserIsAdmin();
Message previousMessage = this.messageDAO.findByActive(true);
try {
if (previousMessage != null) {
previousMessage.setActive(false);
this.messageDAO.save(previousMessage);
}
} catch (UnexpectedRollbackException e) {
throw new VBoardException(e.getMessage(), e.getMostSpecificCause());
}
return previousMessage;
}
use of org.springframework.transaction.UnexpectedRollbackException in project vboard by voyages-sncf-technologies.
the class MessagesController method addMessage.
// Add a new displayable message
@RequestMapping(value = "", method = RequestMethod.POST)
@ResponseBody
@Valid
public Message addMessage(@Valid @RequestBody MessageParams params) {
final String content = params.getContent();
final String type = params.getType();
permission.ensureCurrentUserIsAdmin();
final Message message = new Message(type, content);
try {
this.logger.debug("addMessage: author={} - type={} -content={}", permission.getSessionUser().getUserString(), type, content);
// Find the previous active message (if one if found)
final Message previousMessage = this.messageDAO.findByActive(true);
if (previousMessage != null) {
// Deactivate the previous active message
previousMessage.setActive(false);
this.messageDAO.save(previousMessage);
}
this.messageDAO.save(message);
} catch (UnexpectedRollbackException e) {
throw new VBoardException(e.getMessage(), e.getMostSpecificCause());
}
return message;
}
use of org.springframework.transaction.UnexpectedRollbackException in project vboard by voyages-sncf-technologies.
the class PinsController method addNewPin.
@RequestMapping(value = "", method = RequestMethod.POST)
@ResponseBody
@Valid
public // Parsing the params in the JSON body requires using a dedicated @RequestBody annotated class instead of simple @RequestParam arguments
Pin addNewPin(@Valid @RequestBody AddNewPinParams params) {
Pin retval;
// Save
String title = params.getTitle();
String url = params.getUrl();
String imgType = params.getImgType();
String description = params.getDescription();
String[] labels = params.getLabels();
String strLabels = labels == null || labels.length == 0 ? "" : String.join(",", labels);
String author = params.getAuthor();
// Check if the author given is effectively the one that posted the pin
permission.ensureNewEntityAuthorMatchesSessionUser(author);
DateTime postDateUTC = new DateTime(DateTimeZone.UTC);
Pin newPin = new Pin(title, url, 0, imgType, strLabels, description, author, postDateUTC);
// If the media is an image (!<iframe) and is a base64image (custom) (version compatibility) the image points out on its localisation (relative url)
if (this.isMediaBase64Image(imgType)) {
String nasURL = "/pinImg/" + newPin.getPinId() + ".png";
newPin.setImgType(nasURL);
}
// If the media is a video, the content is set as it is
if (this.isMediaVideo(imgType)) {
newPin.setImgType(imgType);
}
try {
this.logger.debug("addNewPin: title={} - url={} - likes=0 - imgType={} - description={} - labels={} - author={}", title, url, newPin.getImgType(), description, strLabels, author);
retval = this.pinDAO.save(newPin);
this.elsClient.addPin(newPin);
// If the image given is not a video (iframe) and exists, the image is saved (if not url, see inside the method) in the NAS
if (this.isMediaBase64Image(params.getImgType()) || this.isMediaInternetImage(params.getImgType())) {
uploadsManager.savePinImage(params.getImgType(), retval.getPinId());
}
// Update the stats
this.gamification.updateStats(permission.getSessionUserWithSyncFromDB());
} catch (UnexpectedRollbackException e) {
throw new VBoardException(e.getMessage(), e.getMostSpecificCause());
}
// Send a notification
this.notifications.addNotificationsFromPin(newPin.getPinId(), "a ajouté une épingle avec un label que vous suivez");
// Add the new labels in the list of labels
if (!isBlank(strLabels)) {
List<String> pinLabels = Arrays.asList(strLabels.split(","));
pinLabels.forEach(l -> this.labelDAO.save(new Label(l)));
}
return retval;
}
use of org.springframework.transaction.UnexpectedRollbackException in project vboard by voyages-sncf-technologies.
the class PinsController method addNewPinVblog.
// Post pins from Vblog (wordpress) (see previous method)
@RequestMapping(value = "/vblog", method = RequestMethod.POST, consumes = { "application/x-www-form-urlencoded" })
@ResponseBody
@Valid
public Pin addNewPinVblog(@RequestParam("title") final String title, @RequestParam("url") final String url, @RequestParam("imgType") String imgType, @RequestParam("description") final String description, @RequestParam("labels") String labels, @RequestParam("author") String author, @RequestParam("ID") final String ID) {
// TODO only authorize wordpress (vblog) to access that url/method
if (!this.isMediaInternetImage(imgType)) {
imgType = null;
}
if (!isBlank(labels)) {
labels = "#" + labels;
}
User user = this.userDAO.findByEmail(author);
if (user != null) {
author = user.getUserString();
}
Pin pin = this.pinDAO.findByPinId("vblog-" + ID);
if (pin == null) {
DateTime postDateUTC = new DateTime(DateTimeZone.UTC);
pin = new Pin("vblog-" + ID, title, url, 0, imgType, labels, description, author, postDateUTC);
} else {
pin.setPinTitle(title);
pin.setHrefUrl(url);
pin.setImgType(imgType);
pin.setLabels(labels);
pin.setIndexableTextContent(description);
pin.setAuthor(author);
}
try {
this.logger.debug("addNewPinVblog: pinId= vblog-{} title={} - url={} - likes=0 - imgType={} - description={} - labels={} - author={}", ID, title, url, imgType, description, labels, author);
pin = this.pinDAO.save(pin);
this.elsClient.updatePin(pin);
} catch (UnexpectedRollbackException e) {
throw new VBoardException(e.getMessage(), e.getMostSpecificCause());
}
// Add the new labels in the list of labels
if (!isBlank(labels)) {
List<String> pinLabels = Arrays.asList(labels.split(","));
pinLabels.forEach(l -> this.labelDAO.save(new Label(l)));
}
if (this.isMediaInternetImage(imgType)) {
uploadsManager.savePinImage(imgType, pin.getPinId());
}
if (user != null) {
this.gamification.updateStats(user);
}
return pin;
}
Aggregations