Search in sources :

Example 41 with Post

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

the class FeedsServlet method createCategoryFeed.

private void createCategoryFeed(SyndFeed feed, Integer id, String url, String urlType) throws ModuleException {
    Category category = forumsModule.findCategoryById(id);
    feed.setTitle("Rubia Forums Category Feed: " + category.getTitle());
    feed.setLink(categoryLink(id.toString(), url, urlType));
    feed.setDescription("Messages posted in category " + category.getTitle());
    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    List<Post> posts = forumsModule.findPostsFromCategoryDesc(category, POST_LIMIT);
    for (int i = 0; i < posts.size(); i++) {
        entries.add(getEntry(posts.get(i), url, urlType));
    }
    feed.setEntries(entries);
}
Also used : Category(it.vige.rubia.model.Category) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) Post(it.vige.rubia.model.Post) ArrayList(java.util.ArrayList)

Example 42 with Post

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

the class FeedsServlet method createTopicFeed.

private void createTopicFeed(SyndFeed feed, Integer id, String url, String urlType) throws ModuleException {
    Topic topic = forumsModule.findTopicById(id);
    feed.setTitle("Rubia Forums Topic Feed: " + topic.getSubject());
    feed.setLink(topicLink(id.toString(), url, urlType));
    feed.setDescription("Messages posted in topic " + topic.getSubject() + " in forum " + topic.getForum().getName() + " in category " + topic.getForum().getCategory().getTitle());
    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    List<Post> posts = forumsModule.findPostsByTopicId(topic);
    for (int i = 0; i < posts.size(); i++) {
        entries.add(getEntry(posts.get(i), url, urlType));
    }
    feed.setEntries(entries);
}
Also used : SyndEntry(com.rometools.rome.feed.synd.SyndEntry) Post(it.vige.rubia.model.Post) ArrayList(java.util.ArrayList) Topic(it.vige.rubia.model.Topic)

Example 43 with Post

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

the class FeedsServlet method createForumFeed.

private void createForumFeed(SyndFeed feed, Integer id, String url, String urlType) throws ModuleException {
    Forum forum = forumsModule.findForumById(id);
    feed.setTitle("Rubia Forums Forum Feed: " + forum.getName());
    feed.setLink(forumLink(id.toString(), url, urlType));
    feed.setDescription("Messages posted in forum " + forum.getName() + " in category " + forum.getCategory().getTitle());
    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    List<Post> posts = forumsModule.findPostsFromForumDesc(forum, POST_LIMIT);
    for (int i = 0; i < posts.size(); i++) {
        entries.add(getEntry(posts.get(i), url, urlType));
    }
    feed.setEntries(entries);
}
Also used : SyndEntry(com.rometools.rome.feed.synd.SyndEntry) Post(it.vige.rubia.model.Post) ArrayList(java.util.ArrayList) Forum(it.vige.rubia.model.Forum)

Example 44 with Post

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

the class ForumsSearchModuleImpl method findPosts.

@SuppressWarnings("unchecked")
public ResultPage<Post> findPosts(SearchCriteria criteria) throws ModuleException {
    if (criteria != null) {
        try {
            EntityManager session = getSession();
            FullTextSession fullTextSession = getFullTextSession((Session) session.getDelegate());
            Builder builder = new Builder();
            String keywords = criteria.getKeywords();
            if (keywords != null && keywords.length() != 0) {
                String[] fields = null;
                Searching searching = Searching.valueOf(criteria.getSearching());
                switch(searching) {
                    case TITLE_MSG:
                        fields = new String[] { "message.text", "topic.subject" };
                        break;
                    case MSG:
                        fields = new String[] { "message.text" };
                        break;
                }
                MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, new StandardAnalyzer());
                builder.add(parser.parse(keywords), MUST);
            }
            String forumId = criteria.getForum();
            if (forumId != null && forumId.length() != 0) {
                builder.add(new TermQuery(new Term("topic.forum.id", forumId)), MUST);
            }
            String categoryId = criteria.getCategory();
            if (categoryId != null && categoryId.length() != 0) {
                builder.add(new TermQuery(new Term("topic.forum.category.id", categoryId)), MUST);
            }
            String userName = criteria.getAuthor();
            if (userName != null && userName.length() != 0) {
                builder.add(new WildcardQuery(new Term("poster.userId", userName)), MUST);
            }
            String timePeriod = criteria.getTimePeriod();
            if (timePeriod != null && timePeriod.length() != 0) {
                addPostTimeQuery(builder, TimePeriod.valueOf(timePeriod));
            }
            FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(builder.build(), Post.class);
            SortOrder sortOrder = SortOrder.valueOf(criteria.getSortOrder());
            String sortByStr = criteria.getSortBy();
            SortBy sortBy = null;
            if (sortByStr != null)
                sortBy = valueOf(sortByStr);
            fullTextQuery.setSort(getSort(sortBy, sortOrder));
            fullTextQuery.setFirstResult(criteria.getPageSize() * criteria.getPageNumber());
            fullTextQuery.setMaxResults(criteria.getPageSize());
            ResultPage<Post> resultPage = new ResultPage<Post>();
            resultPage.setPage(fullTextQuery.list());
            resultPage.setResultSize(fullTextQuery.getResultSize());
            return resultPage;
        } catch (ParseException e) {
            return null;
        } catch (Exception e) {
            throw new ModuleException(e.getMessage(), e);
        }
    } else {
        throw new IllegalArgumentException("criteria cannot be null");
    }
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) FullTextSession(org.hibernate.search.FullTextSession) Search.getFullTextSession(org.hibernate.search.Search.getFullTextSession) MultiFieldQueryParser(org.apache.lucene.queryparser.classic.MultiFieldQueryParser) SortBy(it.vige.rubia.search.SortBy) Post(it.vige.rubia.model.Post) Builder(org.apache.lucene.search.BooleanQuery.Builder) SortOrder(it.vige.rubia.search.SortOrder) Term(org.apache.lucene.index.Term) ParseException(org.apache.lucene.queryparser.classic.ParseException) ModuleException(it.vige.rubia.ModuleException) EntityManager(javax.persistence.EntityManager) Searching(it.vige.rubia.search.Searching) ResultPage(it.vige.rubia.search.ResultPage) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) ParseException(org.apache.lucene.queryparser.classic.ParseException) FullTextQuery(org.hibernate.search.FullTextQuery) ModuleException(it.vige.rubia.ModuleException)

