fix(rest): Added code to filter user based on givenname lastname emaid.#4105
fix(rest): Added code to filter user based on givenname lastname emaid.#4105
Conversation
a97b53e to
f0be599
Compare
d390ce3 to
f2692dd
Compare
| if (CommonUtils.isNotNullEmptyOrWhitespace(searchText)) { | ||
| if (luceneSearch) { | ||
| paginatedUsers = userService.searchUsersByNameOrEmail(searchText.trim(), pageable); | ||
| } else { | ||
| paginatedUsers = userService.searchUsersByNameOrEmailExact(searchText.trim(), pageable); | ||
| } |
There was a problem hiding this comment.
Ah, searchText will only work with luceneSearch=true. With lucene as false, the usecase does not make sense!
| public Map<PaginationData, List<User>> searchUsersByNameOrEmailExact(String searchTerm, Pageable pageable) throws TException { | ||
| UserService.Iface sw360UserClient = getThriftUserClient(); | ||
| PaginationData pageData = pageableToPaginationData(pageable); | ||
| return sw360UserClient.searchUsersByNameOrEmailExact(searchTerm, pageData); | ||
| } | ||
|
|
| /** | ||
| * Search users by an exact term matched against givenname, lastname, or email. | ||
| * Uses CouchDB $eq OR query — no wildcard or regex. | ||
| **/ | ||
| map<PaginationData, list<User>> searchUsersByNameOrEmailExact(1: string searchTerm, 2: PaginationData pageData) throws (1: SW360Exception exp); | ||
|
|
| // Exception propagated (unlikely as connector swallows it) — fall back immediately | ||
| log.warn("Lucene/Nouveau search threw exception for text='{}', falling back to query: {}", text, e.getMessage()); | ||
| return repository.searchByNameOrEmail(text, pageData); |
There was a problem hiding this comment.
No, no fallback is required. If the nouveau query failed, the entire request must fail.
| /** | ||
| * Search users where givenname, lastname, or email exactly matches the search term. | ||
| */ | ||
| public Map<PaginationData, List<User>> searchByNameOrEmailExact(String searchTerm, PaginationData pageData) { |
There was a problem hiding this comment.
As mentioned, we don't need this function.
| List<User> users = getConnector().getQueryResultPaginated( | ||
| qb, User.class, pageData, sortSelector | ||
| ); |
There was a problem hiding this comment.
Using query here will not get you results from Nouveau.
There was a problem hiding this comment.
Please create a function similar to VulnerabilitySearchHandler::search() in UserSearchHandler
As you can see, this function takes a search string as input and matches it against Title and External ID, which will be the user's name and email in this case.
| */ | ||
| public Map<PaginationData, List<User>> searchByNameOrEmail(String searchTerm, PaginationData pageData) { | ||
| // Escape special regex chars, then build a case-insensitive prefix pattern | ||
| String escaped = searchTerm.replaceAll("([.+*?^${}()|\\[\\]\\\\])", "\\\\$1"); |
There was a problem hiding this comment.
When using the Nouveau to search as suggested, this filtering will be taken care by NouveauLuceneAwareDatabaseConnector
|
819c09a to
6ed93ae
Compare
|
@GMishx , Comment addressed. |
…lid. Signed-off-by: Nikesh Kumar <kumar.nikesh@siemens.com>
6ed93ae to
1b94976
Compare



Issue: Closes #4095
Suggest Reviewer
How To Test?
URL: get : http://localhost:8080/resource/api/users?searchTerm=@sw360.org&page=0&size=5&sort=lastname,asc
NOTE : Please test "Exact Match" scenario as well.
Checklist
Must: