001    /**
002     * Copyright (c) 2000-2013 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.usersadmin.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.Phone;
023    import com.liferay.portal.model.Website;
024    import com.liferay.portal.service.AddressServiceUtil;
025    import com.liferay.portal.service.EmailAddressServiceUtil;
026    import com.liferay.portal.service.OrgLaborServiceUtil;
027    import com.liferay.portal.service.OrganizationServiceUtil;
028    import com.liferay.portal.service.PhoneServiceUtil;
029    import com.liferay.portal.service.WebsiteServiceUtil;
030    import com.liferay.portal.util.PortalUtil;
031    import com.liferay.portal.util.WebKeys;
032    
033    import javax.portlet.PortletRequest;
034    
035    import javax.servlet.http.HttpServletRequest;
036    
037    /**
038     * @author Brian Wing Shun Chan
039     * @author Alexander Chow
040     */
041    public class ActionUtil {
042    
043            public static void getAddress(HttpServletRequest request) throws Exception {
044                    long addressId = ParamUtil.getLong(request, "addressId");
045    
046                    Address address = null;
047    
048                    if (addressId > 0) {
049                            address = AddressServiceUtil.getAddress(addressId);
050                    }
051    
052                    request.setAttribute(WebKeys.ADDRESS, address);
053            }
054    
055            public static void getAddress(PortletRequest portletRequest)
056                    throws Exception {
057    
058                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
059                            portletRequest);
060    
061                    getAddress(request);
062            }
063    
064            public static void getEmailAddress(HttpServletRequest request)
065                    throws Exception {
066    
067                    long emailAddressId = ParamUtil.getLong(request, "emailAddressId");
068    
069                    EmailAddress emailAddress = null;
070    
071                    if (emailAddressId > 0) {
072                            emailAddress = EmailAddressServiceUtil.getEmailAddress(
073                                    emailAddressId);
074                    }
075    
076                    request.setAttribute(WebKeys.EMAIL_ADDRESS, emailAddress);
077            }
078    
079            public static void getEmailAddress(PortletRequest portletRequest)
080                    throws Exception {
081    
082                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
083                            portletRequest);
084    
085                    getEmailAddress(request);
086            }
087    
088            public static void getOrganization(HttpServletRequest request)
089                    throws Exception {
090    
091                    long organizationId = ParamUtil.getLong(request, "organizationId");
092    
093                    Organization organization = null;
094    
095                    if (organizationId > 0) {
096                            organization = OrganizationServiceUtil.getOrganization(
097                                    organizationId);
098                    }
099    
100                    request.setAttribute(WebKeys.ORGANIZATION, organization);
101            }
102    
103            public static void getOrganization(PortletRequest portletRequest)
104                    throws Exception {
105    
106                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
107                            portletRequest);
108    
109                    getOrganization(request);
110            }
111    
112            public static void getOrgLabor(HttpServletRequest request)
113                    throws Exception {
114    
115                    long orgLaborId = ParamUtil.getLong(request, "orgLaborId");
116    
117                    OrgLabor orgLabor = null;
118    
119                    if (orgLaborId > 0) {
120                            orgLabor = OrgLaborServiceUtil.getOrgLabor(orgLaborId);
121                    }
122    
123                    request.setAttribute(WebKeys.ORG_LABOR, orgLabor);
124            }
125    
126            public static void getOrgLabor(PortletRequest portletRequest)
127                    throws Exception {
128    
129                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
130                            portletRequest);
131    
132                    getOrgLabor(request);
133            }
134    
135            public static void getPhone(HttpServletRequest request) throws Exception {
136                    long phoneId = ParamUtil.getLong(request, "phoneId");
137    
138                    Phone phone = null;
139    
140                    if (phoneId > 0) {
141                            phone = PhoneServiceUtil.getPhone(phoneId);
142                    }
143    
144                    request.setAttribute(WebKeys.PHONE, phone);
145            }
146    
147            public static void getPhone(PortletRequest portletRequest)
148                    throws Exception {
149    
150                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
151                            portletRequest);
152    
153                    getPhone(request);
154            }
155    
156            public static void getWebsite(HttpServletRequest request) throws Exception {
157                    long websiteId = ParamUtil.getLong(request, "websiteId");
158    
159                    Website website = null;
160    
161                    if (websiteId > 0) {
162                            website = WebsiteServiceUtil.getWebsite(websiteId);
163                    }
164    
165                    request.setAttribute(WebKeys.WEBSITE, website);
166            }
167    
168            public static void getWebsite(PortletRequest portletRequest)
169                    throws Exception {
170    
171                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
172                            portletRequest);
173    
174                    getWebsite(request);
175            }
176    
177    }