1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.enterpriseadmin.search;
16  
17  import com.liferay.portal.kernel.dao.search.SearchContainer;
18  import com.liferay.portal.kernel.log.Log;
19  import com.liferay.portal.kernel.log.LogFactoryUtil;
20  import com.liferay.portal.kernel.util.OrderByComparator;
21  import com.liferay.portal.kernel.util.ParamUtil;
22  import com.liferay.portal.kernel.util.Validator;
23  import com.liferay.portal.model.Group;
24  import com.liferay.portal.util.PortletKeys;
25  import com.liferay.portlet.PortalPreferences;
26  import com.liferay.portlet.PortletPreferencesFactoryUtil;
27  import com.liferay.portlet.enterpriseadmin.util.EnterpriseAdminUtil;
28  
29  import java.util.ArrayList;
30  import java.util.HashMap;
31  import java.util.List;
32  import java.util.Map;
33  
34  import javax.portlet.PortletRequest;
35  import javax.portlet.PortletURL;
36  
37  /**
38   * <a href="GroupSearch.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Brian Wing Shun Chan
41   */
42  public class GroupSearch extends SearchContainer<Group> {
43  
44      static List<String> headerNames = new ArrayList<String>();
45      static Map<String, String> orderableHeaders = new HashMap<String, String>();
46  
47      static {
48          headerNames.add("name");
49          headerNames.add("type");
50  
51          orderableHeaders.put("name", "name");
52          orderableHeaders.put("type", "type");
53      }
54  
55      public static final String EMPTY_RESULTS_MESSAGE =
56          "no-communities-were-found";
57  
58      public GroupSearch(PortletRequest portletRequest, PortletURL iteratorURL) {
59          super(
60              portletRequest, new GroupDisplayTerms(portletRequest),
61              new GroupSearchTerms(portletRequest), DEFAULT_CUR_PARAM,
62              DEFAULT_DELTA, iteratorURL, headerNames, EMPTY_RESULTS_MESSAGE);
63  
64          GroupDisplayTerms displayTerms = (GroupDisplayTerms)getDisplayTerms();
65  
66          iteratorURL.setParameter(
67              GroupDisplayTerms.NAME, displayTerms.getName());
68          iteratorURL.setParameter(
69              GroupDisplayTerms.DESCRIPTION, displayTerms.getDescription());
70  
71          try {
72              PortalPreferences preferences =
73                  PortletPreferencesFactoryUtil.getPortalPreferences(
74                      portletRequest);
75  
76              String orderByCol = ParamUtil.getString(
77                  portletRequest, "orderByCol");
78              String orderByType = ParamUtil.getString(
79                  portletRequest, "orderByType");
80  
81              if (Validator.isNotNull(orderByCol) &&
82                  Validator.isNotNull(orderByType)) {
83  
84                  preferences.setValue(
85                      PortletKeys.ENTERPRISE_ADMIN, "groups-order-by-col",
86                      orderByCol);
87                  preferences.setValue(
88                      PortletKeys.ENTERPRISE_ADMIN, "groups-order-by-type",
89                      orderByType);
90              }
91              else {
92                  orderByCol = preferences.getValue(
93                      PortletKeys.ENTERPRISE_ADMIN, "groups-order-by-col",
94                      "name");
95                  orderByType = preferences.getValue(
96                      PortletKeys.ENTERPRISE_ADMIN, "groups-order-by-type",
97                      "asc");
98              }
99  
100             OrderByComparator orderByComparator =
101                 EnterpriseAdminUtil.getGroupOrderByComparator(
102                     orderByCol, orderByType);
103 
104             setOrderableHeaders(orderableHeaders);
105             setOrderByCol(orderByCol);
106             setOrderByType(orderByType);
107             setOrderByComparator(orderByComparator);
108         }
109         catch (Exception e) {
110             _log.error(e);
111         }
112     }
113 
114     private static Log _log = LogFactoryUtil.getLog(GroupSearch.class);
115 
116 }