1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.shopping.action;
16  
17  import com.liferay.portal.kernel.util.ParamUtil;
18  import com.liferay.portal.theme.ThemeDisplay;
19  import com.liferay.portal.util.PortalUtil;
20  import com.liferay.portal.util.WebKeys;
21  import com.liferay.portlet.shopping.model.ShoppingCategory;
22  import com.liferay.portlet.shopping.model.ShoppingCoupon;
23  import com.liferay.portlet.shopping.model.ShoppingItem;
24  import com.liferay.portlet.shopping.model.ShoppingOrder;
25  import com.liferay.portlet.shopping.model.impl.ShoppingCategoryImpl;
26  import com.liferay.portlet.shopping.service.ShoppingCategoryServiceUtil;
27  import com.liferay.portlet.shopping.service.ShoppingCouponServiceUtil;
28  import com.liferay.portlet.shopping.service.ShoppingItemServiceUtil;
29  import com.liferay.portlet.shopping.service.ShoppingOrderServiceUtil;
30  
31  import javax.portlet.ActionRequest;
32  import javax.portlet.RenderRequest;
33  
34  import javax.servlet.http.HttpServletRequest;
35  
36  /**
37   * <a href="ActionUtil.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   */
41  public class ActionUtil {
42  
43      public static void getCategory(ActionRequest actionRequest)
44          throws Exception {
45  
46          HttpServletRequest request = PortalUtil.getHttpServletRequest(
47              actionRequest);
48  
49          getCategory(request);
50      }
51  
52      public static void getCategory(RenderRequest renderRequest)
53          throws Exception {
54  
55          HttpServletRequest request = PortalUtil.getHttpServletRequest(
56              renderRequest);
57  
58          getCategory(request);
59      }
60  
61      public static void getCategory(HttpServletRequest request)
62          throws Exception {
63  
64          long categoryId = ParamUtil.getLong(request, "categoryId");
65  
66          ShoppingCategory category = null;
67  
68          if ((categoryId > 0) &&
69              (categoryId != ShoppingCategoryImpl.DEFAULT_PARENT_CATEGORY_ID)) {
70  
71              category = ShoppingCategoryServiceUtil.getCategory(categoryId);
72          }
73  
74          request.setAttribute(WebKeys.SHOPPING_CATEGORY, category);
75      }
76  
77      public static void getCoupon(ActionRequest actionRequest) throws Exception {
78          HttpServletRequest request = PortalUtil.getHttpServletRequest(
79              actionRequest);
80  
81          getCoupon(request);
82      }
83  
84      public static void getCoupon(RenderRequest renderRequest) throws Exception {
85          HttpServletRequest request = PortalUtil.getHttpServletRequest(
86              renderRequest);
87  
88          getCoupon(request);
89      }
90  
91      public static void getCoupon(HttpServletRequest request) throws Exception {
92          ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
93              WebKeys.THEME_DISPLAY);
94  
95          long couponId = ParamUtil.getLong(request, "couponId");
96  
97          ShoppingCoupon coupon = null;
98  
99          if (couponId > 0) {
100             coupon = ShoppingCouponServiceUtil.getCoupon(
101                 themeDisplay.getScopeGroupId(), couponId);
102         }
103 
104         request.setAttribute(WebKeys.SHOPPING_COUPON, coupon);
105     }
106 
107     public static void getItem(ActionRequest actionRequest) throws Exception {
108         HttpServletRequest request = PortalUtil.getHttpServletRequest(
109             actionRequest);
110 
111         getItem(request);
112     }
113 
114     public static void getItem(RenderRequest renderRequest) throws Exception {
115         HttpServletRequest request = PortalUtil.getHttpServletRequest(
116             renderRequest);
117 
118         getItem(request);
119     }
120 
121     public static void getItem(HttpServletRequest request) throws Exception {
122         long itemId = ParamUtil.getLong(request, "itemId");
123 
124         ShoppingItem item = null;
125 
126         if (itemId > 0) {
127             item = ShoppingItemServiceUtil.getItem(itemId);
128         }
129 
130         request.setAttribute(WebKeys.SHOPPING_ITEM, item);
131     }
132 
133     public static void getOrder(ActionRequest actionRequest) throws Exception {
134         HttpServletRequest request = PortalUtil.getHttpServletRequest(
135             actionRequest);
136 
137         getOrder(request);
138     }
139 
140     public static void getOrder(RenderRequest renderRequest) throws Exception {
141         HttpServletRequest request = PortalUtil.getHttpServletRequest(
142             renderRequest);
143 
144         getOrder(request);
145     }
146 
147     public static void getOrder(HttpServletRequest request) throws Exception {
148         ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
149             WebKeys.THEME_DISPLAY);
150 
151         long orderId = ParamUtil.getLong(request, "orderId");
152 
153         ShoppingOrder order = null;
154 
155         if (orderId > 0) {
156             order = ShoppingOrderServiceUtil.getOrder(
157                 themeDisplay.getScopeGroupId(), orderId);
158         }
159 
160         request.setAttribute(WebKeys.SHOPPING_ORDER, order);
161     }
162 
163 }