Skip to content

Commit

Permalink
Merge pull request #4 from protegeproject/test-branch
Browse files Browse the repository at this point in the history
fixed user query
  • Loading branch information
alexsilaghi authored Jul 30, 2024
2 parents 79dc60b + 95ef27f commit 722e502
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 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
@@ -1,8 +1,10 @@
package edu.stanford.protege.webprotegeusermanagement.commands.dto;

import com.fasterxml.jackson.annotation.*;
import edu.stanford.protege.webprotege.common.Request;

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

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

Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ webprotege:
keycloak:
serverUrl: http://webprotege-local.edu/auth
realmName: webprotege
clientId: admin-cli
clientSecret: C1MYgWgr9qpLsnNnPS3nbFNf5nGDe5H7
clientId: user-management
clientSecret: d4c1e0f1-599f-411c-bc1b-0fafb05424ac
username: admin
password: password

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 722e502

Please sign in to comment.