use of net.jforum.exceptions.CategoryNotFoundException in project jforum2 by rafaelsteil.
the class ForumRepository method loadForums.
/**
* Loads all forums.
* @param fm ForumDAO
*/
private void loadForums(ForumDAO fm) {
List l = fm.selectAll();
Map m = (Map) cache.get(FQN, RELATION);
if (m == null) {
m = new HashMap();
}
int lastId = 0;
Category c = null;
String catId = null;
for (Iterator iter = l.iterator(); iter.hasNext(); ) {
Forum f = (Forum) iter.next();
if (f.getCategoryId() != lastId) {
if (c != null) {
cache.add(FQN, catId, c);
}
lastId = f.getCategoryId();
catId = Integer.toString(f.getCategoryId());
c = (Category) cache.get(FQN, catId);
}
if (c == null) {
throw new CategoryNotFoundException("Category for forum #" + f.getId() + " not found");
}
String forumId = Integer.toString(f.getId());
c.addForum(f);
m.put(forumId, catId);
}
if (c != null) {
cache.add(FQN, catId, c);
}
cache.add(FQN, RELATION, m);
}
use of net.jforum.exceptions.CategoryNotFoundException in project jforum2 by rafaelsteil.
the class ForumRepository method getAllCategories.
/**
* Gets all categories from the cache.
*
* @param userId int
* @return <code>List</code> with the categories. Each entry is a <code>Category</code> object.
*/
public static List getAllCategories(int userId) {
PermissionControl pc = SecurityRepository.get(userId);
List l = new ArrayList();
Set categoriesSet = (Set) cache.get(FQN, CATEGORIES_SET);
if (categoriesSet == null) {
synchronized (ForumRepository.instance) {
if (categoriesSet == null) {
logger.warn("Categories set returned null from the cache. Trying to reload");
try {
ForumRepository.instance.loadCategories(DataAccessDriver.getInstance().newCategoryDAO());
ForumRepository.instance.loadForums(DataAccessDriver.getInstance().newForumDAO());
} catch (Exception e) {
throw new CategoryNotFoundException("Failed to get the category", e);
}
categoriesSet = (Set) cache.get(FQN, CATEGORIES_SET);
if (categoriesSet == null) {
throw new CategoryNotFoundException("Could not find all categories. There must be a problem with the cache");
}
}
}
}
for (Iterator iter = categoriesSet.iterator(); iter.hasNext(); ) {
Category c = getCategory(pc, ((Category) iter.next()).getId());
if (c != null) {
l.add(c);
}
}
return l;
}
Aggregations