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.Group;
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="GroupSearch.java.html"><b><i>View Source</i></b></a>
44   *
45   * @author Brian Wing Shun Chan
46   *
47   */
48  public class GroupSearch extends SearchContainer<Group> {
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("type");
56  
57          orderableHeaders.put("name", "name");
58          orderableHeaders.put("type", "type");
59      }
60  
61      public static final String EMPTY_RESULTS_MESSAGE =
62          "no-communities-were-found";
63  
64      public GroupSearch(PortletRequest portletRequest, PortletURL iteratorURL) {
65          super(
66              portletRequest, new GroupDisplayTerms(portletRequest),
67              new GroupSearchTerms(portletRequest), DEFAULT_CUR_PARAM,
68              DEFAULT_DELTA, iteratorURL, headerNames, EMPTY_RESULTS_MESSAGE);
69  
70          GroupDisplayTerms displayTerms = (GroupDisplayTerms)getDisplayTerms();
71  
72          iteratorURL.setParameter(
73              GroupDisplayTerms.NAME, displayTerms.getName());
74          iteratorURL.setParameter(
75              GroupDisplayTerms.DESCRIPTION, displayTerms.getDescription());
76  
77          try {
78              PortalPreferences prefs =
79                  PortletPreferencesFactoryUtil.getPortalPreferences(
80                      portletRequest);
81  
82              String orderByCol = ParamUtil.getString(
83                  portletRequest, "orderByCol");
84              String orderByType = ParamUtil.getString(
85                  portletRequest, "orderByType");
86  
87              if (Validator.isNotNull(orderByCol) &&
88                  Validator.isNotNull(orderByType)) {
89  
90                  prefs.setValue(
91                      PortletKeys.ENTERPRISE_ADMIN, "groups-order-by-col",
92                      orderByCol);
93                  prefs.setValue(
94                      PortletKeys.ENTERPRISE_ADMIN, "groups-order-by-type",
95                      orderByType);
96              }
97              else {
98                  orderByCol = prefs.getValue(
99                      PortletKeys.ENTERPRISE_ADMIN, "groups-order-by-col",
100                     "name");
101                 orderByType = prefs.getValue(
102                     PortletKeys.ENTERPRISE_ADMIN, "groups-order-by-type",
103                     "asc");
104             }
105 
106             OrderByComparator orderByComparator =
107                 EnterpriseAdminUtil.getGroupOrderByComparator(
108                     orderByCol, orderByType);
109 
110             setOrderableHeaders(orderableHeaders);
111             setOrderByCol(orderByCol);
112             setOrderByType(orderByType);
113             setOrderByComparator(orderByComparator);
114         }
115         catch (Exception e) {
116             _log.error(e);
117         }
118     }
119 
120     private static Log _log = LogFactoryUtil.getLog(GroupSearch.class);
121 
122 }