1   /**
2    * Copyright (c) 2000-2009 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.log.Log;
27  import com.liferay.portal.kernel.log.LogFactoryUtil;
28  import com.liferay.portal.kernel.util.OrderByComparator;
29  import com.liferay.portal.kernel.util.ParamUtil;
30  import com.liferay.portal.kernel.util.Validator;
31  import com.liferay.portal.model.UserGroup;
32  import com.liferay.portal.util.PortletKeys;
33  import com.liferay.portlet.PortalPreferences;
34  import com.liferay.portlet.PortletPreferencesFactoryUtil;
35  import com.liferay.portlet.enterpriseadmin.util.EnterpriseAdminUtil;
36  
37  import java.util.ArrayList;
38  import java.util.HashMap;
39  import java.util.List;
40  import java.util.Map;
41  
42  import javax.portlet.PortletRequest;
43  import javax.portlet.PortletURL;
44  
45  /**
46   * <a href="UserGroupSearch.java.html"><b><i>View Source</i></b></a>
47   *
48   * @author Charles May
49   *
50   */
51  public class UserGroupSearch extends SearchContainer<UserGroup> {
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(
68          PortletRequest portletRequest, PortletURL iteratorURL) {
69  
70          super(
71              portletRequest, new UserGroupDisplayTerms(portletRequest),
72              new UserGroupSearchTerms(portletRequest), DEFAULT_CUR_PARAM,
73              DEFAULT_DELTA, iteratorURL, headerNames, EMPTY_RESULTS_MESSAGE);
74  
75          UserGroupDisplayTerms displayTerms =
76              (UserGroupDisplayTerms)getDisplayTerms();
77  
78          iteratorURL.setParameter(
79              UserGroupDisplayTerms.NAME, displayTerms.getName());
80          iteratorURL.setParameter(
81              UserGroupDisplayTerms.DESCRIPTION, displayTerms.getDescription());
82  
83          try {
84              PortalPreferences preferences =
85                  PortletPreferencesFactoryUtil.getPortalPreferences(
86                      portletRequest);
87  
88              String orderByCol = ParamUtil.getString(
89                  portletRequest, "orderByCol");
90              String orderByType = ParamUtil.getString(
91                  portletRequest, "orderByType");
92  
93              if (Validator.isNotNull(orderByCol) &&
94                  Validator.isNotNull(orderByType)) {
95  
96                  preferences.setValue(
97                      PortletKeys.ENTERPRISE_ADMIN, "user-groups-order-by-col",
98                      orderByCol);
99                  preferences.setValue(
100                     PortletKeys.ENTERPRISE_ADMIN, "user-groups-order-by-type",
101                     orderByType);
102             }
103             else {
104                 orderByCol = preferences.getValue(
105                     PortletKeys.ENTERPRISE_ADMIN, "user-groups-order-by-col",
106                     "name");
107                 orderByType = preferences.getValue(
108                     PortletKeys.ENTERPRISE_ADMIN, "user-groups-order-by-type",
109                     "asc");
110             }
111 
112             OrderByComparator orderByComparator =
113                 EnterpriseAdminUtil.getUserGroupOrderByComparator(
114                     orderByCol, orderByType);
115 
116             setOrderableHeaders(orderableHeaders);
117             setOrderByCol(orderByCol);
118             setOrderByType(orderByType);
119             setOrderByComparator(orderByComparator);
120         }
121         catch (Exception e) {
122             _log.error(e);
123         }
124     }
125 
126     private static Log _log = LogFactoryUtil.getLog(UserGroupSearch.class);
127 
128 }