Package com.apress.progwt.client.domain

Examples of com.apress.progwt.client.domain.ForumPost


            return schoolDAO.getUserThreads(user.getId(), start, max);
        } else if (forumTopic instanceof School) {
            School school = (School) forumTopic;
            return schoolDAO.getSchoolThreads(school.getId(), start, max);
        } else if (forumTopic instanceof ForumPost) {
            ForumPost post = (ForumPost) forumTopic;
            return schoolDAO.getPostsForThread(post, start, max);
        } else if (forumTopic instanceof RecentForumPostTopic) {
            return schoolDAO.getRecentForumPosts(start, max);
        } else {
            throw new RuntimeException("Unknown forumTopic: "
View Full Code Here


            if (obj instanceof School) {
                School sch = (School) obj;
                res.getSchools().add(sch);
            }
            if (obj instanceof ForumPost) {
                ForumPost fp = (ForumPost) obj;
                res.getForumPosts().add(fp);
            }
            log.debug("Found: " + res);
        }
    }
View Full Code Here

     * @param text
     */
    public void create(User author, String title, String text) {
        // ForumPost p = new ForumPost()

        ForumPost sfp = null;

        Log.debug("Create! " + originalTopic + " cur " + currentTopic);

        // originalTopic should be a School or User, currentTopic
        // shouldn't be null unless load hasn't completed.
View Full Code Here

        currentCommand = fc;
        if (fc.getType().equals("School")) {
            School s = new School(fc.getId());
            gotoSchool(s, fc.getStart(), fc.isCreate());
        } else if (fc.getType().equals("SchoolForumPost")) {
            ForumPost fp = new SchoolForumPost();
            fp.setId(fc.getId());
            gotoThread(fp, fc.getStart(), fc.isCreate());
        } else if (fc.getType().equals("User")) {
            User u = new User();
            u.setId(fc.getId());
            gotoUser(u, fc.getStart(), fc.isCreate());
        } else if (fc.getType().equals("UserForumPost")) {
            ForumPost fp = new UserForumPost();
            fp.setId(fc.getId());
            gotoThread(fp, fc.getStart(), fc.isCreate());
        } else if (fc.getType().equals("RecentForumPost")) {
            gotoForum(new RecentForumPostTopic(), fc.getStart(), false,
                    FORUM_THREAD_MAX, fc.isCreate());
        } else {
View Full Code Here

                assertNotNull(sc);

                User currentUser = getUser();
                assertNotNull(currentUser);

                ForumPost fp = new SchoolForumPost(sc, currentUser,
                        TITLE, TEXT, null);

                schoolService.executeAndSaveCommand(
                        new SaveForumPostCommand(fp), false);
            }
View Full Code Here

        assertNotNull(sc);

        User currentUser = getUser();
        assertNotNull(currentUser);

        ForumPost fp = new SchoolForumPost(sc, currentUser, TITLE, TEXT,
                null);

        executeWithToken(new SaveForumPostCommand(fp), false);

        PostsList posts = schoolService.getForum(sc, 0, 10);

        assertEquals(1, posts.getTotalCount());
        assertEquals(1, posts.getPosts().size());

        ForumPost saved = posts.getPosts().get(0);
        assertNotNull(saved);
        assertEquals(SchoolForumPost.class, saved.getClass());
        assertTrue(saved.getId() > 0);
        assertEquals(TITLE, saved.getPostTitle());
        assertEquals(TEXT, saved.getPostString());
        assertEquals(0, saved.getReplyCount());

        assertEquals(null, saved.getThreadPost());

        assertEquals(currentUser, saved.getAuthor());

        // save a second post to the same thread
        ForumPost fp2 = new SchoolForumPost(sc, currentUser, TITLE, TEXT,
                saved);
        executeWithToken(new SaveForumPostCommand(fp2), false);

        // assert that there's still just 1 top level thread
        posts = schoolService.getForum(sc, 0, 10);
        assertEquals(1, posts.getTotalCount());
        assertEquals(1, posts.getPosts().size());

        // relies on setting the inverse side of the association for
        // testing
        assertEquals(1, posts.getPosts().get(0).getReplyCount());
        assertEquals(1, saved.getReplyCount());

        // get the posts in this thread
        posts = schoolService.getForum(saved, 0, 10);
        assertEquals(2, posts.getTotalCount());
        assertEquals(2, posts.getPosts().size());

        ForumPost saved1 = posts.getPosts().get(0);
        assertEquals(saved, saved1);
        ForumPost saved2 = posts.getPosts().get(1);
        assertNotNull(saved2);
        assertEquals(SchoolForumPost.class, saved2.getClass());
        assertTrue(saved2.getId() > 0);
        assertEquals(TITLE, saved2.getPostTitle());
        assertEquals(TEXT, saved2.getPostString());

        assertEquals(saved1, saved2.getThreadPost());
        assertEquals(currentUser, saved2.getAuthor());

    }
