1 25 26 package com.j2biz.blogunity.web.actions.my; 27 28 import java.util.Iterator ; 29 30 import javax.servlet.http.HttpServletRequest ; 31 import javax.servlet.http.HttpServletResponse ; 32 33 import com.j2biz.blogunity.dao.BlogDAO; 34 import com.j2biz.blogunity.dao.CategoryDAO; 35 import com.j2biz.blogunity.dao.EntryDAO; 36 import com.j2biz.blogunity.exception.BlogunityException; 37 import com.j2biz.blogunity.i18n.I18N; 38 import com.j2biz.blogunity.i18n.I18NStatusFactory; 39 import com.j2biz.blogunity.pojo.Blog; 40 import com.j2biz.blogunity.pojo.Category; 41 import com.j2biz.blogunity.pojo.Entry; 42 import com.j2biz.blogunity.web.ActionResultFactory; 43 import com.j2biz.blogunity.web.IActionResult; 44 45 52 public class DeleteGlobalCategoryExecAction extends MyAbstractAction { 53 54 private static final IActionResult CATEGORIES_LIST_REDIRECT = ActionResultFactory 55 .buildRedirect("/my/listGlobalCategories"); 56 57 63 public IActionResult execute(HttpServletRequest request, HttpServletResponse response) 64 throws BlogunityException{ 65 66 String id = request.getParameter("id"); 67 68 if (!user.isAdministrator()) 69 throw new BlogunityException(I18NStatusFactory 70 .create(I18N.ERRORS.USER_NOT_AUTHORIZED_FOR_EXECUTION)); 71 72 CategoryDAO categoryDAO = new CategoryDAO(); 73 BlogDAO blogDAO = new BlogDAO(); 74 EntryDAO entryDAO = new EntryDAO(); 75 76 Category cat = categoryDAO.getCategoryByID(Long.parseLong(id)); 77 78 Iterator it = cat.getBlogs().iterator(); 80 while (it.hasNext()) { 81 Blog b = (Blog) it.next(); 82 b.getCategories().remove(cat); 83 blogDAO.updateBlog(b); 84 } 85 86 for (Iterator i = cat.getEntries().iterator(); i.hasNext();) { 88 Entry e = (Entry) i.next(); 89 e.getCategories().remove(cat); 90 entryDAO.updateEntry(e); 91 } 92 93 categoryDAO.deleteCategory(cat); 94 95 navigationStack.pop(); 96 return CATEGORIES_LIST_REDIRECT; 97 } 98 99 } | Popular Tags |