Skip to content

Commit

Permalink
fixed some issues with user matching
Browse files Browse the repository at this point in the history
  • Loading branch information
soimugeo committed Jul 2, 2024
1 parent 34dc80c commit 95ef27f
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

public interface UserRepository {

public List<UserId> findUserIdsFromName(String name);
List<UserId> findUserIdsFromName(String name, boolean exactMatch);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Class<UsersQueryRequest> getRequestClass() {
@Override
public Mono<UsersQueryResponse> handleRequest(UsersQueryRequest request, ExecutionContext executionContext) {
LOGGER.info("Handle request");
List<UserId> users = userRepository.findUserIdsFromName(request.userName());
List<UserId> users = userRepository.findUserIdsFromName(request.userName(), request.exactMatch());
return Mono.just(new UsersQueryResponse(users));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public KeycloakUserRepository( @Value("${webprotege.keycloak.realmName}") String


@Override
public List<UserId> findUserIdsFromName(String name) {
public List<UserId> findUserIdsFromName(String name, boolean exactMatch) {
try {
return keycloak.realm(realmName)
.users().search(name, false).stream()
.users().search(name, exactMatch).stream()
.map(userRepresentation -> new UserId(userRepresentation.getUsername()))
.collect(Collectors.toList());
}catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import edu.stanford.protege.webprotege.common.Request;

@JsonTypeName(UsersQueryRequest.CHANNEL)
public record UsersQueryRequest(@JsonProperty("completionText") String userName) implements Request<UsersQueryResponse> {
public record UsersQueryRequest(@JsonProperty("completionText") String userName, @JsonProperty("exactMatch") boolean exactMatch) implements Request<UsersQueryResponse> {

public final static String CHANNEL = "webprotege.usersquery.QueryUsers";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import edu.stanford.protege.webprotege.common.UserId;
import edu.stanford.protege.webprotegeusermanagement.commands.dto.KeycloakUserRepository;
import org.apache.http.ConnectionClosedException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -51,7 +50,7 @@ public void GIVEN_anExistingUser_WHEN_queryForUsers_THEN_userIsCorrectlyMapped()
user.setUsername("johndoe");
when(userResource.search(eq("john"), eq(false))).thenReturn(Arrays.asList(user));

List<UserId> response = repository.findUserIdsFromName("john");
List<UserId> response = repository.findUserIdsFromName("john", false);

assertNotNull(response);
assertEquals(1, response.size());
Expand All @@ -62,7 +61,7 @@ public void GIVEN_anExistingUser_WHEN_queryForUsers_THEN_userIsCorrectlyMapped()
public void GIVEN_missingUser_WHEN_queryForUsers_THEN_responseIsEmpty(){
when(userResource.search(eq("alice"), eq(false))).thenReturn(new ArrayList<>());

List<UserId> response = repository.findUserIdsFromName("alice");
List<UserId> response = repository.findUserIdsFromName("alice", false);

assertNotNull(response);
assertEquals(0, response.size());
Expand All @@ -72,7 +71,7 @@ public void GIVEN_missingUser_WHEN_queryForUsers_THEN_responseIsEmpty(){
public void GIVEN_exception_WHEN_fetchForUsers_THEN_responseIsEmpty(){
when(userResource.search(eq("bob"), eq(false))).thenThrow(new RuntimeException());

List<UserId> response = repository.findUserIdsFromName("bob");
List<UserId> response = repository.findUserIdsFromName("bob", false);

assertNotNull(response);
assertEquals(0, response.size());
Expand Down

0 comments on commit 95ef27f

Please sign in to comment.