play.data.Form Java Examples

The following examples show how to use play.data.Form. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AccountController.java    From htwplus with MIT License 6 votes vote down vote up
/**
 * Default authentication action.
 *
 * @return Result
 */
public Result authenticate() {
    Form<Login> form = formFactory.form(Login.class).bindFromRequest();
    String username = form.field("email").value();

    // save originURL before clearing the session (it gets cleared in defaultAuthenticate() and LdapAuthenticate())
    String redirect = session().get("originURL");
    if (redirect == null) redirect = "/";

    LOG.info("Login attempt from: " + username);
    LOG.info("Redirecting to " + redirect);
    if (username.contains("@")) {
        return emailAuthenticate(redirect);
    } else if (username.length() == 0) {
        LOG.info("... no name given");
        flash("error", "Also deine Matrikelnummer brauchen wir schon!");
        return badRequest(landingpage.render(form));
    } else {
        return ldapAuthenticate(redirect);
    }
}
 
Example #2
Source File: LessonController.java    From judgels with GNU General Public License v2.0 6 votes vote down vote up
@Transactional
@RequireCSRFCheck
public Result postEditLesson(long lessonId) throws LessonNotFoundException {
    Lesson lesson = lessonService.findLessonById(lessonId);

    if (!LessonControllerUtils.isAllowedToUpdateLesson(lessonService, lesson)) {
        return notFound();
    }

    Form<LessonEditForm> lessonEditForm = Form.form(LessonEditForm.class).bindFromRequest();

    if (formHasErrors(lessonEditForm)) {
        return showEditLesson(lessonEditForm, lesson);
    }

    if (!lesson.getSlug().equals(lessonEditForm.get().slug) && lessonService.lessonExistsBySlug(lessonEditForm.get().slug)) {
        lessonEditForm.reject("slug", Messages.get("error.lesson.slugExists"));
    }

    LessonEditForm lessonEditData = lessonEditForm.get();
    lessonService.updateLesson(lesson.getJid(), lessonEditData.slug, lessonEditData.additionalNote, IdentityUtils.getUserJid(), IdentityUtils.getIpAddress());

    return redirect(routes.LessonController.viewLesson(lesson.getId()));
}
 
Example #3
Source File: OutputOnlyGradingEngineAdapter.java    From judgels with GNU General Public License v2.0 6 votes vote down vote up
@Override
public GradingConfig createConfigFromForm(Form<?> form) {
    @SuppressWarnings("unchecked")
    Form<OutputOnlyGradingConfigForm> castForm = (Form<OutputOnlyGradingConfigForm>) form;
    OutputOnlyGradingConfigForm formData = castForm.get();

    List<Object> parts = createSingleSourceFileWithoutSubtasksBlackBoxGradingConfigPartsFromForm(formData);

    @SuppressWarnings("unchecked")
    List<TestGroup> testData = (List<TestGroup>) parts.get(2);

    String customScorer;
    if (formData.customScorer.equals("(none)")) {
        customScorer = null;
    } else {
        customScorer = formData.customScorer;
    }

    return new OutputOnlyGradingConfig.Builder()
            .testData(testData)
            .customScorer(Optional.ofNullable(customScorer))
            .build();
}
 
Example #4
Source File: GroupController.java    From htwplus with MIT License 6 votes vote down vote up
@Transactional
public Result edit(Long id) {
    Group group = groupManager.findById(id);

    if (group == null) {
        flash("error", messagesApi.get(Lang.defaultLang(), "group.group_not_found"));
        return redirect(controllers.routes.GroupController.index());
    }

    // Check rights
    if (!Secured.editGroup(group)) {
        return redirect(controllers.routes.GroupController.view(id));
    }

    Navigation.set(Level.GROUPS, "Bearbeiten", group.title, controllers.routes.GroupController.stream(group.id, PAGE, false));
    Form<Group> groupForm = formFactory.form(Group.class).fill(group);
    groupForm.data().put("type", String.valueOf(group.groupType.ordinal()));
    return ok(edit.render(group, groupForm));

}
 
