play.data.DynamicForm Java Examples

The following examples show how to use play.data.DynamicForm. 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: ClientProblemAPIControllerV2.java    From judgels with GNU General Public License v2.0 6 votes vote down vote up
@Transactional(readOnly = true)
public Result translateAllowedSlugToJids() {
    authenticateAsJudgelsAppClient(clientChecker);

    String userJid = DynamicForm.form().bindFromRequest().get("userJid");

    Map<String, String> result = new HashMap<>();

    JsonNode slugs = request().body().asJson();
    for (JsonNode slugNode : slugs) {
        String slug = slugNode.asText();
        if (!problemService.problemExistsBySlug(slug)) {
            continue;
        }
        Problem problem = problemService.findProblemBySlug(slug);
        if (isPartnerOrAbove(userJid, problem)) {
            result.put(slug, problem.getJid());
        }
    }

    return okAsJson(result);
}
 
Example #2
Source File: AdminController.java    From htwplus with MIT License 6 votes vote down vote up
@Transactional
public Result deleteAccount(Long accountId) {
    Account current = accountManager.findById(accountId);

    if (!Secured.deleteAccount(current)) {
        flash("error", messagesApi.get(Lang.defaultLang(), "profile.delete.nopermission"));
        return redirect(controllers.routes.AdminController.listAccounts());
    }

    DynamicForm df = formFactory.form().bindFromRequest();
    if (!df.get("confirmText").toLowerCase().equals("account wirklich löschen")) {
        flash("error", messagesApi.get(Lang.defaultLang(), "admin.delete_account.wrongconfirm"));
        return redirect(controllers.routes.AdminController.listAccounts());
    }

    // ACTUAL DELETION //
    Logger.info("Deleting Account[#" + current.id + "]...");
    accountManager.delete(current);

    // override logout message
    flash("success", messagesApi.get(Lang.defaultLang(), "admin.delete_account.success"));
    return redirect(routes.AdminController.listAccounts());
}
 
Example #3
Source File: Application.java    From dr-elephant with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the help based on the version
 *
 * @param version The version for which help page has to be returned
 * @return The help page based on the version
 */
private static Result getHelp(Version version) {
  DynamicForm form = Form.form().bindFromRequest(request());
  String topic = form.get("topic");
  Html page = null;
  String title = "Help";
  if (topic != null && !topic.isEmpty()) {
    // check if it is a heuristic help
    page = ElephantContext.instance().getHeuristicToView().get(topic);

    // check if it is a metrics help
    if (page == null) {
      page = getMetricsNameView().get(topic);
    }

    if (page != null) {
      title = topic;
    }
  }

  if (version.equals(Version.NEW)) {
    return ok(helpPage.render(title, page));
  }
  return ok(oldHelpPage.render(title, page));
}
 
Example #4
Source File: Application.java    From dr-elephant with Apache License 2.0 6 votes vote down vote up
public static Map<String, String> getSearchParams() {
  Map<String, String> searchParams = new HashMap<String, String>();

  DynamicForm form = Form.form().bindFromRequest(request());
  String username = form.get(USERNAME);
  username = username != null ? username.trim().toLowerCase() : null;
  searchParams.put(USERNAME, username);
  String queuename = form.get(QUEUE_NAME);
  queuename = queuename != null ? queuename.trim().toLowerCase() : null;
  searchParams.put(QUEUE_NAME, queuename);
  searchParams.put(SEVERITY, form.get(SEVERITY));
  searchParams.put(JOB_TYPE, form.get(JOB_TYPE));
  searchParams.put(ANALYSIS, form.get(ANALYSIS));
  searchParams.put(FINISHED_TIME_BEGIN, form.get(FINISHED_TIME_BEGIN));
  searchParams.put(FINISHED_TIME_END, form.get(FINISHED_TIME_END));
  searchParams.put(STARTED_TIME_BEGIN, form.get(STARTED_TIME_BEGIN));
  searchParams.put(STARTED_TIME_END, form.get(STARTED_TIME_END));

  return searchParams;
}
 
