use of org.springframework.transaction.UnexpectedRollbackException in project vboard by voyages-sncf-technologies.
the class CommentsController method addComment.
@RequestMapping(value = "", method = RequestMethod.POST)
@ResponseBody
@Valid
public Comment addComment(@Valid @RequestBody CommentParams params) {
String author = params.getAuthor();
String pinId = params.getPinId();
String text = params.getText();
DateTime postDateUTC = new DateTime(DateTimeZone.UTC);
Comment comment = new Comment(pinId, author, text, postDateUTC);
// Check if the author given is the same as the session user (the author param could be deleted and replaced with the session one)
permission.ensureNewEntityAuthorMatchesSessionUser(author);
try {
this.logger.debug("addComment: author={} - pin={} -text={}", author, pinId, text);
this.commentDAO.save(comment);
Pin pin = this.pinDAO.findByPinId(pinId);
if (pin != null) {
pin.increaseCommentsNumber();
this.pinDAO.save(pin);
}
// Increase the number of comments for the given pin in elasticsearch
this.elsClient.addComment(comment.getPinId());
// Update the stats (for the user, and for the author of the pin where the comment has been added)
this.gamification.updateStats(permission.getSessionUserWithSyncFromDB());
if (pin != null && User.getEmailFromString(pin.getAuthor()).isPresent()) {
User userAuthor = this.userDAO.findByEmail(User.getEmailFromString(pin.getAuthor()).get());
if (userAuthor != null && userAuthor != permission.getSessionUserWithSyncFromDB()) {
this.gamification.updateStats(userAuthor);
}
}
} catch (UnexpectedRollbackException e) {
throw new VBoardException(e.getMessage(), e.getMostSpecificCause());
}
// Send comment notifications
notifications.addNotificationsFromComment(pinId);
return comment;
}
use of org.springframework.transaction.UnexpectedRollbackException in project vboard by voyages-sncf-technologies.
the class CommentsController method addCommentFromVblog.
// Comments posted from VBlog (wordpress)
@RequestMapping(value = "/vblog", method = RequestMethod.POST, consumes = { "application/x-www-form-urlencoded" })
@ResponseBody
@Valid
public Comment addCommentFromVblog(@RequestParam("text") final String text, @RequestParam("pinId") String pinId, @RequestParam("author") String author, @RequestParam("ID") final String ID, HttpServletRequest request) {
Comment comment = this.commentDAO.findById("vblog-" + ID);
// Should restrict the host name from wordpress (vblog)
/*if (!request.getRemoteHost().equals(hostName.getHostName())) {
throw new VBoardException("Unknown web site - The hostname that is using this method is not authorized: hostname: " + request.getRemoteHost());
}*/
User user = this.userDAO.findByEmail(author);
if (user != null) {
author = user.getUserString();
}
if (comment == null) {
DateTime postDateUTC = new DateTime(DateTimeZone.UTC);
comment = new Comment("vblog-" + ID, "vblog-" + pinId, author, text, postDateUTC.toString());
Pin pin = this.pinDAO.findByPinId("vblog-" + pinId);
if (pin != null) {
pin.increaseCommentsNumber();
this.pinDAO.save(pin);
if (User.getEmailFromString(pin.getAuthor()).isPresent()) {
User userAuthor = this.userDAO.findByEmail(User.getEmailFromString(pin.getAuthor()).get());
if (userAuthor != null && userAuthor != permission.getSessionUserWithSyncFromDB()) {
// Update the pin's author stats
this.gamification.updateStats(userAuthor);
}
}
}
} else {
comment.setText(text);
comment.setAuthor(author);
}
try {
this.logger.debug("addComment: author={} - pin={} -text={}", author, "vblog-" + pinId, text);
this.commentDAO.save(comment);
// Increase the number of comments for the given pin in elasticsearch
this.elsClient.addComment(comment.getPinId());
// Send comment notifications
notifications.addNotificationsFromComment(comment.getPinId());
} catch (UnexpectedRollbackException e) {
throw new VBoardException(e.getMessage(), e.getMostSpecificCause());
}
if (user != null) {
// Update the user's stats
this.gamification.updateStats(user);
}
return comment;
}
use of org.springframework.transaction.UnexpectedRollbackException in project vboard by voyages-sncf-technologies.
the class GamificationController method trackConnection.
// Add a new connexion to the user's stats
@RequestMapping(value = "/connexion", method = RequestMethod.POST)
@ResponseBody
@Valid
public int trackConnection() {
final User user = permission.getSessionUserWithSyncFromDB();
Stats stats = this.statsDAO.findByEmail(user.getEmail());
// If the user has no stats yet, a new one is created
if (stats == null) {
stats = new Stats(user.getEmail(), user.getTeam());
}
// Get the last stat connexion
DateTime lastConnexion = new DateTime(DateTimeZone.UTC);
String date = stats.getLastConnexion();
if (date == null) {
// Used for version compatibility (new stats should get a default one)
stats.setLastConnexion(new DateTime(DateTimeZone.UTC).toString());
} else {
try {
lastConnexion = new DateTime(date);
}// NOPMD
catch (IllegalArgumentException e) {
}
}
// Gamification connexion can only be increased once a day.
if (lastConnexion.plusDays(1).isBeforeNow()) {
// Update all the stats before
stats = this.getStats(user);
stats.setLastConnexion(new DateTime(DateTimeZone.UTC).toString());
// If the connexion level increased enough for the user to get a badge, a notification is sent.
if (gamification.getLevel(stats.getConnexionNumber() * CONNEXIONS_WEIGHT) < gamification.getLevel((stats.getConnexionNumber() + 1) * CONNEXIONS_WEIGHT) && gamification.levels().contains(gamification.getLevel((stats.getConnexionNumber() + 1) * CONNEXIONS_WEIGHT))) {
notifications.addNotificationsFromBadges(user, "\"Lecteur " + gamification.badgesMessageUser(gamification.getLevel((stats.getConnexionNumber() + 1) * CONNEXIONS_WEIGHT)) + "\"");
}
stats.incrementConnexionNumber();
}
try {
this.statsDAO.save(stats);
this.logger.debug("Connexion: User: {}, connexion number: {}", user.getNiceName(), stats.getConnexionNumber());
} catch (UnexpectedRollbackException e) {
throw new VBoardException(e.getMessage(), e.getMostSpecificCause());
}
return stats.getConnexionNumber();
}
use of org.springframework.transaction.UnexpectedRollbackException in project vboard by voyages-sncf-technologies.
the class UsersController method addNewUser.
@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
User addNewUser(@Valid @RequestBody UserParams params) {
final String email = params.getEmail();
final String firstName = params.getFirst_name();
final String lastName = params.getLast_name();
final User newUser = new User(email, firstName, lastName);
try {
this.logger.debug("addNewUser: email={} - first_name={} - last_name={}", email, firstName, lastName);
return this.userDAO.save(newUser);
} catch (UnexpectedRollbackException e) {
throw new VBoardException(e.getMessage(), e.getMostSpecificCause());
}
}
use of org.springframework.transaction.UnexpectedRollbackException in project spring-data-commons by spring-projects.
the class ChainedTransactionManager method rollback.
/*
* (non-Javadoc)
* @see org.springframework.transaction.PlatformTransactionManager#rollback(org.springframework.transaction.TransactionStatus)
*/
public void rollback(TransactionStatus status) throws TransactionException {
Exception rollbackException = null;
PlatformTransactionManager rollbackExceptionTransactionManager = null;
MultiTransactionStatus multiTransactionStatus = (MultiTransactionStatus) status;
for (PlatformTransactionManager transactionManager : reverse(transactionManagers)) {
try {
multiTransactionStatus.rollback(transactionManager);
} catch (Exception ex) {
if (rollbackException == null) {
rollbackException = ex;
rollbackExceptionTransactionManager = transactionManager;
} else {
LOGGER.warn("Rollback exception (" + transactionManager + ") " + ex.getMessage(), ex);
}
}
}
if (multiTransactionStatus.isNewSynchonization()) {
synchronizationManager.clearSynchronization();
}
if (rollbackException != null) {
throw new UnexpectedRollbackException("Rollback exception, originated at (" + rollbackExceptionTransactionManager + ") " + rollbackException.getMessage(), rollbackException);
}
}
Aggregations