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);
}
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;
}
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);
}
}
}
}
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);
}
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");
}
}
Aggregations