use of cn.edu.zju.acm.onlinejudge.form.RoleForm in project zoj by licheng.
the class EditRoleAction method execute.
/**
* Edit Role.
*
* <pre>
* </pre>
*
* @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 {
// check admin
ActionForward forward = this.checkAdmin(mapping, context);
if (forward != null) {
return forward;
}
RoleForm roleForm = (RoleForm) form;
AuthorizationPersistence authorizationPersistence = PersistenceManager.getInstance().getAuthorizationPersistence();
if (roleForm.getId() == null || roleForm.getId().trim().length() == 0) {
long roleId = Utility.parseLong(context.getRequest().getParameter("roleId"));
RoleSecurity role = authorizationPersistence.getRole(roleId);
if (role == null) {
return this.handleSuccess(mapping, context, "success");
}
// add contest names
Map<Long, String> contestNames = new TreeMap<Long, String>();
for (AbstractContest contest : ContestManager.getInstance().getAllContests()) {
contestNames.put(contest.getId(), contest.getTitle());
}
for (AbstractContest contest : ContestManager.getInstance().getAllProblemsets()) {
contestNames.put(contest.getId(), contest.getTitle());
}
for (AbstractContest contest : ContestManager.getInstance().getAllCourses()) {
contestNames.put(contest.getId(), contest.getTitle());
}
context.setAttribute("ContestNames", contestNames);
// TODO add forums
Map<Long, String> forumNames = new TreeMap<Long, String>();
forumNames.put(1L, "ZOJ Forum");
context.setAttribute("ForumNames", forumNames);
roleForm.populate(role);
return this.handleSuccess(mapping, context, "failure");
}
RoleSecurity role = roleForm.toRole();
authorizationPersistence.updateRole(role, context.getUserProfile().getId());
if (role.getId() == 1) {
ContextAdapter.resetDefaultUserSecurity();
}
return this.handleSuccess(mapping, context, "success");
}
Aggregations