Search in sources :

Example 6 with Category

use of net.jforum.entities.Category in project jforum2 by rafaelsteil.

the class ForumRepository method getListAllowedForums.

public static String getListAllowedForums() {
    int n = 0;
    StringBuffer buf = new StringBuffer();
    List allCategories = ForumRepository.getAllCategories();
    for (Iterator iter = allCategories.iterator(); iter.hasNext(); ) {
        Collection forums = ((Category) iter.next()).getForums();
        for (Iterator tmpIterator = forums.iterator(); tmpIterator.hasNext(); ) {
            Forum f = (Forum) tmpIterator.next();
            if (ForumRepository.isForumAccessible(f.getId())) {
                if (n++ > 0) {
                    buf.append(',');
                }
                buf.append(f.getId());
            }
        }
    }
    if (n <= 0) {
        return "-1";
    }
    return buf.toString();
}
Also used : Category(net.jforum.entities.Category) Iterator(java.util.Iterator) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) Forum(net.jforum.entities.Forum)

Example 7 with Category

use of net.jforum.entities.Category in project jforum2 by rafaelsteil.

the class ForumRepository method removeForum.

/**
	 * Removes a forum from the cache.
	 * 
	 * @param forum The forum instance to remove.
	 */
public static synchronized void removeForum(Forum forum) {
    String id = Integer.toString(forum.getId());
    Map m = (Map) cache.get(FQN, RELATION);
    m.remove(id);
    cache.add(FQN, RELATION, m);
    id = Integer.toString(forum.getCategoryId());
    Category c = (Category) cache.get(FQN, id);
    c.removeForum(forum.getId());
    cache.add(FQN, id, c);
    Set s = (Set) cache.get(FQN, CATEGORIES_SET);
    cache.add(FQN, CATEGORIES_SET, s);
}
Also used : Category(net.jforum.entities.Category) TreeSet(java.util.TreeSet) Set(java.util.Set) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with Category

use of net.jforum.entities.Category in project jforum2 by rafaelsteil.

the class ForumRepository method reloadCategory.

/**
	 * Updates some category.
	 * This method only updated the "name" and "order" fields. 
	 *  
	 * @param c The category to update. The method will search for a category
	 * with the same id and update its data.
	 */
public static synchronized void reloadCategory(Category c) {
    Category current = (Category) cache.get(FQN, Integer.toString(c.getId()));
    Category currentAtOrder = findCategoryByOrder(c.getOrder());
    Set tmpSet = new TreeSet(new CategoryOrderComparator());
    tmpSet.addAll((Set) cache.get(FQN, CATEGORIES_SET));
    if (currentAtOrder != null) {
        tmpSet.remove(currentAtOrder);
        cache.remove(FQN, Integer.toString(currentAtOrder.getId()));
    }
    tmpSet.add(c);
    cache.add(FQN, Integer.toString(c.getId()), c);
    if (currentAtOrder != null && c.getId() != currentAtOrder.getId()) {
        tmpSet.remove(current);
        currentAtOrder.setOrder(current.getOrder());
        tmpSet.add(currentAtOrder);
        cache.add(FQN, Integer.toString(currentAtOrder.getId()), currentAtOrder);
    }
    cache.add(FQN, CATEGORIES_SET, tmpSet);
}
Also used : Category(net.jforum.entities.Category) TreeSet(java.util.TreeSet) Set(java.util.Set) CategoryOrderComparator(net.jforum.util.CategoryOrderComparator) TreeSet(java.util.TreeSet)

Example 9 with Category

use of net.jforum.entities.Category in project jforum2 by rafaelsteil.

the class ForumCommon method getAllCategoriesAndForums.

/**
	 * Gets all forums available to the user.
	 * 
	 * @param us An <code>UserSession</code> instance with user information
	 * @param anonymousUserId The id which represents the anonymous user
	 * @param tracking <code>Map</code> instance with information 
	 * about the topics read by the user
	 * @param checkUnreadPosts <code>true</code> if is to search for unread topics inside the forums, 
	 * or <code>false</code> if this action is not needed. 
	 * @return A <code>List</code> instance where each record is an instance of a <code>Category</code>
	 * object
	 */
public static List getAllCategoriesAndForums(UserSession us, int anonymousUserId, Map tracking, boolean checkUnreadPosts) {
    long lastVisit = 0;
    int userId = anonymousUserId;
    if (us != null) {
        lastVisit = us.getLastVisit().getTime();
        userId = us.getUserId();
    }
    // Do not check for unread posts if the user is not logged in
    checkUnreadPosts = checkUnreadPosts && (userId != anonymousUserId);
    List categories = ForumRepository.getAllCategories(userId);
    if (!checkUnreadPosts) {
        return categories;
    }
    List returnCategories = new ArrayList();
    for (Iterator iter = categories.iterator(); iter.hasNext(); ) {
        Category c = new Category((Category) iter.next());
        for (Iterator tmpIterator = c.getForums().iterator(); tmpIterator.hasNext(); ) {
            Forum f = (Forum) tmpIterator.next();
            ForumCommon.checkUnreadPosts(f, tracking, lastVisit);
        }
        returnCategories.add(c);
    }
    return returnCategories;
}
Also used : Category(net.jforum.entities.Category) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Forum(net.jforum.entities.Forum)

Example 10 with Category

use of net.jforum.entities.Category in project jforum2 by rafaelsteil.

the class ForumRepository method addForum.

/**
	 * Adds a new forum to the cache repository.	 
	 * 
	 * @param forum The forum to add
	 */
public static synchronized void addForum(Forum forum) {
    String categoryId = Integer.toString(forum.getCategoryId());
    Category c = (Category) cache.get(FQN, categoryId);
    c.addForum(forum);
    cache.add(FQN, categoryId, c);
    Map m = (Map) cache.get(FQN, RELATION);
    m.put(Integer.toString(forum.getId()), categoryId);
    cache.add(FQN, RELATION, m);
    Set s = (Set) cache.get(FQN, CATEGORIES_SET);
    cache.add(FQN, CATEGORIES_SET, s);
}
Also used : Category(net.jforum.entities.Category) TreeSet(java.util.TreeSet) Set(java.util.Set) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Category (net.jforum.entities.Category)20 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Forum (net.jforum.entities.Forum)7 Iterator (java.util.Iterator)6 Map (java.util.Map)6 Set (java.util.Set)6 TreeSet (java.util.TreeSet)6 HashMap (java.util.HashMap)5 CategoryNotFoundException (net.jforum.exceptions.CategoryNotFoundException)2 DatabaseException (net.jforum.exceptions.DatabaseException)2 PermissionControl (net.jforum.security.PermissionControl)2 CategoryOrderComparator (net.jforum.util.CategoryOrderComparator)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Collection (java.util.Collection)1 ForumDAO (net.jforum.dao.ForumDAO)1 GroupSecurityDAO (net.jforum.dao.GroupSecurityDAO)1