Search in sources :

Example 51 with Post

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

the class ForumsModuleImpl method findFirstPost.

@Override
public Post findFirstPost(Topic topic) throws ModuleException {
    try {
        TypedQuery<Post> query = em.createNamedQuery("findFirstPost", Post.class);
        query.setParameter("lastPostDate", topic.getLastPostDate(), DATE);
        query.setParameter("topicId", "" + topic.getId());
        query.setFirstResult(0);
        query.setMaxResults(1);
        Post firstPost = uniqueElement(query.getResultList());
        return firstPost;
    } catch (Exception e) {
        log.error(e);
        return null;
    }
}
Also used : Post(it.vige.rubia.model.Post) NoResultException(javax.persistence.NoResultException) NonUniqueResultException(javax.persistence.NonUniqueResultException)

Example 52 with Post

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

the class ForumsModuleImpl method createPost.

@Override
public Post createPost(Topic topic, Forum forum, Message message, Date creationDate, Poster poster, Collection<Attachment> attachments) throws ModuleException {
    try {
        Poster posterOld = findPosterByUserId(poster.getUserId());
        if (posterOld == null) {
            em.persist(poster);
        }
        em.merge(poster);
        Post post = new Post();
        post.setMessage(message);
        post.setCreateDate(creationDate);
        post.setPoster(poster);
        if (attachments != null)
            for (Attachment attachment : attachments) {
                em.persist(attachment);
                post.addAttachment(attachment);
            }
        em.persist(post);
        em.flush();
        post.setTopic(topic);
        topic.setLastPostDate(post.getCreateDate());
        topic.setReplies(topic.getReplies() + 1);
        em.merge(topic);
        forum.addPostSize();
        em.merge(forum);
        notificationEngine.scheduleForNotification(post.getId(), MODE_REPLY);
        em.flush();
        return post;
    } catch (Exception e) {
        String errorMessage = "Cannot create topic";
        throw new ModuleException(errorMessage, e);
    }
}
Also used : Post(it.vige.rubia.model.Post) Poster(it.vige.rubia.model.Poster) Attachment(it.vige.rubia.model.Attachment) NoResultException(javax.persistence.NoResultException) NonUniqueResultException(javax.persistence.NonUniqueResultException)

Example 53 with Post

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

the class ForumsModuleImpl method createTopic.

@Override
public Post createTopic(Forum forum, Message message, Date creationDate, Poster poster, Poll poll, Collection<Attachment> attachments, TopicType type) throws ModuleException {
    try {
        if (poster.getId() == null || em.find(Poster.class, poster.getId()) == null)
            em.persist(poster);
        em.merge(poster);
        em.persist(poll);
        for (PollOption pollOption : poll.getOptions()) em.persist(pollOption);
        em.flush();
        Post post = new Post();
        post.setMessage(message);
        post.setCreateDate(creationDate);
        post.setPoster(poster);
        if (attachments != null)
            for (Attachment attachment : attachments) {
                em.persist(attachment);
                post.addAttachment(attachment);
            }
        Topic topic = new Topic();
        topic.setSubject(message.getSubject());
        topic.setForum(forum);
        topic.setPoster(poster);
        post.setTopic(topic);
        topic.setLastPostDate(creationDate);
        topic.setType(type);
        topic.setStatus(TOPIC_UNLOCKED);
        topic.setPoll(poll);
        em.persist(topic);
        em.persist(post);
        em.flush();
        forum.addTopicSize();
        forum.addPostSize();
        em.merge(forum);
        post.setTopic(topic);
        em.persist(post);
        notificationEngine.scheduleForNotification(post.getId(), MODE_POST);
        em.flush();
        return post;
    } catch (Exception e) {
        String errorMessage = "Cannot create topic";
        throw new ModuleException(errorMessage, e);
    }
}
Also used : Post(it.vige.rubia.model.Post) PollOption(it.vige.rubia.model.PollOption) Attachment(it.vige.rubia.model.Attachment) Topic(it.vige.rubia.model.Topic) NoResultException(javax.persistence.NoResultException) NonUniqueResultException(javax.persistence.NonUniqueResultException)

Example 54 with Post

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

the class EditPost method start.

// action processing
// methods-----------------------------------------------------------------------------------------------------
/**
 * @return the navigation state of the application
 */
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public String start() {
    String navState = null;
    try {
        int postId = -1;
        String p = getParameter(p_postId);
        if (p != null && p.trim().length() > 0) {
            postId = parseInt(p);
        }
        // grab the post information
        if (postId != -1) {
            // re-initialize this controller to edit the specified post
            cleanup();
            // get the post from the module
            Post post = forumsModule.findPostById(postId);
            Topic topic = post.getTopic();
            // set the selected post's topic id
            topicId = topic.getId().intValue();
            this.postId = postId;
            // set the subject of the post
            subject = post.getMessage().getSubject();
            // set the message of the post
            message = post.getMessage().getText();
            // set the topicType
            topicType = topic.getType();
            // setup poll related information
            setupPoll(topic.getPoll());
            attachments = forumsModule.findAttachments(post);
            // setup the attachment related information
            List<Post> posts = forumsModule.findPostsByTopicId(topic);
            isFirstPost = false;
            if (posts.get(0).getId().intValue() == post.getId().intValue()) {
                isFirstPost = true;
            }
        }
        navState = START_EDIT_POST;
    } catch (Exception e) {
        handleException(e);
    }
    return navState;
}
Also used : Post(it.vige.rubia.model.Post) Topic(it.vige.rubia.model.Topic) JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException) Interceptors(javax.interceptor.Interceptors) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 55 with Post

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

the class Search method search.

public String search() throws Exception {
    int currentPage = 0;
    SearchCriteria criteria = getSearchCriteria();
    criteria.setPageSize(userPreferences.getPostsPerTopic());
    criteria.setPageNumber(currentPage);
    if (criteria.getDisplayAs().equals(POSTS.name())) {
        ResultPage<Post> resultPage = forumsSearchModule.findPosts(criteria);
        viewSearch.setPosts(resultPage.getPage());
        viewSearch.setPostsDataModel(new ListDataModel<Post>(viewSearch.getPosts()));
        if (viewSearch.getPosts() != null && viewSearch.getPosts().isEmpty()) {
            viewSearch.setPosts(null);
            viewSearch.setPostsDataModel(null);
        }
        return "posts";
    } else {
        ResultPage<Topic> resultPage = forumsSearchModule.findTopics(criteria);
        viewSearch.setTopics(resultPage.getPage());
        viewSearch.setTopicsDataModel(new ListDataModel<Topic>(viewSearch.getTopics()));
        if (viewSearch.getTopics() == null || viewSearch.getTopics().isEmpty()) {
            viewSearch.setTopics(null);
            viewSearch.setTopicsDataModel(null);
        } else {
            viewSearch.setTopicLastPosts(forumsModule.findLastPostsOfTopics(viewSearch.getTopics()));
        }
        return "topics";
    }
}
Also used : Post(it.vige.rubia.model.Post) Topic(it.vige.rubia.model.Topic) SearchCriteria(it.vige.rubia.search.SearchCriteria)

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