-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add user search methods by email/name fragment
- Loading branch information
Showing
8 changed files
with
272 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,7 @@ | |
* | ||
* @author Max Shaposhnik ([email protected]) | ||
* @author Yevhenii Voevodin | ||
* @author Anton Korneta | ||
*/ | ||
@Singleton | ||
public class UserManager { | ||
|
@@ -220,6 +221,58 @@ public Page<UserImpl> getAll(int maxItems, long skipCount) throws ServerExceptio | |
return userDao.getAll(maxItems, skipCount); | ||
} | ||
|
||
/** | ||
* Returns all users whose email address contains specified {@code emailPart}. | ||
* | ||
* @param emailPart | ||
* fragment of user's email | ||
* @param maxItems | ||
* the maximum number of users to return | ||
* @param skipCount | ||
* the number of users to skip | ||
* @return list of matched users | ||
* @throws NullPointerException | ||
* when {@code emailPart} is null | ||
* @throws IllegalArgumentException | ||
* when {@code maxItems} or {@code skipCount} is negative or | ||
* when {@code skipCount} more than {@value Integer#MAX_VALUE} | ||
* @throws ServerException | ||
* when any other error occurs | ||
*/ | ||
public Page<? extends User> getByEmailPart(String emailPart, int maxItems, long skipCount) throws ServerException { | ||
requireNonNull(emailPart, "Required non-null email part"); | ||
checkArgument(maxItems >= 0, "The number of items to return can't be negative"); | ||
checkArgument(skipCount >= 0 && skipCount <= Integer.MAX_VALUE, | ||
"The number of items to skip can't be negative or greater than " + Integer.MAX_VALUE); | ||
return userDao.getByEmailPart(emailPart, maxItems, skipCount); | ||
} | ||
|
||
/** | ||
* Returns all users whose name contains specified {@code namePart}. | ||
* | ||
* @param namePart | ||
* fragment of user's name | ||
* @param maxItems | ||
* the maximum number of users to return | ||
* @param skipCount | ||
* the number of users to skip | ||
* @return list of matched users | ||
* @throws NullPointerException | ||
* when {@code namePart} is null | ||
* @throws IllegalArgumentException | ||
* when {@code maxItems} or {@code skipCount} is negative or | ||
* when {@code skipCount} more than {@value Integer#MAX_VALUE} | ||
* @throws ServerException | ||
* when any other error occurs | ||
*/ | ||
public Page<? extends User> getByNamePart(String namePart, int maxItems, long skipCount) throws ServerException { | ||
requireNonNull(namePart, "Required non-null name part"); | ||
checkArgument(maxItems >= 0, "The number of items to return can't be negative"); | ||
checkArgument(skipCount >= 0 && skipCount <= Integer.MAX_VALUE, | ||
"The number of items to skip can't be negative or greater than " + Integer.MAX_VALUE); | ||
return userDao.getByNamePart(namePart, maxItems, skipCount); | ||
} | ||
|
||
/** | ||
* Gets total count of all users | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
* such kind of inconsistencies are expected by design and may be treated further. | ||
* | ||
* @author Yevhenii Voevodin | ||
* @author Anton Korneta | ||
*/ | ||
public interface UserDao { | ||
|
||
|
@@ -176,6 +177,56 @@ public interface UserDao { | |
*/ | ||
Page<UserImpl> getAll(int maxItems, long skipCount) throws ServerException; | ||
|
||
/** | ||
* Returns all users whose name contains(case insensitively) specified {@code namePart}. | ||
* | ||
* @param namePart | ||
* fragment of user's name | ||
* @param maxItems | ||
* the maximum number of users to return | ||
* @param skipCount | ||
* the number of users to skip | ||
* @return list of matched users | ||
* @throws NullPointerException | ||
* when {@code namePart} is null | ||
* @throws IllegalArgumentException | ||
* when {@code maxItems} or {@code skipCount} is negative or | ||
* when {@code skipCount} more than {@value Integer#MAX_VALUE} | ||
* @throws ServerException | ||
* when any other error occurs | ||
*/ | ||
Page<UserImpl> getByNamePart(String namePart, int maxItems, long skipCount) throws ServerException; | ||
|
||
/** | ||
* Returns all users whose email address contains(case insensitively) specified {@code emailPart}. | ||
* | ||
* <p>For example if email fragment would be 'CHE' then result of search will include the following: | ||
* <pre> | ||
* | emails | result | | ||
* | [email protected] | + | | ||
* | [email protected] | + | | ||
* | [email protected] | + | | ||
* | [email protected] | - | | ||
* | [email protected] | + | | ||
* </pre> | ||
* | ||
* @param emailPart | ||
* fragment of user's email | ||
* @param maxItems | ||
* the maximum number of users to return | ||
* @param skipCount | ||
* the number of users to skip | ||
* @return list of matched users | ||
* @throws NullPointerException | ||
* when {@code emailPart} is null | ||
* @throws IllegalArgumentException | ||
* when {@code maxItems} or {@code skipCount} is negative or | ||
* when {@code skipCount} more than {@value Integer#MAX_VALUE} | ||
* @throws ServerException | ||
* when any other error occurs | ||
*/ | ||
Page<UserImpl> getByEmailPart(String emailPart, int maxItems, long skipCount) throws ServerException; | ||
|
||
/** | ||
* Get count of all users from persistent layer. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...e-sql-schema/src/main/resources/che-schema/5.11.0/1__optimize_user_email_search_index.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-- | ||
-- [2012] - [2017] Codenvy, S.A. | ||
-- All Rights Reserved. | ||
-- | ||
-- NOTICE: All information contained herein is, and remains | ||
-- the property of Codenvy S.A. and its suppliers, | ||
-- if any. The intellectual and technical concepts contained | ||
-- herein are proprietary to Codenvy S.A. | ||
-- and its suppliers and may be covered by U.S. and Foreign Patents, | ||
-- patents in process, and are protected by trade secret or copyright law. | ||
-- Dissemination of this information or reproduction of this material | ||
-- is strictly forbidden unless prior written permission is obtained | ||
-- from Codenvy S.A.. | ||
-- | ||
|
17 changes: 17 additions & 0 deletions
17
...a/src/main/resources/che-schema/5.11.0/postgresql/1__optimize_user_email_search_index.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
-- | ||
-- [2012] - [2017] Codenvy, S.A. | ||
-- All Rights Reserved. | ||
-- | ||
-- NOTICE: All information contained herein is, and remains | ||
-- the property of Codenvy S.A. and its suppliers, | ||
-- if any. The intellectual and technical concepts contained | ||
-- herein are proprietary to Codenvy S.A. | ||
-- and its suppliers and may be covered by U.S. and Foreign Patents, | ||
-- patents in process, and are protected by trade secret or copyright law. | ||
-- Dissemination of this information or reproduction of this material | ||
-- is strictly forbidden unless prior written permission is obtained | ||
-- from Codenvy S.A.. | ||
-- | ||
CREATE EXTENSION pg_trgm; | ||
CREATE INDEX index_user_lower_email ON usr USING GIN (LOWER(email) gin_trgm_ops); | ||
CREATE INDEX index_user_lower_name ON usr USING GIN (LOWER(name) gin_trgm_ops); |