package org.mapache.business;
import java.util.LinkedList;
import java.util.List;
import org.mapache.business.blog.Blog;
import org.mapache.business.blog.BlogManager;
import org.mapache.business.category.Category;
import org.mapache.business.category.CategoryManager;
import org.mapache.business.reply.Reply;
import org.mapache.business.reply.ReplyManager;
import org.mapache.business.topic.Topic;
import org.mapache.business.topic.TopicManager;
import org.mapache.business.user.User;
import org.mapache.business.user.UserManager;
public class BusinessController {
private BlogManager _blogManager;
private TopicManager _topicManager;
private CategoryManager _categoryManager;
private ReplyManager _replyManager;
private UserManager _userManager;
public BusinessController() {
}
private CategoryManager getCategoryManager() {
if(_categoryManager==null){
_categoryManager = new CategoryManager();
}
return _categoryManager;
}
private TopicManager getTopicManager(){
if(_topicManager==null){
_topicManager = new TopicManager();
}
return _topicManager;
}
private UserManager getUserManager(){
if(_userManager ==null){
_userManager = new UserManager();
}
return _userManager;
}
private ReplyManager getReplyManager(){
if(_replyManager == null){
_replyManager = new ReplyManager();
}
return _replyManager;
}
private BlogManager getBlogManager(){
if(_blogManager == null){
_blogManager = new BlogManager();
}
return _blogManager;
}
public List<Blog> loadAllBlogs() throws MapacheException {
return getBlogManager().loadAllBlogs();
}
public void saveBlog(Blog _blog) throws MapacheException {
getBlogManager().saveBlog(_blog);
}
public void deleteBlog(Blog _blog) throws MapacheException {
getBlogManager().deleteBlog(_blog);
}
public void createBlog(Blog newBlog) throws MapacheException {
getBlogManager().createBlog(newBlog);
}
public Blog loadBlogByBlogID(int blogID) throws MapacheException {
return getBlogManager().loadBlogByBlogID(blogID);
}
public List<Topic> loadTopicsOfBlog(Blog _blog) throws MapacheException {
if(_blog.getBlogID()==-1){
return getTopicManager().loadAllTopics();
}
else{
return getTopicManager().loadTopicsOfBlog(_blog);
}
}
public void saveTopic(Topic _topic) throws MapacheException {
getTopicManager().saveTopic(_topic);
}
public List<Category> loadAllCategories() throws MapacheException {
return getCategoryManager().loadAllCategories();
}
public Category loadCategoryByCategoryId(int categoryID) throws MapacheException {
return getCategoryManager().loadCategoryByCategoryId(categoryID);
}
public void deleteTopic(Topic _topic) throws MapacheException {
getTopicManager().deleteTopic(_topic);
}
public void createTopic(Topic newTopic,int blogID) throws MapacheException {
getTopicManager().createTopic(newTopic,blogID);
}
public void saveCategory(Category _category) throws MapacheException{
getCategoryManager().saveCategory(_category);
}
public void deleteCategory(Category _category) throws MapacheException {
getCategoryManager().deleteCategory(_category);
}
public void createCategory(Category newCategory) throws MapacheException {
getCategoryManager().createCategory(newCategory);
}
public Topic loadTopicByTopicID(int topicID) throws MapacheException{
return getTopicManager().loadTopicByTopicID(topicID);
}
public List<Reply> loadRepliesOfTopic(Topic _topic) throws MapacheException{
if(_topic.getTopicID()==-1){
return getReplyManager().loadAllReplies();
}
else{
return getReplyManager().loadRepliesOfTopic(_topic);
}
}
public void createReply(Reply newReply, int topicID) throws MapacheException{
getReplyManager().createReply(newReply,topicID);
}
public boolean authenticateUser(User user) throws MapacheException {
return getUserManager().authenticateUser(user);
}
}