users = users.subList(page * pageSize,
Math.min(startIndex + pageSize, users.size()));
JSONArray array = new JSONArray();
for (String user : users) {
NuxeoPrincipal principal = userManager.getPrincipal(user);
JSONObject o = new JSONObject();
o.element("id", principal.getName());
o.element("firstName", principal.getFirstName());
o.element("lastName", principal.getLastName());
o.element("profileURL",
ActivityMessageHelper.getUserProfileURL(principal.getName()));
o.element("avatarURL", getAvatarURL(principal));
array.add(o);
}
result.put("users", array);