Search in sources :

Example 76 with Post

use of it.vige.rubia.model.Post in project rubia-forums by flashboss.

the class SplitTopic method splitPosts.

/**
 * This user interface action is spliting topic bh=y moving all selected by
 * user posts into newly created topic.
 *
 * @return the name of the operation
 */
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public String splitPosts() {
    // Checking whether topic has only one post, so it can't be splitted
    if (posts.size() == 1) {
        setWarnBundleMessage("ERR_SPLIT_ONE_POST_TOPIC");
        return "";
    }
    // Removing all not slected posts
    Iterator<Integer> selectIt = checkboxes.keySet().iterator();
    while (selectIt.hasNext()) {
        Boolean postFlag = checkboxes.get(selectIt.next());
        if (!postFlag.booleanValue()) {
            selectIt.remove();
        }
    }
    // Checking if user selected anything.
    if (checkboxes.size() == 0) {
        setWarnBundleMessage("ERR_NO_POST_SELECTED");
        return "";
    }
    // Checking if user didn't select all posts.
    if (checkboxes.size() == posts.size()) {
        setWarnBundleMessage("ERR_SPLIT_ALL");
        return "";
    }
    // Trying to get destination forum for new topic.
    String toForumId = getParameter(p_forum_to_id);
    if (toForumId == null || toForumId.trim().compareToIgnoreCase("-1") == 0 || toForumId.trim().length() == 0) {
        setWarnBundleMessage("ERR_DEST_FORUM");
        return "";
    }
    // Checking if user gave subject for new topic.
    if (newTopicTitle == null || newTopicTitle.trim().compareToIgnoreCase("-1") == 0 || newTopicTitle.trim().length() == 0) {
        setWarnBundleMessage("ERR_NO_SUBJECT_GIVEN");
        return "";
    }
    try {
        Forum destForum = forumsModule.findForumById(new Integer(toForumId));
        // Creating new topic in selected destination forum.
        Topic newTopic = forumsModule.createTopic(destForum, getUser(userModule).getId().toString(), newTopicTitle, topic.getType());
        // Moving all selected posts to new topic.
        selectIt = checkboxes.keySet().iterator();
        Post movedPost = null;
        List<Post> postsToRemove = new ArrayList<Post>();
        while (selectIt.hasNext()) {
            movedPost = forumsModule.findPostById(selectIt.next());
            movedPost.setTopic(newTopic);
            forumsModule.update(movedPost);
            postsToRemove.add(movedPost);
        }
        Forum fromForum = topic.getForum();
        topic.setReplies(topic.getReplies() - checkboxes.size());
        fromForum.setPostCount(fromForum.getPostCount() - checkboxes.size());
        posts.removeAll(postsToRemove);
        topic.setLastPostDate(posts.get(posts.size() - 1).getCreateDate());
        newTopic.setReplies(checkboxes.size() - 1);
        List<Post> postsNewTopic = forumsModule.findPostsByTopicId(newTopic);
        newTopic.setLastPostDate(postsNewTopic.get(postsNewTopic.size() - 1).getCreateDate());
        destForum.addTopicSize();
        destForum.setPostCount(destForum.getPostCount() + newTopic.getReplies() + 1);
        forumsModule.update(topic);
        forumsModule.update(newTopic);
        forumsModule.update(fromForum);
        forumsModule.update(destForum);
    } catch (Exception e) {
        log.error(e);
        setWarnBundleMessage("ERR_INTERNAL");
        return "";
    }
    // Setting message that everything went smooth.
    setInfoBundleMessage("SUCC_TOPIC_SPLITTED");
    return "";
}
Also used : Post(it.vige.rubia.model.Post) ArrayList(java.util.ArrayList) Topic(it.vige.rubia.model.Topic) ModuleException(it.vige.rubia.ModuleException) Forum(it.vige.rubia.model.Forum) SecureActionForum(it.vige.rubia.auth.SecureActionForum) Interceptors(javax.interceptor.Interceptors) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 77 with Post

use of it.vige.rubia.model.Post in project rubia-forums by flashboss.

the class OperationPostTest method setUp.

