Search in sources :

Example 91 with ActionForward

use of org.apache.struts.action.ActionForward in project zoj by licheng.

the class AddRoleAction method execute.

/**
 * AddRoleAction.
 *
 * @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;
    }
    String name = context.getRequest().getParameter("name");
    if (name == null || name.trim().length() == 0) {
        return this.handleSuccess(mapping, context, "success");
    }
    String description = context.getRequest().getParameter("description");
    if (description == null) {
        description = "";
    }
    RoleSecurity role = new RoleSecurity(-1, name, description);
    AuthorizationPersistence ap = PersistenceManager.getInstance().getAuthorizationPersistence();
    ap.createRole(role, context.getUserProfile().getId());
    return this.handleSuccess(mapping, context, "success");
}
Also used : AuthorizationPersistence(cn.edu.zju.acm.onlinejudge.persistence.AuthorizationPersistence) ActionForward(org.apache.struts.action.ActionForward) RoleSecurity(cn.edu.zju.acm.onlinejudge.security.RoleSecurity)

Example 92 with ActionForward

use of org.apache.struts.action.ActionForward in project zoj by licheng.

the class BaseAction method execute.

/**
 * This is where the action processes the request. It forwards the invocation to the abstract execute() method and
 * returns its forward. Unexcepted exceptions are handled.
 *
 * @param mapping
 *            the action mapping that holds the forwards.
 * @param form
 *            the form bean for input.
 * @param request
 *            the http servlet request.
 * @param response
 *            the http servlet response.
 *
 * @return an action forward or null if the response is committed.
 */
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
    UserProfile user = (UserProfile) request.getSession().getAttribute(ContextAdapter.USER_PROFILE_SESSION_KEY);
    long actionId = PerformanceManager.getInstance().actionStart(this, request, user);
    ContextAdapter context = null;
    ActionForward forward = null;
    try {
        context = new ContextAdapter(request, response);
        this.info(this.makeInfo(BaseAction.ENTER_OP, context.getOperator(), null, request));
        // log parameters with debug level
        /*
             * debug("Received parameters:"); for (Enumeration enu = request.getParameterNames();
             * enu.hasMoreElements();) { String name = (String) enu.nextElement(); debug("[" + name + "]"); for (int i =
             * 0; i < request.getParameterValues(name).length; ++i) { debug("   [" + request.getParameterValues(name)[i]
             * + "]"); } }
             */
        forward = this.execute(mapping, form, context);
    } catch (Exception e) {
        this.error(e);
        forward = this.handleFailure(mapping, context, BaseAction.GENERIC_ERROR_RESOURCE_KEY);
    }
    PerformanceManager.getInstance().actionEnd(actionId);
    return forward;
}
Also used : UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) ActionForward(org.apache.struts.action.ActionForward) RedirectingActionForward(org.apache.struts.action.RedirectingActionForward) PersistenceException(cn.edu.zju.acm.onlinejudge.persistence.PersistenceException)

Example 93 with ActionForward

use of org.apache.struts.action.ActionForward in project zoj by licheng.

the class BaseAction method handleSuccess.

/**
 * Handle successful exit with log. Helper method.
 *
 * @param mapping
 *            the action mapping that holds the forwards.
 * @param context
 *            the action context to access resources.
 * @param forwardName
 *            represents messsageKey if fail, forward name if succeed.
 *
 * @return the specified forward.
 */
protected ActionForward handleSuccess(ActionMapping mapping, ContextAdapter context, String forwardName, String parameter) {
    String newPath = mapping.findForward(forwardName).getPath() + parameter;
    ActionForward forward = new RedirectingActionForward(newPath);
    return this.handleSuccess(forward, context, forwardName);
}
Also used : RedirectingActionForward(org.apache.struts.action.RedirectingActionForward) ActionForward(org.apache.struts.action.ActionForward) RedirectingActionForward(org.apache.struts.action.RedirectingActionForward)

Example 94 with ActionForward

use of org.apache.struts.action.ActionForward in project zoj by licheng.

the class DeleteProblemAction method execute.

/**
 * Register.
 *
 * @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 problem
    boolean isProblemset = context.getRequest().getRequestURI().endsWith("deleteProblem.do");
    ActionForward forward = this.checkProblemAdminPermission(mapping, context, isProblemset);
    if (forward != null) {
        return forward;
    }
    Problem problem = context.getProblem();
    ActionMessages messages = new ActionMessages();
    ProblemPersistence problemPersistence = PersistenceManager.getInstance().getProblemPersistence();
    problemPersistence.deleteProblem(problem.getId(), context.getUserProfile().getId());
    messages.add("message", new ActionMessage("onlinejudge.deleteProblem.success"));
    this.saveErrors(context.getRequest(), messages);
    String back = isProblemset ? "showProblems" : "showContestProblems";
    context.setAttribute("back", back + ".do?contestId=" + context.getContest().getId());
    ContestManager.getInstance().refreshContest(context.getContest().getId());
    return this.handleSuccess(mapping, context, "success");
}
Also used : ActionMessages(org.apache.struts.action.ActionMessages) ActionMessage(org.apache.struts.action.ActionMessage) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) ActionForward(org.apache.struts.action.ActionForward) ProblemPersistence(cn.edu.zju.acm.onlinejudge.persistence.ProblemPersistence)

Example 95 with ActionForward

use of org.apache.struts.action.ActionForward in project zoj by licheng.

the class ShowRolesAction method execute.

/**
 * ShowRolesAction.
 *
 * @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;
    }
    AuthorizationPersistence authorizationPersistence = PersistenceManager.getInstance().getAuthorizationPersistence();
    List<RoleSecurity> roles = authorizationPersistence.getAllRoles();
    context.setAttribute("Roles", roles);
    return this.handleSuccess(mapping, context, "success");
}
Also used : AuthorizationPersistence(cn.edu.zju.acm.onlinejudge.persistence.AuthorizationPersistence) ActionForward(org.apache.struts.action.ActionForward) RoleSecurity(cn.edu.zju.acm.onlinejudge.security.RoleSecurity)

Aggregations

ActionForward (org.apache.struts.action.ActionForward)125 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)16 ActionMessages (org.apache.struts.action.ActionMessages)14 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)11 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)11 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)9 ActionMessage (org.apache.struts.action.ActionMessage)9 KualiDocumentFormBase (org.kuali.kfs.kns.web.struts.form.KualiDocumentFormBase)8 IWantDocument (edu.cornell.kfs.module.purap.document.IWantDocument)7 PurApFavoriteAccountLineBuilderForIWantDocument (edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument)7 ActionMapping (org.apache.struts.action.ActionMapping)7 UserContext (org.mifos.security.util.UserContext)7 IOException (java.io.IOException)6 Date (java.util.Date)6 AuthorizationPersistence (cn.edu.zju.acm.onlinejudge.persistence.AuthorizationPersistence)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 List (java.util.List)5 Cookie (javax.servlet.http.Cookie)5 IWantDocumentService (edu.cornell.kfs.module.purap.document.service.IWantDocumentService)4