Exemplo n.º 1
0
  @Transactional
  @RequireCSRFCheck
  public Result postEditProblem(long contestId, long contestProblemId)
      throws ContestNotFoundException, ContestProblemNotFoundException {
    Contest contest = contestService.findContestById(contestId);
    ContestProblem contestProblem = contestProblemService.findContestProblemById(contestProblemId);
    if (contest.isLocked()
        || !isAllowedToSuperviseProblems(contest)
        || !contestProblem.getContestJid().equals(contest.getJid())) {
      return ContestControllerUtils.getInstance()
          .tryEnteringContest(contest, IdentityUtils.getUserJid());
    }

    Form<ContestProblemEditForm> contestProblemEditForm =
        Form.form(ContestProblemEditForm.class).bindFromRequest();

    if (formHasErrors(contestProblemEditForm)) {
      return showEditProblem(contestProblemEditForm, contest, contestProblem);
    }

    ContestProblemEditForm contestProblemEditData = contestProblemEditForm.get();
    contestProblemService.updateContestProblem(
        contestProblem.getId(),
        contestProblemEditData.alias,
        contestProblemEditData.submissionsLimit,
        ContestProblemStatus.valueOf(contestProblemEditData.status),
        IdentityUtils.getUserJid(),
        IdentityUtils.getIpAddress());

    UrielControllerUtils.getInstance()
        .addActivityLog(
            BasicActivityKeys.EDIT_IN.construct(
                CONTEST,
                contest.getJid(),
                contest.getName(),
                PROBLEM,
                contestProblem.getProblemJid(),
                SandalphonResourceDisplayNameUtils.parseSlugByLanguage(
                    JidCacheServiceImpl.getInstance()
                        .getDisplayName(contestProblem.getProblemJid()))));

    return redirect(routes.ContestProblemController.viewProblems(contest.getId()));
  }
Exemplo n.º 2
0
  @Transactional
  @RequireCSRFCheck
  public Result postAddProblem(long contestId) throws ContestNotFoundException {
    Contest contest = contestService.findContestById(contestId);
    if (contest.isLocked() || !isAllowedToSuperviseProblems(contest)) {
      return ContestControllerUtils.getInstance()
          .tryEnteringContest(contest, IdentityUtils.getUserJid());
    }

    Form<ContestProblemAddForm> contestProblemCreateForm =
        Form.form(ContestProblemAddForm.class).bindFromRequest();

    if (formHasErrors(contestProblemCreateForm)) {
      return showAddProblem(contestProblemCreateForm, contest);
    }

    ContestProblemAddForm contestProblemAddData = contestProblemCreateForm.get();

    if (contestProblemService.isProblemInContestByJidOrAlias(
        contest.getJid(), contestProblemAddData.problemJid, contestProblemAddData.alias)) {
      contestProblemCreateForm.reject("error.problem.create.problemJidOrAliasUsed");
      return showAddProblem(contestProblemCreateForm, contest);
    }

    SandalphonProblem sandalphonProblem;
    try {
      sandalphonProblem =
          sandalphonClientAPI.findClientProblem(
              contestProblemAddData.problemJid, contestProblemAddData.problemSecret);
    } catch (JudgelsAPIClientException e) {
      if (e.getStatusCode() >= Http.Status.INTERNAL_SERVER_ERROR) {
        contestProblemCreateForm.reject("error.system.sandalphon.connection");
      } else {
        contestProblemCreateForm.reject("error.problem.create.problemJidOrSecretInvalid");
      }
      return showAddProblem(contestProblemCreateForm, contest);
    }

    contestProblemService.createContestProblem(
        contest.getJid(),
        contestProblemAddData.problemJid,
        contestProblemAddData.problemSecret,
        contestProblemAddData.alias,
        contestProblemAddData.submissionsLimit,
        ContestProblemStatus.valueOf(contestProblemAddData.status),
        IdentityUtils.getUserJid(),
        IdentityUtils.getIpAddress());
    JidCacheServiceImpl.getInstance()
        .putDisplayName(
            contestProblemAddData.problemJid,
            sandalphonProblem.getDisplayName(),
            IdentityUtils.getUserJid(),
            IdentityUtils.getIpAddress());

    UrielControllerUtils.getInstance()
        .addActivityLog(
            BasicActivityKeys.ADD_IN.construct(
                CONTEST,
                contest.getJid(),
                contest.getName(),
                PROBLEM,
                contestProblemAddData.problemJid,
                sandalphonProblem.getSlug()));

    return redirect(routes.ContestProblemController.viewProblems(contest.getId()));
  }