1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
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.model.UserGroup;
30  import com.liferay.portal.util.PortletKeys;
31  import com.liferay.portlet.PortalPreferences;
32  import com.liferay.portlet.PortletPreferencesFactoryUtil;
33  import com.liferay.portlet.enterpriseadmin.util.EnterpriseAdminUtil;
34  
35  import java.util.ArrayList;
36  import java.util.HashMap;
37  import java.util.List;
38  import java.util.Map;
39  
40  import javax.portlet.PortletURL;
41  import javax.portlet.RenderRequest;
42  
43  import org.apache.commons.logging.Log;
44  import org.apache.commons.logging.LogFactory;
45  
46  /**
47   * <a href="UserGroupSearch.java.html"><b><i>View Source</i></b></a>
48   *
49   * @author Charles May
50   *
51   */
52  public class UserGroupSearch extends SearchContainer<UserGroup> {
53  
54      static List<String> headerNames = new ArrayList<String>();
55      static Map<String, String> orderableHeaders = new HashMap<String, String>();
56  
57      static {
58          headerNames.add("name");
59          headerNames.add("description");
60  
61          orderableHeaders.put("name", "name");
62          orderableHeaders.put("description", "description");
63      }
64  
65      public static final String EMPTY_RESULTS_MESSAGE =
66          "no-user-groups-were-found";
67  
68      public UserGroupSearch(
69          RenderRequest renderRequest, PortletURL iteratorURL) {
70  
71          super(
72              renderRequest, new UserGroupDisplayTerms(renderRequest),
73              new UserGroupSearchTerms(renderRequest), DEFAULT_CUR_PARAM,
74              DEFAULT_DELTA, iteratorURL, headerNames, EMPTY_RESULTS_MESSAGE);
75  
76          UserGroupDisplayTerms displayTerms =
77              (UserGroupDisplayTerms)getDisplayTerms();
78  
79          iteratorURL.setParameter(
80              UserGroupDisplayTerms.NAME, displayTerms.getName());
81          iteratorURL.setParameter(
82              UserGroupDisplayTerms.DESCRIPTION, displayTerms.getDescription());
83  
84          try {
85              PortalPreferences prefs =
86                  PortletPreferencesFactoryUtil.getPortalPreferences(
87                      renderRequest);
88  
89              String orderByCol = ParamUtil.getString(
90                  renderRequest, "orderByCol");
91              String orderByType = ParamUtil.getString(
92                  renderRequest, "orderByType");
93  
94              if (Validator.isNotNull(orderByCol) &&
95                  Validator.isNotNull(orderByType)) {
96  
97                  prefs.setValue(
98                      PortletKeys.ENTERPRISE_ADMIN, "user-groups-order-by-col",
99                      orderByCol);
100                 prefs.setValue(
101                     PortletKeys.ENTERPRISE_ADMIN, "user-groups-order-by-type",
102                     orderByType);
103             }
104             else {
105                 orderByCol = prefs.getValue(
106                     PortletKeys.ENTERPRISE_ADMIN, "user-groups-order-by-col",
107                     "name");
108                 orderByType = prefs.getValue(
109                     PortletKeys.ENTERPRISE_ADMIN, "user-groups-order-by-type",
110                     "asc");
111             }
112 
113             OrderByComparator orderByComparator =
114                 EnterpriseAdminUtil.getUserGroupOrderByComparator(
115                     orderByCol, orderByType);
116 
117             setOrderableHeaders(orderableHeaders);
118             setOrderByCol(orderByCol);
119             setOrderByType(orderByType);
120             setOrderByComparator(orderByComparator);
121         }
122         catch (Exception e) {
123             _log.error(e);
124         }
125     }
126 
127     private static Log _log = LogFactory.getLog(UserGroupSearch.class);
128 
129 }