Example #5
Source File: Account.java    From gsn with GNU General Public License v3.0 6 votes vote down vote up
@Restrict(@Group(LocalAuthController.USER_ROLE))
public static Result doChangePassword() {
	com.feth.play.module.pa.controllers.Authenticate.noCache(response());
	final Form<Account.PasswordChange> filledForm = PASSWORD_CHANGE_FORM
			.bindFromRequest();
	if (filledForm.hasErrors()) {
		// User did not select whether to link or not link
		return badRequest(password_change.render(filledForm));
	} else {
		final User user = LocalAuthController.getLocalUser(session());
		final String newPassword = filledForm.get().password;
		user.changePassword(new GSNUsernamePasswordAuthUser(newPassword),
				true);
		flash(LocalAuthController.FLASH_MESSAGE_KEY,
				Messages.get("playauthenticate.change_password.success"));
		return redirect(routes.LocalAuthController.profile());
	}
}
 
Example #6
Source File: PortfolioController.java    From reactive-stock-trader with Apache License 2.0 6 votes vote down vote up
public CompletionStage<Result> openPortfolio() {
    Form<OpenPortfolioForm> form = openPortfolioForm.bindFromRequest();
    if (form.hasErrors()) {
        return CompletableFuture.completedFuture(badRequest(form.errorsAsJson()));
    } else {
        OpenPortfolioDetails openRequest = form.get().toRequest();
        return portfolioService
                .openPortfolio()
                .invoke(openRequest)
                .thenApply(portfolioId -> {
                    val jsonResult = Json.newObject()
                            .put("portfolioId", portfolioId.getId());
                    return Results.created(jsonResult);
                });
    }
}
 
Example #7
Source File: ProblemController.java    From judgels with GNU General Public License v2.0 6 votes vote down vote up
@Transactional
@RequireCSRFCheck
public Result postCreateProblem() {
    Form<ProblemCreateForm> problemCreateForm = Form.form(ProblemCreateForm.class).bindFromRequest();

    if (formHasErrors(problemCreateForm)) {
        return showCreateProblem(problemCreateForm);
    }

    if (problemService.problemExistsBySlug(problemCreateForm.get().slug)) {
        problemCreateForm.reject("slug", Messages.get("error.problem.slugExists"));
    }

    ProblemCreateForm problemCreateData = problemCreateForm.get();
    ProblemControllerUtils.setJustCreatedProblem(problemCreateData.slug, problemCreateData.additionalNote, problemCreateData.initLanguageCode);

    if (problemCreateData.type.equals(ProblemType.PROGRAMMING.name())) {
        return redirect(org.iatoki.judgels.sandalphon.problem.programming.routes.ProgrammingProblemController.createProgrammingProblem());
    } else if (problemCreateData.type.equals(ProblemType.BUNDLE.name())) {
        return redirect(org.iatoki.judgels.sandalphon.problem.bundle.routes.BundleProblemController.createBundleProblem());
    }

    return internalServerError();
}
 
Example #8
Source File: LessonController.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Transactional(readOnly = true)
@AddCSRFToken
public Result createLesson() {
    Form<LessonCreateForm> lessonCreateForm = Form.form(LessonCreateForm.class);

    return showCreateLesson(lessonCreateForm);
}
 
Example #9
Source File: FunctionalWithSubtasksGradingEngineAdapter.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Html renderUpdateGradingConfig(Form<?> form, Call postUpdateGradingConfigCall, List<FileInfo> testDataFiles, List<FileInfo> helperFiles) {
    @SuppressWarnings("unchecked")
    Form<FunctionalWithSubtasksGradingConfigForm> castForm = (Form<FunctionalWithSubtasksGradingConfigForm>) form;

    return functionalWithSubtasksGradingConfigView.render(castForm, postUpdateGradingConfigCall, testDataFiles, helperFiles);
}
 
Example #10
Source File: InteractiveWithSubtasksGradingEngineAdapter.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Override
public GradingConfig createConfigFromForm(Form<?> form) {
    @SuppressWarnings("unchecked")
    Form<InteractiveWithSubtasksGradingConfigForm> castForm = (Form<InteractiveWithSubtasksGradingConfigForm>) form;
    InteractiveWithSubtasksGradingConfigForm formData = castForm.get();

    List<Object> parts = createSingleSourceFileWithSubtasksBlackBoxGradingConfigPartsFromForm(formData);

    int timeLimit = (int) parts.get(0);
    int memoryLimit = (int) parts.get(1);

    @SuppressWarnings("unchecked")
    List<TestGroup> testData = (List<TestGroup>) parts.get(2);

    @SuppressWarnings("unchecked")
    List<Integer> subtaskPoints = (List<Integer>) parts.get(3);

    String communicator;
    if (formData.communicator.equals("(none)")) {
        communicator = null;
    } else {
        communicator = formData.communicator;
    }

    return new InteractiveWithSubtasksGradingConfig.Builder()
            .timeLimit(timeLimit)
            .memoryLimit(memoryLimit)
            .testData(testData)
            .subtaskPoints(subtaskPoints)
            .communicator(Optional.ofNullable(communicator))
            .build();
}
 