Example #5
Source File: ClientLessonAPIControllerV2.java    From judgels with GNU General Public License v2.0 6 votes vote down vote up
@Transactional(readOnly = true)
public Result translateAllowedSlugToJids() {
    authenticateAsJudgelsAppClient(clientChecker);

    String userJid = DynamicForm.form().bindFromRequest().get("userJid");

    Map<String, String> result = new HashMap<>();

    JsonNode slugs = request().body().asJson();
    for (JsonNode slugNode : slugs) {
        String slug = slugNode.asText();
        if (!lessonService.lessonExistsBySlug(slug)) {
            continue;
        }
        Lesson lesson = lessonService.findLessonBySlug(slug);
        if (isPartnerOrAbove(userJid, lesson)) {
            result.put(slug, lesson.getJid());
        }
    }

    return okAsJson(result);
}
 
Example #6
Source File: ClientLessonAPIControllerV2.java    From judgels with GNU General Public License v2.0 6 votes vote down vote up
@Transactional(readOnly = true)
public Result getLessonStatement(String lessonJid) throws IOException {
    authenticateAsJudgelsAppClient(clientChecker);

    if (!lessonService.lessonExistsByJid(lessonJid)) {
        return Results.notFound();
    }

    String language = sanitizeLanguageCode(lessonJid, DynamicForm.form().bindFromRequest().get("language"));

    LessonStatement statement = lessonService.getStatement(null, lessonJid, language);

    judgels.sandalphon.api.lesson.LessonStatement result = new judgels.sandalphon.api.lesson.LessonStatement.Builder()
            .title(statement.getTitle())
            .text(statement.getText())
            .build();

    return okAsJson(result);
}
 
Example #7
Source File: BundleProblemSubmissionController.java    From judgels with GNU General Public License v2.0 6 votes vote down vote up
@Transactional
public Result postSubmit(long problemId) throws ProblemNotFoundException {
    Problem problem = problemService.findProblemById(problemId);

    boolean isClean = !problemService.userCloneExists(IdentityUtils.getUserJid(), problem.getJid());
    if (!BundleProblemControllerUtils.isAllowedToSubmit(problemService, problem) && isClean) {
        return notFound();
    }

    DynamicForm dForm = Form.form().bindFromRequest();

    BundleAnswer bundleAnswer = bundleSubmissionService.createBundleAnswerFromNewSubmission(dForm, ProblemControllerUtils.getCurrentStatementLanguage());
    String submissionJid = bundleSubmissionService.submit(problem.getJid(), null, bundleAnswer, IdentityUtils.getUserJid(), IdentityUtils.getIpAddress());
    bundleSubmissionService.storeSubmissionFiles(bundleSubmissionFileSystemProvider, null, submissionJid, bundleAnswer);

    return redirect(routes.BundleProblemSubmissionController.viewSubmissions(problem.getId()));
}
 
Example #8
Source File: ProblemStatementController.java    From judgels with GNU General Public License v2.0 6 votes vote down vote up
@Transactional
public Result postAddStatementLanguage(long problemId) throws ProblemNotFoundException {
    Problem problem = problemService.findProblemById(problemId);

    if (!ProblemControllerUtils.isAllowedToManageStatementLanguages(problemService, problem)) {
        return notFound();
    }

    problemService.createUserCloneIfNotExists(IdentityUtils.getUserJid(), problem.getJid());

    String languageCode;
    try {
        languageCode = DynamicForm.form().bindFromRequest().get("langCode");
        if (!WorldLanguageRegistry.getInstance().getLanguages().containsKey(languageCode)) {
            // TODO should use form so it can be rejected
            throw new IllegalStateException("Languages is not from list.");
        }

        problemService.addLanguage(IdentityUtils.getUserJid(), problem.getJid(), languageCode);
    } catch (IOException e) {
        // TODO should use form so it can be rejected
        throw new IllegalStateException(e);
    }

    return redirect(routes.ProblemStatementController.listStatementLanguages(problem.getId()));
}
 
