1
22
23 package com.liferay.portlet.enterpriseadmin.search;
24
25 import com.liferay.portal.kernel.dao.search.SearchContainer;
26 import com.liferay.portal.kernel.util.OrderByComparator;
27 import com.liferay.portal.kernel.util.ParamUtil;
28 import com.liferay.portal.kernel.util.Validator;
29 import com.liferay.portal.util.PortletKeys;
30 import com.liferay.portlet.PortalPreferences;
31 import com.liferay.portlet.PortletPreferencesFactoryUtil;
32 import com.liferay.portlet.enterpriseadmin.util.EnterpriseAdminUtil;
33
34 import java.util.ArrayList;
35 import java.util.HashMap;
36 import java.util.List;
37 import java.util.Map;
38
39 import javax.portlet.PortletURL;
40 import javax.portlet.RenderRequest;
41
42 import org.apache.commons.logging.Log;
43 import org.apache.commons.logging.LogFactory;
44
45
51 public class UserGroupSearch extends SearchContainer {
52
53 static List<String> headerNames = new ArrayList<String>();
54 static Map<String, String> orderableHeaders = new HashMap<String, String>();
55
56 static {
57 headerNames.add("name");
58 headerNames.add("description");
59
60 orderableHeaders.put("name", "name");
61 orderableHeaders.put("description", "description");
62 }
63
64 public static final String EMPTY_RESULTS_MESSAGE =
65 "no-user-groups-were-found";
66
67 public UserGroupSearch(RenderRequest req, PortletURL iteratorURL) {
68 super(req, new UserGroupDisplayTerms(req),
69 new UserGroupSearchTerms(req), DEFAULT_CUR_PARAM,
70 DEFAULT_DELTA, iteratorURL, headerNames, EMPTY_RESULTS_MESSAGE);
71
72 UserGroupDisplayTerms displayTerms =
73 (UserGroupDisplayTerms)getDisplayTerms();
74
75 iteratorURL.setParameter(
76 UserGroupDisplayTerms.NAME, displayTerms.getName());
77 iteratorURL.setParameter(
78 UserGroupDisplayTerms.DESCRIPTION, displayTerms.getDescription());
79
80 try {
81 PortalPreferences prefs =
82 PortletPreferencesFactoryUtil.getPortalPreferences(req);
83
84 String orderByCol = ParamUtil.getString(req, "orderByCol");
85 String orderByType = ParamUtil.getString(req, "orderByType");
86
87 if (Validator.isNotNull(orderByCol) &&
88 Validator.isNotNull(orderByType)) {
89
90 prefs.setValue(
91 PortletKeys.ENTERPRISE_ADMIN, "user-groups-order-by-col",
92 orderByCol);
93 prefs.setValue(
94 PortletKeys.ENTERPRISE_ADMIN, "user-groups-order-by-type",
95 orderByType);
96 }
97 else {
98 orderByCol = prefs.getValue(
99 PortletKeys.ENTERPRISE_ADMIN, "user-groups-order-by-col",
100 "name");
101 orderByType = prefs.getValue(
102 PortletKeys.ENTERPRISE_ADMIN, "user-groups-order-by-type",
103 "asc");
104 }
105
106 OrderByComparator orderByComparator =
107 EnterpriseAdminUtil.getUserGroupOrderByComparator(
108 orderByCol, orderByType);
109
110 setOrderableHeaders(orderableHeaders);
111 setOrderByCol(orderByCol);
112 setOrderByType(orderByType);
113 setOrderByComparator(orderByComparator);
114 }
115 catch (Exception e) {
116 _log.error(e);
117 }
118 }
119
120 private static Log _log = LogFactory.getLog(UserGroupSearch.class);
121
122 }