1
14
15 package com.liferay.portlet.shopping.action;
16
17 import com.liferay.portal.kernel.servlet.SessionErrors;
18 import com.liferay.portal.kernel.util.ParamUtil;
19 import com.liferay.portal.security.auth.PrincipalException;
20 import com.liferay.portal.struts.PortletAction;
21 import com.liferay.portal.util.WebKeys;
22 import com.liferay.portlet.shopping.NoSuchCouponException;
23 import com.liferay.portlet.shopping.model.ShoppingCoupon;
24 import com.liferay.portlet.shopping.service.ShoppingCouponLocalServiceUtil;
25
26 import javax.portlet.PortletConfig;
27 import javax.portlet.RenderRequest;
28 import javax.portlet.RenderResponse;
29
30 import org.apache.struts.action.ActionForm;
31 import org.apache.struts.action.ActionForward;
32 import org.apache.struts.action.ActionMapping;
33
34
39 public class ViewCouponAction extends PortletAction {
40
41 public ActionForward render(
42 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
43 RenderRequest renderRequest, RenderResponse renderResponse)
44 throws Exception {
45
46 try {
47 long couponId = ParamUtil.getLong(renderRequest, "couponId");
48
49 String code = ParamUtil.getString(renderRequest, "code");
50
51 ShoppingCoupon coupon = null;
52
53 if (couponId > 0) {
54 coupon = ShoppingCouponLocalServiceUtil.getCoupon(couponId);
55 }
56 else {
57 coupon = ShoppingCouponLocalServiceUtil.getCoupon(code);
58 }
59
60 renderRequest.setAttribute(WebKeys.SHOPPING_COUPON, coupon);
61 }
62 catch (Exception e) {
63 if (e instanceof NoSuchCouponException ||
64 e instanceof PrincipalException) {
65
66 SessionErrors.add(renderRequest, e.getClass().getName());
67
68 return mapping.findForward("portlet.shopping.error");
69 }
70 else {
71 throw e;
72 }
73 }
74
75 return mapping.findForward("portlet.shopping.view_coupon");
76 }
77
78 }