Example #9
Source File: LessonStatementController.java    From judgels with GNU General Public License v2.0 6 votes vote down vote up
@Transactional
public Result postAddStatementLanguage(long lessonId) throws LessonNotFoundException {
    Lesson lesson = lessonService.findLessonById(lessonId);

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

    lessonService.createUserCloneIfNotExists(IdentityUtils.getUserJid(), lesson.getJid());

    String languageCode;
    try {
        languageCode = DynamicForm.form().bindFromRequest().get("langCode");
        if (!WorldLanguageRegistry.getInstance().getLanguages().containsKey(languageCode)) {
            // TODO should use form so it can be rejected
            throw new IllegalStateException("Languages is not from list.");
        }

        lessonService.addLanguage(IdentityUtils.getUserJid(), lesson.getJid(), languageCode);
    } catch (IOException e) {
        // TODO should use form so it can be rejected
        throw new IllegalStateException(e);
    }

    return redirect(routes.LessonStatementController.listStatementLanguages(lesson.getId()));
}
 
Example #10
Source File: AbstractJudgelsAPIController.java    From judgels with GNU General Public License v2.0 6 votes vote down vote up
protected static Result okAsJson(Object responseBody) {
    String finalResponseBody;
    if (responseBody instanceof JsonObject) {
        finalResponseBody = responseBody.toString();
    } else {
        finalResponseBody = new Gson().toJson(responseBody);
    }

    DynamicForm dForm = DynamicForm.form().bindFromRequest();
    String callback = dForm.get("callback");

    if (callback != null) {
        response().setContentType("application/javascript");
        return ok(callback + "(" + finalResponseBody + ");");
    } else {
        response().setContentType("application/json");
        return ok(finalResponseBody);
    }
}
 
Example #11
Source File: ClientProblemAPIControllerV2.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Transactional(readOnly = true)
public Result getProgrammingProblemWorksheet(String problemJid) throws IOException {
    authenticateAsJudgelsAppClient(clientChecker);

    if (!problemService.problemExistsByJid(problemJid)) {
        return Results.notFound();
    }

    Problem problem = problemService.findProblemByJid(problemJid);
    if (ProblemType.valueOf(problem.getType().name()) != ProblemType.PROGRAMMING) {
        return Results.notFound();
    }

    judgels.sandalphon.api.problem.programming.ProblemWorksheet.Builder result =
            new judgels.sandalphon.api.problem.programming.ProblemWorksheet.Builder();

    ProblemSubmissionConfig submissionConfig = getSubmissionConfig(problemJid);
    result.submissionConfig(submissionConfig);

    GradingConfig config = getBlackBoxGradingConfig(problemJid, submissionConfig.getGradingEngine());

    String language = sanitizeLanguageCode(problemJid, DynamicForm.form().bindFromRequest().get("language"));

    ProblemStatement statement = problemService.getStatement(null, problemJid, language);
    result.statement(statement);

    ProblemLimits limits = new ProblemLimits.Builder()
            .timeLimit(config.getTimeLimit())
            .memoryLimit(config.getMemoryLimit())
            .build();
    result.limits(limits);

    return okAsJson(result.build());
}
 
Example #12
Source File: Web.java    From dr-elephant with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the filter parameters for the user summary
 * @return The filter parameters for the user summary
 */
public static Map<String, String> getFilterParamsForUserSummary() {
  DynamicForm form = Form.form().bindFromRequest(request());
  Map<String, String> filterParams = new HashMap<String, String>();
  filterParams.put(Application.FINISHED_TIME_BEGIN, form.get(Application.FINISHED_TIME_BEGIN));
  filterParams.put(Application.FINISHED_TIME_END, form.get(Application.FINISHED_TIME_END));
  filterParams.put(Application.STARTED_TIME_BEGIN, form.get(Application.STARTED_TIME_BEGIN));
  filterParams.put(Application.STARTED_TIME_END, form.get(Application.STARTED_TIME_END));
  return filterParams;
}
 
