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