@BeforeClass
public static void setUp() {
    driver.get(HOME_URL);
    String message = createCategory(driver, new Category("First Test Category"));
    assertTrue(message.equals(CREATED_CATEGORY_1_MESSAGE));
    message = createCategory(driver, new Category("Second Test Category"));
    assertTrue(message.equals(CREATED_CATEGORY_2_MESSAGE));
    message = createForum(driver, new Forum("First Test Forum", "First Test Description", new Category("First Test Category")));
    assertTrue(message.equals(CREATED_FORUM_0_MESSAGE));
    message = createTopic(driver, new Topic(new Forum("First Test Forum"), "First Test Topic", asList(new Post[] { new Post("First Test Body", asList(new Attachment("first", "First Test File"), new Attachment("second", "Second Test File"), new Attachment("third", "Third Test File"))) }), NORMAL, new Poll("First Test Question", asList(new PollOption[] { new PollOption("First Test Answer"), new PollOption("Second Test Answer") }), 4)));
    assertTrue(message.equals("First Test Topic"));
    message = createPost(driver, new Post(new Topic(new Forum("First Test Forum"), "First Test Topic"), "First Test Post", asList(new Attachment("first", "First Test File"), new Attachment("second", "Second Test File"), new Attachment("third", "Third Test File"))));
    assertTrue(message.equals("First Test Post"));
    message = createPost(driver, new Post(new Topic(new Forum("First Test Forum"), "First Test Topic"), "Second Test Post", asList(new Attachment("first", "First Test File"), new Attachment("second", "Second Test File"), new Attachment("third", "Third Test File"))));
    assertTrue(message.equals("Second Test Post"));
    message = createPost(driver, new Post(new Topic(new Forum("First Test Forum"), "First Test Topic"), "Third Test Post", asList(new Attachment("first", "First Test File"), new Attachment("second", "Second Test File"), new Attachment("third", "Third Test File"))));
    assertTrue(message.equals("Third Test Post"));
    message = createPost(driver, new Post(new Topic(new Forum("First Test Forum"), "First Test Topic"), "Fourth Test Post", asList(new Attachment("first", "First Test File"), new Attachment("second", "Second Test File"), new Attachment("third", "Third Test File"))));
    assertTrue(message.equals("Fourth Test Post"));
    message = createTopic(driver, new Topic(new Forum("First Test Forum"), "Second Test Topic", asList(new Post[] { new Post("Second Test Body", asList(new Attachment("first", "First Test File"), new Attachment("second", "Second Test File"), new Attachment("third", "Third Test File"))) }), IMPORTANT, new Poll("Second Test Question", asList(new PollOption[] { new PollOption("Third Test Answer"), new PollOption("Fourth Test Answer") }), 8)));
    assertTrue(message.equals("Second Test Topic"));
    message = createPost(driver, new Post(new Topic(new Forum("First Test Forum"), "Second Test Topic"), "Fifth Test with Truncation over 25 characters Post", asList(new Attachment("first", "First Test File"), new Attachment("second", "Second Test File"), new Attachment("third", "Third Test File"))));
    assertTrue(message.equals("Fifth Test with Truncation over 25 characters Post"));
    message = createPost(driver, new Post(new Topic(new Forum("First Test Forum"), "Second Test Topic"), "Sixth Test Post", asList(new Attachment("first", "First Test File"), new Attachment("second", "Second Test File"), new Attachment("third", "Third Test File"))));
    assertTrue(message.equals("Sixth Test Post"));
    message = createPost(driver, new Post(new Topic(new Forum("First Test Forum"), "Second Test Topic"), "Seventh Test Post", asList(new Attachment("first", "First Test File"), new Attachment("second", "Second Test File"), new Attachment("third", "Third Test File"))));
    assertTrue(message.equals("Seventh Test Post"));
    message = createForum(driver, new Forum("Second Test Forum", "Second Test Description", new Category("First Test Category")));
    assertTrue(message.equals(CREATED_FORUM_1_MESSAGE));
    message = createTopic(driver, new Topic(new Forum("Second Test Forum"), "Third Test Topic", asList(new Post[] { new Post("Third Test Body", asList(new Attachment("first", "First Test File"), new Attachment("second", "Second Test File"), new Attachment("third", "Third Test File"))) }), ADVICE, new Poll("Third Test Question", asList(new PollOption[] { new PollOption("Fifth Test with Truncation over 25 characters Answer"), new PollOption("Sixth Test Answer") }), 9)));
    assertTrue(message.equals("Third Test Topic"));
    message = createPost(driver, new Post(new Topic(new Forum("Second Test Forum"), "Third Test Topic"), "Eight Test Post", asList(new Attachment("first", "First Test File"), new Attachment("second", "Second Test File"), new Attachment("third", "Third Test File"))));
    assertTrue(message.equals("Eight Test Post"));
    message = createPost(driver, new Post(new Topic(new Forum("Second Test Forum"), "Third Test Topic"), "Ninth Test Post", asList(new Attachment("first", "First Test File"), new Attachment("second", "Second Test File"), new Attachment("third", "Third Test File"))));
    assertTrue(message.equals("Ninth Test Post"));
    message = createTopic(driver, new Topic(new Forum("Second Test Forum"), "Fourth Test Topic", asList(new Post[] { new Post("Fourth Test Body", asList(new Attachment("fourth", "Fourth Test File"), new Attachment("fifth", "Fifth Test with Truncation over 25 characters File"), new Attachment("sixth", "Sixth Test File"))) }), IMPORTANT, new Poll("Fourth Test Question", asList(new PollOption[] { new PollOption("Seventh Test Answer"), new PollOption("Eight Test Answer") }), 0)));
    assertTrue(message.equals("Fourth Test Topic"));
    message = createPost(driver, new Post(new Topic(new Forum("Second Test Forum"), "Fourth Test Topic"), "Ten Test Post", asList(new Attachment("fourth", "Fourth Test File"), new Attachment("fifth", "Fifth Test with Truncation over 25 characters File"), new Attachment("sixth", "Sixth Test File"))));
    assertTrue(message.equals("Ten Test Post"));
}
Also used : CreateCategory.createCategory(it.vige.rubia.selenium.adminpanel.action.CreateCategory.createCategory) RemoveCategory.removeCategory(it.vige.rubia.selenium.adminpanel.action.RemoveCategory.removeCategory) Category(it.vige.rubia.model.Category) RemovePost.removePost(it.vige.rubia.selenium.forum.action.RemovePost.removePost) VerifyTopic.getPosterLastPost(it.vige.rubia.selenium.forum.action.VerifyTopic.getPosterLastPost) CreatePost.createPost(it.vige.rubia.selenium.forum.action.CreatePost.createPost) Post(it.vige.rubia.model.Post) Poll(it.vige.rubia.model.Poll) Attachment(it.vige.rubia.model.Attachment) PollOption(it.vige.rubia.model.PollOption) RemoveTopic.removeTopic(it.vige.rubia.selenium.forum.action.RemoveTopic.removeTopic) CreateTopic.createTopic(it.vige.rubia.selenium.forum.action.CreateTopic.createTopic) Topic(it.vige.rubia.model.Topic) Forum(it.vige.rubia.model.Forum) VerifyPost.getLastPostOfCurrentForum(it.vige.rubia.selenium.forum.action.VerifyPost.getLastPostOfCurrentForum) RemoveForum.removeForum(it.vige.rubia.selenium.adminpanel.action.RemoveForum.removeForum) CreateForum.createForum(it.vige.rubia.selenium.adminpanel.action.CreateForum.createForum) BeforeClass(org.junit.BeforeClass)

