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