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