001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.enterpriseadmin.util;
022:
023: import com.liferay.portal.kernel.util.OrderByComparator;
024: import com.liferay.portal.model.Organization;
025: import com.liferay.portal.util.comparator.ContactFirstNameComparator;
026: import com.liferay.portal.util.comparator.ContactJobTitleComparator;
027: import com.liferay.portal.util.comparator.ContactLastNameComparator;
028: import com.liferay.portal.util.comparator.GroupNameComparator;
029: import com.liferay.portal.util.comparator.GroupTypeComparator;
030: import com.liferay.portal.util.comparator.OrganizationNameComparator;
031: import com.liferay.portal.util.comparator.OrganizationTypeComparator;
032: import com.liferay.portal.util.comparator.PasswordPolicyDescriptionComparator;
033: import com.liferay.portal.util.comparator.PasswordPolicyNameComparator;
034: import com.liferay.portal.util.comparator.RoleDescriptionComparator;
035: import com.liferay.portal.util.comparator.RoleNameComparator;
036: import com.liferay.portal.util.comparator.RoleTypeComparator;
037: import com.liferay.portal.util.comparator.UserEmailAddressComparator;
038: import com.liferay.portal.util.comparator.UserGroupDescriptionComparator;
039: import com.liferay.portal.util.comparator.UserGroupNameComparator;
040: import com.liferay.portal.util.comparator.UserScreenNameComparator;
041:
042: import java.util.List;
043:
044: /**
045: * <a href="EnterpriseAdminUtil.java.html"><b><i>View Source</i></b></a>
046: *
047: * @author Brian Wing Shun Chan
048: *
049: */
050: public class EnterpriseAdminUtil {
051:
052: public static OrderByComparator getGroupOrderByComparator(
053: String orderByCol, String orderByType) {
054:
055: boolean orderByAsc = false;
056:
057: if (orderByType.equals("asc")) {
058: orderByAsc = true;
059: }
060:
061: OrderByComparator orderByComparator = null;
062:
063: if (orderByCol.equals("name")) {
064: orderByComparator = new GroupNameComparator(orderByAsc);
065: } else if (orderByCol.equals("type")) {
066: orderByComparator = new GroupTypeComparator(orderByAsc);
067: } else {
068: orderByComparator = new GroupNameComparator(orderByAsc);
069: }
070:
071: return orderByComparator;
072: }
073:
074: public static Long[] getOrganizationIds(List organizations) {
075: Long[] organizationIds = new Long[organizations.size()];
076:
077: for (int i = 0; i < organizations.size(); i++) {
078: Organization organization = (Organization) organizations
079: .get(i);
080:
081: organizationIds[i] = new Long(organization
082: .getOrganizationId());
083: }
084:
085: return organizationIds;
086: }
087:
088: public static OrderByComparator getOrganizationOrderByComparator(
089: String orderByCol, String orderByType) {
090:
091: boolean orderByAsc = false;
092:
093: if (orderByType.equals("asc")) {
094: orderByAsc = true;
095: }
096:
097: OrderByComparator orderByComparator = null;
098:
099: if (orderByCol.equals("name")) {
100: orderByComparator = new OrganizationNameComparator(
101: orderByAsc);
102: } else if (orderByCol.equals("type")) {
103: orderByComparator = new OrganizationTypeComparator(
104: orderByAsc);
105: } else {
106: orderByComparator = new OrganizationNameComparator(
107: orderByAsc);
108: }
109:
110: return orderByComparator;
111: }
112:
113: public static OrderByComparator getPasswordPolicyOrderByComparator(
114: String orderByCol, String orderByType) {
115:
116: boolean orderByAsc = false;
117:
118: if (orderByType.equals("asc")) {
119: orderByAsc = true;
120: }
121:
122: OrderByComparator orderByComparator = null;
123:
124: if (orderByCol.equals("name")) {
125: orderByComparator = new PasswordPolicyNameComparator(
126: orderByAsc);
127: } else if (orderByCol.equals("description")) {
128: orderByComparator = new PasswordPolicyDescriptionComparator(
129: orderByAsc);
130: } else {
131: orderByComparator = new PasswordPolicyNameComparator(
132: orderByAsc);
133: }
134:
135: return orderByComparator;
136: }
137:
138: public static OrderByComparator getRoleOrderByComparator(
139: String orderByCol, String orderByType) {
140:
141: boolean orderByAsc = false;
142:
143: if (orderByType.equals("asc")) {
144: orderByAsc = true;
145: }
146:
147: OrderByComparator orderByComparator = null;
148:
149: if (orderByCol.equals("name")) {
150: orderByComparator = new RoleNameComparator(orderByAsc);
151: } else if (orderByCol.equals("description")) {
152: orderByComparator = new RoleDescriptionComparator(
153: orderByAsc);
154: } else if (orderByCol.equals("type")) {
155: orderByComparator = new RoleTypeComparator(orderByAsc);
156: } else {
157: orderByComparator = new RoleNameComparator(orderByAsc);
158: }
159:
160: return orderByComparator;
161: }
162:
163: public static OrderByComparator getUserGroupOrderByComparator(
164: String orderByCol, String orderByType) {
165:
166: boolean orderByAsc = false;
167:
168: if (orderByType.equals("asc")) {
169: orderByAsc = true;
170: }
171:
172: OrderByComparator orderByComparator = null;
173:
174: if (orderByCol.equals("name")) {
175: orderByComparator = new UserGroupNameComparator(orderByAsc);
176: } else if (orderByCol.equals("description")) {
177: orderByComparator = new UserGroupDescriptionComparator(
178: orderByAsc);
179: } else {
180: orderByComparator = new UserGroupNameComparator(orderByAsc);
181: }
182:
183: return orderByComparator;
184: }
185:
186: public static OrderByComparator getUserOrderByComparator(
187: String orderByCol, String orderByType) {
188:
189: boolean orderByAsc = false;
190:
191: if (orderByType.equals("asc")) {
192: orderByAsc = true;
193: }
194:
195: OrderByComparator orderByComparator = null;
196:
197: if (orderByCol.equals("email-address")) {
198: orderByComparator = new UserEmailAddressComparator(
199: orderByAsc);
200: } else if (orderByCol.equals("first-name")) {
201: orderByComparator = new ContactFirstNameComparator(
202: orderByAsc);
203: } else if (orderByCol.equals("job-title")) {
204: orderByComparator = new ContactJobTitleComparator(
205: orderByAsc);
206: } else if (orderByCol.equals("last-name")) {
207: orderByComparator = new ContactLastNameComparator(
208: orderByAsc);
209: } else if (orderByCol.equals("screen-name")) {
210: orderByComparator = new UserScreenNameComparator(orderByAsc);
211: } else {
212: orderByComparator = new ContactLastNameComparator(
213: orderByAsc);
214: }
215:
216: return orderByComparator;
217: }
218:
219: }
|