Search in sources :

Example 31 with Category

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);
}
Also used : Category(it.vige.rubia.model.Category) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) Post(it.vige.rubia.model.Post) ArrayList(java.util.ArrayList)

Example 32 with Category

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);
    }
}
Also used : Category(it.vige.rubia.model.Category) LinkedList(java.util.LinkedList) NoResultException(javax.persistence.NoResultException) NonUniqueResultException(javax.persistence.NonUniqueResultException)

Example 33 with Category

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;
}
Also used : Category(it.vige.rubia.model.Category) JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException) ModuleException(it.vige.rubia.ModuleException) Forum(it.vige.rubia.model.Forum) ViewForum(it.vige.rubia.ui.view.ViewForum) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 34 with Category

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);
    }
}
Also used : Category(it.vige.rubia.model.Category) ModuleException(it.vige.rubia.ModuleException) JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException) ModuleException(it.vige.rubia.ModuleException) Forum(it.vige.rubia.model.Forum) ViewForum(it.vige.rubia.ui.view.ViewForum) SecureActionForum(it.vige.rubia.auth.SecureActionForum) PostConstruct(javax.annotation.PostConstruct)

Example 35 with Category

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;
}
Also used : Category(it.vige.rubia.model.Category) JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException) ModuleException(it.vige.rubia.ModuleException)

Aggregations

Category (it.vige.rubia.model.Category)71 Forum (it.vige.rubia.model.Forum)50 CreateCategory.createCategory (it.vige.rubia.selenium.adminpanel.action.CreateCategory.createCategory)48 RemoveCategory.removeCategory (it.vige.rubia.selenium.adminpanel.action.RemoveCategory.removeCategory)48 CreateForum.createForum (it.vige.rubia.selenium.adminpanel.action.CreateForum.createForum)40 Topic (it.vige.rubia.model.Topic)36 Post (it.vige.rubia.model.Post)34 RemoveForum.removeForum (it.vige.rubia.selenium.adminpanel.action.RemoveForum.removeForum)32 CreateTopic.createTopic (it.vige.rubia.selenium.forum.action.CreateTopic.createTopic)30 RemoveTopic.removeTopic (it.vige.rubia.selenium.forum.action.RemoveTopic.removeTopic)24 AfterClass (org.junit.AfterClass)16 BeforeClass (org.junit.BeforeClass)16 Attachment (it.vige.rubia.model.Attachment)15 Poll (it.vige.rubia.model.Poll)14 PollOption (it.vige.rubia.model.PollOption)12 Test (org.junit.Test)11 JSFUtil.handleException (it.vige.rubia.ui.JSFUtil.handleException)8 Poster (it.vige.rubia.model.Poster)7 CreatePost.createPost (it.vige.rubia.selenium.forum.action.CreatePost.createPost)7 ModuleException (it.vige.rubia.ModuleException)6