Search in sources :

Example 1 with UserSearchSpecification

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;
}
Also used : UserSearchSpecification(org.haiku.haikudepotserver.user.model.UserSearchSpecification) AccessDeniedException(org.springframework.security.access.AccessDeniedException) User(org.haiku.haikudepotserver.dataobjects.User) ObjectContext(org.apache.cayenne.ObjectContext)

Aggregations

ObjectContext (org.apache.cayenne.ObjectContext)1 User (org.haiku.haikudepotserver.dataobjects.User)1 UserSearchSpecification (org.haiku.haikudepotserver.user.model.UserSearchSpecification)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1