From 049a3e274537bcd70b0597550049cbe18352bf8c Mon Sep 17 00:00:00 2001 From: Erling Jahr Date: Thu, 19 Dec 2024 20:09:32 +0100 Subject: [PATCH] FKS-1103 api/users accept list of userType and not only one userType --- .../java/no/fintlabs/user/ResponseFactory.java | 9 ++++----- src/main/java/no/fintlabs/user/UserController.java | 2 +- src/main/java/no/fintlabs/user/UserService.java | 3 +-- .../no/fintlabs/user/UserSpesificationBuilder.java | 14 +++++++------- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/main/java/no/fintlabs/user/ResponseFactory.java b/src/main/java/no/fintlabs/user/ResponseFactory.java index 3390add..f1fe46c 100644 --- a/src/main/java/no/fintlabs/user/ResponseFactory.java +++ b/src/main/java/no/fintlabs/user/ResponseFactory.java @@ -27,15 +27,14 @@ public ResponseEntity> toResponseEntity( FintJwtEndUserPrincipal principal, String search, List orgUnits, - String userType, + List userType, int page, int size ) { - List simpleUsers = userService.getSimpleUsersUsingSpec(search,orgUnits,userType); - ResponseEntity> entity = toResponseEntity( - toPage(simpleUsers,PageRequest.of(page, size))); + List simpleUsers = userService.getSimpleUsersUsingSpec(search,orgUnits,userType); - return entity; + return toResponseEntity( + toPage(simpleUsers,PageRequest.of(page, size))); } public ResponseEntity> toResponseEntity(Page userPage) { diff --git a/src/main/java/no/fintlabs/user/UserController.java b/src/main/java/no/fintlabs/user/UserController.java index dc9007f..2120f34 100644 --- a/src/main/java/no/fintlabs/user/UserController.java +++ b/src/main/java/no/fintlabs/user/UserController.java @@ -44,7 +44,7 @@ public UserController(UserService userService, ResponseFactory responseFactory, public ResponseEntity> getSimpleUsers(@AuthenticationPrincipal Jwt jwt, @RequestParam(value = "search", defaultValue = "%") String search, @RequestParam(value = "orgUnits", required = false) List orgUnits, - @RequestParam(value = "userType", defaultValue = "ALLTYPES") String userType, + @RequestParam(value = "userType", defaultValue = "ALLTYPES") List userType, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "${fint.kontroll.user-catalog.pagesize:20}") int size ) { diff --git a/src/main/java/no/fintlabs/user/UserService.java b/src/main/java/no/fintlabs/user/UserService.java index b699c1a..6a43750 100644 --- a/src/main/java/no/fintlabs/user/UserService.java +++ b/src/main/java/no/fintlabs/user/UserService.java @@ -84,11 +84,10 @@ public Optional getUserById(Long id) { } - public List getSimpleUsersUsingSpec( String search, List orgUnits, - String userType + List userType ){ UserSpesificationBuilder userSpesification = new UserSpesificationBuilder(search,orgUnits,userType); List userList = userRepository.findAll(userSpesification.build()); diff --git a/src/main/java/no/fintlabs/user/UserSpesificationBuilder.java b/src/main/java/no/fintlabs/user/UserSpesificationBuilder.java index 2048e2a..90aeffa 100644 --- a/src/main/java/no/fintlabs/user/UserSpesificationBuilder.java +++ b/src/main/java/no/fintlabs/user/UserSpesificationBuilder.java @@ -13,9 +13,9 @@ public class UserSpesificationBuilder { private final String search; private final List orgUnits; - private final String userType; + private final List userType; - public UserSpesificationBuilder(String search, List orgUnits, String userType) { + public UserSpesificationBuilder(String search, List orgUnits, List userType) { this.search = search; this.orgUnits = orgUnits; this.userType = userType; @@ -33,22 +33,22 @@ public Specification build() { if (!search.isEmpty()) { userSpec = userSpec.and(usersNameLike(search)); } - if (!userType.equals("ALLTYPES")) { - userSpec = userSpec.and(userTypeEquals(userType.toLowerCase())); + + if (!userType.contains("ALLTYPES")) { + userSpec = userSpec.and(userTypeEquals(userType)); } return userSpec; } private Specification allAutorizedOrgUnits(List orgUnits) { - return (root, query, criteriaBuilder) -> criteriaBuilder .in(root.get("mainOrganisationUnitId")).value(orgUnits); } - private Specification userTypeEquals(String userType) { + private Specification userTypeEquals(List userType) { return (root, query, criteriaBuilder) -> criteriaBuilder - .equal(criteriaBuilder.lower(root.get("userType")), userType); + .in(root.get("userType")).value(userType); }