From 9a40951aa31f225e39eb1036094b9c75c981bdd1 Mon Sep 17 00:00:00 2001 From: Slawomir Wieczorek Date: Tue, 3 Dec 2024 08:12:56 +0100 Subject: [PATCH] filter by an email --- .../hellodata/portal/user/service/UserService.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/hello-data-portal/hello-data-portal-api/src/main/java/ch/bedag/dap/hellodata/portal/user/service/UserService.java b/hello-data-portal/hello-data-portal-api/src/main/java/ch/bedag/dap/hellodata/portal/user/service/UserService.java index 67a3a79e..d476d04b 100644 --- a/hello-data-portal/hello-data-portal-api/src/main/java/ch/bedag/dap/hellodata/portal/user/service/UserService.java +++ b/hello-data-portal/hello-data-portal-api/src/main/java/ch/bedag/dap/hellodata/portal/user/service/UserService.java @@ -397,9 +397,16 @@ public void validateUserHasAccessToContext(String contextKey, String reason) { public List searchUser(String email) { if (email == null || email.length() < 3) { - return new ArrayList<>(); + return Collections.emptyList(); } - return new ArrayList<>(new LinkedHashSet<>(userLookupProviderManager.searchUserByEmail(email))); + + List users = userLookupProviderManager.searchUserByEmail(email); + Set uniqueEmails = new HashSet<>(); + + return users.stream() + .filter(Objects::nonNull) + .filter(user -> uniqueEmails.add(user.getEmail())) + .collect(Collectors.toList()); } @Transactional(readOnly = true)