Search in sources :

Example 46 with Topic

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

the class OperationPostTest method verifyPostFromForumPageLastPost.

@Test
public void verifyPostFromForumPageLastPost() {
    Forum forum = new Forum("Second Test Forum", "Second Test Description", new Category("First Test Category"));
    goTo(driver, forum);
    Topic topic = new Topic(forum, "Third Test Topic");
    Poster poster = getPosterLastPost(driver, topic);
    goTo(driver, forum);
    Post post = getLastPostOfCurrentForum(driver, topic);
    assertTrue(post != null);
    assertEquals(RE + "Third Test Topic", post.getMessage().getSubject());
    assertTrue(poster != null);
    assertEquals("root", poster.getUserId());
    assertTrue(poster.getPostCount() >= 14);
}
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) 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 47 with Topic

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

the class ViewAtomLink method getPage.

public static Topic getPage(WebDriver driver, Topic topic) {
    VerifyTopic.goTo(driver, topic);
    goTo(driver);
    Topic result = new Topic();
    result.setSubject(driver.findElement(id(FEED_TITLE_TEXT)).getText().split(": ")[1]);
    String[] splittedText = driver.findElement(id(FEED_SUBTITLE_TEXT)).getText().split(" in topic | in forum | in category ");
    result.setForum(new Forum(splittedText[2]));
    result.getForum().setCategory(new Category(splittedText[3]));
    List<Post> posts = new ArrayList<Post>();
    int entriesSize = driver.findElements(className(ENTRY_LINK)).size();
    DateFormat dateFormat = new SimpleDateFormat("d MMM yyyy, HH:mm");
    for (int i = 0; i < entriesSize; i++) {
        WebElement entry = driver.findElements(className(ENTRY_LINK)).get(i);
        String[] entryText = entry.getText().split(BY);
        String lastUpdated = entry.findElement(className(LAST_UPDATED)).getText();
        Post post = new Post(entryText[0]);
        post.setPoster(new Poster(entryText[1].split("\n")[0]));
        try {
            post.setCreateDate(dateFormat.parse(lastUpdated));
        } catch (ParseException e) {
        }
        post.setMessage(new Message(entry.findElement(className(FEED_ENTRY_CONTENT)).getText()));
        post.getMessage().setSubject(entryText[0]);
        posts.add(post);
        WebElement entryLink = driver.findElement(linkText(entry.getText().split("\n")[0]));
        entryLink.click();
        List<Attachment> attachments = getAttachmentsOfCurrentPostInPage(driver, post);
        post.setAttachments(attachments);
        if (topic.getPoll() == null) {
            Poll poll = getPollOfCurrentTopic(driver);
            result.setPoll(poll);
        }
        VerifyTopic.goTo(driver, result);
        goTo(driver);
    }
    result.setPosts(posts);
    returnToHome(driver);
    return result;
}
Also used : Category(it.vige.rubia.model.Category) Message(it.vige.rubia.model.Message) Post(it.vige.rubia.model.Post) ArrayList(java.util.ArrayList) Attachment(it.vige.rubia.model.Attachment) WebElement(org.openqa.selenium.WebElement) Forum(it.vige.rubia.model.Forum) VerifyForum(it.vige.rubia.selenium.forum.action.VerifyForum) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Poster(it.vige.rubia.model.Poster) Poll(it.vige.rubia.model.Poll) ParseException(java.text.ParseException) VerifyTopic(it.vige.rubia.selenium.forum.action.VerifyTopic) Topic(it.vige.rubia.model.Topic) VerifyPoll.getPollOfCurrentTopic(it.vige.rubia.selenium.forum.action.VerifyPoll.getPollOfCurrentTopic) SimpleDateFormat(java.text.SimpleDateFormat)

Example 48 with Topic

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

the class ViewMyForumsBase method execute.

/**
 * @throws Exception
 *             an error exception is launched
 */
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public void execute() throws Exception {
    Collection<Topic> topics = getWatchedTopics();
    // minipaging
    if (topics != null) {
        for (Topic courTopic : topics) {
            if (courTopic.getReplies() > 0) {
                PageNavigator topicNav = new PageNavigator(courTopic.getReplies() + 1, // this
                getUserPreferences().getPostsPerTopic(), // current page of the navigator
                0) {

                    /**
                     */
                    private static final long serialVersionUID = 1L;

                    protected Collection<Integer> initializePage() {
                        return null;
                    }
                };
                topicNavigator.put(courTopic.getId(), topicNav);
            }
        }
    }
}
Also used : PageNavigator(it.vige.rubia.ui.PageNavigator) Topic(it.vige.rubia.model.Topic) Interceptors(javax.interceptor.Interceptors) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 49 with Topic

