1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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.UserGroup;
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="UserGroupSearch.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Charles May
41   */
42  public class UserGroupSearch extends SearchContainer<UserGroup> {
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("description");
50  
51          orderableHeaders.put("name", "name");
52          orderableHeaders.put("description", "description");
53      }
54  
55      public static final String EMPTY_RESULTS_MESSAGE =
56          "no-user-groups-were-found";
57  
58      public UserGroupSearch(
59          PortletRequest portletRequest, PortletURL iteratorURL) {
60  
61          super(
62              portletRequest, new UserGroupDisplayTerms(portletRequest),
63              new UserGroupSearchTerms(portletRequest), DEFAULT_CUR_PARAM,
64              DEFAULT_DELTA, iteratorURL, headerNames, EMPTY_RESULTS_MESSAGE);
65  
66          UserGroupDisplayTerms displayTerms =
67              (UserGroupDisplayTerms)getDisplayTerms();
68  
69          iteratorURL.setParameter(
70              UserGroupDisplayTerms.NAME, displayTerms.getName());
71          iteratorURL.setParameter(
72              UserGroupDisplayTerms.DESCRIPTION, displayTerms.getDescription());
73  
74          try {
75              PortalPreferences preferences =
76                  PortletPreferencesFactoryUtil.getPortalPreferences(
77                      portletRequest);
78  
79              String orderByCol = ParamUtil.getString(
80                  portletRequest, "orderByCol");
81              String orderByType = ParamUtil.getString(
82                  portletRequest, "orderByType");
83  
84              if (Validator.isNotNull(orderByCol) &&
85                  Validator.isNotNull(orderByType)) {
86  
87                  preferences.setValue(
88                      PortletKeys.ENTERPRISE_ADMIN, "user-groups-order-by-col",
89                      orderByCol);
90                  preferences.setValue(
91                      PortletKeys.ENTERPRISE_ADMIN, "user-groups-order-by-type",
92                      orderByType);
93              }
94              else {
95                  orderByCol = preferences.getValue(
96                      PortletKeys.ENTERPRISE_ADMIN, "user-groups-order-by-col",
97                      "name");
98                  orderByType = preferences.getValue(
99                      PortletKeys.ENTERPRISE_ADMIN, "user-groups-order-by-type",
100                     "asc");
101             }
102 
103             OrderByComparator orderByComparator =
104                 EnterpriseAdminUtil.getUserGroupOrderByComparator(
105                     orderByCol, orderByType);
106 
107             setOrderableHeaders(orderableHeaders);
108             setOrderByCol(orderByCol);
109             setOrderByType(orderByType);
110             setOrderByComparator(orderByComparator);
111         }
112         catch (Exception e) {
113             _log.error(e);
114         }
115     }
116 
117     private static Log _log = LogFactoryUtil.getLog(UserGroupSearch.class);
118 
119 }