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