use of it.vige.rubia.model.Topic 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 50 with Topic

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

the class ForumsSearchModuleImpl method findTopics.

@SuppressWarnings("unchecked")
public ResultPage<Topic> findTopics(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());
            SortBy sortBy = valueOf(criteria.getSortBy());
            fullTextQuery.setSort(getSort(sortBy, sortOrder));
            fullTextQuery.setProjection("topic.id");
            LinkedHashSet<Integer> topicIds = new LinkedHashSet<Integer>();
            LinkedHashSet<Integer> topicToDispIds = new LinkedHashSet<Integer>();
            int start = criteria.getPageSize() * criteria.getPageNumber();
            int end = start + criteria.getPageSize();
            int index = 0;
            for (Object o : fullTextQuery.list()) {
                Integer id = (Integer) ((Object[]) o)[0];
                if (topicIds.add(id)) {
                    if (index >= start && index < end) {
                        topicToDispIds.add(id);
                    }
                    index++;
                }
            }
            List<Topic> topics = null;
            if (topicToDispIds.size() > 0) {
                Query q = session.createQuery("from Topic as t join fetch t.poster where t.id IN ( :topicIds )");
                q.setParameter("topicIds", topicToDispIds);
                List<Topic> results = q.getResultList();
                topics = new LinkedList<Topic>();
                for (Integer id : topicToDispIds) {
                    for (Topic topic : results) {
                        if (id.equals(topic.getId())) {
                            topics.add(topic);
                            break;
                        }
                    }
                }
            }
            ResultPage<Topic> resultPage = new ResultPage<Topic>();
            resultPage.setPage(topics);
            resultPage.setResultSize(topicIds.size());
            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 : LinkedHashSet(java.util.LinkedHashSet) WildcardQuery(org.apache.lucene.search.WildcardQuery) FullTextSession(org.hibernate.search.FullTextSession) Search.getFullTextSession(org.hibernate.search.Search.getFullTextSession) FullTextQuery(org.hibernate.search.FullTextQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) Query(javax.persistence.Query) TermQuery(org.apache.lucene.search.TermQuery) SortBy(it.vige.rubia.search.SortBy) Builder(org.apache.lucene.search.BooleanQuery.Builder) ResultPage(it.vige.rubia.search.ResultPage) Topic(it.vige.rubia.model.Topic) ModuleException(it.vige.rubia.ModuleException) TermQuery(org.apache.lucene.search.TermQuery) MultiFieldQueryParser(org.apache.lucene.queryparser.classic.MultiFieldQueryParser) 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) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) ParseException(org.apache.lucene.queryparser.classic.ParseException) FullTextQuery(org.hibernate.search.FullTextQuery)

Aggregations

Topic (it.vige.rubia.model.Topic)112 CreateTopic.createTopic (it.vige.rubia.selenium.forum.action.CreateTopic.createTopic)64 Forum (it.vige.rubia.model.Forum)63 Post (it.vige.rubia.model.Post)62 CreateForum.createForum (it.vige.rubia.selenium.adminpanel.action.CreateForum.createForum)49 RemoveTopic.removeTopic (it.vige.rubia.selenium.forum.action.RemoveTopic.removeTopic)48 RemoveForum.removeForum (it.vige.rubia.selenium.adminpanel.action.RemoveForum.removeForum)39 Category (it.vige.rubia.model.Category)36 Test (org.junit.Test)36 CreateCategory.createCategory (it.vige.rubia.selenium.adminpanel.action.CreateCategory.createCategory)30 RemoveCategory.removeCategory (it.vige.rubia.selenium.adminpanel.action.RemoveCategory.removeCategory)30 Poll (it.vige.rubia.model.Poll)25 PollOption (it.vige.rubia.model.PollOption)24 Attachment (it.vige.rubia.model.Attachment)23 Poster (it.vige.rubia.model.Poster)17 CreatePost.createPost (it.vige.rubia.selenium.forum.action.CreatePost.createPost)16 WebElement (org.openqa.selenium.WebElement)16 SecureActionForum (it.vige.rubia.auth.SecureActionForum)14 Date (java.util.Date)14 Interceptors (javax.interceptor.Interceptors)13