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.PasswordPolicy;
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="PasswordPolicySearch.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Scott Lee
41   */
42  public class PasswordPolicySearch extends SearchContainer<PasswordPolicy> {
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-password-policies-were-found";
57  
58      public PasswordPolicySearch(
59          PortletRequest portletRequest, PortletURL iteratorURL) {
60  
61          super(
62              portletRequest, new PasswordPolicyDisplayTerms(portletRequest),
63              new PasswordPolicySearchTerms(portletRequest), DEFAULT_CUR_PARAM,
64              DEFAULT_DELTA, iteratorURL, headerNames, EMPTY_RESULTS_MESSAGE);
65  
66          PasswordPolicyDisplayTerms displayTerms =
67              (PasswordPolicyDisplayTerms)getDisplayTerms();
68  
69          iteratorURL.setParameter(
70              PasswordPolicyDisplayTerms.NAME, displayTerms.getName());
71  
72          try {
73              PortalPreferences preferences =
74                  PortletPreferencesFactoryUtil.getPortalPreferences(
75                      portletRequest);
76  
77              String orderByCol = ParamUtil.getString(
78                  portletRequest, "orderByCol");
79              String orderByType = ParamUtil.getString(
80                  portletRequest, "orderByType");
81  
82              if (Validator.isNotNull(orderByCol) &&
83                  Validator.isNotNull(orderByType)) {
84  
85                  preferences.setValue(
86                      PortletKeys.ENTERPRISE_ADMIN,
87                      "password-policies-order-by-col", orderByCol);
88                  preferences.setValue(
89                      PortletKeys.ENTERPRISE_ADMIN,
90                      "password-policies-order-by-type", orderByType);
91              }
92              else {
93                  orderByCol = preferences.getValue(
94                      PortletKeys.ENTERPRISE_ADMIN,
95                      "password-policies-order-by-col", "name");
96                  orderByType = preferences.getValue(
97                      PortletKeys.ENTERPRISE_ADMIN,
98                      "password-policies-order-by-type", "asc");
99              }
100 
101             OrderByComparator orderByComparator =
102                 EnterpriseAdminUtil.getPasswordPolicyOrderByComparator(
103                     orderByCol, orderByType);
104 
105             setOrderableHeaders(orderableHeaders);
106             setOrderByCol(orderByCol);
107             setOrderByType(orderByType);
108             setOrderByComparator(orderByComparator);
109         }
110         catch (Exception e) {
111             _log.error(e);
112         }
113     }
114 
115     private static Log _log = LogFactoryUtil.getLog(PasswordPolicySearch.class);
116 
117 }