1 package com.dotmarketing.portlets.user.action; 2 3 import java.util.List ; 4 5 import javax.portlet.ActionRequest; 6 import javax.portlet.ActionResponse; 7 import javax.portlet.PortletConfig; 8 import javax.servlet.http.HttpServletRequest ; 9 import javax.servlet.http.HttpServletResponse ; 10 11 import org.apache.struts.action.ActionForm; 12 import org.apache.struts.action.ActionMapping; 13 14 import com.dotmarketing.beans.UserProxy; 15 import com.dotmarketing.db.DotHibernate; 16 import com.dotmarketing.factories.InodeFactory; 17 import com.dotmarketing.factories.UserProxyFactory; 18 import com.dotmarketing.portal.struts.DotPortletAction; 19 import com.dotmarketing.portlets.categories.factories.CategoryFactory; 20 import com.dotmarketing.portlets.categories.model.Category; 21 import com.dotmarketing.portlets.user.struts.UserCategoriesForm; 22 import com.dotmarketing.util.Logger; 23 import com.liferay.portlet.ActionRequestImpl; 24 import com.liferay.portlet.ActionResponseImpl; 25 import com.liferay.util.servlet.SessionMessages; 26 27 public class EditUserCategoriesAction extends DotPortletAction 28 { 29 30 36 37 public void processAction( 38 ActionMapping mapping, ActionForm form, PortletConfig config, 39 ActionRequest req, ActionResponse res) 40 throws Exception { 41 UserCategoriesForm userCategoriesForm = (UserCategoriesForm) form; 42 ActionResponseImpl resImpl = (ActionResponseImpl) res; 43 ActionRequestImpl reqImpl = (ActionRequestImpl) req; 44 HttpServletResponse httpRes = resImpl.getHttpServletResponse(); 45 HttpServletRequest httpReq = reqImpl.getHttpServletRequest(); 46 47 String referer = req.getParameter("referer"); 48 49 53 long userProxyInode = userCategoriesForm.getUserProxy(); 54 UserProxy userProxy = UserProxyFactory.getUserProxy(userProxyInode); 55 String [] categories = userCategoriesForm.getCategories(); 56 if(categories != null && userProxy.getInode() != 0) 57 { 58 try 59 { 60 new DotHibernate().startTransaction(); 61 List myUserCategories = InodeFactory.getChildrenClass(userProxy,Category.class); 62 InodeFactory.deleteChildrenOfClass(userProxy,Category.class); 63 for(int i = 0;i < categories.length;i++) 64 { 65 Category category = CategoryFactory.getCategory(categories[i]); 66 if(category.getInode() != 0) 67 { 68 userProxy.addChild(category); 69 } 70 } 71 new DotHibernate().commitTransaction(); 72 } 73 catch(Exception ex) 74 { 75 Logger.warn(this,ex.toString()); 76 new DotHibernate().rollbackTransaction(); 77 } 78 79 } 80 referer += "&layer=other"; 81 _sendToReferral(req,res,referer); 82 SessionMessages.add(req,"categories"); 83 } 84 } 85 | Popular Tags |