<commit_before>package controllers;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import model.JobResult;
import model.JobType;
import views.html.*;
import play.api.Play;
import play.api.templates.Html;
import play.data.DynamicForm;
import play.data.Form;
import play.libs.Json;
import play.mvc.Controller;
import play.mvc.Result;

import com.avaje.ebean.ExpressionList;
import com.linkedin.drelephant.analysis.Severity;
import com.linkedin.drelephant.util.HeuristicConf;
import com.linkedin.drelephant.util.HeuristicConfData;


public class Application extends Controller {
  private static final Logger logger = Logger.getLogger(Application.class);
  private static final long DAY = 24 * 60 * 60 * 1000;
  private static final long FETCH_DELAY = 60 * 1000;
  private static long _lastFetch = 0;
  private static int _numJobsAnalyzed = 0;
  private static int _numJobsCritical = 0;
  private static int _numJobsSevere = 0;
  private static Map<String, Html> _helpPages = new HashMap<String, Html>();

  static {
    try {
      logger.info("Loading pluggable heuristics help pages.");
      fillHelpPages();
    } catch (Exception e) {
      logger.error("Error loading pluggable heuristics help pages.", e);
      throw new RuntimeException(e);
    }
  }

  public static Result search() {
    DynamicForm form = Form.form().bindFromRequest(request());
    String jobId = form.get("jobid");
    jobId = (jobId != null) ? jobId.trim() : null;
    String flowUrl = form.get("flowurl");
    flowUrl = (flowUrl != null) ? flowUrl.trim() : null;
    String username = form.get("user");
    username = (username != null) ? username.trim() : null;
    String severity = form.get("severity");
    String jobtype = form.get("jobtype");
    String analysis = form.get("analysis");
    String dateStart = form.get("start-date");
    String dateEnd = form.get("end-date");
    SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
    if (jobId != null && !jobId.isEmpty()) {
      JobResult result = JobResult.find.byId(jobId);
      if (result != null) {
        return ok(search.render(singlejob.render(result)));
      } else {
        return ok(search.render(singlejob.render(null)));
      }
    } else if(flowUrl != null && !flowUrl.isEmpty()) {
      List<JobResult> results = JobResult.find.where().eq("flow_exec_url", flowUrl).findList();
      Map<String, List<JobResult>> map = groupJobsByExec(results);
      return ok(search.render(relatedjob.render(flowUrl, map)));
    } else {
      ExpressionList<JobResult> query = JobResult.find.where();
      if (username != null && !username.isEmpty()) {
        query = query.ilike("username", username);
      }
      if (jobtype != null && !jobtype.isEmpty()) {
        query = query.eq("job_type", JobType.getDbName(jobtype));
      }
      if (severity != null && !severity.isEmpty()) {
        query = query.ge("heuristicResults.severity", severity);
      }
      if (analysis != null && !analysis.isEmpty()) {
        query = query.eq("heuristicResults.analysisName", analysis);
      }
      if (dateStart != null && !dateStart.isEmpty()) {
        try {
          Date date = dateFormat.parse(dateStart);
          query = query.gt("startTime", date.getTime());
        } catch (ParseException e) {
          e.printStackTrace();
        }
      }
      if (dateEnd != null && !dateEnd.isEmpty()) {
        try {
          Date date = dateFormat.parse(dateEnd);
          Calendar c = Calendar.getInstance();
          c.setTime(date);<commit_msg>HADOOP-8096: Property 'username' is converted to lowercase before supplying it to the query instead of asking the query to perform the case-insensitive comparison.<commit_after>package controllers;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import model.JobResult;
import model.JobType;
import views.html.*;
import play.api.Play;
import play.api.templates.Html;
import play.data.DynamicForm;
import play.data.Form;
import play.libs.Json;
import play.mvc.Controller;
import play.mvc.Result;

import com.avaje.ebean.ExpressionList;
import com.linkedin.drelephant.analysis.Severity;
import com.linkedin.drelephant.util.HeuristicConf;
import com.linkedin.drelephant.util.HeuristicConfData;


public class Application extends Controller {
  private static final Logger logger = Logger.getLogger(Application.class);
  private static final long DAY = 24 * 60 * 60 * 1000;
  private static final long FETCH_DELAY = 60 * 1000;
  private static long _lastFetch = 0;
  private static int _numJobsAnalyzed = 0;
  private static int _numJobsCritical = 0;
  private static int _numJobsSevere = 0;
  private static Map<String, Html> _helpPages = new HashMap<String, Html>();

  static {
    try {
      logger.info("Loading pluggable heuristics help pages.");
      fillHelpPages();
    } catch (Exception e) {
      logger.error("Error loading pluggable heuristics help pages.", e);
      throw new RuntimeException(e);
    }
  }

  public static Result search() {
    DynamicForm form = Form.form().bindFromRequest(request());
    String jobId = form.get("jobid");
    jobId = (jobId != null) ? jobId.trim() : null;
    String flowUrl = form.get("flowurl");
    flowUrl = (flowUrl != null) ? flowUrl.trim() : null;
    String username = form.get("user");
    username = (username != null) ? username.trim().toLowerCase() : null;
    String severity = form.get("severity");
    String jobtype = form.get("jobtype");
    String analysis = form.get("analysis");
    String dateStart = form.get("start-date");
    String dateEnd = form.get("end-date");
    SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
    if (jobId != null && !jobId.isEmpty()) {
      JobResult result = JobResult.find.byId(jobId);
      if (result != null) {
        return ok(search.render(singlejob.render(result)));
      } else {
        return ok(search.render(singlejob.render(null)));
      }
    } else if(flowUrl != null && !flowUrl.isEmpty()) {
      List<JobResult> results = JobResult.find.where().eq("flow_exec_url", flowUrl).findList();
      Map<String, List<JobResult>> map = groupJobsByExec(results);
      return ok(search.render(relatedjob.render(flowUrl, map)));
    } else {
      ExpressionList<JobResult> query = JobResult.find.where();
      if (username != null && !username.isEmpty()) {
        query = query.like("username", username);
      }
      if (jobtype != null && !jobtype.isEmpty()) {
        query = query.eq("job_type", JobType.getDbName(jobtype));
      }
      if (severity != null && !severity.isEmpty()) {
        query = query.ge("heuristicResults.severity", severity);
      }
      if (analysis != null && !analysis.isEmpty()) {
        query = query.eq("heuristicResults.analysisName", analysis);
      }
      if (dateStart != null && !dateStart.isEmpty()) {
        try {
          Date date = dateFormat.parse(dateStart);
          query = query.gt("startTime", date.getTime());
        } catch (ParseException e) {
          e.printStackTrace();
        }
      }
      if (dateEnd != null && !dateEnd.isEmpty()) {
        try {
          Date date = dateFormat.parse(dateEnd);
          Calendar c = Calendar.getInstance();
          c.setTime(date);
{'fraction_non_alphanumeric': 0.13311897106109324, 'fraction_numerical': 0.005916398713826367, 'mean_word_length': 3.4307692307692306, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7637008', 'n_tokens_mistral': 2382, 'n_tokens_neox': 2290, 'n_words': 555}