Example 45 with Post

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

the class ForumsSearchModuleImpl method findPosts.

@SuppressWarnings("unchecked")
public ResultPage<Post> findPosts(SearchCriteria criteria) throws ModuleException {
    if (criteria != null) {
        try {
            EntityManager session = getSession();
            FullTextSession fullTextSession = getFullTextSession((Session) session.getDelegate());
            Builder builder = new Builder();
            String keywords = criteria.getKeywords();
            if (keywords != null && keywords.length() != 0) {
                String[] fields = null;
                Searching searching = Searching.valueOf(criteria.getSearching());
                switch(searching) {
                    case TITLE_MSG:
                        fields = new String[] { "message.text", "topic.subject" };
                        break;
                    case MSG:
                        fields = new String[] { "message.text" };
                        break;
                }
                MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, new StandardAnalyzer());
                builder.add(parser.parse(keywords), MUST);
            }
            String forumId = criteria.getForum();
            if (forumId != null && forumId.length() != 0) {
                builder.add(new TermQuery(new Term("topic.forum.id", forumId)), MUST);
            }
            String categoryId = criteria.getCategory();
            if (categoryId != null && categoryId.length() != 0) {
                builder.add(new TermQuery(new Term("topic.forum.category.id", categoryId)), MUST);
            }
            String userName = criteria.getAuthor();
            if (userName != null && userName.length() != 0) {
                builder.add(new WildcardQuery(new Term("poster.userId", userName)), MUST);
            }
            String timePeriod = criteria.getTimePeriod();
            if (timePeriod != null && timePeriod.length() != 0) {
                addPostTimeQuery(builder, TimePeriod.valueOf(timePeriod));
            }
            FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(builder.build(), Post.class);
            SortOrder sortOrder = SortOrder.valueOf(criteria.getSortOrder());
            String sortByStr = criteria.getSortBy();
            SortBy sortBy = null;
            if (sortByStr != null)
                sortBy = valueOf(sortByStr);
            fullTextQuery.setSort(getSort(sortBy, sortOrder));
            fullTextQuery.setFirstResult(criteria.getPageSize() * criteria.getPageNumber());
            fullTextQuery.setMaxResults(criteria.getPageSize());
            ResultPage<Post> resultPage = new ResultPage<Post>();
            resultPage.setPage(fullTextQuery.list());
            resultPage.setResultSize(fullTextQuery.getResultSize());
            return resultPage;
        } catch (ParseException e) {
            return null;
        } catch (Exception e) {
            throw new ModuleException(e.getMessage(), e);
        }
    } else {
        throw new IllegalArgumentException("criteria cannot be null");
    }
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) FullTextSession(org.hibernate.search.FullTextSession) Search.getFullTextSession(org.hibernate.search.Search.getFullTextSession) MultiFieldQueryParser(org.apache.lucene.queryparser.classic.MultiFieldQueryParser) SortBy(it.vige.rubia.search.SortBy) Post(it.vige.rubia.model.Post) Builder(org.apache.lucene.search.BooleanQuery.Builder) SortOrder(it.vige.rubia.search.SortOrder) Term(org.apache.lucene.index.Term) ParseException(org.apache.lucene.queryparser.classic.ParseException) ModuleException(it.vige.rubia.ModuleException) EntityManager(javax.persistence.EntityManager) Searching(it.vige.rubia.search.Searching) ResultPage(it.vige.rubia.search.ResultPage) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) ParseException(org.apache.lucene.queryparser.classic.ParseException) FullTextQuery(org.hibernate.search.FullTextQuery) ModuleException(it.vige.rubia.ModuleException)

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