001
014
015 package com.liferay.portlet.enterpriseadmin.search;
016
017 import com.liferay.portal.kernel.dao.search.SearchContainer;
018 import com.liferay.portal.kernel.log.Log;
019 import com.liferay.portal.kernel.log.LogFactoryUtil;
020 import com.liferay.portal.kernel.util.OrderByComparator;
021 import com.liferay.portal.kernel.util.ParamUtil;
022 import com.liferay.portal.kernel.util.Validator;
023 import com.liferay.portal.model.Role;
024 import com.liferay.portal.util.PortletKeys;
025 import com.liferay.portal.util.PropsValues;
026 import com.liferay.portlet.PortalPreferences;
027 import com.liferay.portlet.PortletPreferencesFactoryUtil;
028 import com.liferay.portlet.enterpriseadmin.util.EnterpriseAdminUtil;
029
030 import java.util.ArrayList;
031 import java.util.HashMap;
032 import java.util.List;
033 import java.util.Map;
034
035 import javax.portlet.PortletRequest;
036 import javax.portlet.PortletURL;
037
038
041 public class RoleSearch extends SearchContainer<Role> {
042
043 static List<String> headerNames = new ArrayList<String>();
044 static Map<String, String> orderableHeaders = new HashMap<String, String>();
045
046 static {
047 headerNames.add("name");
048 headerNames.add("type");
049
050 if ((PropsValues.ROLES_COMMUNITY_SUBTYPES.length > 0) ||
051 (PropsValues.ROLES_ORGANIZATION_SUBTYPES.length > 0) ||
052 (PropsValues.ROLES_REGULAR_SUBTYPES.length > 0)) {
053
054 headerNames.add("subtype");
055 }
056
057 headerNames.add("description");
058
059 orderableHeaders.put("name", "name");
060 orderableHeaders.put("type", "type");
061 orderableHeaders.put("description", "description");
062 }
063
064 public static final String EMPTY_RESULTS_MESSAGE = "no-roles-were-found";
065
066 public RoleSearch(PortletRequest portletRequest, PortletURL iteratorURL) {
067 super(
068 portletRequest, new RoleDisplayTerms(portletRequest),
069 new RoleSearchTerms(portletRequest), DEFAULT_CUR_PARAM,
070 DEFAULT_DELTA, iteratorURL, headerNames, EMPTY_RESULTS_MESSAGE);
071
072 RoleDisplayTerms displayTerms = (RoleDisplayTerms)getDisplayTerms();
073
074 iteratorURL.setParameter(
075 RoleDisplayTerms.DESCRIPTION, displayTerms.getDescription());
076 iteratorURL.setParameter(RoleDisplayTerms.NAME, displayTerms.getName());
077 iteratorURL.setParameter(
078 RoleDisplayTerms.TYPE, String.valueOf(displayTerms.getType()));
079
080 try {
081 PortalPreferences preferences =
082 PortletPreferencesFactoryUtil.getPortalPreferences(
083 portletRequest);
084
085 String orderByCol = ParamUtil.getString(
086 portletRequest, "orderByCol");
087 String orderByType = ParamUtil.getString(
088 portletRequest, "orderByType");
089
090 if (Validator.isNotNull(orderByCol) &&
091 Validator.isNotNull(orderByType)) {
092
093 preferences.setValue(
094 PortletKeys.ENTERPRISE_ADMIN, "roles-order-by-col",
095 orderByCol);
096 preferences.setValue(
097 PortletKeys.ENTERPRISE_ADMIN, "roles-order-by-type",
098 orderByType);
099 }
100 else {
101 orderByCol = preferences.getValue(
102 PortletKeys.ENTERPRISE_ADMIN, "roles-order-by-col", "name");
103 orderByType = preferences.getValue(
104 PortletKeys.ENTERPRISE_ADMIN, "roles-order-by-type", "asc");
105 }
106
107 OrderByComparator orderByComparator =
108 EnterpriseAdminUtil.getRoleOrderByComparator(
109 orderByCol, orderByType);
110
111 setOrderableHeaders(orderableHeaders);
112 setOrderByCol(orderByCol);
113 setOrderByType(orderByType);
114 setOrderByComparator(orderByComparator);
115 }
116 catch (Exception e) {
117 _log.error(e);
118 }
119 }
120
121 private static Log _log = LogFactoryUtil.getLog(RoleSearch.class);
122
123 }