001
014
015 package com.liferay.portlet.shopping.action;
016
017 import com.liferay.portal.kernel.servlet.SessionErrors;
018 import com.liferay.portal.kernel.util.ParamUtil;
019 import com.liferay.portal.security.auth.PrincipalException;
020 import com.liferay.portal.struts.PortletAction;
021 import com.liferay.portal.util.WebKeys;
022 import com.liferay.portlet.shopping.NoSuchCouponException;
023 import com.liferay.portlet.shopping.model.ShoppingCoupon;
024 import com.liferay.portlet.shopping.service.ShoppingCouponLocalServiceUtil;
025
026 import javax.portlet.PortletConfig;
027 import javax.portlet.RenderRequest;
028 import javax.portlet.RenderResponse;
029
030 import org.apache.struts.action.ActionForm;
031 import org.apache.struts.action.ActionForward;
032 import org.apache.struts.action.ActionMapping;
033
034
037 public class ViewCouponAction extends PortletAction {
038
039 @Override
040 public ActionForward render(
041 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
042 RenderRequest renderRequest, RenderResponse renderResponse)
043 throws Exception {
044
045 try {
046 long couponId = ParamUtil.getLong(renderRequest, "couponId");
047
048 String code = ParamUtil.getString(renderRequest, "code");
049
050 ShoppingCoupon coupon = null;
051
052 if (couponId > 0) {
053 coupon = ShoppingCouponLocalServiceUtil.getCoupon(couponId);
054 }
055 else {
056 coupon = ShoppingCouponLocalServiceUtil.getCoupon(code);
057 }
058
059 renderRequest.setAttribute(WebKeys.SHOPPING_COUPON, coupon);
060 }
061 catch (Exception e) {
062 if (e instanceof NoSuchCouponException ||
063 e instanceof PrincipalException) {
064
065 SessionErrors.add(renderRequest, e.getClass().getName());
066
067 return mapping.findForward("portlet.shopping.error");
068 }
069 else {
070 throw e;
071 }
072 }
073
074 return mapping.findForward("portlet.shopping.view_coupon");
075 }
076
077 }