1 7 package com.dotmarketing.portlets.discountcode.action; 8 9 import java.net.URLDecoder ; 10 import java.text.SimpleDateFormat ; 11 import java.util.ArrayList ; 12 import java.util.Date ; 13 14 import javax.portlet.ActionRequest; 15 import javax.portlet.ActionResponse; 16 import javax.portlet.PortletConfig; 17 import javax.portlet.RenderRequest; 18 import javax.portlet.RenderResponse; 19 import javax.portlet.WindowState; 20 import javax.servlet.jsp.PageContext ; 21 22 import org.apache.commons.beanutils.BeanUtils; 23 import org.apache.struts.action.ActionForm; 24 import org.apache.struts.action.ActionForward; 25 import org.apache.struts.action.ActionMapping; 26 27 import com.dotmarketing.db.DotHibernate; 28 import com.dotmarketing.portal.struts.DotPortletAction; 29 import com.dotmarketing.util.Logger; 30 import com.dotmarketing.util.UtilMethods; 31 import com.dotmarketing.util.WebKeys; 32 import com.liferay.portal.model.User; 33 import com.liferay.portal.util.Constants; 34 import com.dotmarketing.portlets.discountcode.factories.DiscountCodeFactory; 37 import com.dotmarketing.portlets.discountcode.struts.DiscountCodeForm; 38 39 45 public class ViewDiscountCodeAction extends DotPortletAction 46 { 47 public ActionForward render( 48 ActionMapping mapping, ActionForm form, PortletConfig config, 49 RenderRequest req, RenderResponse res) 50 throws Exception { 51 ArrayList discounts; 52 try { 53 String orderBy = req.getParameter(WebKeys.DISCOUNTCODE_ORDER_BY); 54 String direction = req.getParameter(WebKeys.DISCOUNTCODE_DIRECTION); 55 56 orderBy = (UtilMethods.isSet(orderBy) ? orderBy : "code_description"); 57 direction = (UtilMethods.isSet(direction) ? direction : "asc"); 58 59 if (req.getWindowState().equals(WindowState.NORMAL)) 60 { 61 Logger.debug(this, "Showing view answer question minimized"); 62 int limit = 5; 63 discounts = _loadDiscountCode(form,orderBy,direction,limit); 64 req.setAttribute(WebKeys.DISCOUNTCODE_DISCOUNTS,discounts); 65 return mapping.findForward("portlet.ext.discountcode.view"); 66 } 67 else 68 { 69 Logger.debug(this, "Showing view answer question maximized"); 70 int limit = -1; 71 discounts = _loadDiscountCode(form,orderBy,direction,limit); 72 req.setAttribute(WebKeys.DISCOUNTCODE_DISCOUNTS,discounts); 73 return mapping.findForward("portlet.ext.discountcode.view_discountcode"); 74 } 75 } 76 catch (Exception e) { 77 req.setAttribute(PageContext.EXCEPTION, e); 78 return mapping.findForward(com.liferay.portal.util.Constants.COMMON_ERROR); 79 } 80 } 81 82 public void processAction(ActionMapping mapping, ActionForm form,PortletConfig config, ActionRequest req, ActionResponse res) throws Exception 83 { 84 String cmd = req.getParameter(Constants.CMD); 85 String referer = req.getParameter("referer"); 86 87 89 if ((referer != null) && (referer.length() != 0)) { 90 referer = URLDecoder.decode(referer, "UTF-8"); 91 } 92 93 DotHibernate.startTransaction(); 94 95 User user = _getUser(req); 96 97 if ((cmd != null) && cmd.equals(Constants.EDIT)) 98 { 99 try 100 { 101 Logger.debug(this, "Calling Edit Method"); 102 _editWebAsset(req, res, config, form, user); 103 } 104 catch (Exception ae) 105 { 106 _handleException(ae, req); 107 return; 108 } 109 } 110 111 if ((cmd != null) && cmd.equals(Constants.ADD)) 112 { 113 try { 114 Logger.debug(this, "Calling Add Method"); 115 _saveWebAsset(req, res, config, form, user); 116 _sendToReferral(req, res, referer); 117 } catch (Exception ae) 118 { 119 return; 120 } 121 } 122 DotHibernate.commitTransaction(); 123 setForward(req, "portlet.ext.askquint.edit_askquint"); 124 } 125 126 public void _editWebAsset(ActionRequest req, ActionResponse res, PortletConfig config, ActionForm form, User user) 127 throws Exception { 128 130 } 131 132 public void _saveWebAsset(ActionRequest req, ActionResponse res, PortletConfig config, ActionForm form, User user) 133 throws Exception 134 { 135 try 136 { 137 } 142 catch(Exception ex) 143 { 144 145 } 146 } 147 148 private ArrayList _loadDiscountCode(ActionForm form, String orderBy, String direction, int limit) throws Exception 149 { 150 DiscountCodeForm discountCodeForm = (DiscountCodeForm) form; 151 SimpleDateFormat df = new SimpleDateFormat (WebKeys.DateFormats.SHORTDATE); 152 int discountType = discountCodeForm.getDiscountType(); 153 Date startDate = null; 154 try 155 { 156 if (UtilMethods.isSet(discountCodeForm.getStartDate())) 157 { 158 startDate = df.parse(discountCodeForm.getStartDate()); 159 } 160 } 161 catch(Exception ex) 162 { 163 Logger.debug(ex.toString()); 164 } 165 166 Date endDate = null; 167 try 168 { 169 if (UtilMethods.isSet(discountCodeForm.getEndDate())) 170 { 171 endDate = df.parse(discountCodeForm.getEndDate()); 172 } 173 } 174 catch(Exception ex) 175 { 176 Logger.debug(ex.toString()); 177 } 178 String codeId = discountCodeForm.getCodeId(); 179 String codeDesc = discountCodeForm.getCodeDescription(); 180 181 ArrayList discounts; 182 discounts = (ArrayList ) DiscountCodeFactory.searchDiscountCode(discountType,startDate,endDate,codeId,codeDesc,orderBy,direction,limit); 183 return discounts; 184 } 185 } | Popular Tags |