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.search;
016    
017    import com.liferay.portal.NoSuchCountryException;
018    import com.liferay.portal.NoSuchRegionException;
019    import com.liferay.portal.kernel.dao.search.DAOParamUtil;
020    import com.liferay.portal.kernel.exception.PortalException;
021    import com.liferay.portal.kernel.exception.SystemException;
022    import com.liferay.portal.kernel.log.Log;
023    import com.liferay.portal.kernel.log.LogFactoryUtil;
024    import com.liferay.portal.kernel.util.ParamUtil;
025    import com.liferay.portal.model.Country;
026    import com.liferay.portal.model.Region;
027    import com.liferay.portal.service.CountryServiceUtil;
028    import com.liferay.portal.service.RegionServiceUtil;
029    
030    import javax.portlet.PortletRequest;
031    
032    /**
033     * @author Brian Wing Shun Chan
034     * @author Hugo Huijser
035     */
036    public class OrganizationSearchTerms extends OrganizationDisplayTerms {
037    
038            public OrganizationSearchTerms(PortletRequest portletRequest) {
039                    super(portletRequest);
040    
041                    city = DAOParamUtil.getLike(portletRequest, CITY);
042                    countryId = ParamUtil.getLong(portletRequest, COUNTRY_ID);
043                    name = DAOParamUtil.getLike(portletRequest, NAME);
044                    parentOrganizationId = ParamUtil.getLong(
045                            portletRequest, PARENT_ORGANIZATION_ID);
046                    regionId = ParamUtil.getLong(portletRequest, REGION_ID);
047                    street = DAOParamUtil.getLike(portletRequest, STREET);
048                    type = DAOParamUtil.getString(portletRequest, TYPE);
049                    zip = DAOParamUtil.getLike(portletRequest, ZIP);
050            }
051    
052            public Long getCountryIdObj() {
053                    if (countryId == 0) {
054                            return null;
055                    }
056                    else {
057                            return new Long(countryId);
058                    }
059            }
060    
061            public String getCountryName() throws PortalException, SystemException {
062                    String countryName = null;
063    
064                    if (countryId != 0) {
065                            try {
066                                    Country country = CountryServiceUtil.getCountry(countryId);
067    
068                                    countryName = country.getName().toLowerCase();
069                            }
070                            catch (NoSuchCountryException nsce) {
071                                    if (_log.isWarnEnabled()) {
072                                            _log.warn(nsce.getMessage());
073                                    }
074                            }
075                    }
076    
077                    return countryName;
078            }
079    
080            public Long getRegionIdObj() {
081                    if (regionId == 0) {
082                            return null;
083                    }
084                    else {
085                            return new Long(regionId);
086                    }
087            }
088    
089            public String getRegionName() throws PortalException, SystemException {
090                    String regionName = null;
091    
092                    if (regionId != 0) {
093                            try {
094                                    Region region = RegionServiceUtil.getRegion(regionId);
095    
096                                    regionName = region.getName().toLowerCase();
097                            }
098                            catch (NoSuchRegionException nsre) {
099                                    if (_log.isWarnEnabled()) {
100                                            _log.warn(nsre.getMessage());
101                                    }
102                            }
103                    }
104    
105                    return regionName;
106            }
107    
108            private static Log _log = LogFactoryUtil.getLog(
109                    OrganizationSearchTerms.class);
110    
111    }