Example 78 with Post

use of it.vige.rubia.model.Post in project rubia-forums by flashboss.

the class OperationPostTest method verifyPostProfileFromTopicPage.

@Test
public void verifyPostProfileFromTopicPage() {
    goTo(driver, new Topic(new Forum("Second Test Forum"), "Third Test Topic"));
    Post post = new Post("Ninth Test Post");
    Poster poster = getPosterFromLink(driver, post);
    assertTrue(poster != null);
    assertEquals("root", poster.getUserId());
    assertTrue(poster.getPostCount() >= 14);
}
Also used : RemovePost.removePost(it.vige.rubia.selenium.forum.action.RemovePost.removePost) VerifyTopic.getPosterLastPost(it.vige.rubia.selenium.forum.action.VerifyTopic.getPosterLastPost) CreatePost.createPost(it.vige.rubia.selenium.forum.action.CreatePost.createPost) Post(it.vige.rubia.model.Post) Poster(it.vige.rubia.model.Poster) VerifyTopic.getPoster(it.vige.rubia.selenium.forum.action.VerifyTopic.getPoster) RemoveTopic.removeTopic(it.vige.rubia.selenium.forum.action.RemoveTopic.removeTopic) CreateTopic.createTopic(it.vige.rubia.selenium.forum.action.CreateTopic.createTopic) Topic(it.vige.rubia.model.Topic) Forum(it.vige.rubia.model.Forum) VerifyPost.getLastPostOfCurrentForum(it.vige.rubia.selenium.forum.action.VerifyPost.getLastPostOfCurrentForum) RemoveForum.removeForum(it.vige.rubia.selenium.adminpanel.action.RemoveForum.removeForum) CreateForum.createForum(it.vige.rubia.selenium.adminpanel.action.CreateForum.createForum) Test(org.junit.Test)

