1   /**
2    * Copyright (c) 2000-2007 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 req) throws Exception {
62          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
63  
64          getAddress(httpReq);
65      }
66  
67      public static void getAddress(RenderRequest req) throws Exception {
68          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
69  
70          getAddress(httpReq);
71      }
72  
73      public static void getAddress(HttpServletRequest req) throws Exception {
74          long addressId = ParamUtil.getLong(req, "addressId");
75  
76          Address address = null;
77  
78          if (addressId > 0) {
79              address = AddressServiceUtil.getAddress(addressId);
80          }
81  
82          req.setAttribute(WebKeys.ADDRESS, address);
83      }
84  
85      public static void getEmailAddress(ActionRequest req) throws Exception {
86          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
87  
88          getEmailAddress(httpReq);
89      }
90  
91      public static void getEmailAddress(RenderRequest req) throws Exception {
92          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
93  
94          getEmailAddress(httpReq);
95      }
96  
97      public static void getEmailAddress(
98          HttpServletRequest req) throws Exception {
99  
100         long emailAddressId = ParamUtil.getLong(req, "emailAddressId");
101 
102         EmailAddress emailAddress = null;
103 
104         if (emailAddressId > 0) {
105             emailAddress =
106                 EmailAddressServiceUtil.getEmailAddress(emailAddressId);
107         }
108 
109         req.setAttribute(WebKeys.EMAIL_ADDRESS, emailAddress);
110     }
111 
112     public static void getPhone(ActionRequest req) throws Exception {
113         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
114 
115         getPhone(httpReq);
116     }
117 
118     public static void getPhone(RenderRequest req) throws Exception {
119         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
120 
121         getPhone(httpReq);
122     }
123 
124     public static void getPhone(HttpServletRequest req) throws Exception {
125         long phoneId = ParamUtil.getLong(req, "phoneId");
126 
127         Phone phone = null;
128 
129         if (phoneId > 0) {
130             phone = PhoneServiceUtil.getPhone(phoneId);
131         }
132 
133         req.setAttribute(WebKeys.PHONE, phone);
134     }
135 
136     public static void getOrganization(ActionRequest req) throws Exception {
137         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
138 
139         getOrganization(httpReq);
140     }
141 
142     public static void getOrganization(RenderRequest req) throws Exception {
143         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
144 
145         getOrganization(httpReq);
146     }
147 
148     public static void getOrganization(HttpServletRequest req)
149         throws Exception {
150 
151         long organizationId = ParamUtil.getLong(req, "organizationId");
152 
153         Organization organization = null;
154 
155         if (organizationId > 0) {
156             organization =
157                 OrganizationServiceUtil.getOrganization(organizationId);
158         }
159 
160         req.setAttribute(WebKeys.ORGANIZATION, organization);
161     }
162 
163     public static void getOrgLabor(ActionRequest req) throws Exception {
164         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
165 
166         getOrgLabor(httpReq);
167     }
168 
169     public static void getOrgLabor(RenderRequest req) throws Exception {
170         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
171 
172         getOrgLabor(httpReq);
173     }
174 
175     public static void getOrgLabor(HttpServletRequest req) throws Exception {
176         long orgLaborId = ParamUtil.getLong(req, "orgLaborId");
177 
178         OrgLabor orgLabor = null;
179 
180         if (orgLaborId > 0) {
181             orgLabor = OrgLaborServiceUtil.getOrgLabor(orgLaborId);
182         }
183 
184         req.setAttribute(WebKeys.ORG_LABOR, orgLabor);
185     }
186 
187     public static void getPasswordPolicy(ActionRequest req) throws Exception {
188         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
189 
190         getPasswordPolicy(httpReq);
191     }
192 
193     public static void getPasswordPolicy(RenderRequest req) throws Exception {
194         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
195 
196         getPasswordPolicy(httpReq);
197     }
198 
199     public static void getPasswordPolicy(HttpServletRequest req)
200         throws Exception {
201 
202         long passwordPolicyId = ParamUtil.getLong(req, "passwordPolicyId");
203 
204         PasswordPolicy passwordPolicy = null;
205 
206         if (passwordPolicyId > 0) {
207             passwordPolicy = PasswordPolicyLocalServiceUtil.getPasswordPolicy(
208                 passwordPolicyId);
209         }
210 
211         req.setAttribute(WebKeys.PASSWORD_POLICY, passwordPolicy);
212     }
213 
214     public static void getRole(ActionRequest req) throws Exception {
215         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
216 
217         getRole(httpReq);
218     }
219 
220     public static void getRole(RenderRequest req) throws Exception {
221         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
222 
223         getRole(httpReq);
224     }
225 
226     public static void getRole(HttpServletRequest req)
227         throws Exception {
228 
229         long roleId = ParamUtil.getLong(req, "roleId");
230 
231         Role role = null;
232 
233         if (roleId > 0) {
234             role = RoleServiceUtil.getRole(roleId);
235         }
236 
237         req.setAttribute(WebKeys.ROLE, role);
238     }
239 
240     public static void getUserGroup(ActionRequest req) throws Exception {
241         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
242 
243         getUserGroup(httpReq);
244     }
245 
246     public static void getUserGroup(RenderRequest req) throws Exception {
247         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
248 
249         getUserGroup(httpReq);
250     }
251 
252     public static void getUserGroup(HttpServletRequest req)
253         throws Exception {
254 
255         long userGroupId = ParamUtil.getLong(req, "userGroupId");
256 
257         UserGroup userGroup = null;
258 
259         if (userGroupId > 0) {
260             userGroup = UserGroupServiceUtil.getUserGroup(userGroupId);
261         }
262 
263         req.setAttribute(WebKeys.USER_GROUP, userGroup);
264     }
265 
266     public static void getWebsite(ActionRequest req) throws Exception {
267         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
268 
269         getWebsite(httpReq);
270     }
271 
272     public static void getWebsite(RenderRequest req) throws Exception {
273         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
274 
275         getWebsite(httpReq);
276     }
277 
278     public static void getWebsite(HttpServletRequest req) throws Exception {
279         long websiteId = ParamUtil.getLong(req, "websiteId");
280 
281         Website website = null;
282 
283         if (websiteId > 0) {
284             website = WebsiteServiceUtil.getWebsite(websiteId);
285         }
286 
287         req.setAttribute(WebKeys.WEBSITE, website);
288     }
289 
290 }