1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.enterpriseadmin.search;
21  
22  import com.liferay.portal.kernel.dao.search.SearchContainer;
23  import com.liferay.portal.kernel.log.Log;
24  import com.liferay.portal.kernel.log.LogFactoryUtil;
25  import com.liferay.portal.kernel.util.OrderByComparator;
26  import com.liferay.portal.kernel.util.ParamUtil;
27  import com.liferay.portal.kernel.util.Validator;
28  import com.liferay.portal.model.UserGroup;
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.PortletRequest;
40  import javax.portlet.PortletURL;
41  
42  /**
43   * <a href="UserGroupSearch.java.html"><b><i>View Source</i></b></a>
44   *
45   * @author Charles May
46   *
47   */
48  public class UserGroupSearch extends SearchContainer<UserGroup> {
49  
50      static List<String> headerNames = new ArrayList<String>();
51      static Map<String, String> orderableHeaders = new HashMap<String, String>();
52  
53      static {
54          headerNames.add("name");
55          headerNames.add("description");
56  
57          orderableHeaders.put("name", "name");
58          orderableHeaders.put("description", "description");
59      }
60  
61      public static final String EMPTY_RESULTS_MESSAGE =
62          "no-user-groups-were-found";
63  
64      public UserGroupSearch(
65          PortletRequest portletRequest, PortletURL iteratorURL) {
66  
67          super(
68              portletRequest, new UserGroupDisplayTerms(portletRequest),
69              new UserGroupSearchTerms(portletRequest), 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(
83                      portletRequest);
84  
85              String orderByCol = ParamUtil.getString(
86                  portletRequest, "orderByCol");
87              String orderByType = ParamUtil.getString(
88                  portletRequest, "orderByType");
89  
90              if (Validator.isNotNull(orderByCol) &&
91                  Validator.isNotNull(orderByType)) {
92  
93                  prefs.setValue(
94                      PortletKeys.ENTERPRISE_ADMIN, "user-groups-order-by-col",
95                      orderByCol);
96                  prefs.setValue(
97                      PortletKeys.ENTERPRISE_ADMIN, "user-groups-order-by-type",
98                      orderByType);
99              }
100             else {
101                 orderByCol = prefs.getValue(
102                     PortletKeys.ENTERPRISE_ADMIN, "user-groups-order-by-col",
103                     "name");
104                 orderByType = prefs.getValue(
105                     PortletKeys.ENTERPRISE_ADMIN, "user-groups-order-by-type",
106                     "asc");
107             }
108 
109             OrderByComparator orderByComparator =
110                 EnterpriseAdminUtil.getUserGroupOrderByComparator(
111                     orderByCol, orderByType);
112 
113             setOrderableHeaders(orderableHeaders);
114             setOrderByCol(orderByCol);
115             setOrderByType(orderByType);
116             setOrderByComparator(orderByComparator);
117         }
118         catch (Exception e) {
119             _log.error(e);
120         }
121     }
122 
123     private static Log _log = LogFactoryUtil.getLog(UserGroupSearch.class);
124 
125 }