Example 79 with Post

use of it.vige.rubia.model.Post in project rubia-forums by flashboss.

the class OperationPostTest method verifyPostProfileFromTopicPageButton.

@Test
public void verifyPostProfileFromTopicPageButton() {
    goTo(driver, new Topic(new Forum("Second Test Forum"), "Fourth Test Topic"));
    Post post = new Post("Fourth Test Body");
    Poster poster = getPosterFromButton(driver, post);
    assertTrue(poster != null);
    assertEquals("root", poster.getUserId());
    assertTrue(poster.getPostCount() >= 14);
}
Also used : RemovePost.removePost(it.vige.rubia.selenium.forum.action.RemovePost.removePost) VerifyTopic.getPosterLastPost(it.vige.rubia.selenium.forum.action.VerifyTopic.getPosterLastPost) CreatePost.createPost(it.vige.rubia.selenium.forum.action.CreatePost.createPost) Post(it.vige.rubia.model.Post) Poster(it.vige.rubia.model.Poster) VerifyTopic.getPoster(it.vige.rubia.selenium.forum.action.VerifyTopic.getPoster) RemoveTopic.removeTopic(it.vige.rubia.selenium.forum.action.RemoveTopic.removeTopic) CreateTopic.createTopic(it.vige.rubia.selenium.forum.action.CreateTopic.createTopic) Topic(it.vige.rubia.model.Topic) Forum(it.vige.rubia.model.Forum) VerifyPost.getLastPostOfCurrentForum(it.vige.rubia.selenium.forum.action.VerifyPost.getLastPostOfCurrentForum) RemoveForum.removeForum(it.vige.rubia.selenium.adminpanel.action.RemoveForum.removeForum) CreateForum.createForum(it.vige.rubia.selenium.adminpanel.action.CreateForum.createForum) Test(org.junit.Test)

Example 80 with Post

use of it.vige.rubia.model.Post in project rubia-forums by flashboss.

the class OperationPostTest method stop.

