use of com.vsct.vboard.models.Comment 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 com.vsct.vboard.models.Comment in project vboard by voyages-sncf-technologies.
the class CommentControllerTest method getCommentsFromPin.
@Test
public void getCommentsFromPin() {
this.pinDAO.save(new Pin("0", "title", "", 0, "", "", "content", "auth", new DateTime()));
Pin pin = pinDAO.findAll().iterator().next();
Comment comment = new Comment("3", pin.getPinId(), "auth", "comment", new DateTime().toString());
ArrayList<Comment> listComment = new ArrayList<>();
listComment.add(comment);
this.commentDAO.save(comment);
this.commentDAO.save(new Comment("5", "2", "auth", "comment2", new DateTime().toString()));
this.commentDAO.save(new Comment("2", "3", "auth3", "comment2", new DateTime().toString()));
Assert.assertEquals(listComment.toString(), commentsController.getCommentsFromPin(pin.getPinId()));
}
Aggregations