Example #11
Source File: ItemShortAnswerConfAdapter.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Form bindFormFromRequest(Http.Request request) {
    Form form = Form.form(ItemShortAnswerConfForm.class).bindFromRequest();
    if (!(form.hasErrors() || form.hasGlobalErrors())) {
        ItemShortAnswerConfForm confForm = ((Form<ItemShortAnswerConfForm>) form).get();
        if (!isRegexValid(confForm.inputValidationRegex)) {
            form.reject(Messages.get("error.problem.bundle.item.shortAnswer.invalidInputValidationRegex"));
        }
        if (!confForm.gradingRegex.isEmpty() && !isRegexValid(confForm.gradingRegex)) {
            form.reject(Messages.get("error.problem.bundle.item.shortAnswer.invalidGradingRegex"));
        }
    }
    return form;
}
 
Example #12
Source File: FunctionalGradingEngineAdapter.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Override
public GradingConfig createConfigFromForm(Form<?> form) {
    @SuppressWarnings("unchecked")
    Form<FunctionalGradingConfigForm> castForm = (Form<FunctionalGradingConfigForm>) form;
    FunctionalGradingConfigForm formData = castForm.get();

    List<Object> parts = createMultipleSourceFileBlackBoxGradingConfigPartsFromForm(formData);

    int timeLimit = (int) parts.get(0);
    int memoryLimit = (int) parts.get(1);

    @SuppressWarnings("unchecked")
    List<TestGroup> testData = (List<TestGroup>) parts.get(2);

    @SuppressWarnings("unchecked")
    List<String> sourceFileFieldKeys = (List<String>) parts.get(3);

    String customScorer;
    if (formData.customScorer.equals("(none)")) {
        customScorer = null;
    } else {
        customScorer = formData.customScorer;
    }

    return new FunctionalGradingConfig.Builder()
            .timeLimit(timeLimit)
            .memoryLimit(memoryLimit)
            .testData(testData)
            .sourceFileFieldKeys(sourceFileFieldKeys)
            .customScorer(Optional.ofNullable(customScorer))
            .build();
}
 
Example #13
Source File: ProgrammingProblemGradingController.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Transactional(readOnly = true)
@AddCSRFToken
public Result listGradingHelperFiles(long problemId) throws ProblemNotFoundException {
    Problem problem = problemService.findProblemById(problemId);

    if (!ProgrammingProblemControllerUtils.isAllowedToManageGrading(problemService, problem)) {
        return notFound();
    }

    Form<UploadFileForm> uploadFileForm = Form.form(UploadFileForm.class);
    List<FileInfo> helperFiles = programmingProblemService.getGradingHelperFiles(IdentityUtils.getUserJid(), problem.getJid());

    return showListGradingHelperFiles(uploadFileForm, problem, helperFiles);
}
 
Example #14
Source File: ProgrammingProblemGradingController.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Transactional(readOnly = true)
@AddCSRFToken
public Result listGradingTestDataFiles(long problemId) throws ProblemNotFoundException {
    Problem problem = problemService.findProblemById(problemId);

    if (!ProgrammingProblemControllerUtils.isAllowedToManageGrading(problemService, problem)) {
        return notFound();
    }

    Form<UploadFileForm> uploadFileForm = Form.form(UploadFileForm.class);
    List<FileInfo> testDataFiles = programmingProblemService.getGradingTestDataFiles(IdentityUtils.getUserJid(), problem.getJid());

    return showListGradingTestDataFiles(uploadFileForm, problem, testDataFiles);
}
 
Example #15
Source File: Application.java    From dr-elephant with Apache License 2.0 5 votes vote down vote up
/**
 Controls the Compare Feature
 */
