package org.mapache.business.topic;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import org.mapache.business.MapacheException;
import org.mapache.business.blog.Blog;
import org.mapache.business.category.Category;
import org.mapache.business.configuration.ConfigurationManager;
import org.mapache.data.DAOException;
import org.mapache.data.TopicDAO;
public class TopicManager {
private TopicDAO topicDataAccess;
public TopicManager() {
topicDataAccess =
ConfigurationManager.getInstance().getDAOFactory().getTopicDAO();
}
public List<Topic> loadAllTopics() throws MapacheException {
return topicDataAccess.loadAllTopics();
}
public List<Topic> loadTopicsOfBlog(Blog blog) throws MapacheException {
return topicDataAccess.loadTopicsForBlog(blog.getBlogID());
}
public void saveTopic(Topic _topic) throws MapacheException {
topicDataAccess.saveTopic(_topic);
}
public void deleteTopic(Topic topic) throws MapacheException {
if(topic.getReplyCount()>0){
throw new MapacheException("Topic contains replies, can't delete blog",null);
}
else{
topicDataAccess.deleteTopic(topic);
}
}
public void createTopic(Topic newTopic,int blogID) throws MapacheException {
topicDataAccess.createTopic(newTopic,blogID);
}
public Topic loadTopicByTopicID(int topicID) throws MapacheException{
return topicDataAccess.loadTopicByTopicID(topicID);
}
public List<Topic> loadAllTopics_visitor(Blog _blog,Category _category) throws MapacheException {
if(_category!=null){
return topicDataAccess.loadTopicsOfCategory_visitor(_category.getCategoryID());
}else if(_blog!=null){
return topicDataAccess.loadTopicsOfBlog_visitor(_blog.getBlogID());
}
return topicDataAccess.loadAllTopics_visitor();
}
public Topic loadTopicByTopicTitle(String title) throws MapacheException {
return topicDataAccess.loadTopicByTitle_visitor(title);
}
public List<Topic> loadTopicsBySearch(String[] params) throws MapacheException{
return topicDataAccess.loadTopicsBySearch(params);
}
}