Java Code Examples for play.data.DynamicForm#get()

The following examples show how to use play.data.DynamicForm#get() . 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: 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 2
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 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 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 5
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 6
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));
}