use of cn.edu.zju.acm.onlinejudge.bean.request.UserCriteria in project zoj by licheng.
the class UserSearchAction method execute.
/**
* ShowRunsAction.
*
* @param mapping
* action mapping
* @param form
* action form
* @param request
* http servlet request
* @param response
* http servlet response
*
* @return action forward instance
*
* @throws Exception
* any errors happened
*/
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
ActionForward forward = this.checkAdmin(mapping, context);
if (forward != null) {
return forward;
}
context.setAttribute("UserSearchForm", form);
context.getRequest().setAttribute("Countries", PersistenceManager.getInstance().getUserPersistence().getAllCountries());
context.getRequest().setAttribute("Roles", PersistenceManager.getInstance().getAuthorizationPersistence().getAllRoles());
UserSearchForm userForm = (UserSearchForm) form;
if (this.empty(userForm.getCountryId()) && this.empty(userForm.getEmail()) && this.empty(userForm.getFirstName()) && this.empty(userForm.getHandle()) && this.empty(userForm.getLastName()) && this.empty(userForm.getRoleId()) && this.empty(userForm.getSchool())) {
return this.handleSuccess(mapping, context, "success");
}
UserCriteria criteria = userForm.toUserCriteria();
String export = context.getRequest().getParameter("exportFormat");
if ("txt".equalsIgnoreCase(export)) {
List<UserProfile> users = PersistenceManager.getInstance().getUserPersistence().searchUserProfiles(criteria, 0, Integer.MAX_VALUE);
return this.export(context, criteria, users, export);
} else if ("xls".equalsIgnoreCase(export)) {
List<UserProfile> users = PersistenceManager.getInstance().getUserPersistence().searchUserProfiles(criteria, 0, Integer.MAX_VALUE);
return this.export(context, criteria, users, export);
}
long paging = Utility.parseLong(userForm.getPaging(), 10, 50);
;
long usersNumber = PersistenceManager.getInstance().getUserPersistence().searchUserProfilesCount(criteria);
if (usersNumber == 0) {
context.setAttribute("users", new ArrayList<UserProfile>());
context.setAttribute("pageNumber", new Long(0));
context.setAttribute("totalPages", new Long(0));
context.setAttribute("paging", new Long(paging));
context.setAttribute("total", new Long(0));
return this.handleSuccess(mapping, context, "success");
}
long totalPages = (usersNumber - 1) / paging + 1;
long pageNumber = Utility.parseLong(userForm.getPageNumber(), 1, totalPages);
long startIndex = paging * (pageNumber - 1);
List<UserProfile> users = PersistenceManager.getInstance().getUserPersistence().searchUserProfiles(criteria, (int) startIndex, (int) paging);
context.setAttribute("users", users);
context.setAttribute("pageNumber", new Long(pageNumber));
context.setAttribute("totalPages", new Long(totalPages));
context.setAttribute("paging", new Long(paging));
context.setAttribute("total", new Long(usersNumber));
return this.handleSuccess(mapping, context, "success");
}
Aggregations