Search in sources :

Example 46 with Forum

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

the class ForumsModuleImpl method createForum.

@Override
public Forum createForum(Category category, String name, String description) throws ModuleException {
    try {
        Forum forum = new Forum();
        forum.setCategory(category);
        forum.setName(name);
        forum.setDescription(description);
        forum.setOrder(getLastForumOrder(category) + 10);
        em.persist(forum);
        em.flush();
        return forum;
    } catch (Exception e) {
        String errorMessage = "Cannot create forum";
        throw new ModuleException(errorMessage, e);
    }
}
Also used : NoResultException(javax.persistence.NoResultException) NonUniqueResultException(javax.persistence.NonUniqueResultException) Forum(it.vige.rubia.model.Forum)

Example 47 with Forum

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

the class ForumsModuleImpl method addAllForums.

@Override
public void addAllForums(Category source, Category target) throws ModuleException {
    List<Forum> sourceForums = findForumsByCategory(source);
    List<Forum> targetForums = findForumsByCategory(target);
    targetForums.addAll(sourceForums);
    for (Forum forum : targetForums) {
        forum.setCategory(target);
    }
    source.setForums(new ArrayList<Forum>());
}
Also used : Forum(it.vige.rubia.model.Forum)

Example 48 with Forum

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

the class ForumsModuleImpl method removePost.

@Override
public void removePost(int postId, boolean isLastPost) throws ModuleException {
    try {
        Post post = em.find(Post.class, postId);
        Topic topic = post.getTopic();
        Forum forum = topic.getForum();
        em.remove(post);
        topic.setReplies(topic.getReplies() - 1);
        forum.setPostCount(forum.getPostCount() - 1);
        List<Post> posts = findPostsByTopicId(topic);
        Post lastPost = posts.get(posts.size() - 1);
        if (isLastPost) {
            topic.setLastPostDate(lastPost.getCreateDate());
        }
        em.merge(topic);
        em.merge(forum);
        em.flush();
    } catch (Exception e) {
        String errorMessage = "Cannot delete post";
        throw new ModuleException(errorMessage, e);
    }
}
Also used : Post(it.vige.rubia.model.Post) Topic(it.vige.rubia.model.Topic) NoResultException(javax.persistence.NoResultException) NonUniqueResultException(javax.persistence.NonUniqueResultException) Forum(it.vige.rubia.model.Forum)

Example 49 with Forum

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

the class ForumsModuleImpl method removeTopic.

@Override
public void removeTopic(int topicId) throws ModuleException {
    try {
        Topic topic = em.find(Topic.class, topicId);
        Forum forum = topic.getForum();
        if (forum != null) {
            topic.setForum(null);
            forum.setPostCount(forum.getPostCount() - topic.getReplies() - 1);
            forum.setTopicCount(forum.getTopicCount() - 1);
            em.merge(forum);
            em.remove(em.merge(topic));
        } else {
            em.remove(topic);
        }
        em.flush();
    } catch (Exception e) {
        String errorMessage = "Cannot delete topic";
        throw new ModuleException(errorMessage, e);
    }
}
Also used : Topic(it.vige.rubia.model.Topic) NoResultException(javax.persistence.NoResultException) NonUniqueResultException(javax.persistence.NonUniqueResultException) Forum(it.vige.rubia.model.Forum)

Example 50 with Forum

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

the class AdminController method moveForumDown.

/**
 * @return the navigation state of the application
 */
public String moveForumDown() {
    String navState = null;
    try {
        // get the categoryId where this forum should be added
        int forumId = -1;
        String cour = ForumUtil.getParameter(p_forumId);
        if (cour != null && cour.trim().length() > 0) {
            forumId = Integer.parseInt(cour);
        }
        Forum forum = forumsModule.findForumById(forumId);
        forum.setOrder(forum.getOrder() + down);
        forumsModule.update(forum);
        Iterator<Forum> forums = forumsModule.findForumsByCategory(forum.getCategory()).iterator();
        for (int index = 10; forums.hasNext(); index += 10) {
            forum = forums.next();
            forum.setOrder(index);
            forumsModule.update(forum);
        }
    } catch (Exception e) {
        handleException(e);
    }
    return navState;
}
Also used : JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException) ModuleException(it.vige.rubia.ModuleException) Forum(it.vige.rubia.model.Forum) ViewForum(it.vige.rubia.ui.view.ViewForum) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Aggregations

Forum (it.vige.rubia.model.Forum)100 CreateForum.createForum (it.vige.rubia.selenium.adminpanel.action.CreateForum.createForum)65 Topic (it.vige.rubia.model.Topic)63 RemoveForum.removeForum (it.vige.rubia.selenium.adminpanel.action.RemoveForum.removeForum)55 Post (it.vige.rubia.model.Post)52 Category (it.vige.rubia.model.Category)50 CreateTopic.createTopic (it.vige.rubia.selenium.forum.action.CreateTopic.createTopic)49 CreateCategory.createCategory (it.vige.rubia.selenium.adminpanel.action.CreateCategory.createCategory)40 RemoveCategory.removeCategory (it.vige.rubia.selenium.adminpanel.action.RemoveCategory.removeCategory)40 RemoveTopic.removeTopic (it.vige.rubia.selenium.forum.action.RemoveTopic.removeTopic)34 Test (org.junit.Test)33 Poll (it.vige.rubia.model.Poll)23 Attachment (it.vige.rubia.model.Attachment)21 PollOption (it.vige.rubia.model.PollOption)21 SecureActionForum (it.vige.rubia.auth.SecureActionForum)16 CreatePost.createPost (it.vige.rubia.selenium.forum.action.CreatePost.createPost)15 Poster (it.vige.rubia.model.Poster)14 JSFUtil.handleException (it.vige.rubia.ui.JSFUtil.handleException)14 BeforeClass (org.junit.BeforeClass)14 AfterClass (org.junit.AfterClass)13