Example #13
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 #14
Source File: ClientProblemAPIControllerV2.java    From judgels with GNU General Public License v2.0 4 votes vote down vote up
@Transactional(readOnly = true)
public Result getBundleProblemWorksheet(String problemJid) throws IOException {
    authenticateAsJudgelsAppClient(clientChecker);
    if (!problemService.problemExistsByJid(problemJid)) {
        return Results.notFound();
    }

    Problem problem = problemService.findProblemByJid(problemJid);
    if (ProblemType.valueOf(problem.getType().name()) != ProblemType.BUNDLE) {
        return Results.notFound();
    }

    String language = sanitizeLanguageCode(problemJid, DynamicForm.form().bindFromRequest().get("language"));

    ProblemStatement statement = problemService.getStatement(null, problemJid, language);

    List<BundleItem> items = bundleItemService.getBundleItemsInProblemWithClone(problemJid, null);
    List<Item> itemsWithConfig = new ArrayList<>();
    for (BundleItem item : items) {
        String itemConfigString = bundleItemService.getItemConfInProblemWithCloneByJid(
                problemJid, null, item.getJid(), language);
        ItemType type = ItemType.valueOf(item.getType().name());
        Optional<Integer> number = item.getNumber() == null
                ? Optional.empty()
                : Optional.of(item.getNumber().intValue());

        Item itemWithConfig = new Item.Builder()
                .jid(item.getJid())
                .type(type)
                .number(number)
                .meta(item.getMeta())
                .config(itemProcessorRegistry.get(type).parseItemConfigFromString(MAPPER, itemConfigString))
                .build();
        itemsWithConfig.add(itemWithConfig);
    }

    return okAsJson(
            new judgels.sandalphon.api.problem.bundle.ProblemWorksheet.Builder()
                    .statement(statement)
                    .items(itemsWithConfig)
                    .build()
    );
}
 
Example #15
Source File: AbstractBundleSubmissionServiceImpl.java    From judgels with GNU General Public License v2.0 4 votes vote down vote up
@Override
public BundleAnswer createBundleAnswerFromNewSubmission(DynamicForm data, String languageCode) {
    return new BundleAnswer(data.data(), languageCode);
}
 
Example #16
Source File: ProblemController.java    From judgels with GNU General Public License v2.0 4 votes vote down vote up
public Result switchLanguage(long problemId) {
    String languageCode = DynamicForm.form().bindFromRequest().get("langCode");
    ProblemControllerUtils.setCurrentStatementLanguage(languageCode);

    return redirect(request().getHeader("Referer"));
}
 
Example #17
Source File: LessonController.java    From judgels with GNU General Public License v2.0 4 votes vote down vote up
public Result switchLanguage(long lessonId) {
    String languageCode = DynamicForm.form().bindFromRequest().get("langCode");
    LessonControllerUtils.setCurrentStatementLanguage(languageCode);

    return redirect(request().getHeader("Referer"));
}
 
Example #18
Source File: Web.java    From dr-elephant with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the search results for the given query
 * @return
 * JsonObject:
 *
 * <pre>
 *   {
 *         search-results: {
 *         id: "id"
 *         start: 0,
 *         end: 20,
 *         total: 0,
 *         summaries: [
 *                  {
 *                    application_summary_object
 *                  }
 *                ]
 *          }
 *  }
 * </pre>
 */
