1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.enterpriseadmin.action;
24  
25  import com.liferay.portal.kernel.util.ParamUtil;
26  import com.liferay.portal.model.Address;
27  import com.liferay.portal.model.EmailAddress;
28  import com.liferay.portal.model.OrgLabor;
29  import com.liferay.portal.model.Organization;
30  import com.liferay.portal.model.PasswordPolicy;
31  import com.liferay.portal.model.Phone;
32  import com.liferay.portal.model.Role;
33  import com.liferay.portal.model.UserGroup;
34  import com.liferay.portal.model.Website;
35  import com.liferay.portal.service.AddressServiceUtil;
36  import com.liferay.portal.service.EmailAddressServiceUtil;
37  import com.liferay.portal.service.OrgLaborServiceUtil;
38  import com.liferay.portal.service.OrganizationServiceUtil;
39  import com.liferay.portal.service.PasswordPolicyLocalServiceUtil;
40  import com.liferay.portal.service.PhoneServiceUtil;
41  import com.liferay.portal.service.RoleServiceUtil;
42  import com.liferay.portal.service.UserGroupServiceUtil;
43  import com.liferay.portal.service.WebsiteServiceUtil;
44  import com.liferay.portal.util.PortalUtil;
45  import com.liferay.portal.util.WebKeys;
46  
47  import javax.portlet.ActionRequest;
48  import javax.portlet.RenderRequest;
49  
50  import javax.servlet.http.HttpServletRequest;
51  
52  /**
53   * <a href="ActionUtil.java.html"><b><i>View Source</i></b></a>
54   *
55   * @author Brian Wing Shun Chan
56   * @author Alexander Chow
57   *
58   */
59  public class ActionUtil {
60  
61      public static void getAddress(ActionRequest actionRequest)
62          throws Exception {
63  
64          HttpServletRequest request = PortalUtil.getHttpServletRequest(
65              actionRequest);
66  
67          getAddress(request);
68      }
69  
70      public static void getAddress(RenderRequest renderRequest)
71          throws Exception {
72  
73          HttpServletRequest request = PortalUtil.getHttpServletRequest(
74              renderRequest);
75  
76          getAddress(request);
77      }
78  
79      public static void getAddress(HttpServletRequest request)
80          throws Exception {
81  
82          long addressId = ParamUtil.getLong(request, "addressId");
83  
84          Address address = null;
85  
86          if (addressId > 0) {
87              address = AddressServiceUtil.getAddress(addressId);
88          }
89  
90          request.setAttribute(WebKeys.ADDRESS, address);
91      }
92  
93      public static void getEmailAddress(ActionRequest actionRequest)
94          throws Exception {
95  
96          HttpServletRequest request = PortalUtil.getHttpServletRequest(
97              actionRequest);
98  
99          getEmailAddress(request);
100     }
101 
102     public static void getEmailAddress(RenderRequest renderRequest)
103         throws Exception {
104 
105         HttpServletRequest request = PortalUtil.getHttpServletRequest(
106             renderRequest);
107 
108         getEmailAddress(request);
109     }
110 
111     public static void getEmailAddress(HttpServletRequest request)
112         throws Exception {
113 
114         long emailAddressId = ParamUtil.getLong(request, "emailAddressId");
115 
116         EmailAddress emailAddress = null;
117 
118         if (emailAddressId > 0) {
119             emailAddress =
120                 EmailAddressServiceUtil.getEmailAddress(emailAddressId);
121         }
122 
123         request.setAttribute(WebKeys.EMAIL_ADDRESS, emailAddress);
124     }
125 
126     public static void getPhone(ActionRequest actionRequest) throws Exception {
127         HttpServletRequest request = PortalUtil.getHttpServletRequest(
128             actionRequest);
129 
130         getPhone(request);
131     }
132 
133     public static void getPhone(RenderRequest renderRequest) throws Exception {
134         HttpServletRequest request = PortalUtil.getHttpServletRequest(
135             renderRequest);
136 
137         getPhone(request);
138     }
139 
140     public static void getPhone(HttpServletRequest request) throws Exception {
141         long phoneId = ParamUtil.getLong(request, "phoneId");
142 
143         Phone phone = null;
144 
145         if (phoneId > 0) {
146             phone = PhoneServiceUtil.getPhone(phoneId);
147         }
148 
149         request.setAttribute(WebKeys.PHONE, phone);
150     }
151 
152     public static void getOrganization(ActionRequest actionRequest)
153         throws Exception {
154 
155         HttpServletRequest request = PortalUtil.getHttpServletRequest(
156             actionRequest);
157 
158         getOrganization(request);
159     }
160 
161     public static void getOrganization(RenderRequest renderRequest)
162         throws Exception {
163 
164         HttpServletRequest request = PortalUtil.getHttpServletRequest(
165             renderRequest);
166 
167         getOrganization(request);
168     }
169 
170     public static void getOrganization(HttpServletRequest request)
171         throws Exception {
172 
173         long organizationId = ParamUtil.getLong(request, "organizationId");
174 
175         Organization organization = null;
176 
177         if (organizationId > 0) {
178             organization =
179                 OrganizationServiceUtil.getOrganization(organizationId);
180         }
181 
182         request.setAttribute(WebKeys.ORGANIZATION, organization);
183     }
184 
185     public static void getOrgLabor(ActionRequest actionRequest)
186         throws Exception {
187 
188         HttpServletRequest request = PortalUtil.getHttpServletRequest(
189             actionRequest);
190 
191         getOrgLabor(request);
192     }
193 
194     public static void getOrgLabor(RenderRequest renderRequest)
195         throws Exception {
196 
197         HttpServletRequest request = PortalUtil.getHttpServletRequest(
198             renderRequest);
199 
200         getOrgLabor(request);
201     }
202 
203     public static void getOrgLabor(HttpServletRequest request)
204         throws Exception {
205 
206         long orgLaborId = ParamUtil.getLong(request, "orgLaborId");
207 
208         OrgLabor orgLabor = null;
209 
210         if (orgLaborId > 0) {
211             orgLabor = OrgLaborServiceUtil.getOrgLabor(orgLaborId);
212         }
213 
214         request.setAttribute(WebKeys.ORG_LABOR, orgLabor);
215     }
216 
217     public static void getPasswordPolicy(ActionRequest actionRequest)
218         throws Exception {
219 
220         HttpServletRequest request = PortalUtil.getHttpServletRequest(
221             actionRequest);
222 
223         getPasswordPolicy(request);
224     }
225 
226     public static void getPasswordPolicy(RenderRequest renderRequest)
227         throws Exception {
228 
229         HttpServletRequest request = PortalUtil.getHttpServletRequest(
230             renderRequest);
231 
232         getPasswordPolicy(request);
233     }
234 
235     public static void getPasswordPolicy(HttpServletRequest request)
236         throws Exception {
237 
238         long passwordPolicyId = ParamUtil.getLong(request, "passwordPolicyId");
239 
240         PasswordPolicy passwordPolicy = null;
241 
242         if (passwordPolicyId > 0) {
243             passwordPolicy = PasswordPolicyLocalServiceUtil.getPasswordPolicy(
244                 passwordPolicyId);
245         }
246 
247         request.setAttribute(WebKeys.PASSWORD_POLICY, passwordPolicy);
248     }
249 
250     public static void getRole(ActionRequest actionRequest) throws Exception {
251         HttpServletRequest request = PortalUtil.getHttpServletRequest(
252             actionRequest);
253 
254         getRole(request);
255     }
256 
257     public static void getRole(RenderRequest renderRequest) throws Exception {
258         HttpServletRequest request = PortalUtil.getHttpServletRequest(
259             renderRequest);
260 
261         getRole(request);
262     }
263 
264     public static void getRole(HttpServletRequest request)
265         throws Exception {
266 
267         long roleId = ParamUtil.getLong(request, "roleId");
268 
269         Role role = null;
270 
271         if (roleId > 0) {
272             role = RoleServiceUtil.getRole(roleId);
273         }
274 
275         request.setAttribute(WebKeys.ROLE, role);
276     }
277 
278     public static void getUserGroup(ActionRequest actionRequest)
279         throws Exception {
280 
281         HttpServletRequest request = PortalUtil.getHttpServletRequest(
282             actionRequest);
283 
284         getUserGroup(request);
285     }
286 
287     public static void getUserGroup(RenderRequest renderRequest)
288         throws Exception {
289 
290         HttpServletRequest request = PortalUtil.getHttpServletRequest(
291             renderRequest);
292 
293         getUserGroup(request);
294     }
295 
296     public static void getUserGroup(HttpServletRequest request)
297         throws Exception {
298 
299         long userGroupId = ParamUtil.getLong(request, "userGroupId");
300 
301         UserGroup userGroup = null;
302 
303         if (userGroupId > 0) {
304             userGroup = UserGroupServiceUtil.getUserGroup(userGroupId);
305         }
306 
307         request.setAttribute(WebKeys.USER_GROUP, userGroup);
308     }
309 
310     public static void getWebsite(ActionRequest actionRequest)
311         throws Exception {
312 
313         HttpServletRequest request = PortalUtil.getHttpServletRequest(
314             actionRequest);
315 
316         getWebsite(request);
317     }
318 
319     public static void getWebsite(RenderRequest renderRequest)
320         throws Exception {
321 
322         HttpServletRequest request = PortalUtil.getHttpServletRequest(
323             renderRequest);
324 
325         getWebsite(request);
326     }
327 
328     public static void getWebsite(HttpServletRequest request) throws Exception {
329         long websiteId = ParamUtil.getLong(request, "websiteId");
330 
331         Website website = null;
332 
333         if (websiteId > 0) {
334             website = WebsiteServiceUtil.getWebsite(websiteId);
335         }
336 
337         request.setAttribute(WebKeys.WEBSITE, website);
338     }
339 
340 }