001
014
015 package com.liferay.portlet.usersadmin.search;
016
017 import com.liferay.portal.exception.NoSuchCountryException;
018 import com.liferay.portal.exception.NoSuchRegionException;
019 import com.liferay.portal.kernel.dao.search.DAOParamUtil;
020 import com.liferay.portal.kernel.exception.PortalException;
021 import com.liferay.portal.kernel.log.Log;
022 import com.liferay.portal.kernel.log.LogFactoryUtil;
023 import com.liferay.portal.kernel.util.ParamUtil;
024 import com.liferay.portal.kernel.util.StringPool;
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 Long.valueOf(countryId);
060 }
061 }
062
063 public String getCountryName() throws PortalException {
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 countryName = StringUtil.quote(countryName, StringPool.QUOTE);
073 }
074 catch (NoSuchCountryException nsce) {
075 if (_log.isWarnEnabled()) {
076 _log.warn(nsce.getMessage());
077 }
078 }
079 }
080
081 return countryName;
082 }
083
084 public Long getRegionIdObj() {
085 if (regionId == 0) {
086 return null;
087 }
088 else {
089 return Long.valueOf(regionId);
090 }
091 }
092
093 public String getRegionName() throws PortalException {
094 String regionName = null;
095
096 if (regionId != 0) {
097 try {
098 Region region = RegionServiceUtil.getRegion(regionId);
099
100 regionName = StringUtil.toLowerCase(region.getName());
101
102 regionName = StringUtil.quote(regionName, StringPool.QUOTE);
103 }
104 catch (NoSuchRegionException nsre) {
105 if (_log.isWarnEnabled()) {
106 _log.warn(nsre.getMessage());
107 }
108 }
109 }
110
111 return regionName;
112 }
113
114 public boolean hasSearchTerms() {
115 if (isAdvancedSearch()) {
116 if (Validator.isNotNull(city) || (countryId > 0) ||
117 Validator.isNotNull(name) || (regionId > 0) ||
118 Validator.isNotNull(street) || Validator.isNotNull(type) ||
119 Validator.isNotNull(zip)) {
120
121 return true;
122 }
123 }
124 else {
125 if (Validator.isNotNull(keywords)) {
126 return true;
127 }
128 }
129
130 return false;
131 }
132
133 private static final Log _log = LogFactoryUtil.getLog(
134 OrganizationSearchTerms.class);
135
136 }