public static Result compare() {
  DynamicForm form = Form.form().bindFromRequest(request());
  String partialFlowExecId1 = form.get(COMPARE_FLOW_ID1);
  partialFlowExecId1 = (partialFlowExecId1 != null) ? partialFlowExecId1.trim() : null;
  String partialFlowExecId2 = form.get(COMPARE_FLOW_ID2);
  partialFlowExecId2 = (partialFlowExecId2 != null) ? partialFlowExecId2.trim() : null;

  List<AppResult> results1 = null;
  List<AppResult> results2 = null;
  if (partialFlowExecId1 != null && !partialFlowExecId1.isEmpty() && partialFlowExecId2 != null && !partialFlowExecId2.isEmpty()) {
    IdUrlPair flowExecIdPair1 = bestSchedulerInfoMatchGivenPartialId(partialFlowExecId1, AppResult.TABLE.FLOW_EXEC_ID);
    IdUrlPair flowExecIdPair2 = bestSchedulerInfoMatchGivenPartialId(partialFlowExecId2, AppResult.TABLE.FLOW_EXEC_ID);
    results1 = AppResult.find
        .select(AppResult.getSearchFields() + "," + AppResult.TABLE.JOB_DEF_ID + "," + AppResult.TABLE.JOB_DEF_URL
            + "," + AppResult.TABLE.FLOW_EXEC_ID + "," + AppResult.TABLE.FLOW_EXEC_URL)
        .where().eq(AppResult.TABLE.FLOW_EXEC_ID, flowExecIdPair1.getId()).setMaxRows(100)
        .fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS, AppHeuristicResult.getSearchFields())
        .findList();
    results2 = AppResult.find
        .select(
            AppResult.getSearchFields() + "," + AppResult.TABLE.JOB_DEF_ID + "," + AppResult.TABLE.JOB_DEF_URL + ","
                + AppResult.TABLE.FLOW_EXEC_ID + "," + AppResult.TABLE.FLOW_EXEC_URL)
        .where().eq(AppResult.TABLE.FLOW_EXEC_ID, flowExecIdPair2.getId()).setMaxRows(100)
        .fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS, AppHeuristicResult.getSearchFields())
        .findList();
  }
  return ok(comparePage.render(compareResults.render(compareFlows(results1, results2))));
}
 
Example #16
Source File: CheckoutAddressPageContentFactory.java    From commercetools-sunrise-java with Apache License 2.0 5 votes vote down vote up
@Override
protected final void initialize(final CheckoutAddressPageContent viewModel, final Cart cart, final Form<? extends CheckoutAddressFormData> form) {
    super.initialize(viewModel, cart, form);
    fillCart(viewModel, cart, form);
    fillForm(viewModel, cart, form);
    fillFormSettings(viewModel, cart, form);
}
 
Example #17
Source File: ItemMultipleChoiceConfAdapter.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Form generateForm(String conf, String meta) {
    ItemMultipleChoiceConf itemConf = new Gson().fromJson(conf, ItemMultipleChoiceConf.class);
    ItemMultipleChoiceConfForm itemForm = new ItemMultipleChoiceConfForm();
    itemForm.statement = itemConf.statement;
    itemForm.meta = meta;
    if (itemConf.score != null) {
        itemForm.score = itemConf.score;
    }
    if (itemConf.penalty != null) {
        itemForm.penalty = itemConf.penalty;
    }
    itemForm.choiceAliases = Lists.newArrayList();
    itemForm.choiceContents = Lists.newArrayList();
    itemForm.isCorrects = Lists.newArrayList();
    for (ItemChoice itemChoice : itemConf.choices) {
        itemForm.choiceAliases.add(itemChoice.getAlias());
        itemForm.choiceContents.add(itemChoice.getContent().replace("'", "\\'"));
        if (itemChoice.isCorrect()) {
            itemForm.isCorrects.add(true);
        } else {
            itemForm.isCorrects.add(null);
        }
    }

    return Form.form(ItemMultipleChoiceConfForm.class).fill(itemForm);
}
 
Example #18
Source File: SunriseSignUpController.java    From commercetools-sunrise-java with Apache License 2.0 5 votes vote down vote up
@Override
public CompletionStage<Result> handleClientErrorFailedAction(final Void input, final Form<? extends SignUpFormData> form, final ClientErrorException clientErrorException) {
    if (isDuplicatedEmailFieldError(clientErrorException)) {
        saveFormError(form, "A user with this email already exists"); // TODO i18n
        return showFormPageWithErrors(input, form);
    } else {
        return WithContentFormFlow.super.handleClientErrorFailedAction(input, form, clientErrorException);
    }
}
 
