Skip to content

Commit

Permalink
FKS-812 added criteria for full name
Browse files Browse the repository at this point in the history
  • Loading branch information
Erling Jahr committed Jun 12, 2024
1 parent 9fac449 commit 8750798
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/main/java/no/fintlabs/user/UserSpesificationBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public UserSpesificationBuilder(String search, List<String> orgUnits, String use
public Specification<User> build() {
Specification<User> userSpec;

if (orgUnits.contains(OrgUnitType.ALLORGUNITS.name()) ) {
if (orgUnits.contains(OrgUnitType.ALLORGUNITS.name())) {
userSpec = Specification.where(null);
} else {
userSpec = allAutorizedOrgUnits(orgUnits);
Expand Down Expand Up @@ -50,12 +50,22 @@ private Specification<User> userTypeEquals(String userType) {
}

private Specification<User> 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)

);
};
}


Expand Down

0 comments on commit 8750798

Please sign in to comment.