1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.enterpriseadmin.search;
24  
25  import com.liferay.portal.kernel.dao.search.SearchContainer;
26  import com.liferay.portal.kernel.util.OrderByComparator;
27  import com.liferay.portal.kernel.util.ParamUtil;
28  import com.liferay.portal.kernel.util.Validator;
29  import com.liferay.portal.model.PasswordPolicy;
30  import com.liferay.portal.util.PortletKeys;
31  import com.liferay.portlet.PortalPreferences;
32  import com.liferay.portlet.PortletPreferencesFactoryUtil;
33  import com.liferay.portlet.enterpriseadmin.util.EnterpriseAdminUtil;
34  
35  import java.util.ArrayList;
36  import java.util.HashMap;
37  import java.util.List;
38  import java.util.Map;
39  
40  import javax.portlet.PortletURL;
41  import javax.portlet.RenderRequest;
42  
43  import org.apache.commons.logging.Log;
44  import org.apache.commons.logging.LogFactory;
45  
46  /**
47   * <a href="PasswordPolicySearch.java.html"><b><i>View Source</i></b></a>
48   *
49   * @author Scott Lee
50   *
51   */
52  public class PasswordPolicySearch extends SearchContainer<PasswordPolicy> {
53  
54      static List<String> headerNames = new ArrayList<String>();
55      static Map<String, String> orderableHeaders = new HashMap<String, String>();
56  
57      static {
58          headerNames.add("name");
59          headerNames.add("description");
60  
61          orderableHeaders.put("name", "name");
62          orderableHeaders.put("description", "description");
63      }
64  
65      public static final String EMPTY_RESULTS_MESSAGE =
66          "no-password-policies-were-found";
67  
68      public PasswordPolicySearch(
69          RenderRequest renderRequest, PortletURL iteratorURL) {
70  
71          super(
72              renderRequest, new PasswordPolicyDisplayTerms(renderRequest),
73              new PasswordPolicySearchTerms(renderRequest), DEFAULT_CUR_PARAM,
74              DEFAULT_DELTA, iteratorURL, headerNames, EMPTY_RESULTS_MESSAGE);
75  
76          PasswordPolicyDisplayTerms displayTerms =
77              (PasswordPolicyDisplayTerms)getDisplayTerms();
78  
79          iteratorURL.setParameter(
80              PasswordPolicyDisplayTerms.NAME, displayTerms.getName());
81  
82          try {
83              PortalPreferences prefs =
84                  PortletPreferencesFactoryUtil.getPortalPreferences(
85                      renderRequest);
86  
87              String orderByCol = ParamUtil.getString(
88                  renderRequest, "orderByCol");
89              String orderByType = ParamUtil.getString(
90                  renderRequest, "orderByType");
91  
92              if (Validator.isNotNull(orderByCol) &&
93                  Validator.isNotNull(orderByType)) {
94  
95                  prefs.setValue(
96                      PortletKeys.ENTERPRISE_ADMIN,
97                      "password-policies-order-by-col", orderByCol);
98                  prefs.setValue(
99                      PortletKeys.ENTERPRISE_ADMIN,
100                     "password-policies-order-by-type", orderByType);
101             }
102             else {
103                 orderByCol = prefs.getValue(
104                     PortletKeys.ENTERPRISE_ADMIN,
105                     "password-policies-order-by-col", "name");
106                 orderByType = prefs.getValue(
107                     PortletKeys.ENTERPRISE_ADMIN,
108                     "password-policies-order-by-type", "asc");
109             }
110 
111             OrderByComparator orderByComparator =
112                 EnterpriseAdminUtil.getPasswordPolicyOrderByComparator(
113                     orderByCol, orderByType);
114 
115             setOrderableHeaders(orderableHeaders);
116             setOrderByCol(orderByCol);
117             setOrderByType(orderByType);
118             setOrderByComparator(orderByComparator);
119         }
120         catch (Exception e) {
121             _log.error(e);
122         }
123     }
124 
125     private static Log _log = LogFactory.getLog(PasswordPolicySearch.class);
126 
127 }