Search in sources :

Example 6 with Comment

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;
}
Also used : Comment(com.vsct.vboard.models.Comment) User(com.vsct.vboard.models.User) VBoardException(com.vsct.vboard.models.VBoardException) Pin(com.vsct.vboard.models.Pin) UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException) DateTime(org.joda.time.DateTime) Valid(javax.validation.Valid)

Example 7 with 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()));
}
Also used : Comment(com.vsct.vboard.models.Comment) Pin(com.vsct.vboard.models.Pin) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Comment (com.vsct.vboard.models.Comment)7 Pin (com.vsct.vboard.models.Pin)6 DateTime (org.joda.time.DateTime)5 Valid (javax.validation.Valid)4 VBoardException (com.vsct.vboard.models.VBoardException)3 Test (org.junit.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 UnexpectedRollbackException (org.springframework.transaction.UnexpectedRollbackException)3 User (com.vsct.vboard.models.User)2 ArrayList (java.util.ArrayList)2