001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.shopping.action;
016    
017    import com.liferay.portal.kernel.util.ParamUtil;
018    import com.liferay.portal.theme.ThemeDisplay;
019    import com.liferay.portal.util.PortalUtil;
020    import com.liferay.portal.util.WebKeys;
021    import com.liferay.portlet.shopping.model.ShoppingCategory;
022    import com.liferay.portlet.shopping.model.ShoppingCategoryConstants;
023    import com.liferay.portlet.shopping.model.ShoppingCoupon;
024    import com.liferay.portlet.shopping.model.ShoppingItem;
025    import com.liferay.portlet.shopping.model.ShoppingOrder;
026    import com.liferay.portlet.shopping.service.ShoppingCategoryServiceUtil;
027    import com.liferay.portlet.shopping.service.ShoppingCouponServiceUtil;
028    import com.liferay.portlet.shopping.service.ShoppingItemServiceUtil;
029    import com.liferay.portlet.shopping.service.ShoppingOrderServiceUtil;
030    
031    import javax.portlet.PortletRequest;
032    
033    import javax.servlet.http.HttpServletRequest;
034    
035    /**
036     * @author Brian Wing Shun Chan
037     */
038    public class ActionUtil {
039    
040            public static void getCategory(HttpServletRequest request)
041                    throws Exception {
042    
043                    long categoryId = ParamUtil.getLong(request, "categoryId");
044    
045                    ShoppingCategory category = null;
046    
047                    if ((categoryId > 0) &&
048                            (categoryId !=
049                                    ShoppingCategoryConstants.DEFAULT_PARENT_CATEGORY_ID)) {
050    
051                            category = ShoppingCategoryServiceUtil.getCategory(categoryId);
052                    }
053    
054                    request.setAttribute(WebKeys.SHOPPING_CATEGORY, category);
055            }
056    
057            public static void getCategory(PortletRequest portletRequest)
058                    throws Exception {
059    
060                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
061                            portletRequest);
062    
063                    getCategory(request);
064            }
065    
066            public static void getCoupon(HttpServletRequest request) throws Exception {
067                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
068                            WebKeys.THEME_DISPLAY);
069    
070                    long couponId = ParamUtil.getLong(request, "couponId");
071    
072                    ShoppingCoupon coupon = null;
073    
074                    if (couponId > 0) {
075                            coupon = ShoppingCouponServiceUtil.getCoupon(
076                                    themeDisplay.getScopeGroupId(), couponId);
077                    }
078    
079                    request.setAttribute(WebKeys.SHOPPING_COUPON, coupon);
080            }
081    
082            public static void getCoupon(PortletRequest portletRequest)
083                    throws Exception {
084    
085                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
086                            portletRequest);
087    
088                    getCoupon(request);
089            }
090    
091            public static void getItem(HttpServletRequest request) throws Exception {
092                    long itemId = ParamUtil.getLong(request, "itemId");
093    
094                    ShoppingItem item = null;
095    
096                    if (itemId > 0) {
097                            item = ShoppingItemServiceUtil.getItem(itemId);
098                    }
099    
100                    request.setAttribute(WebKeys.SHOPPING_ITEM, item);
101            }
102    
103            public static void getItem(PortletRequest portletRequest) throws Exception {
104                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
105                            portletRequest);
106    
107                    getItem(request);
108            }
109    
110            public static void getOrder(HttpServletRequest request) throws Exception {
111                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
112                            WebKeys.THEME_DISPLAY);
113    
114                    long orderId = ParamUtil.getLong(request, "orderId");
115    
116                    ShoppingOrder order = null;
117    
118                    if (orderId > 0) {
119                            order = ShoppingOrderServiceUtil.getOrder(
120                                    themeDisplay.getScopeGroupId(), orderId);
121                    }
122    
123                    request.setAttribute(WebKeys.SHOPPING_ORDER, order);
124            }
125    
126            public static void getOrder(PortletRequest portletRequest)
127                    throws Exception {
128    
129                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
130                            portletRequest);
131    
132                    getOrder(request);
133            }
134    
135    }