View Full Code Here

        commandService.assertUserIsAuthenticated(author);

        ForumTopic loadedTopic = commandService.get(forumPost
                .getTopicClass(), topicID);
        ForumPost threadP = commandService.get(ForumPost.class, threadID);

        Log.debug("SaveForumPostCommand" + toString());

        toSave = commandService.get(ForumPost.class, forumPost.getId());

        // if it's a new creation, just use the one we wanted to save
        if (toSave == null) {
            toSave = forumPost;
        } else {
            // Post edit. Assert that this post is actually ours to edit
            commandService.assertUserIsAuthenticated(toSave.getAuthor());
        }

        toSave.setAuthor(author);
        toSave.setTopic(loadedTopic);
        toSave.setThreadPost(threadP);

        toSave.setDate(forumPost.getDate());
        toSave.setPostString(commandService.filterHTML(forumPost
                .getPostString()));
        toSave.setPostTitle(commandService.filterHTML(forumPost
                .getPostTitle()));

        // update the inverse side of the relationship
        if (threadP != null) {
            threadP.getReplies().add(toSave);
        }

        commandService.save(toSave);

    }
View Full Code Here

        User u = userDAO.getUserByUsername("test");
        assertNotNull(u);

        // Create a first thread for this school
        ForumPost post = new SchoolForumPost(sc, u, A, A, null);
        post = (ForumPost) schoolDAO.save(post);

        threads = schoolDAO.getSchoolThreads(sc.getId(), 0, 10);
        assertEquals(1, threads.getTotalCount());
        assertEquals(1, threads.getPosts().size());

        ForumPost saved = threads.getPosts().get(0);
        assertNotNull(saved.getDate());
        assertEquals(sc, saved.getTopic());

        // save a second post in the same thread
        ForumPost post2 = new SchoolForumPost(sc, u, null, A, saved);
        post2 = (ForumPost) schoolDAO.save(post2);

        // should only be 1 top level thread still.
        threads = schoolDAO.getSchoolThreads(sc.getId(), 0, 10);
        assertEquals(1, threads.getTotalCount());
View Full Code Here

        User au = new User();
        au.setId(77);
        au.setUsername("Author");

        ForumPost fp = new SchoolForumPost(sc, au, TITLE, TEXT, null);

        SaveForumPostCommand command = new SaveForumPostCommand(fp);

        MockCommandService commandService = new MockCommandService(
                command);

        assertNull(command.getToSave());

        command.execute(commandService);

        ForumPost saved = command.getToSave();
        assertEquals(TITLE, saved.getPostTitle());
        assertEquals(TEXT, saved.getPostString());

        assertEquals(sc, saved.getTopic());
        assertEquals(au, saved.getAuthor());
        assertEquals(null, saved.getThreadPost());

    }
View Full Code Here

        User au = new User();
        au.setId(77);
        au.setUsername("Author");

        ForumPost fp = new SchoolForumPost(sc, au, TEXT_XSS, TEXT_XSS,
                null);

        SaveForumPostCommand command = new SaveForumPostCommand(fp);

        MockCommandService commandService = new MockCommandService(
                command);

        assertNull(command.getToSave());

        command.execute(commandService);

        ForumPost saved = command.getToSave();
        assertEquals(TEXT_XSS_C, saved.getPostTitle());
        assertEquals(TEXT_XSS_C, saved.getPostString());

        assertEquals(sc, saved.getTopic());
        assertEquals(au, saved.getAuthor());
        assertEquals(null, saved.getThreadPost());

    }
View Full Code Here

TOP

Related Classes of com.apress.progwt.client.domain.ForumPost

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.