1 package autotest.afe; 2 3 import autotest.common.StaticDataRepository; 4 import autotest.common.StatusSummary; 5 import autotest.common.table.DynamicTable; 6 import autotest.common.table.RpcDataSource; 7 import autotest.common.table.DataSource.SortDirection; 8 9 import com.google.gwt.json.client.JSONObject; 10 import com.google.gwt.json.client.JSONArray; 11 import com.google.gwt.json.client.JSONString; 12 13 14 /** 15 * A table to display jobs, including a summary of host queue entries. 16 */ 17 public class JobTable extends DynamicTable { 18 public static final String HOSTS_SUMMARY = "hosts_summary"; 19 public static final String RESULTS_SUMMARY = "results_summary"; 20 public static final String CREATED_TEXT = "created_text"; 21 22 protected StaticDataRepository staticData = StaticDataRepository.getRepository(); 23 24 private static final String GROUP_COUNT_FIELD = "group_count"; 25 private static final String PASS_COUNT_FIELD = "pass_count"; 26 private static final String COMPLETE_COUNT_FIELD = "complete_count"; 27 private static final String INCOMPLETE_COUNT_FIELD = "incomplete_count"; 28 private static final String[][] DEFAULT_JOB_COLUMNS = { 29 {CLICKABLE_WIDGET_COLUMN, "Select"}, 30 { "id", "ID" }, { "owner", "Owner" }, { "name", "Name" }, 31 { "priority", "Priority" }, { "control_type", "Client/Server" }, 32 { CREATED_TEXT, "Created" }, { HOSTS_SUMMARY, "Status" } 33 }; 34 35 private static String[][] jobColumns; 36 JobTable()37 public JobTable() { 38 this(DEFAULT_JOB_COLUMNS); 39 } 40 JobTable(String[][] jobColumns)41 public JobTable(String[][] jobColumns) { 42 super(jobColumns, new RpcDataSource("get_jobs_summary", "get_num_jobs")); 43 this.jobColumns = jobColumns; 44 sortOnColumn("created_on", SortDirection.DESCENDING); 45 } 46 47 @Override preprocessRow(JSONObject row)48 protected void preprocessRow(JSONObject row) { 49 JSONObject status_counts = row.get("status_counts").isObject(); 50 String statusCountString = AfeUtils.formatStatusCounts(status_counts, "\n"); 51 row.put(HOSTS_SUMMARY, new JSONString(statusCountString)); 52 53 JSONArray result_counts = row.get("result_counts").isObject().get("groups").isArray(); 54 if (result_counts.size() > 0) { 55 StatusSummary statusSummary = StatusSummary.getStatusSummary( 56 result_counts.get(0).isObject(), PASS_COUNT_FIELD, 57 COMPLETE_COUNT_FIELD, INCOMPLETE_COUNT_FIELD, 58 GROUP_COUNT_FIELD); 59 String resultCountString = statusSummary.formatContents(); 60 row.put(RESULTS_SUMMARY, new JSONString(resultCountString)); 61 } 62 63 Double priorityValue = row.get("priority").isNumber().getValue(); 64 String priorityName = staticData.getPriorityName(priorityValue); 65 row.put("priority", new JSONString(priorityName)); 66 67 // remove seconds from created time 68 AfeUtils.removeSecondsFromDateField(row, "created_on", CREATED_TEXT); 69 } 70 } 71