001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.file; 029 030import org.opencms.security.CmsOrganizationalUnit; 031 032import java.util.Collection; 033import java.util.HashSet; 034import java.util.List; 035import java.util.Set; 036 037/** 038 * An object which represents search criteria for retrieving users.<p> 039 * 040 * @since 8.0.0 041 */ 042public class CmsUserSearchParameters { 043 044 /** An enum used for indicating searchable columns. */ 045 public enum SearchKey { 046 /** Email address. */ 047 email, 048 /** Full name. */ 049 fullName, 050 /** Organizational unit. */ 051 orgUnit; 052 } 053 054 /** An enum used for indicating sort order. */ 055 public enum SortKey { 056 /** User activation status. */ 057 activated, 058 /** Email address. */ 059 email, 060 /** Flags. */ 061 flagStatus, 062 /** Full name: "firstname lastname (loginname)". */ 063 fullName, 064 /** Last login date. */ 065 lastLogin, 066 /** Login name. */ 067 loginName, 068 /** Organizational unit. */ 069 orgUnit 070 } 071 072 /** The list of allowed OUs. */ 073 private List<CmsOrganizationalUnit> m_allowedOus; 074 075 /** A collection of groups such that returned users must be in at least one of them. */ 076 private Collection<CmsGroup> m_anyGroups; 077 078 /** Indicates whether the results should be retrieved in ascending/descending order. */ 079 private boolean m_ascending; 080 081 /** Indicates whether search should be case sensitive. */ 082 private boolean m_caseSensitive = true; 083 084 /** The email address to filter. */ 085 private String m_email; 086 087 /** Indicates whether only users which match the given group's OU should be returned. */ 088 private boolean m_filterByGroupOu; 089 090 /** True if non-core users should be filtered out. */ 091 private boolean m_filterCore; 092 093 /** The flags to filter by. */ 094 private int m_flags; 095 096 /** The group to which a resulting user must belong. */ 097 private CmsGroup m_group; 098 099 /** If true, core users will not be filtered out if filtering by flags. */ 100 private boolean m_keepCoreUsers; 101 102 /** A collection of groups such that returned users must be in none of them. */ 103 private Collection<CmsGroup> m_notAnyGroups; 104 105 /** The group to which a resulting user may not belong. */ 106 private CmsGroup m_notGroup; 107 108 /** The organizational unit to which a resulting user must belong. */ 109 private CmsOrganizationalUnit m_orgUnit; 110 111 /** The results page index. */ 112 private int m_page; 113 114 /** The maximum results page size. */ 115 private int m_pageSize = -1; 116 117 /** If true, and an OU has been set, users of sub-OUs will also be retrieved. */ 118 private boolean m_recursiveOrgUnits; 119 120 /** The search term entered by the user. */ 121 private String m_searchFilter; 122 123 /** The set of search keys to use. */ 124 private Set<SearchKey> m_searchKeys = new HashSet<SearchKey>(); 125 126 /** The bit mask used for flag sorting. */ 127 private int m_sortFlags; 128 129 /** The key which indicates by which column the table should be sorted. */ 130 private SortKey m_sortKey; 131 132 /** 133 * Adds a search key.<p> 134 * 135 * @param key the search key to add 136 */ 137 public void addSearch(SearchKey key) { 138 139 m_searchKeys.add(key); 140 } 141 142 /** 143 * Returns the list of OUs from which users may be returned.<p> 144 * 145 * @return a list of OUs 146 */ 147 public List<CmsOrganizationalUnit> getAllowedOus() { 148 149 return m_allowedOus; 150 } 151 152 /** 153 * Returns the collection of groups such that returned users must be in at least one of them.<p> 154 * 155 * @return a collection of groups 156 */ 157 public Collection<CmsGroup> getAnyGroups() { 158 159 return m_anyGroups; 160 } 161 162 /** 163 * Gets the email address to search for. 164 * 165 * @return the email address to search for 166 */ 167 public String getEmail() { 168 169 return m_email; 170 } 171 172 /** 173 * Returns the flags to filter by.<p> 174 * 175 * @return the flags 176 */ 177 public int getFlags() { 178 179 return m_flags; 180 } 181 182 /** 183 * Returns the group such that users which are not in the group will be filtered out.<p> 184 * 185 * @return a group 186 */ 187 public CmsGroup getGroup() { 188 189 return m_group; 190 } 191 192 /** 193 * Returns the groups whose users may not appear in the search results.<p> 194 * 195 * @return the groups whose users may not appear in the search results 196 */ 197 public Collection<CmsGroup> getNotAnyGroups() { 198 199 return m_notAnyGroups; 200 } 201 202 /** 203 * Returns the group such that users not in that group will be filtered out.<p> 204 * 205 * @return a group 206 */ 207 public CmsGroup getNotGroup() { 208 209 return m_notGroup; 210 } 211 212 /** 213 * Gets the organizational unit to which a user must belong. 214 * 215 * @return the organizational unit 216 */ 217 public CmsOrganizationalUnit getOrganizationalUnit() { 218 219 return m_orgUnit; 220 } 221 222 /** 223 * Returns the results page index.<p> 224 * 225 * @return the results page index 226 */ 227 public int getPage() { 228 229 return m_page; 230 } 231 232 /** 233 * Returns the maximum results page size.<p> 234 * 235 * @return the page size 236 */ 237 public int getPageSize() { 238 239 return m_pageSize; 240 } 241 242 /** 243 * Returns the search term. 244 * 245 * @return the search term 246 */ 247 public String getSearchFilter() { 248 249 return m_searchFilter; 250 } 251 252 /** 253 * Returns the set of search keys.<p> 254 * 255 * @return the set of search keys 256 */ 257 public Set<SearchKey> getSearchKeys() { 258 259 return m_searchKeys; 260 } 261 262 /** 263 * Returns the bit mask to be used for ordering by flags.<p> 264 * 265 * @return the bit mask to be used for ordering by flags 266 */ 267 public int getSortFlags() { 268 269 return m_sortFlags; 270 } 271 272 /** 273 * Returns the key indicating by which column the results should be sorted.<p> 274 * 275 * @return the sort key 276 */ 277 public SortKey getSortKey() { 278 279 return m_sortKey; 280 } 281 282 /** 283 * If true, the results should be sorted in ascending order, else in descending order.<p> 284 * 285 * @return the flag indicating the sort order 286 */ 287 public boolean isAscending() { 288 289 return m_ascending; 290 } 291 292 /** 293 * Returns true if the search filter should be case sensitive.<p> 294 * 295 * The default value is <code>true</code>. 296 * 297 * @return true if the search filter should be case sensitive 298 */ 299 public boolean isCaseSensitive() { 300 301 return m_caseSensitive; 302 } 303 304 /** 305 * Returns true if users of different OUs than the search group's OU will be filtered out.<p> 306 * 307 * @return the "filter by group OU" flag 308 */ 309 public boolean isFilterByGroupOu() { 310 311 return m_filterByGroupOu; 312 } 313 314 /** 315 * Returns true if non-core users should be filtered out.<p> 316 * 317 * @return true if non-core users should be filtered out 318 */ 319 public boolean isFilterCore() { 320 321 return m_filterCore; 322 } 323 324 /** 325 * Return true if core users should not be filtered out if filtering by flag.<p> 326 * 327 * @return true if core users should not be filtered out if filtering by flag.<p> 328 */ 329 public boolean keepCoreUsers() { 330 331 return m_keepCoreUsers; 332 } 333 334 /** 335 * Returns true if sub-OU users will be returned in the result.<p> 336 * 337 * @return true if sub-OU users will be returned in the result 338 */ 339 public boolean recursiveOrgUnits() { 340 341 return m_recursiveOrgUnits; 342 } 343 344 /** 345 * Sets the OUs from which users should be returned.<p> 346 * 347 * @param ous a list of OUs 348 */ 349 public void setAllowedOus(List<CmsOrganizationalUnit> ous) { 350 351 m_allowedOus = ous; 352 } 353 354 /** 355 * Sets the groups such that returned users must be in at least one of them.<p> 356 * 357 * @param anyGroups the groups 358 */ 359 public void setAnyGroups(Collection<CmsGroup> anyGroups) { 360 361 m_anyGroups = anyGroups; 362 } 363 364 /** 365 * Sets the case sensitivity for the search filter.<p> 366 * 367 * @param caseSensitive if true, the search filter will be case sensitive. 368 */ 369 public void setCaseSensitive(boolean caseSensitive) { 370 371 m_caseSensitive = caseSensitive; 372 } 373 374 /** 375 * Sets the "filter by group OU" flag.<p> 376 * 377 * If the flag is true, users of a different OU than the search group's OU will be filtered out.<p> 378 * 379 * @param filterByGroupOu the "filter by group OU" flag 380 */ 381 public void setFilterByGroupOu(boolean filterByGroupOu) { 382 383 m_filterByGroupOu = filterByGroupOu; 384 } 385 386 /** 387 * Enables or disables the filtering of non-core users.<p> 388 * 389 * @param filterCore if true, non-core users will be filtered out 390 */ 391 public void setFilterCore(boolean filterCore) { 392 393 m_filterCore = filterCore; 394 } 395 396 /** 397 * Sets the email address to search for. 398 * 399 * @param email the email address to search for 400 */ 401 public void setFilterEmail(String email) { 402 403 m_email = email; 404 } 405 406 /** 407 * Sets the flags to filter by.<p> 408 * 409 * @param flags the flags 410 */ 411 public void setFlags(int flags) { 412 413 m_flags = flags; 414 } 415 416 /** 417 * Sets the group such that users which are not in the group will be filtered out.<p> 418 * 419 * @param group a group 420 */ 421 public void setGroup(CmsGroup group) { 422 423 m_group = group; 424 } 425 426 /** 427 * If this is set to true, core users will not be filtered out if filtering by flag.<p> 428 * 429 * @param keepCoreUsers true if core users should not be filtered out when filtering by flag 430 */ 431 public void setKeepCoreUsers(boolean keepCoreUsers) { 432 433 m_keepCoreUsers = keepCoreUsers; 434 } 435 436 /** 437 * Sets the groups whose users may not appear in the search results.<p> 438 * 439 * @param groups the groups whose users may not appear in the search results 440 */ 441 public void setNotAnyGroups(Collection<CmsGroup> groups) { 442 443 m_notAnyGroups = groups; 444 } 445 446 /** 447 * Sets the group such that users not in that group will be filtered out.<p> 448 * 449 * @param group a group 450 */ 451 public void setNotGroup(CmsGroup group) { 452 453 m_notGroup = group; 454 } 455 456 /** 457 * Sets the organizational unit to which a user must belong.<p> 458 * 459 * @param ou the organizational unit 460 */ 461 public void setOrganizationalUnit(CmsOrganizationalUnit ou) { 462 463 m_orgUnit = ou; 464 } 465 466 /** 467 * Sets the paging parameters.<p> 468 * 469 * @param pageSize the maximum page size 470 * @param page the page index 471 */ 472 public void setPaging(int pageSize, int page) { 473 474 m_pageSize = pageSize; 475 m_page = page; 476 } 477 478 /** 479 * Enables fetching of users of sub-OUs (if an OU has been set).<p> 480 * 481 * @param recursive if true, enable sub-OU users in the result 482 */ 483 public void setRecursiveOrgUnits(boolean recursive) { 484 485 m_recursiveOrgUnits = recursive; 486 } 487 488 /** 489 * Sets the search term.<p> 490 * 491 * @param searchFilter the search term 492 */ 493 public void setSearchFilter(String searchFilter) { 494 495 m_searchFilter = searchFilter; 496 } 497 498 /** 499 * Sets the bit mask used when the results should be ordered by flags.<p> 500 * 501 * @param sortFlags the bit mask for ordering by flags 502 */ 503 public void setSortFlags(int sortFlags) { 504 505 m_sortFlags = sortFlags; 506 } 507 508 /** 509 * Sets the sort key and order.<p> 510 * 511 * @param key the sort key 512 * @param ascending the sort order (ascending if true, descending if false) 513 */ 514 public void setSorting(SortKey key, boolean ascending) { 515 516 m_sortKey = key; 517 m_ascending = ascending; 518 } 519 520}