Example #19
Source File: DefaultAddDiscountCodeFormDataTest.java    From commercetools-sunrise-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReportEmptyDiscountCodeFormData() {
    final Form<DefaultAddDiscountCodeFormData> validFormData =
            form.bind(addDiscountCodeFormData(""));
    assertThat(validFormData.errors()).hasSize(1);
    assertThat(validFormData.error("code")).isNotNull();
}
 
Example #20
Source File: BatchGradingEngineAdapter.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Form<?> createFormFromConfig(GradingConfig config) {
    BatchGradingConfigForm form = new BatchGradingConfigForm();
    BatchGradingConfig castConfig = (BatchGradingConfig) config;
    fillSingleSourceFileWithoutSubtasksBlackBoxGradingConfigFormPartsFromConfig(form, castConfig);

    if (!castConfig.getCustomScorer().isPresent()) {
        form.customScorer = "(none)";
    } else {
        form.customScorer = castConfig.getCustomScorer().get();
    }

    return Form.form(BatchGradingConfigForm.class).fill(form);
}
 
Example #21
Source File: FunctionalGradingEngineAdapter.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Html renderUpdateGradingConfig(Form<?> form, Call postUpdateGradingConfigCall, List<FileInfo> testDataFiles, List<FileInfo> helperFiles) {
    @SuppressWarnings("unchecked")
    Form<FunctionalGradingConfigForm> castForm = (Form<FunctionalGradingConfigForm>) form;

    return functionalGradingConfigView.render(castForm, postUpdateGradingConfigCall, testDataFiles, helperFiles);
}
 
Example #22
Source File: InteractiveGradingEngineAdapter.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Form<?> createFormFromConfig(GradingConfig config) {
    InteractiveGradingConfigForm form = new InteractiveGradingConfigForm();
    InteractiveGradingConfig castConfig = (InteractiveGradingConfig) config;
    fillSingleSourceFileWithoutSubtasksBlackBoxGradingConfigFormPartsFromConfig(form, castConfig);

    if (!castConfig.getCommunicator().isPresent()) {
        form.communicator = "(none)";
    } else {
        form.communicator = castConfig.getCommunicator().get();
    }

    return Form.form(InteractiveGradingConfigForm.class).fill(form);
}
 
Example #23
Source File: BundleProblemPartnerController.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Transactional
@RequireCSRFCheck
public Result postEditPartner(long problemId, long partnerId) throws ProblemNotFoundException, ProblemPartnerNotFoundException {
    Problem problem = problemService.findProblemById(problemId);

    if (!ProblemControllerUtils.isAuthorOrAbove(problem)) {
        return notFound();
    }

    ProblemPartner problemPartner = problemService.findProblemPartnerById(partnerId);

    Form<ProblemPartnerUpsertForm> problemForm = Form.form(ProblemPartnerUpsertForm.class).bindFromRequest();
    Form<BundlePartnerUpsertForm> bundleForm = Form.form(BundlePartnerUpsertForm.class).bindFromRequest();

    if (formHasErrors(problemForm) || formHasErrors(bundleForm)) {
        return showEditPartner(problemForm, bundleForm, problem, problemPartner);
    }

    ProblemPartnerUpsertForm problemData = problemForm.get();

    ProblemPartnerConfig problemConfig = new ProblemPartnerConfigBuilder()
          .setIsAllowedToUpdateProblem(problemData.isAllowedToUpdateProblem)
          .setIsAllowedToUpdateStatement(problemData.isAllowedToUpdateStatement)
          .setIsAllowedToUploadStatementResources(problemData.isAllowedToUploadStatementResources)
          .setAllowedStatementLanguagesToView(PartnerControllerUtils.splitByComma(problemData.allowedStatementLanguagesToView))
          .setAllowedStatementLanguagesToUpdate(PartnerControllerUtils.splitByComma(problemData.allowedStatementLanguagesToUpdate))
          .setIsAllowedToManageStatementLanguages(problemData.isAllowedToManageStatementLanguages)
          .setIsAllowedToViewVersionHistory(problemData.isAllowedToViewVersionHistory)
          .setIsAllowedToRestoreVersionHistory(problemData.isAllowedToRestoreVersionHistory)
          .setIsAllowedToManageProblemClients(problemData.isAllowedToManageProblemClients)
          .build();

    BundlePartnerUpsertForm bundleData = bundleForm.get();

    BundleProblemPartnerConfig bundleConfig = new BundleProblemPartnerConfig(bundleData.isAllowedToSubmit, bundleData.isAllowedToManageItems);

    problemService.updateProblemPartner(partnerId, problemConfig, bundleConfig, IdentityUtils.getUserJid(), IdentityUtils.getIpAddress());

    return redirect(org.iatoki.judgels.sandalphon.problem.base.partner.routes.ProblemPartnerController.editPartner(problem.getId(), problemPartner.getId()));
}
 