@AfterClass
public static void stop() {
    String message = removePost(driver, new Post(new Topic(new Forum("First Test Forum"), "First Test Topic"), "First Test Post"));
    assertTrue(message.equals(OK));
    message = removePost(driver, new Post(new Topic(new Forum("First Test Forum"), "First Test Topic"), "Second Test Post"));
    assertTrue(message.equals(OK));
    message = removePost(driver, new Post(new Topic(new Forum("First Test Forum"), "First Test Topic"), "Third Test Post"));
    assertTrue(message.equals(OK));
    message = removePost(driver, new Post(new Topic(new Forum("First Test Forum"), "First Test Topic"), "Fourth Test Post"));
    assertTrue(message.equals(OK));
    message = removePost(driver, new Post(new Topic(new Forum("First Test Forum"), "Second Test Topic"), "Fifth Test with Truncation over 25 characters Post"));
    assertTrue(message.equals(OK));
    message = removePost(driver, new Post(new Topic(new Forum("First Test Forum"), "Second Test Topic"), "Sixth Test Post"));
    assertTrue(message.equals(OK));
    message = removePost(driver, new Post(new Topic(new Forum("First Test Forum"), "Second Test Topic"), "Seventh Test Post"));
    assertTrue(message.equals(OK));
    message = removePost(driver, new Post(new Topic(new Forum("Second Test Forum"), "Third Test Topic"), "Eight Test Post"));
    assertTrue(message.equals(OK));
    message = removePost(driver, new Post(new Topic(new Forum("Second Test Forum"), "Third Test Topic"), "Ninth Test Post"));
    assertTrue(message.equals(OK));
    message = removePost(driver, new Post(new Topic(new Forum("Second Test Forum"), "Fourth Test Topic"), "Ten Test Post"));
    assertTrue(message.equals(OK));
    message = removeTopic(driver, new Topic(new Forum("First Test Forum"), "First Test Topic", asList(new Post[] { new Post("First Test Body") })));
    assertTrue(message.equals(OK));
    message = removeTopic(driver, new Topic(new Forum("First Test Forum"), "Second Test Topic", asList(new Post[] { new Post("Second Test Body") })));
    assertTrue(message.equals(OK));
    message = removeTopic(driver, new Topic(new Forum("Second Test Forum"), "Third Test Topic", asList(new Post[] { new Post("Third Test Body") })));
    assertTrue(message.equals(OK));
    message = removeTopic(driver, new Topic(new Forum("Second Test Forum"), "Fourth Test Topic", asList(new Post[] { new Post("Fourth Test Body") })));
    assertTrue(message.equals(OK));
    message = removeForum(driver, new Forum("First Test Forum"), "Second Test Forum");
    assertTrue(message.equals(REMOVED_FORUM_0_MESSAGE));
    message = removeForum(driver, new Forum("Second Test Forum"), SELECT_FORUM_TYPE);
    assertTrue(message.equals(REMOVED_FORUM_1_MESSAGE));
    message = removeCategory(driver, new Category("First Test Category"), SELECT_CATEGORY_TYPE);
    assertTrue(message.equals(REMOVED_CATEGORY_0_MESSAGE));
    message = removeCategory(driver, new Category("Second Test Category"), SELECT_CATEGORY_TYPE);
    assertTrue(message.equals(REMOVED_CATEGORY_1_MESSAGE));
}
Also used : CreateCategory.createCategory(it.vige.rubia.selenium.adminpanel.action.CreateCategory.createCategory) RemoveCategory.removeCategory(it.vige.rubia.selenium.adminpanel.action.RemoveCategory.removeCategory) Category(it.vige.rubia.model.Category) RemovePost.removePost(it.vige.rubia.selenium.forum.action.RemovePost.removePost) VerifyTopic.getPosterLastPost(it.vige.rubia.selenium.forum.action.VerifyTopic.getPosterLastPost) CreatePost.createPost(it.vige.rubia.selenium.forum.action.CreatePost.createPost) Post(it.vige.rubia.model.Post) RemoveTopic.removeTopic(it.vige.rubia.selenium.forum.action.RemoveTopic.removeTopic) CreateTopic.createTopic(it.vige.rubia.selenium.forum.action.CreateTopic.createTopic) Topic(it.vige.rubia.model.Topic) Forum(it.vige.rubia.model.Forum) VerifyPost.getLastPostOfCurrentForum(it.vige.rubia.selenium.forum.action.VerifyPost.getLastPostOfCurrentForum) RemoveForum.removeForum(it.vige.rubia.selenium.adminpanel.action.RemoveForum.removeForum) CreateForum.createForum(it.vige.rubia.selenium.adminpanel.action.CreateForum.createForum) AfterClass(org.junit.AfterClass)

Aggregations

Post (it.vige.rubia.model.Post)98 Topic (it.vige.rubia.model.Topic)62 Forum (it.vige.rubia.model.Forum)52 CreateTopic.createTopic (it.vige.rubia.selenium.forum.action.CreateTopic.createTopic)43 CreateForum.createForum (it.vige.rubia.selenium.adminpanel.action.CreateForum.createForum)38 Category (it.vige.rubia.model.Category)34 RemoveTopic.removeTopic (it.vige.rubia.selenium.forum.action.RemoveTopic.removeTopic)32 RemoveForum.removeForum (it.vige.rubia.selenium.adminpanel.action.RemoveForum.removeForum)31 CreateCategory.createCategory (it.vige.rubia.selenium.adminpanel.action.CreateCategory.createCategory)28 RemoveCategory.removeCategory (it.vige.rubia.selenium.adminpanel.action.RemoveCategory.removeCategory)28 Attachment (it.vige.rubia.model.Attachment)25 Test (org.junit.Test)25 Poll (it.vige.rubia.model.Poll)21 Poster (it.vige.rubia.model.Poster)20 PollOption (it.vige.rubia.model.PollOption)19 CreatePost.createPost (it.vige.rubia.selenium.forum.action.CreatePost.createPost)17 Message (it.vige.rubia.model.Message)14 Date (java.util.Date)14 BeforeClass (org.junit.BeforeClass)12 WebElement (org.openqa.selenium.WebElement)12