use of it.vige.rubia.model.Forum in project rubia-forums by flashboss.
the class ForumsModuleImpl method createForum.
@Override
public Forum createForum(Category category, String name, String description) throws ModuleException {
try {
Forum forum = new Forum();
forum.setCategory(category);
forum.setName(name);
forum.setDescription(description);
forum.setOrder(getLastForumOrder(category) + 10);
em.persist(forum);
em.flush();
return forum;
} catch (Exception e) {
String errorMessage = "Cannot create forum";
throw new ModuleException(errorMessage, e);
}
}
use of it.vige.rubia.model.Forum in project rubia-forums by flashboss.
the class ForumsModuleImpl method addAllForums.
@Override
public void addAllForums(Category source, Category target) throws ModuleException {
List<Forum> sourceForums = findForumsByCategory(source);
List<Forum> targetForums = findForumsByCategory(target);
targetForums.addAll(sourceForums);
for (Forum forum : targetForums) {
forum.setCategory(target);
}
source.setForums(new ArrayList<Forum>());
}
use of it.vige.rubia.model.Forum in project rubia-forums by flashboss.
the class ForumsModuleImpl method removePost.
@Override
public void removePost(int postId, boolean isLastPost) throws ModuleException {
try {
Post post = em.find(Post.class, postId);
Topic topic = post.getTopic();
Forum forum = topic.getForum();
em.remove(post);
topic.setReplies(topic.getReplies() - 1);
forum.setPostCount(forum.getPostCount() - 1);
List<Post> posts = findPostsByTopicId(topic);
Post lastPost = posts.get(posts.size() - 1);
if (isLastPost) {
topic.setLastPostDate(lastPost.getCreateDate());
}
em.merge(topic);
em.merge(forum);
em.flush();
} catch (Exception e) {
String errorMessage = "Cannot delete post";
throw new ModuleException(errorMessage, e);
}
}
use of it.vige.rubia.model.Forum in project rubia-forums by flashboss.
the class ForumsModuleImpl method removeTopic.
@Override
public void removeTopic(int topicId) throws ModuleException {
try {
Topic topic = em.find(Topic.class, topicId);
Forum forum = topic.getForum();
if (forum != null) {
topic.setForum(null);
forum.setPostCount(forum.getPostCount() - topic.getReplies() - 1);
forum.setTopicCount(forum.getTopicCount() - 1);
em.merge(forum);
em.remove(em.merge(topic));
} else {
em.remove(topic);
}
em.flush();
} catch (Exception e) {
String errorMessage = "Cannot delete topic";
throw new ModuleException(errorMessage, e);
}
}
use of it.vige.rubia.model.Forum in project rubia-forums by flashboss.
the class AdminController method moveForumDown.
/**
* @return the navigation state of the application
*/
public String moveForumDown() {
String navState = null;
try {
// get the categoryId where this forum should be added
int forumId = -1;
String cour = ForumUtil.getParameter(p_forumId);
if (cour != null && cour.trim().length() > 0) {
forumId = Integer.parseInt(cour);
}
Forum forum = forumsModule.findForumById(forumId);
forum.setOrder(forum.getOrder() + down);
forumsModule.update(forum);
Iterator<Forum> forums = forumsModule.findForumsByCategory(forum.getCategory()).iterator();
for (int index = 10; forums.hasNext(); index += 10) {
forum = forums.next();
forum.setOrder(index);
forumsModule.update(forum);
}
} catch (Exception e) {
handleException(e);
}
return navState;
}
Aggregations