use of org.haiku.haikudepotserver.user.model.UserSearchSpecification in project haikudepotserver by haiku.
the class UserApiImpl method searchUsers.
@Override
public SearchUsersResult searchUsers(SearchUsersRequest searchUsersRequest) {
Preconditions.checkNotNull(searchUsersRequest);
final ObjectContext context = serverRuntime.newContext();
if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), null, Permission.USER_LIST)) {
throw new AccessDeniedException("unable to list users");
}
UserSearchSpecification specification = new UserSearchSpecification();
String exp = searchUsersRequest.expression;
if (null != exp) {
exp = Strings.emptyToNull(exp.trim().toLowerCase());
}
specification.setExpression(exp);
if (null != searchUsersRequest.expressionType) {
specification.setExpressionType(PkgSearchSpecification.ExpressionType.valueOf(searchUsersRequest.expressionType.name()));
}
specification.setLimit(searchUsersRequest.limit);
specification.setOffset(searchUsersRequest.offset);
specification.setIncludeInactive(null != searchUsersRequest.includeInactive && searchUsersRequest.includeInactive);
SearchUsersResult result = new SearchUsersResult();
result.total = userService.total(context, specification);
result.items = Collections.emptyList();
if (0 != result.total) {
List<User> searchedUsers = userService.search(context, specification);
result.items = searchedUsers.stream().map(u -> {
SearchUsersResult.User resultUser = new SearchUsersResult.User();
resultUser.active = u.getActive();
resultUser.nickname = u.getNickname();
return resultUser;
}).collect(Collectors.toList());
}
return result;
}
Aggregations