*
* @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp) {
TimerEventListForm timerEventListForm = (TimerEventListForm) form;
UserManager userManager = new UserManager(locale, session);
Group groupToDisplay = getCurrentGroup(req);
if (Boolean.TRUE.equals(timerEventListForm.getAllGroups()) && UserManager.isUserInRole(webUser, UserManagerBase.ADMINISTRATOR)) {
groupToDisplay = null;
}
User userToDisplay = null;
Long selectedUserId = timerEventListForm.getUserId() == null ? ALL_ID : timerEventListForm.getUserId();
if (UserManager.isUserInRole(webUser, UserManagerBase.GROUP_ADMINISTRATOR)) {
User[] users;
if (groupToDisplay == null) {
users = userManager.getUsers(false);
} else {
users = userManager.getUsers(groupToDisplay, false); // all users with a username
}
if (users.length > MAX_USERLIST_LENGTH) {
users = new User[0];
}
// sort users by username
Arrays.sort(users, new Comparator<User>() {
public int compare(User o1, User o2) {
String n1 = o1.getUsername() != null ? o1.getUsername() : "";
String n2 = o2.getUsername() != null ? o2.getUsername() : "";
return n1.compareToIgnoreCase(n2);
}});
req.setAttribute("users", users);
} else {
selectedUserId = webUser.getId();
timerEventListForm.setUserId(selectedUserId);
req.setAttribute("users", new User[]{webUser});
}
if (!selectedUserId.equals(ALL_ID)) {
userToDisplay = userManager.getUserDetails(selectedUserId);
Hibernate.initialize(userToDisplay); // used to fetch