use of it.vige.rubia.model.Category 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.Category in project rubia-forums by flashboss.
the class ForumsModuleImpl method findCategoriesFetchForums.
@Override
public List<Category> findCategoriesFetchForums(Integer indexInstance) throws ModuleException {
try {
TypedQuery<Category> query = em.createNamedQuery("findCategoriesFetchForums", Category.class);
query.setParameter("forumInstanceId", indexInstance);
List<Category> categoriesWithDuplicates = query.getResultList();
List<Category> categories = new LinkedList<Category>();
for (Category category : categoriesWithDuplicates) {
if (!categories.contains(category)) {
categories.add(category);
}
}
return categories;
} catch (Exception e) {
String message = "Cannot find categories";
throw new ModuleException(message, e);
}
}
use of it.vige.rubia.model.Category in project rubia-forums by flashboss.
the class AdminController method editForum.
/**
* @return the navigation state of the application
*/
public String editForum() {
String navState = null;
boolean success = false;
try {
int forumId = -1;
String cour = ForumUtil.getParameter(p_forumId);
if (cour != null && cour.trim().length() > 0) {
forumId = Integer.parseInt(cour);
}
// grab the forum from the module and set the proper information
Forum forum = forumsModule.findForumById(forumId);
Category selectedCategory = forumsModule.findCategoryById(this.selectedCategory);
forum.setCategory(selectedCategory);
forum.setName(forumName);
forum.setDescription(forumDescription);
forumsModule.update(forum);
String start = getBundleMessage("ResourceJSF", "Forum_updated_0");
String end = getBundleMessage("ResourceJSF", "Forum_updated_1");
setMessage(FEEDBACK, start + " \"" + forumName + "\" " + end);
navState = "";
success = true;
} catch (Exception e) {
handleException(e);
} finally {
if (success) {
// cleanup the state
cleanup();
}
}
return navState;
}
use of it.vige.rubia.model.Category in project rubia-forums by flashboss.
the class AdminController method startService.
/**
* Start the admin controller as service
*/
@PostConstruct
public void startService() {
try {
// load the selected category if a categoryid is found
// fetch the category to be edited/deleted
int categoryId = -1;
String cour = ForumUtil.getParameter(p_categoryId);
if (cour != null && cour.trim().length() > 0) {
categoryId = Integer.parseInt(cour);
}
if (categoryId != -1) {
Category category = null;
try {
category = forumsModule.findCategoryById(categoryId);
} catch (ModuleException e) {
// Category was deleted
}
if (category != null) {
categoryName = category.getTitle();
selectedCategory = category.getId().intValue();
}
}
// load the selected forum is a forumid is found
// fetch the forum to be edited/deleted
int forumId = -1;
String forumIdStr = ForumUtil.getParameter(p_forumId);
if (forumIdStr != null && forumIdStr.trim().length() > 0) {
forumId = Integer.parseInt(forumIdStr);
}
if (forumId != -1) {
Forum forum = null;
try {
forum = forumsModule.findForumById(forumId);
} catch (ModuleException e) {
// Forum was deleted
}
if (forum != null) {
forumName = forum.getName();
forumDescription = forum.getDescription();
selectedCategory = forum.getCategory().getId().intValue();
selectedForum = forum.getId().intValue();
}
}
// Checking for editModes flags
String editCatStr = ForumUtil.getParameter(EDIT_CATEGORY);
if (editCatStr != null && editCatStr.trim().length() > 0) {
editCategoryMode = Boolean.valueOf(editCatStr).booleanValue();
}
String editForStr = ForumUtil.getParameter(EDIT_FORUM);
if (editForStr != null && editForStr.trim().length() > 0) {
editForumMode = Boolean.valueOf(editForStr).booleanValue();
}
// Checking for addModes flags
String addCatStr = ForumUtil.getParameter(ADD_CATEGORY);
if (addCatStr != null && addCatStr.trim().length() > 0) {
addCategoryMode = Boolean.valueOf(addCatStr).booleanValue();
}
String addForStr = ForumUtil.getParameter(ADD_FORUM);
if (addForStr != null && addForStr.trim().length() > 0) {
addForumMode = Boolean.valueOf(addForStr).booleanValue();
}
} catch (Exception e) {
handleException(e);
}
}
use of it.vige.rubia.model.Category in project rubia-forums by flashboss.
the class AdminController method deleteCategory.
/**
* @return the navigation state of the application
*/
public String deleteCategory() {
String navState = null;
boolean success = false;
try {
int categoryId = -1;
String cour = ForumUtil.getParameter(p_categoryId);
if (cour != null && cour.trim().length() > 0) {
categoryId = Integer.parseInt(cour);
}
// grab the category from the module and set the title
Category source = forumsModule.findCategoryById(categoryId);
if (selectedCategory != -1) {
Category target = forumsModule.findCategoryById(selectedCategory);
// move all the forums from source category to the selected
// target category
forumsModule.addAllForums(source, target);
}
// remove the source category
forumsModule.removeCategory(source.getId());
String start = getBundleMessage("ResourceJSF", "Category_deleted_0");
String end = getBundleMessage("ResourceJSF", "Category_deleted_1");
setMessage(FEEDBACK, start + " \"" + categoryName + "\" " + end);
navState = DELETE_CATEGORY;
success = true;
} catch (Exception e) {
handleException(e);
} finally {
if (success) {
// cleanup the state
cleanup();
}
}
return navState;
}
Aggregations