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.enterpriseadmin.action;
016    
017    import com.liferay.portal.kernel.util.ParamUtil;
018    import com.liferay.portal.model.Address;
019    import com.liferay.portal.model.EmailAddress;
020    import com.liferay.portal.model.OrgLabor;
021    import com.liferay.portal.model.Organization;
022    import com.liferay.portal.model.PasswordPolicy;
023    import com.liferay.portal.model.Phone;
024    import com.liferay.portal.model.Role;
025    import com.liferay.portal.model.UserGroup;
026    import com.liferay.portal.model.Website;
027    import com.liferay.portal.service.AddressServiceUtil;
028    import com.liferay.portal.service.EmailAddressServiceUtil;
029    import com.liferay.portal.service.OrgLaborServiceUtil;
030    import com.liferay.portal.service.OrganizationServiceUtil;
031    import com.liferay.portal.service.PasswordPolicyLocalServiceUtil;
032    import com.liferay.portal.service.PhoneServiceUtil;
033    import com.liferay.portal.service.RoleServiceUtil;
034    import com.liferay.portal.service.UserGroupServiceUtil;
035    import com.liferay.portal.service.WebsiteServiceUtil;
036    import com.liferay.portal.util.PortalUtil;
037    import com.liferay.portal.util.WebKeys;
038    
039    import javax.portlet.PortletRequest;
040    
041    import javax.servlet.http.HttpServletRequest;
042    
043    /**
044     * @author Brian Wing Shun Chan
045     * @author Alexander Chow
046     */
047    public class ActionUtil {
048    
049            public static void getAddress(HttpServletRequest request)
050                    throws Exception {
051    
052                    long addressId = ParamUtil.getLong(request, "addressId");
053    
054                    Address address = null;
055    
056                    if (addressId > 0) {
057                            address = AddressServiceUtil.getAddress(addressId);
058                    }
059    
060                    request.setAttribute(WebKeys.ADDRESS, address);
061            }
062    
063            public static void getAddress(PortletRequest portletRequest)
064                    throws Exception {
065    
066                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
067                            portletRequest);
068    
069                    getAddress(request);
070            }
071    
072            public static void getEmailAddress(HttpServletRequest request)
073                    throws Exception {
074    
075                    long emailAddressId = ParamUtil.getLong(request, "emailAddressId");
076    
077                    EmailAddress emailAddress = null;
078    
079                    if (emailAddressId > 0) {
080                            emailAddress =
081                                    EmailAddressServiceUtil.getEmailAddress(emailAddressId);
082                    }
083    
084                    request.setAttribute(WebKeys.EMAIL_ADDRESS, emailAddress);
085            }
086    
087            public static void getEmailAddress(PortletRequest portletRequest)
088                    throws Exception {
089    
090                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
091                            portletRequest);
092    
093                    getEmailAddress(request);
094            }
095    
096            public static void getOrganization(HttpServletRequest request)
097                    throws Exception {
098    
099                    long organizationId = ParamUtil.getLong(request, "organizationId");
100    
101                    Organization organization = null;
102    
103                    if (organizationId > 0) {
104                            organization =
105                                    OrganizationServiceUtil.getOrganization(organizationId);
106                    }
107    
108                    request.setAttribute(WebKeys.ORGANIZATION, organization);
109            }
110    
111            public static void getOrganization(PortletRequest portletRequest)
112                    throws Exception {
113    
114                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
115                            portletRequest);
116    
117                    getOrganization(request);
118            }
119    
120            public static void getOrgLabor(HttpServletRequest request)
121                    throws Exception {
122    
123                    long orgLaborId = ParamUtil.getLong(request, "orgLaborId");
124    
125                    OrgLabor orgLabor = null;
126    
127                    if (orgLaborId > 0) {
128                            orgLabor = OrgLaborServiceUtil.getOrgLabor(orgLaborId);
129                    }
130    
131                    request.setAttribute(WebKeys.ORG_LABOR, orgLabor);
132            }
133    
134            public static void getOrgLabor(PortletRequest portletRequest)
135                    throws Exception {
136    
137                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
138                            portletRequest);
139    
140                    getOrgLabor(request);
141            }
142    
143            public static void getPasswordPolicy(HttpServletRequest request)
144                    throws Exception {
145    
146                    long passwordPolicyId = ParamUtil.getLong(request, "passwordPolicyId");
147    
148                    PasswordPolicy passwordPolicy = null;
149    
150                    if (passwordPolicyId > 0) {
151                            passwordPolicy = PasswordPolicyLocalServiceUtil.getPasswordPolicy(
152                                    passwordPolicyId);
153                    }
154    
155                    request.setAttribute(WebKeys.PASSWORD_POLICY, passwordPolicy);
156            }
157    
158            public static void getPasswordPolicy(PortletRequest portletRequest)
159                    throws Exception {
160    
161                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
162                            portletRequest);
163    
164                    getPasswordPolicy(request);
165            }
166    
167            public static void getPhone(HttpServletRequest request) throws Exception {
168                    long phoneId = ParamUtil.getLong(request, "phoneId");
169    
170                    Phone phone = null;
171    
172                    if (phoneId > 0) {
173                            phone = PhoneServiceUtil.getPhone(phoneId);
174                    }
175    
176                    request.setAttribute(WebKeys.PHONE, phone);
177            }
178    
179            public static void getPhone(PortletRequest portletRequest)
180                    throws Exception {
181    
182                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
183                            portletRequest);
184    
185                    getPhone(request);
186            }
187    
188            public static void getRole(HttpServletRequest request)
189                    throws Exception {
190    
191                    long roleId = ParamUtil.getLong(request, "roleId");
192    
193                    Role role = null;
194    
195                    if (roleId > 0) {
196                            role = RoleServiceUtil.getRole(roleId);
197                    }
198    
199                    request.setAttribute(WebKeys.ROLE, role);
200            }
201    
202            public static void getRole(PortletRequest portletRequest) throws Exception {
203                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
204                            portletRequest);
205    
206                    getRole(request);
207            }
208    
209            public static void getUserGroup(HttpServletRequest request)
210                    throws Exception {
211    
212                    long userGroupId = ParamUtil.getLong(request, "userGroupId");
213    
214                    UserGroup userGroup = null;
215    
216                    if (userGroupId > 0) {
217                            userGroup = UserGroupServiceUtil.getUserGroup(userGroupId);
218                    }
219    
220                    request.setAttribute(WebKeys.USER_GROUP, userGroup);
221            }
222    
223            public static void getUserGroup(PortletRequest portletRequest)
224                    throws Exception {
225    
226                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
227                            portletRequest);
228    
229                    getUserGroup(request);
230            }
231    
232            public static void getWebsite(HttpServletRequest request) throws Exception {
233                    long websiteId = ParamUtil.getLong(request, "websiteId");
234    
235                    Website website = null;
236    
237                    if (websiteId > 0) {
238                            website = WebsiteServiceUtil.getWebsite(websiteId);
239                    }
240    
241                    request.setAttribute(WebKeys.WEBSITE, website);
242            }
243    
244            public static void getWebsite(PortletRequest portletRequest)
245                    throws Exception {
246    
247                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
248                            portletRequest);
249    
250                    getWebsite(request);
251            }
252    
253    }