1
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.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.PortletURL;
40 import javax.portlet.RenderRequest;
41
42 import org.apache.commons.logging.Log;
43 import org.apache.commons.logging.LogFactory;
44
45
51 public class OrganizationSearch extends SearchContainer {
52
53 static List<String> headerNames = new ArrayList<String>();
54 static Map<String, String> orderableHeaders = new HashMap<String, String>();
55
56 static {
57 headerNames.add("name");
58 headerNames.add("parent-organization");
59 headerNames.add("type");
60 headerNames.add("city");
61 headerNames.add("region");
62 headerNames.add("country");
63
64 orderableHeaders.put("name", "name");
65 orderableHeaders.put("type", "type");
66 }
67
68 public static final String EMPTY_RESULTS_MESSAGE =
69 "no-organizations-were-found";
70
71 public OrganizationSearch(RenderRequest req, PortletURL iteratorURL) {
72 super(req, new OrganizationDisplayTerms(req),
73 new OrganizationSearchTerms(req), DEFAULT_CUR_PARAM,
74 DEFAULT_DELTA, iteratorURL, headerNames, EMPTY_RESULTS_MESSAGE);
75
76 OrganizationDisplayTerms displayTerms =
77 (OrganizationDisplayTerms)getDisplayTerms();
78
79 iteratorURL.setParameter(
80 OrganizationDisplayTerms.NAME, displayTerms.getName());
81 iteratorURL.setParameter(
82 OrganizationDisplayTerms.STREET, displayTerms.getStreet());
83 iteratorURL.setParameter(
84 OrganizationDisplayTerms.CITY, displayTerms.getCity());
85 iteratorURL.setParameter(
86 OrganizationDisplayTerms.ZIP, displayTerms.getZip());
87 iteratorURL.setParameter(
88 OrganizationDisplayTerms.COUNTRY_ID,
89 String.valueOf(displayTerms.getCountryId()));
90 iteratorURL.setParameter(
91 OrganizationDisplayTerms.REGION_ID,
92 String.valueOf(displayTerms.getRegionId()));
93 iteratorURL.setParameter(
94 OrganizationDisplayTerms.PARENT_ORGANIZATION_ID,
95 String.valueOf(displayTerms.getParentOrganizationId()));
96
97 try {
98 PortalPreferences prefs =
99 PortletPreferencesFactoryUtil.getPortalPreferences(req);
100
101 String orderByCol = ParamUtil.getString(req, "orderByCol");
102 String orderByType = ParamUtil.getString(req, "orderByType");
103
104 if (Validator.isNotNull(orderByCol) &&
105 Validator.isNotNull(orderByType)) {
106
107 prefs.setValue(
108 PortletKeys.ENTERPRISE_ADMIN, "organizations-order-by-col",
109 orderByCol);
110 prefs.setValue(
111 PortletKeys.ENTERPRISE_ADMIN, "organizations-order-by-type",
112 orderByType);
113 }
114 else {
115 orderByCol = prefs.getValue(
116 PortletKeys.ENTERPRISE_ADMIN, "organizations-order-by-col",
117 "name");
118 orderByType = prefs.getValue(
119 PortletKeys.ENTERPRISE_ADMIN, "organizations-order-by-type",
120 "asc");
121 }
122
123 OrderByComparator orderByComparator =
124 EnterpriseAdminUtil.getOrganizationOrderByComparator(
125 orderByCol, orderByType);
126
127 setOrderableHeaders(orderableHeaders);
128 setOrderByCol(orderByCol);
129 setOrderByType(orderByType);
130 setOrderByComparator(orderByComparator);
131 }
132 catch (Exception e) {
133 _log.error(e);
134 }
135 }
136
137 private static Log _log = LogFactory.getLog(OrganizationSearch.class);
138
139 }