001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH (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 /** Indicates whether only users which match the given group's OU should be returned. */ 085 private boolean m_filterByGroupOu; 086 087 /** True if non-core users should be filtered out. */ 088 private boolean m_filterCore; 089 090 /** The flags to filter by. */ 091 private int m_flags; 092 093 /** The group to which a resulting user must belong. */ 094 private CmsGroup m_group; 095 096 /** If true, core users will not be filtered out if filtering by flags. */ 097 private boolean m_keepCoreUsers; 098 099 /** A collection of groups such that returned users must be in none of them. */ 100 private Collection<CmsGroup> m_notAnyGroups; 101 102 /** The group to which a resulting user may not belong. */ 103 private CmsGroup m_notGroup; 104 105 /** The organizational unit to which a resulting user must belong. */ 106 private CmsOrganizationalUnit m_orgUnit; 107 108 /** The results page index. */ 109 private int m_page; 110 111 /** The maximum results page size. */ 112 private int m_pageSize = -1; 113 114 /** If true, and an OU has been set, users of sub-OUs will also be retrieved. */ 115 private boolean m_recursiveOrgUnits; 116 117 /** The search term entered by the user. */ 118 private String m_searchFilter; 119 120 /** The set of search keys to use. */ 121 private Set<SearchKey> m_searchKeys = new HashSet<SearchKey>(); 122 123 /** The bit mask used for flag sorting. */ 124 private int m_sortFlags; 125 126 /** The key which indicates by which column the table should be sorted. */ 127 private SortKey m_sortKey; 128 129 /** 130 * Adds a search key.<p> 131 * 132 * @param key the search key to add 133 */ 134 public void addSearch(SearchKey key) { 135 136 m_searchKeys.add(key); 137 } 138 139 /** 140 * Returns the list of OUs from which users may be returned.<p> 141 * 142 * @return a list of OUs 143 */ 144 public List<CmsOrganizationalUnit> getAllowedOus() { 145 146 return m_allowedOus; 147 } 148 149 /** 150 * Returns the collection of groups such that returned users must be in at least one of them.<p> 151 * 152 * @return a collection of groups 153 */ 154 public Collection<CmsGroup> getAnyGroups() { 155 156 return m_anyGroups; 157 } 158 159 /** 160 * Returns the flags to filter by.<p> 161 * 162 * @return the flags 163 */ 164 public int getFlags() { 165 166 return m_flags; 167 } 168 169 /** 170 * Returns the group such that users which are not in the group will be filtered out.<p> 171 * 172 * @return a group 173 */ 174 public CmsGroup getGroup() { 175 176 return m_group; 177 } 178 179 /** 180 * Returns the groups whose users may not appear in the search results.<p> 181 * 182 * @return the groups whose users may not appear in the search results 183 */ 184 public Collection<CmsGroup> getNotAnyGroups() { 185 186 return m_notAnyGroups; 187 } 188 189 /** 190 * Returns the group such that users not in that group will be filtered out.<p> 191 * 192 * @return a group 193 */ 194 public CmsGroup getNotGroup() { 195 196 return m_notGroup; 197 } 198 199 /** 200 * Gets the organizational unit to which a user must belong. 201 * 202 * @return the organizational unit 203 */ 204 public CmsOrganizationalUnit getOrganizationalUnit() { 205 206 return m_orgUnit; 207 } 208 209 /** 210 * Returns the results page index.<p> 211 * 212 * @return the results page index 213 */ 214 public int getPage() { 215 216 return m_page; 217 } 218 219 /** 220 * Returns the maximum results page size.<p> 221 * 222 * @return the page size 223 */ 224 public int getPageSize() { 225 226 return m_pageSize; 227 } 228 229 /** 230 * Returns the search term. 231 * 232 * @return the search term 233 */ 234 public String getSearchFilter() { 235 236 return m_searchFilter; 237 } 238 239 /** 240 * Returns the set of search keys.<p> 241 * 242 * @return the set of search keys 243 */ 244 public Set<SearchKey> getSearchKeys() { 245 246 return m_searchKeys; 247 } 248 249 /** 250 * Returns the bit mask to be used for ordering by flags.<p> 251 * 252 * @return the bit mask to be used for ordering by flags 253 */ 254 public int getSortFlags() { 255 256 return m_sortFlags; 257 } 258 259 /** 260 * Returns the key indicating by which column the results should be sorted.<p> 261 * 262 * @return the sort key 263 */ 264 public SortKey getSortKey() { 265 266 return m_sortKey; 267 } 268 269 /** 270 * If true, the results should be sorted in ascending order, else in descending order.<p> 271 * 272 * @return the flag indicating the sort order 273 */ 274 public boolean isAscending() { 275 276 return m_ascending; 277 } 278 279 /** 280 * Returns true if the search filter should be case sensitive.<p> 281 * 282 * The default value is <code>true</code>. 283 * 284 * @return true if the search filter should be case sensitive 285 */ 286 public boolean isCaseSensitive() { 287 288 return m_caseSensitive; 289 } 290 291 /** 292 * Returns true if users of different OUs than the search group's OU will be filtered out.<p> 293 * 294 * @return the "filter by group OU" flag 295 */ 296 public boolean isFilterByGroupOu() { 297 298 return m_filterByGroupOu; 299 } 300 301 /** 302 * Returns true if non-core users should be filtered out.<p> 303 * 304 * @return true if non-core users should be filtered out 305 */ 306 public boolean isFilterCore() { 307 308 return m_filterCore; 309 } 310 311 /** 312 * Return true if core users should not be filtered out if filtering by flag.<p> 313 * 314 * @return true if core users should not be filtered out if filtering by flag.<p> 315 */ 316 public boolean keepCoreUsers() { 317 318 return m_keepCoreUsers; 319 } 320 321 /** 322 * Returns true if sub-OU users will be returned in the result.<p> 323 * 324 * @return true if sub-OU users will be returned in the result 325 */ 326 public boolean recursiveOrgUnits() { 327 328 return m_recursiveOrgUnits; 329 } 330 331 /** 332 * Sets the OUs from which users should be returned.<p> 333 * 334 * @param ous a list of OUs 335 */ 336 public void setAllowedOus(List<CmsOrganizationalUnit> ous) { 337 338 m_allowedOus = ous; 339 } 340 341 /** 342 * Sets the groups such that returned users must be in at least one of them.<p> 343 * 344 * @param anyGroups the groups 345 */ 346 public void setAnyGroups(Collection<CmsGroup> anyGroups) { 347 348 m_anyGroups = anyGroups; 349 } 350 351 /** 352 * Sets the case sensitivity for the search filter.<p> 353 * 354 * @param caseSensitive if true, the search filter will be case sensitive. 355 */ 356 public void setCaseSensitive(boolean caseSensitive) { 357 358 m_caseSensitive = caseSensitive; 359 } 360 361 /** 362 * Sets the "filter by group OU" flag.<p> 363 * 364 * If the flag is true, users of a different OU than the search group's OU will be filtered out.<p> 365 * 366 * @param filterByGroupOu the "filter by group OU" flag 367 */ 368 public void setFilterByGroupOu(boolean filterByGroupOu) { 369 370 m_filterByGroupOu = filterByGroupOu; 371 } 372 373 /** 374 * Enables or disables the filtering of non-core users.<p> 375 * 376 * @param filterCore if true, non-core users will be filtered out 377 */ 378 public void setFilterCore(boolean filterCore) { 379 380 m_filterCore = filterCore; 381 } 382 383 /** 384 * Sets the flags to filter by.<p> 385 * 386 * @param flags the flags 387 */ 388 public void setFlags(int flags) { 389 390 m_flags = flags; 391 } 392 393 /** 394 * Sets the group such that users which are not in the group will be filtered out.<p> 395 * 396 * @param group a group 397 */ 398 public void setGroup(CmsGroup group) { 399 400 m_group = group; 401 } 402 403 /** 404 * If this is set to true, core users will not be filtered out if filtering by flag.<p> 405 * 406 * @param keepCoreUsers true if core users should not be filtered out when filtering by flag 407 */ 408 public void setKeepCoreUsers(boolean keepCoreUsers) { 409 410 m_keepCoreUsers = keepCoreUsers; 411 } 412 413 /** 414 * Sets the groups whose users may not appear in the search results.<p> 415 * 416 * @param groups the groups whose users may not appear in the search results 417 */ 418 public void setNotAnyGroups(Collection<CmsGroup> groups) { 419 420 m_notAnyGroups = groups; 421 } 422 423 /** 424 * Sets the group such that users not in that group will be filtered out.<p> 425 * 426 * @param group a group 427 */ 428 public void setNotGroup(CmsGroup group) { 429 430 m_notGroup = group; 431 } 432 433 /** 434 * Sets the organizational unit to which a user must belong.<p> 435 * 436 * @param ou the organizational unit 437 */ 438 public void setOrganizationalUnit(CmsOrganizationalUnit ou) { 439 440 m_orgUnit = ou; 441 } 442 443 /** 444 * Sets the paging parameters.<p> 445 * 446 * @param pageSize the maximum page size 447 * @param page the page index 448 */ 449 public void setPaging(int pageSize, int page) { 450 451 m_pageSize = pageSize; 452 m_page = page; 453 } 454 455 /** 456 * Enables fetching of users of sub-OUs (if an OU has been set).<p> 457 * 458 * @param recursive if true, enable sub-OU users in the result 459 */ 460 public void setRecursiveOrgUnits(boolean recursive) { 461 462 m_recursiveOrgUnits = recursive; 463 } 464 465 /** 466 * Sets the search term.<p> 467 * 468 * @param searchFilter the search term 469 */ 470 public void setSearchFilter(String searchFilter) { 471 472 m_searchFilter = searchFilter; 473 } 474 475 /** 476 * Sets the bit mask used when the results should be ordered by flags.<p> 477 * 478 * @param sortFlags the bit mask for ordering by flags 479 */ 480 public void setSortFlags(int sortFlags) { 481 482 m_sortFlags = sortFlags; 483 } 484 485 /** 486 * Sets the sort key and order.<p> 487 * 488 * @param key the sort key 489 * @param ascending the sort order (ascending if true, descending if false) 490 */ 491 public void setSorting(SortKey key, boolean ascending) { 492 493 m_sortKey = key; 494 m_ascending = ascending; 495 } 496 497}