001
014
015 package com.liferay.portlet.usersadmin.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.kernel.util.StringUtil;
026 import com.liferay.portal.kernel.util.Validator;
027 import com.liferay.portal.model.Country;
028 import com.liferay.portal.model.Region;
029 import com.liferay.portal.service.CountryServiceUtil;
030 import com.liferay.portal.service.RegionServiceUtil;
031
032 import javax.portlet.PortletRequest;
033
034
038 public class OrganizationSearchTerms extends OrganizationDisplayTerms {
039
040 public OrganizationSearchTerms(PortletRequest portletRequest) {
041 super(portletRequest);
042
043 city = DAOParamUtil.getString(portletRequest, CITY);
044 countryId = ParamUtil.getLong(portletRequest, COUNTRY_ID);
045 name = DAOParamUtil.getString(portletRequest, NAME);
046 parentOrganizationId = ParamUtil.getLong(
047 portletRequest, PARENT_ORGANIZATION_ID);
048 regionId = ParamUtil.getLong(portletRequest, REGION_ID);
049 street = DAOParamUtil.getString(portletRequest, STREET);
050 type = DAOParamUtil.getString(portletRequest, TYPE);
051 zip = DAOParamUtil.getString(portletRequest, ZIP);
052 }
053
054 public Long getCountryIdObj() {
055 if (countryId == 0) {
056 return null;
057 }
058 else {
059 return new Long(countryId);
060 }
061 }
062
063 public String getCountryName() throws PortalException, SystemException {
064 String countryName = null;
065
066 if (countryId != 0) {
067 try {
068 Country country = CountryServiceUtil.getCountry(countryId);
069
070 countryName = StringUtil.toLowerCase(country.getName());
071 }
072 catch (NoSuchCountryException nsce) {
073 if (_log.isWarnEnabled()) {
074 _log.warn(nsce.getMessage());
075 }
076 }
077 }
078
079 return countryName;
080 }
081
082 public Long getRegionIdObj() {
083 if (regionId == 0) {
084 return null;
085 }
086 else {
087 return new Long(regionId);
088 }
089 }
090
091 public String getRegionName() throws PortalException, SystemException {
092 String regionName = null;
093
094 if (regionId != 0) {
095 try {
096 Region region = RegionServiceUtil.getRegion(regionId);
097
098 regionName = StringUtil.toLowerCase(region.getName());
099 }
100 catch (NoSuchRegionException nsre) {
101 if (_log.isWarnEnabled()) {
102 _log.warn(nsre.getMessage());
103 }
104 }
105 }
106
107 return regionName;
108 }
109
110 public boolean hasSearchTerms() {
111 if (isAdvancedSearch()) {
112 if (Validator.isNotNull(city) || (countryId > 0) ||
113 Validator.isNotNull(name) || (regionId > 0) ||
114 Validator.isNotNull(street) || Validator.isNotNull(type) ||
115 Validator.isNotNull(zip)) {
116
117 return true;
118 }
119 }
120 else {
121 if (Validator.isNotNull(keywords)) {
122 return true;
123 }
124 }
125
126 return false;
127 }
128
129 private static Log _log = LogFactoryUtil.getLog(
130 OrganizationSearchTerms.class);
131
132 }