Example #24
Source File: BundleProblemPartnerController.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Transactional(readOnly = true)
@AddCSRFToken
public Result editPartner(long problemId, long partnerId) throws ProblemNotFoundException, ProblemPartnerNotFoundException {
    Problem problem = problemService.findProblemById(problemId);

    if (!ProblemControllerUtils.isAuthorOrAbove(problem)) {
        return notFound();
    }

    ProblemPartner problemPartner = problemService.findProblemPartnerById(partnerId);

    ProblemPartnerConfig problemConfig = problemPartner.getBaseConfig();
    ProblemPartnerUpsertForm problemData = new ProblemPartnerUpsertForm();

    problemData.isAllowedToUpdateProblem = problemConfig.isAllowedToUpdateProblem();
    problemData.isAllowedToUpdateStatement = problemConfig.isAllowedToUpdateStatement();
    problemData.isAllowedToUploadStatementResources = problemConfig.isAllowedToUploadStatementResources();
    problemData.allowedStatementLanguagesToView = PartnerControllerUtils.combineByComma(problemConfig.getAllowedStatementLanguagesToView());
    problemData.allowedStatementLanguagesToUpdate = PartnerControllerUtils.combineByComma(problemConfig.getAllowedStatementLanguagesToUpdate());
    problemData.isAllowedToManageStatementLanguages = problemConfig.isAllowedToManageStatementLanguages();
    problemData.isAllowedToViewVersionHistory = problemConfig.isAllowedToViewVersionHistory();
    problemData.isAllowedToRestoreVersionHistory = problemConfig.isAllowedToRestoreVersionHistory();
    problemData.isAllowedToManageProblemClients = problemConfig.isAllowedToManageProblemClients();

    Form<ProblemPartnerUpsertForm> problemForm = Form.form(ProblemPartnerUpsertForm.class).fill(problemData);

    BundleProblemPartnerConfig bundleConfig = problemPartner.getChildConfig(BundleProblemPartnerConfig.class);
    BundlePartnerUpsertForm bundleData = new BundlePartnerUpsertForm();

    bundleData.isAllowedToManageItems = bundleConfig.isAllowedToManageItems();

    Form<BundlePartnerUpsertForm> bundleForm = Form.form(BundlePartnerUpsertForm.class).fill(bundleData);

    return showEditPartner(problemForm, bundleForm, problem, problemPartner);
}
 
Example #25
Source File: GroupController.java    From htwplus with MIT License 5 votes vote down vote up
public Result validateToken(Long groupId) {
    Group group = groupManager.findById(groupId);

    if (group == null) {
        flash("error", messagesApi.get(Lang.defaultLang(), "group.group_not_found"));
        return redirect(controllers.routes.GroupController.index());
    }

    if (Secured.isMemberOfGroup(group, Component.currentAccount())) {
        flash("error", "Du bist bereits Mitglied dieser Gruppe!");
        return redirect(controllers.routes.GroupController.stream(groupId, PAGE, false));
    }

    Navigation.set(Level.GROUPS, "Token eingeben", group.title, controllers.routes.GroupController.stream(group.id, PAGE, false));
    Form<Group> filledForm = groupForm.bindFromRequest();
    String enteredToken = filledForm.data().get("token");

    if (enteredToken.equals(group.token)) {
        Account account = Component.currentAccount();
        groupAccountManager.create(new GroupAccount(group, account, LinkType.establish));
        flash("success", "Kurs erfolgreich beigetreten!");
        return redirect(controllers.routes.GroupController.stream(groupId, PAGE, false));
    } else {
        flash("error", "Hast du dich vielleicht vertippt? Der Token ist leider falsch.");
        return badRequest(token.render(group, filledForm));
    }
}
 
