Esempio n. 1
0
  // TODO put in meta information?
  // list all users
  @RequestMapping(method = RequestMethod.GET, value = "")
  @ResponseBody
  public Map<String, List<UserDto>> listUsers(
      @RequestParam(value = "currUser", defaultValue = "") String currUser) {
    final Map<String, List<UserDto>> response = new HashMap<String, List<UserDto>>();
    List<UserDto> results = new ArrayList<UserDto>();

    // TODO check if this part works
    if ("true".equals(currUser)) {
      com.google.appengine.api.users.UserService userService = UserServiceFactory.getUserService();
      com.google.appengine.api.users.User currentUser = userService.getCurrentUser();
      if (currentUser != null) {
        UserDto dto = new UserDto();
        dto.setEmailAddress(currentUser.getEmail());
        dto.setUserName(currentUser.getFederatedIdentity());
        results.add(dto);
      }

    } else {
      List<User> users = userDao.list(Constants.ALL_RESULTS);
      if (users != null) {
        for (User u : users) {
          if ("0".equals(u.getPermissionList()) || Boolean.TRUE.equals(u.isSuperAdmin())) {
            continue;
          }
          UserDto dto = new UserDto();
          BeanUtils.copyProperties(u, dto, new String[] {"config"});
          if (u.getKey() != null) {
            dto.setKeyId(u.getKey().getId());
          }
          results.add(dto);
        }
      }
    }

    response.put("users", results);
    return response;
  }