Package org.jtalks.jcommune.model.entity

Examples of org.jtalks.jcommune.model.entity.Post


        Topic topic = new Topic(user, "title");
        topic.setBranch(branch);
        topic.setId(TOPIC_ID);

        post = new Post(user, POST_CONTENT);
        post.setId(POST_ID);
        post.setTopic(topic);
        topic.getPosts().addAll(asList(post));

        when(postService.get(POST_ID)).thenReturn(post);
View Full Code Here


     * @throws NotFoundException when post was not found
     */
    @RequestMapping(method = RequestMethod.DELETE, value = "/posts/{postId}")
    public ModelAndView delete(@PathVariable(POST_ID) Long postId)
            throws NotFoundException {
        Post post = this.postService.get(postId);
        Post nextPost = post.getTopic().getNeighborPost(post);
        deletePostWithLockHandling(postId);
        return new ModelAndView("redirect:/posts/" + nextPost.getId());
    }
View Full Code Here

    }

    private Topic deletePostWithLockHandling(Long postId) throws NotFoundException {
        for (int i = 0; i < UserController.LOGIN_TRIES_AFTER_LOCK; i++) {
            try {
                Post post = postService.get(postId);
        postService.deletePost(post);
                return post.getTopic();
            } catch (HibernateOptimisticLockingFailureException e) {
            }
        }
        try {
            Post post = postService.get(postId);
            postService.deletePost(post);
            return post.getTopic();
        } catch (HibernateOptimisticLockingFailureException e) {
            LOGGER.error("User has been optimistically locked and can't be reread {} times. Username: {}",
                    UserController.LOGIN_TRIES_AFTER_LOCK, userService.getCurrentUser().getUsername());
            throw e;
        }
View Full Code Here

     * @return redirect to post form page
     * @throws NotFoundException when topic or post not found
     */
    @RequestMapping(value = "/posts/{postId}/edit", method = RequestMethod.GET)
    public ModelAndView editPage(@PathVariable(POST_ID) Long postId) throws NotFoundException {
        Post post = postService.get(postId);
        return new ModelAndView("topic/editPost")
                .addObject(POST_DTO, PostDto.getDtoFor(post))
                .addObject(TOPIC_ID, post.getTopic().getId())
                .addObject(POST_ID, postId)
                .addObject(TOPIC_TITLE, post.getTopic().getTitle())
                .addObject("breadcrumbList", breadcrumbBuilder.getForumBreadcrumb(post.getTopic()));
    }
View Full Code Here

     * @throws NotFoundException when topic, branch or post not found
     */
    @RequestMapping(value = "/posts/{postId}/edit", method = RequestMethod.POST)
    public ModelAndView update(@Valid @ModelAttribute PostDto postDto, BindingResult result,
                               @PathVariable(POST_ID) Long postId) throws NotFoundException {
        Post post = postService.get(postId);
        if (result.hasErrors()) {
            return new ModelAndView("topic/editPost")
                    .addObject(TOPIC_ID, post.getTopic().getId())
                    .addObject(POST_ID, postId);
        }
        postService.updatePost(post, postDto.getBodyText());
        return new ModelAndView("redirect:/posts/" + postId);
    }
View Full Code Here

     */
    @RequestMapping(method = RequestMethod.POST, value = "/posts/{postId}/quote")
    @ResponseBody
    public JsonResponse getQuote(@PathVariable(POST_ID) Long postId,
                                 @RequestParam("selection") String selection) throws NotFoundException {
        Post source = postService.get(postId);
        String content = StringUtils.defaultString(selection, source.getPostContent());
        return new JsonResponse(JsonResponseStatus.SUCCESS, bbCodeService.quote(content, source.getUserCreated()));
    }
View Full Code Here

        topic = new Topic(user, "Topic Name");
        topic.setId(ID);
        branch.addTopic(topic);

        post = new Post(user, "");
        topic.addPost(post);
        post.setId(ID);
    }
View Full Code Here

        assertTrue(extractedUserNames.contains("\\yak"), "\\yak is mentioned, so he should be extracted.");
    }

    @Test
    public void notifyNewlyShouldSendEmailForNewlyMentionedUsers() {
        Post mentioningPost = getPost(1L, "In this text we have 3 user mentioning: first [user]Shogun[/user]");
        when(userDao.getByUsernames(asSet("Shogun"))).thenReturn(asList(getJCUser("Shogun", true)));

        MentionedUsers mentionedUsers = MentionedUsers.parse(mentioningPost);
        List<JCUser> notifiedUsers = mentionedUsers.getNewUsersToNotify(userDao);
        assertEquals(notifiedUsers.get(0).getUsername(), "Shogun");
View Full Code Here

     * When a user was notified about him being mentioned in a post, the post should change [user] bb code to
     * [user notified=true] in order not to notify him again.
     */
    @Test
    public void notifyNewlyMentionedUsersShouldMarkBbAsNotified() {
        Post mentioningPost = getPost(1L, "text [user]Shogun[/user]text");
        when(userDao.getByUsernames(asSet("Shogun"))).thenReturn(asList(getJCUser("Shogun", true)));

        MentionedUsers.parse(mentioningPost).markUsersAsAlreadyNotified(postDao);

        assertEquals(mentioningPost.getPostContent(), "text [user notified=true]Shogun[/user]text",
                "After sending email [user][/user] tag should be changed to [user notified=true][/user]");
        verify(postDao).saveOrUpdate(mentioningPost);
    }
View Full Code Here

        verify(postDao).saveOrUpdate(mentioningPost);
    }

    @Test
    public void notifyNewlyMentionedUsersShouldNotNotifyNotAgreedWithNotificationsUsers() {
        Post mentioningPost = getPost(1L, "[user]Shogun[/user]");
        JCUser mentionedUser = getJCUser("Shogun", false);
        when(userDao.getByUsernames(asSet("Shogun"))).thenReturn(asList(mentionedUser));

        List<JCUser> usersToNotify = MentionedUsers.parse(mentioningPost).getNewUsersToNotify(userDao);

        assertEquals(mentioningPost.getPostContent(), "[user]Shogun[/user]",
                "After sending email [user][/user] tag shouldn't be changed");
        assertTrue(usersToNotify.isEmpty());
        verify(postDao, never()).saveOrUpdate(mentioningPost);
    }
View Full Code Here

TOP

Related Classes of org.jtalks.jcommune.model.entity.Post

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.