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.JavaConstants;
025: import com.liferay.portal.kernel.util.OrderByComparator;
026: import com.liferay.portal.kernel.util.ParamUtil;
027: import com.liferay.portal.kernel.util.Validator;
028: import com.liferay.portal.util.PortletKeys;
029: import com.liferay.portlet.PortalPreferences;
030: import com.liferay.portlet.PortletPreferencesFactoryUtil;
031: import com.liferay.portlet.enterpriseadmin.util.EnterpriseAdminUtil;
032: import com.liferay.util.CollectionFactory;
033:
034: import java.util.ArrayList;
035: import java.util.List;
036: import java.util.Map;
037:
038: import javax.portlet.PortletConfig;
039: import javax.portlet.PortletURL;
040: import javax.portlet.RenderRequest;
041:
042: import org.apache.commons.logging.Log;
043: import org.apache.commons.logging.LogFactory;
044:
045: /**
046: * <a href="UserSearch.java.html"><b><i>View Source</i></b></a>
047: *
048: * @author Brian Wing Shun Chan
049: *
050: */
051: public class UserSearch extends SearchContainer {
052:
053: static List headerNames = new ArrayList();
054: static Map orderableHeaders = CollectionFactory.getHashMap();
055:
056: static {
057: headerNames.add("first-name");
058: headerNames.add("last-name");
059: headerNames.add("screen-name");
060: //headerNames.add("email-address");
061: headerNames.add("job-title");
062: headerNames.add("organizations");
063:
064: orderableHeaders.put("first-name", "first-name");
065: orderableHeaders.put("last-name", "last-name");
066: orderableHeaders.put("screen-name", "screen-name");
067: //orderableHeaders.put("email-address", "email-address");
068: orderableHeaders.put("job-title", "job-title");
069: }
070:
071: public static final String EMPTY_RESULTS_MESSAGE = "no-users-were-found";
072:
073: public UserSearch(RenderRequest req, PortletURL iteratorURL) {
074: super (req, new UserDisplayTerms(req), new UserSearchTerms(req),
075: DEFAULT_CUR_PARAM, DEFAULT_DELTA, iteratorURL,
076: headerNames, EMPTY_RESULTS_MESSAGE);
077:
078: PortletConfig portletConfig = (PortletConfig) req
079: .getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
080:
081: UserDisplayTerms displayTerms = (UserDisplayTerms) getDisplayTerms();
082: UserSearchTerms searchTerms = (UserSearchTerms) getSearchTerms();
083:
084: String portletName = portletConfig.getPortletName();
085:
086: if (!portletName.equals(PortletKeys.ENTERPRISE_ADMIN)
087: && !portletName.equals(PortletKeys.ORGANIZATION_ADMIN)) {
088:
089: displayTerms.setActive(true);
090: searchTerms.setActive(true);
091: }
092:
093: iteratorURL.setParameter(UserDisplayTerms.FIRST_NAME,
094: displayTerms.getFirstName());
095: iteratorURL.setParameter(UserDisplayTerms.MIDDLE_NAME,
096: displayTerms.getMiddleName());
097: iteratorURL.setParameter(UserDisplayTerms.LAST_NAME,
098: displayTerms.getLastName());
099: iteratorURL.setParameter(UserDisplayTerms.SCREEN_NAME,
100: displayTerms.getScreenName());
101: iteratorURL.setParameter(UserDisplayTerms.EMAIL_ADDRESS,
102: displayTerms.getEmailAddress());
103: iteratorURL.setParameter(UserDisplayTerms.ACTIVE, String
104: .valueOf(displayTerms.isActive()));
105: iteratorURL.setParameter(UserDisplayTerms.ORGANIZATION_ID,
106: String.valueOf(displayTerms.getOrganizationId()));
107: iteratorURL.setParameter(UserDisplayTerms.ROLE_ID, String
108: .valueOf(displayTerms.getRoleId()));
109: iteratorURL.setParameter(UserDisplayTerms.USER_GROUP_ID, String
110: .valueOf(displayTerms.getUserGroupId()));
111:
112: try {
113: PortalPreferences prefs = PortletPreferencesFactoryUtil
114: .getPortalPreferences(req);
115:
116: String orderByCol = ParamUtil.getString(req, "orderByCol");
117: String orderByType = ParamUtil
118: .getString(req, "orderByType");
119:
120: if (Validator.isNotNull(orderByCol)
121: && Validator.isNotNull(orderByType)) {
122:
123: prefs.setValue(PortletKeys.ENTERPRISE_ADMIN,
124: "users-order-by-col", orderByCol);
125: prefs.setValue(PortletKeys.ENTERPRISE_ADMIN,
126: "users-order-by-type", orderByType);
127: } else {
128: orderByCol = prefs.getValue(
129: PortletKeys.ENTERPRISE_ADMIN,
130: "users-order-by-col", "last-name");
131: orderByType = prefs.getValue(
132: PortletKeys.ENTERPRISE_ADMIN,
133: "users-order-by-type", "asc");
134: }
135:
136: OrderByComparator orderByComparator = EnterpriseAdminUtil
137: .getUserOrderByComparator(orderByCol, orderByType);
138:
139: setOrderableHeaders(orderableHeaders);
140: setOrderByCol(orderByCol);
141: setOrderByType(orderByType);
142: setOrderByComparator(orderByComparator);
143: } catch (Exception e) {
144: _log.error(e);
145: }
146: }
147:
148: private static Log _log = LogFactory.getLog(UserSearch.class);
149:
150: }
|