Example #26
Source File: ProblemController.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
private Result showEditProblem(Form<ProblemEditForm> problemEditForm, Problem problem) {
    HtmlTemplate template = getBaseHtmlTemplate();
    template.setContent(editProblemView.render(problemEditForm, problem));
    template.setMainTitle("#" + problem.getId() + ": " + problem.getSlug());
    template.addMainButton(Messages.get("problem.enter"), routes.ProblemController.enterProblem(problem.getId()));
    template.markBreadcrumbLocation(Messages.get("problem.update"), routes.ProblemController.editProblem(problem.getId()));
    template.setPageTitle("Problem - Update");
    return renderProblemTemplate(template, problemService, problem);
}
 
Example #27
Source File: BundleProblemPartnerController.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Transactional(readOnly = true)
@AddCSRFToken
public Result addPartner(long problemId) throws ProblemNotFoundException {
    Problem problem = problemService.findProblemById(problemId);

    if (!ProblemControllerUtils.isAuthorOrAbove(problem)) {
        return notFound();
    }

    Form<ProblemPartnerUsernameForm> usernameForm = Form.form(ProblemPartnerUsernameForm.class);
    Form<ProblemPartnerUpsertForm> problemForm = Form.form(ProblemPartnerUpsertForm.class);
    Form<BundlePartnerUpsertForm> bundleForm = Form.form(BundlePartnerUpsertForm.class);

    return showAddPartner(usernameForm, problemForm, bundleForm, problem);
}
 
Example #28
Source File: BundleProblemSubmissionController.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Transactional
public Result regradeSubmissions(long problemId, long pageIndex, String orderBy, String orderDir) throws ProblemNotFoundException {
    Problem problem = problemService.findProblemById(problemId);

    if (!BundleProblemControllerUtils.isAllowedToSubmit(problemService, problem)) {
        return notFound();
    }

    ListTableSelectionForm data = Form.form(ListTableSelectionForm.class).bindFromRequest().get();

    List<BundleSubmission> submissions;

    if (data.selectAll) {
        submissions = bundleSubmissionService.getBundleSubmissionsByFilters(orderBy, orderDir, null, problem.getJid(), null);
    } else if (data.selectJids != null) {
        submissions = bundleSubmissionService.getBundleSubmissionsByJids(data.selectJids);
    } else {
        return redirect(routes.BundleProblemSubmissionController.listSubmissions(problemId, pageIndex, orderBy, orderDir));
    }

    for (BundleSubmission bundleSubmission : submissions) {
        BundleAnswer bundleAnswer;
        try {
            bundleAnswer = bundleSubmissionService.createBundleAnswerFromPastSubmission(bundleSubmissionFileSystemProvider, null, bundleSubmission.getJid());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        bundleSubmissionService.regrade(bundleSubmission.getJid(), bundleAnswer, IdentityUtils.getUserJid(), IdentityUtils.getIpAddress());
    }

    return redirect(routes.BundleProblemSubmissionController.listSubmissions(problemId, pageIndex, orderBy, orderDir));
}
 
Example #29
Source File: ProblemStatementController.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Transactional(readOnly = true)
@AddCSRFToken
public Result listStatementMediaFiles(long problemId) throws ProblemNotFoundException {
    Problem problem = problemService.findProblemById(problemId);

    Form<UploadFileForm> uploadFileForm = Form.form(UploadFileForm.class);
    boolean isAllowedToUploadMediaFiles = ProblemControllerUtils.isAllowedToUploadStatementResources(problemService, problem);
    List<FileInfo> mediaFiles = problemService.getStatementMediaFiles(IdentityUtils.getUserJid(), problem.getJid());

    return showListStatementMediaFiles(uploadFileForm, problem, mediaFiles, isAllowedToUploadMediaFiles);
}
 
Example #30
Source File: ProgrammingProblemController.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
private Result showCreateProgrammingProblem(Form<ProgrammingProblemCreateForm> programmingProblemCreateForm) {
    HtmlTemplate template = getBaseHtmlTemplate();
    template.setContent(createProgrammingProblemView.render(programmingProblemCreateForm, ProblemControllerUtils.getJustCreatedProblemSlug(), ProblemControllerUtils.getJustCreatedProblemAdditionalNote(), ProblemControllerUtils.getJustCreatedProblemInitLanguageCode()));
    template.setMainTitle(Messages.get("problem.programming.create"));
    template.markBreadcrumbLocation(Messages.get("problem.problems"), org.iatoki.judgels.sandalphon.problem.base.routes.ProblemController.index());
    template.setPageTitle("Programming Problem - Create");

    return renderTemplate(template);
}