use of it.vige.rubia.ModuleException in project rubia-forums by flashboss.
the class SplitTopic method splitAfter.
// ---------- UI Actions supported by this bean ----------------------------
/**
* This user interface action is spliting topic after post selected by user.
*
* @return the name of the operation
*/
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public String splitAfter() {
// Checking whether topic has only one post, so it can't be splitted
if (posts.size() == 1) {
setWarnBundleMessage("ERR_SPLIT_ONE_POST_TOPIC");
return "";
}
// Removing all not slected posts
Iterator<Integer> selectIt = checkboxes.keySet().iterator();
while (selectIt.hasNext()) {
Boolean postFlag = checkboxes.get(selectIt.next());
if (!postFlag.booleanValue()) {
selectIt.remove();
}
}
// Checking if user selected anything.
if (checkboxes.size() == 0) {
setWarnBundleMessage("ERR_NO_POST_SELECTED");
return "";
}
// User can't select more than one post for this action.
if (checkboxes.size() != 1) {
setWarnBundleMessage("Too_many_error");
return "";
}
// check if user selected first post
try {
posts = forumsModule.findPostsByTopicId(topic);
if (posts.get(0).getId().equals(checkboxes.keySet().iterator().next())) {
setWarnBundleMessage("ERR_SPLIT_ALL");
return "";
}
} catch (ModuleException e1) {
setWarnBundleMessage("ERR_SPLIT_ALL");
return "";
} catch (Exception e1) {
setWarnBundleMessage("ERR_SPLIT_ALL");
return "";
}
// Trying to get destination forum for new topic.
String toForumId = getParameter(p_forum_to_id);
if (toForumId == null || toForumId.trim().compareToIgnoreCase("-1") == 0 || toForumId.trim().length() == 0) {
setWarnBundleMessage("ERR_DEST_FORUM");
return "";
}
// Checking if user gave subject for new topic.
if (newTopicTitle == null || newTopicTitle.trim().compareToIgnoreCase("-1") == 0 || newTopicTitle.trim().length() == 0) {
setWarnBundleMessage("ERR_NO_SUBJECT_GIVEN");
return "";
}
try {
Forum destForum = forumsModule.findForumById(new Integer(toForumId));
// Creating new topic in destination forum.
Topic newTopic = forumsModule.createTopic(destForum, getUser(userModule).getId().toString(), newTopicTitle, topic.getType());
// Getting post id after which the topic must be splitted.
Integer selectedPostId = (Integer) checkboxes.keySet().iterator().next();
// Searching for the split pointing post in topic.
Iterator<Post> it = posts.iterator();
Post tempPost = null;
while (it.hasNext()) {
tempPost = it.next();
// searching for post to split after
if (tempPost.getId().equals(selectedPostId)) {
break;
}
}
List<Post> postsToRemove = new ArrayList<Post>();
// Adding splitting post and all which are after him to new topic.
if (tempPost != null) {
tempPost.setTopic(newTopic);
forumsModule.update(tempPost);
postsToRemove.add(tempPost);
}
while (it.hasNext()) {
Post post = it.next();
post.setTopic(newTopic);
forumsModule.update(post);
postsToRemove.add(post);
}
newTopic = forumsModule.findTopicById(newTopic.getId());
List<Post> postsNewTopic = forumsModule.findPostsByTopicId(newTopic);
newTopic.setReplies(postsNewTopic.size() - 1);
newTopic.setLastPostDate(postsNewTopic.get(postsNewTopic.size() - 1).getCreateDate());
Forum fromForum = topic.getForum();
topic.setReplies(topic.getReplies() - newTopic.getReplies() - 1);
fromForum.setPostCount(fromForum.getPostCount() - newTopic.getReplies() - 1);
posts.removeAll(postsToRemove);
topic.setLastPostDate(posts.get(posts.size() - 1).getCreateDate());
destForum.addTopicSize();
destForum.setPostCount(destForum.getPostCount() + newTopic.getReplies() + 1);
forumsModule.update(newTopic);
forumsModule.update(topic);
forumsModule.update(fromForum);
forumsModule.update(destForum);
} catch (Exception e) {
log.error(e);
setWarnBundleMessage("ERR_INTERNAL");
return "";
}
// Setting message that everything went smooth.
setInfoBundleMessage("SUCC_TOPIC_SPLITTED");
return "";
}
use of it.vige.rubia.ModuleException 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.ModuleException 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.ModuleException 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.ModuleException 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