diff --git a/src/main/java/no/fintlabs/user/UserSpesificationBuilder.java b/src/main/java/no/fintlabs/user/UserSpesificationBuilder.java index 84447b2..809060a 100644 --- a/src/main/java/no/fintlabs/user/UserSpesificationBuilder.java +++ b/src/main/java/no/fintlabs/user/UserSpesificationBuilder.java @@ -22,7 +22,7 @@ public UserSpesificationBuilder(String search, List orgUnits, String use public Specification build() { Specification userSpec; - if (orgUnits.contains(OrgUnitType.ALLORGUNITS.name()) ) { + if (orgUnits.contains(OrgUnitType.ALLORGUNITS.name())) { userSpec = Specification.where(null); } else { userSpec = allAutorizedOrgUnits(orgUnits); @@ -50,12 +50,22 @@ private Specification userTypeEquals(String userType) { } private Specification usersNameLike(String search) { - return (root, query, criteriaBuilder) -> - criteriaBuilder.or( - criteriaBuilder.like(criteriaBuilder.lower(root.get("firstName")), "%" + search.toLowerCase() + "%"), - criteriaBuilder.like(criteriaBuilder.lower(root.get("lastName")), "%" + search.toLowerCase() + "%") - ); + return (root, query, criteriaBuilder) -> { + String searchPattern = "%" + search + "%"; + return criteriaBuilder.or( + criteriaBuilder.like(criteriaBuilder.lower(root.get("firstName")), searchPattern), + criteriaBuilder.like(criteriaBuilder.lower(root.get("lastName")), searchPattern), + criteriaBuilder.like( + criteriaBuilder.lower( + criteriaBuilder.concat( + criteriaBuilder.concat(root.get("firstName"), " "), + root.get("lastName") + ) + ), searchPattern) + + ); + }; }