public static Result search() {
  DynamicForm form = Form.form().bindFromRequest(request());
  JsonObject parent = new JsonObject();

  int offset = SEARCH_DEFAULT_PAGE_OFFSET;
  int limit = SEARCH_DEFAULT_PAGE_LIMIT;
  int end = 0;
  int total = 0;

  if (form.get("offset") != null && form.get("offset") != "") {
    offset = Integer.parseInt(form.get("offset"));
  }

  if (form.get("limit") != null && form.get("limit") != "") {
    limit = Integer.parseInt(form.get("limit"));
  }

  if (offset < 0) {
    offset = 0;
  }

  if (limit > SEARCH_APPLICATION_MAX_OFFSET) {
    limit = SEARCH_APPLICATION_MAX_OFFSET;
  } else if (limit <= 0) {
    return ok(new Gson().toJson(parent));
  }

  Query<AppResult> query =
      Application.generateSearchQuery(AppResult.getSearchFields(), Application.getSearchParams());

  total = query.findRowCount();

  if (offset > total) {
    offset = total;
  }

  List<AppResult> results = query.setFirstRow(offset).setMaxRows(limit)
      .fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS, AppHeuristicResult.getSearchFields()).findList();

  end = offset + results.size();

  JsonArray applicationSummaryArray = new JsonArray();

  for (AppResult application : results) {
    JsonObject applicationObject = new JsonObject();
    JsonArray heuristicsArray = new JsonArray();
    List<AppHeuristicResult> appHeuristicResult = application.yarnAppHeuristicResults;

    for (AppHeuristicResult heuristic : appHeuristicResult) {
      JsonObject heuristicObject = new JsonObject();
      heuristicObject.addProperty(JsonKeys.NAME, heuristic.heuristicName);
      heuristicObject.addProperty(JsonKeys.SEVERITY, heuristic.severity.getText());
      heuristicsArray.add(heuristicObject);
    }

    applicationObject.addProperty(JsonKeys.ID, application.id);
    applicationObject.addProperty(JsonKeys.USERNAME, application.username);
    applicationObject.addProperty(JsonKeys.START_TIME, application.startTime);
    applicationObject.addProperty(JsonKeys.FINISH_TIME, application.finishTime);
    applicationObject.addProperty(JsonKeys.RUNTIME, application.finishTime - application.startTime);
    applicationObject.addProperty(JsonKeys.WAITTIME, application.totalDelay);
    applicationObject.addProperty(JsonKeys.RESOURCE_USED, application.resourceUsed);
    applicationObject.addProperty(JsonKeys.RESOURCE_WASTED, application.resourceWasted);
    applicationObject.addProperty(JsonKeys.SEVERITY, application.severity.getText());
    applicationObject.addProperty(JsonKeys.QUEUE, application.queueName);

    applicationObject.add(JsonKeys.HEURISTICS_SUMMARY, heuristicsArray);
    applicationSummaryArray.add(applicationObject);
  }

  JsonObject searchResults = new JsonObject();
  searchResults.addProperty(JsonKeys.ID, query.toString());
  searchResults.addProperty(JsonKeys.START, offset);
  searchResults.addProperty(JsonKeys.END, end);
  searchResults.addProperty(JsonKeys.TOTAL, total);
  searchResults.add(JsonKeys.SUMMARIES, applicationSummaryArray);
  parent.add(JsonKeys.SEARCH_RESULTS, searchResults);
  return ok(new Gson().toJson(parent));
}
 
Example #19
Source File: Application.java    From dr-elephant with Apache License 2.0 4 votes vote down vote up
/**
 * The Rest API for Compare Feature
 * E.g., localhost:8080/rest/compare?flow-exec-id1=abc&flow-exec-id2=xyz
 */
