1 package com.dotmarketing.portlets.mailinglistbuilder.action; 2 3 import java.util.Iterator ; 4 import java.util.List ; 5 import java.util.Map ; 6 7 import javax.portlet.PortletConfig; 8 import javax.portlet.PortletSession; 9 import javax.portlet.RenderRequest; 10 import javax.portlet.RenderResponse; 11 import javax.portlet.WindowState; 12 import javax.servlet.http.HttpServletRequest ; 13 import javax.servlet.jsp.PageContext ; 14 15 import org.apache.struts.action.ActionForm; 16 import org.apache.struts.action.ActionForward; 17 import org.apache.struts.action.ActionMapping; 18 19 import com.dotmarketing.portal.struts.DotPortletAction; 20 import com.dotmarketing.portlets.mailinglistbuilder.factories.MailingListBuilderFactory; 21 import com.dotmarketing.portlets.mailinglistbuilder.struts.MailingListSearchForm; 22 import com.dotmarketing.portlets.mailinglists.factories.MailingListFactory; 23 import com.dotmarketing.util.Validator; 24 import com.dotmarketing.util.WebKeys; 25 import com.liferay.portal.ejb.UserLocalManagerUtil; 26 import com.liferay.portal.model.Address; 27 import com.liferay.portal.model.User; 28 import com.liferay.portal.util.Constants; 29 import com.liferay.portlet.RenderRequestImpl; 30 31 37 public class ViewMailingListAction extends DotPortletAction { 38 39 42 public ActionForward render( 43 ActionMapping mapping, ActionForm form, PortletConfig config, 44 RenderRequest req, RenderResponse res) 45 throws Exception { 46 47 HttpServletRequest request = ((RenderRequestImpl)req).getHttpServletRequest(); 48 49 String cmd = req.getParameter("cmd"); 50 51 MailingListSearchForm searchForm = (MailingListSearchForm) form; 52 53 try { 54 User user = _getUser(req); 56 57 58 List list = null; 59 boolean isMailingListAdmin = MailingListFactory.isMailingListManager(user); 60 61 if (isMailingListAdmin) 62 list = MailingListFactory.getAllMailingLists(); 63 else { 64 list = MailingListFactory.getMailingListsByUser(user); 65 list.add(MailingListFactory.getUnsubscribersMailingList()); 66 } 67 req.setAttribute(WebKeys.MAILING_LIST_VIEW, list); 68 69 if (!Validator.validate(request, searchForm, mapping)) { 70 if (req.getWindowState().equals(WindowState.NORMAL)) { 71 return mapping.findForward("portlet.ext.mailinglistbuilder.view"); 72 } 73 else { 74 req.setAttribute(WebKeys.MAILINGLISTFORM, searchForm); 75 76 return mapping.findForward("portlet.ext.mailinglistbuilder.view_marketinglist"); 77 } 78 } 79 80 if (req.getWindowState().equals(WindowState.NORMAL)) { 81 return mapping.findForward("portlet.ext.mailinglistbuilder.view"); 82 } 83 else { 84 if (cmd != null && cmd.equals(com.liferay.portal.util.Constants.SEARCH)) { 85 _doSearch (req, searchForm, user); 86 } 87 req.setAttribute(WebKeys.MAILINGLISTFORM, searchForm); 88 return mapping.findForward("portlet.ext.mailinglistbuilder.view_marketinglist"); 89 } 90 } 91 catch (Exception e) { 92 req.setAttribute(PageContext.EXCEPTION, e); 93 return mapping.findForward(Constants.COMMON_ERROR); 94 } 95 } 96 97 101 private void _doSearch(RenderRequest req, MailingListSearchForm searchForm, User webUser) throws Exception { 102 List matches = MailingListBuilderFactory.doSearch(searchForm); 103 String [][] matchesArray = new String [matches.size()][12]; 104 Iterator it = matches.iterator(); 105 for (int i = 0; it.hasNext(); i++) { 106 String userId = (String ) ((Map )it.next()).get("userid"); 107 User user = UserLocalManagerUtil.getUserById(userId); 108 List addresses = user.getAddresses(); 109 Address address = null; 110 if (addresses.size() > 0) { 111 address = (Address) addresses.get(0); 112 } 113 matchesArray[i][0] = userId; 114 matchesArray[i][1] = user.getFirstName(); 115 matchesArray[i][2] = user.getMiddleName(); 116 matchesArray[i][3] = user.getLastName(); 117 matchesArray[i][4] = user.getEmailAddress(); 118 matchesArray[i][5] = (address == null)?"":address.getStreet1(); 119 matchesArray[i][6] = (address == null)?"":address.getStreet2(); 120 matchesArray[i][7] = (address == null)?"":address.getCity(); 121 matchesArray[i][8] = (address == null)?"":address.getState(); 122 matchesArray[i][9] = (address == null)?"":address.getZip(); 123 matchesArray[i][10] = (address == null)?"":address.getCountry(); 124 matchesArray[i][11] = (address == null)?"":address.getPhone(); 125 } 126 req.setAttribute(WebKeys.MAILINGLIST, matchesArray); 127 PortletSession sess = req.getPortletSession(); 128 sess.setAttribute(WebKeys.MAILINGLIST, matchesArray); 129 130 131 } 132 133 134 } | Popular Tags |