From dd7ff1343aeb10a30adab5896387576e8c5b329b Mon Sep 17 00:00:00 2001 From: GeorgeC Date: Mon, 27 May 2024 14:16:48 -0400 Subject: [PATCH] Refactor role creation in FENCEAuthenticationService --- .../avillach/auth/data/repository/RoleRepository.java | 4 ++-- .../auth/service/auth/FENCEAuthenticationService.java | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pic-sure-auth-services/src/main/java/edu/harvard/hms/dbmi/avillach/auth/data/repository/RoleRepository.java b/pic-sure-auth-services/src/main/java/edu/harvard/hms/dbmi/avillach/auth/data/repository/RoleRepository.java index 6c4a6f76d..3c9129048 100644 --- a/pic-sure-auth-services/src/main/java/edu/harvard/hms/dbmi/avillach/auth/data/repository/RoleRepository.java +++ b/pic-sure-auth-services/src/main/java/edu/harvard/hms/dbmi/avillach/auth/data/repository/RoleRepository.java @@ -5,7 +5,7 @@ import javax.enterprise.context.ApplicationScoped; import javax.transaction.Transactional; -import java.util.ArrayList; +import java.util.List; import java.util.UUID; /** @@ -20,7 +20,7 @@ protected RoleRepository() { super(Role.class); } - public void persistAll(ArrayList newRoles) { + public void persistAll(List newRoles) { newRoles.forEach(this::persist); } } diff --git a/pic-sure-auth-services/src/main/java/edu/harvard/hms/dbmi/avillach/auth/service/auth/FENCEAuthenticationService.java b/pic-sure-auth-services/src/main/java/edu/harvard/hms/dbmi/avillach/auth/service/auth/FENCEAuthenticationService.java index 38466df3c..51fb1df99 100644 --- a/pic-sure-auth-services/src/main/java/edu/harvard/hms/dbmi/avillach/auth/service/auth/FENCEAuthenticationService.java +++ b/pic-sure-auth-services/src/main/java/edu/harvard/hms/dbmi/avillach/auth/service/auth/FENCEAuthenticationService.java @@ -217,10 +217,11 @@ public Response getFENCEProfile(String callback_url, Map authReq Set roleNames = new HashSet<>(); project_access_names.forEachRemaining(roleNames::add); - ArrayList newRoles = new ArrayList<>(); - roleNames.parallelStream().forEach(roleName -> { - newRoles.add(createRole(roleName, "FENCE role "+roleName)); - }); + List newRoles = roleNames.parallelStream() + .map(roleName -> createRole(roleName, "FENCE role " + roleName)) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + roleRepo.persistAll(newRoles); if (current_user.getRoles() == null) {