001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.enterpriseadmin.search;
022:
023: import com.liferay.portal.kernel.dao.search.SearchContainer;
024: import com.liferay.portal.kernel.util.OrderByComparator;
025: import com.liferay.portal.kernel.util.ParamUtil;
026: import com.liferay.portal.kernel.util.Validator;
027: import com.liferay.portal.util.PortletKeys;
028: import com.liferay.portlet.PortalPreferences;
029: import com.liferay.portlet.PortletPreferencesFactoryUtil;
030: import com.liferay.portlet.enterpriseadmin.util.EnterpriseAdminUtil;
031: import com.liferay.util.CollectionFactory;
032:
033: import java.util.ArrayList;
034: import java.util.List;
035: import java.util.Map;
036:
037: import javax.portlet.PortletURL;
038: import javax.portlet.RenderRequest;
039:
040: import org.apache.commons.logging.Log;
041: import org.apache.commons.logging.LogFactory;
042:
043: /**
044: * <a href="OrganizationSearch.java.html"><b><i>View Source</i></b></a>
045: *
046: * @author Brian Wing Shun Chan
047: *
048: */
049: public class OrganizationSearch extends SearchContainer {
050:
051: static List headerNames = new ArrayList();
052: static Map orderableHeaders = CollectionFactory.getHashMap();
053:
054: static {
055: headerNames.add("name");
056: headerNames.add("parent-organization");
057: headerNames.add("type");
058: headerNames.add("city");
059: headerNames.add("region");
060: headerNames.add("country");
061:
062: orderableHeaders.put("name", "name");
063: orderableHeaders.put("type", "type");
064: }
065:
066: public static final String EMPTY_RESULTS_MESSAGE = "no-organizations-were-found";
067:
068: public OrganizationSearch(RenderRequest req, PortletURL iteratorURL) {
069: super (req, new OrganizationDisplayTerms(req),
070: new OrganizationSearchTerms(req), DEFAULT_CUR_PARAM,
071: DEFAULT_DELTA, iteratorURL, headerNames,
072: EMPTY_RESULTS_MESSAGE);
073:
074: OrganizationDisplayTerms displayTerms = (OrganizationDisplayTerms) getDisplayTerms();
075:
076: iteratorURL.setParameter(OrganizationDisplayTerms.NAME,
077: displayTerms.getName());
078: iteratorURL.setParameter(OrganizationDisplayTerms.STREET,
079: displayTerms.getStreet());
080: iteratorURL.setParameter(OrganizationDisplayTerms.CITY,
081: displayTerms.getCity());
082: iteratorURL.setParameter(OrganizationDisplayTerms.ZIP,
083: displayTerms.getZip());
084: iteratorURL.setParameter(OrganizationDisplayTerms.COUNTRY_ID,
085: String.valueOf(displayTerms.getCountryId()));
086: iteratorURL.setParameter(OrganizationDisplayTerms.REGION_ID,
087: String.valueOf(displayTerms.getRegionId()));
088: iteratorURL.setParameter(
089: OrganizationDisplayTerms.PARENT_ORGANIZATION_ID,
090: String.valueOf(displayTerms.getParentOrganizationId()));
091:
092: try {
093: PortalPreferences prefs = PortletPreferencesFactoryUtil
094: .getPortalPreferences(req);
095:
096: String orderByCol = ParamUtil.getString(req, "orderByCol");
097: String orderByType = ParamUtil
098: .getString(req, "orderByType");
099:
100: if (Validator.isNotNull(orderByCol)
101: && Validator.isNotNull(orderByType)) {
102:
103: prefs.setValue(PortletKeys.ENTERPRISE_ADMIN,
104: "organizations-order-by-col", orderByCol);
105: prefs.setValue(PortletKeys.ENTERPRISE_ADMIN,
106: "organizations-order-by-type", orderByType);
107: } else {
108: orderByCol = prefs.getValue(
109: PortletKeys.ENTERPRISE_ADMIN,
110: "organizations-order-by-col", "name");
111: orderByType = prefs.getValue(
112: PortletKeys.ENTERPRISE_ADMIN,
113: "organizations-order-by-type", "asc");
114: }
115:
116: OrderByComparator orderByComparator = EnterpriseAdminUtil
117: .getOrganizationOrderByComparator(orderByCol,
118: orderByType);
119:
120: setOrderableHeaders(orderableHeaders);
121: setOrderByCol(orderByCol);
122: setOrderByType(orderByType);
123: setOrderByComparator(orderByComparator);
124: } catch (Exception e) {
125: _log.error(e);
126: }
127: }
128:
129: private static Log _log = LogFactory
130: .getLog(OrganizationSearch.class);
131:
132: }
|