public static Result restCompare() {
  DynamicForm form = Form.form().bindFromRequest(request());
  String flowExecId1 = form.get(COMPARE_FLOW_ID1);
  flowExecId1 = (flowExecId1 != null) ? flowExecId1.trim() : null;
  String flowExecId2 = form.get(COMPARE_FLOW_ID2);
  flowExecId2 = (flowExecId2 != null) ? flowExecId2.trim() : null;

  List<AppResult> results1 = null;
  List<AppResult> results2 = null;
  if (flowExecId1 != null && !flowExecId1.isEmpty() && flowExecId2 != null && !flowExecId2.isEmpty()) {
    results1 = AppResult.find.select("*")
        .where()
        .eq(AppResult.TABLE.FLOW_EXEC_ID, flowExecId1)
        .setMaxRows(100)
        .fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS, "*")
        .fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS + "." + AppHeuristicResult.TABLE.APP_HEURISTIC_RESULT_DETAILS,
            "*")
        .findList();
    results2 = AppResult.find.select("*")
        .where()
        .eq(AppResult.TABLE.FLOW_EXEC_ID, flowExecId2)
        .setMaxRows(100)
        .fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS, "*")
        .fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS + "." + AppHeuristicResult.TABLE.APP_HEURISTIC_RESULT_DETAILS,
            "*")
        .findList();
  }

  Map<IdUrlPair, Map<IdUrlPair, List<AppResult>>> compareResults = compareFlows(results1, results2);

  Map<String, Map<String, List<AppResult>>> resMap = new HashMap<String, Map<String, List<AppResult>>>();
  for (Map.Entry<IdUrlPair, Map<IdUrlPair, List<AppResult>>> entry : compareResults.entrySet()) {
    IdUrlPair jobExecPair = entry.getKey();
    Map<IdUrlPair, List<AppResult>> value = entry.getValue();
    for (Map.Entry<IdUrlPair, List<AppResult>> innerEntry : value.entrySet()) {
      IdUrlPair flowExecPair = innerEntry.getKey();
      List<AppResult> results = innerEntry.getValue();
      Map<String, List<AppResult>> resultMap = new HashMap<String, List<AppResult>>();
      resultMap.put(flowExecPair.getId(), results);
      resMap.put(jobExecPair.getId(), resultMap);
    }
  }

  return ok(Json.toJson(resMap));
}
 
Example #20
Source File: GroupController.java    From htwplus with MIT License 4 votes vote down vote up
@Transactional
public Result inviteMember(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());
    }

    Account currentUser = Component.currentAccount();

    if (Secured.inviteMember(group)) {
        // bind invite list to group
        DynamicForm form = formFactory.form().bindFromRequest();
        group.inviteList = form.data().values();

        // if no one is invited, abort
        if (group.inviteList.size() < 1) {
            flash("error", messagesApi.get(Lang.defaultLang(), "group.invite_no_invite"));
            return redirect(controllers.routes.GroupController.invite(groupId));
        }

        // create GroupAccount link for all invitations
        for (String accountId : group.inviteList) {
            try {
                Account inviteAccount = accountManager.findById(Long.parseLong(accountId));
                GroupAccount groupAccount = groupAccountManager.find(inviteAccount, group);

                // Create group account link to inviteAccount and add to notification recipient list
                // if the inviteAccount is not already member, the sender and recipients are friends
                // and the group account link is not already set up.
                if (!Secured.isMemberOfGroup(group, inviteAccount) && friendshipManager.alreadyFriendly(currentUser, inviteAccount) && groupAccount == null) {
                    groupAccountManager.create(new GroupAccount(group, inviteAccount, LinkType.invite));

                    // add inviteAccount to temporaryRecipients list for notifications later
                    group.addTemporaryRecipient(inviteAccount);
                }
            } catch (Exception e) {
                e.printStackTrace();
                flash("error", "Etwas ist schief gelaufen.");
                return redirect(controllers.routes.GroupController.invite(groupId));
            }
        }

        group.temporarySender = currentUser;
        notificationService.createNotification(group, Group.GROUP_INVITATION);
    }

    flash("success", messagesApi.get(Lang.defaultLang(), "group.invite_invited"));
    return redirect(controllers.routes.GroupController.stream(groupId, PAGE, false));
}
 
Example #21
Source File: BundleSubmissionService.java    From judgels with GNU General Public License v2.0 votes vote down vote up
BundleAnswer createBundleAnswerFromNewSubmission(DynamicForm data, String languageCode);