Permalink
Browse files

Run count badges for users on the admin page

Reports the count of runs by status "SUCCESS", "ERRORS" and count of currently running workflows with status "RUNNING"
  • Loading branch information...
lowery committed Nov 16, 2017
1 parent ce37158 commit cc60432c2ec5f3f75bee638282585ad44fd89799
@@ -16,19 +16,17 @@
*/
package dao;

import com.avaje.ebean.Ebean;
import com.avaje.ebean.SqlQuery;
import com.avaje.ebean.SqlRow;
import com.avaje.ebean.annotation.Transactional;
import com.fasterxml.jackson.databind.JsonNode;
import models.db.user.SecurityRole;
import models.db.user.User;
import models.db.user.UserGroup;
import models.db.user.UserUpload;
import models.db.user.*;
import models.db.workflow.WorkflowRun;
import org.mindrot.jbcrypt.BCrypt;

import java.io.File;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.*;

public class UserDao {

@@ -134,11 +132,27 @@ public User findUserByEmail(String email) {
public List<User> findAllUsers() {
List<User> users = User.find.all();

// TODO: Use the following to report on the user's summary of run counts
// select user.username, count(case when status = 'SUCCESS' then status end) as count_success,
// count(case when status = 'ERRORS' then status end) as count_errors,
// count(case when status = 'RUNNING' then status end) as count_running
// from workflow_run join user on workflow_run.owner_id=user.id group by username;
String sql = "select user.username, count(case when status = 'SUCCESS' then status end) as count_success, " +
"count(case when status = 'ERRORS' then status end) as count_errors, " +
"count(case when status = 'RUNNING' then status end) as count_running " +
"from workflow_run join user on workflow_run.owner_id=user.id group by username;";

SqlQuery sqlQuery = Ebean.createSqlQuery(sql);
List<SqlRow> list = sqlQuery.findList();

Map<String, RunReport> runReports = new HashMap<>();
for (SqlRow row : list) {
RunReport runReport = new RunReport(row.getLong("count_success"),
row.getLong("count_errors"),
row.getLong("count_running"));

runReports.put(row.getString("username"), runReport);
}

for (User user : users) {
String username = user.getUsername();
user.setRunReport(runReports.get(username));
}

return users;
}
@@ -0,0 +1,28 @@
package models.db.user;

/**
* Created by lowery on 11/16/17.
*/
public class RunReport {
private long successCount;
private long errorsCount;
private long runningCount;

public RunReport(long successCount, long errorsCount, long runningCount) {
this.successCount = successCount;
this.errorsCount = errorsCount;
this.runningCount = runningCount;
}

public long getSuccessCount() {
return successCount;
}

public long getErrorsCount() {
return errorsCount;
}

public long getRunningCount() {
return runningCount;
}
}
@@ -75,8 +75,7 @@
private boolean active;

@Transient
@Formula(select = "_b${ta}.run_count", join = "join (select owner_id, count(*) as run_count from workflow_run group by owner_id) as _b${ta} on _b${ta}.owner_id = ${ta}.id")
public int runCount;
private RunReport runReport;

public Long getId() {
return id;
@@ -150,14 +149,6 @@ public boolean isActive() {
return active;
}

public int getRunCount() {
return runCount;
}

public void setRunCount(int runCount) {
this.runCount = runCount;
}

public void setActive(boolean active) {
this.active = active;
}
@@ -202,4 +193,12 @@ public void setRoles(List<SecurityRole> roles) {
public void setPermissions(List<UserPermission> permissions) {
this.permissions = permissions;
}

public void setRunReport(RunReport runReport) {
this.runReport = runReport;
}

public RunReport getRunReport() {
return runReport;
}
}
@@ -57,7 +57,7 @@ public static String generatePassword() {
* Utility for generating guest accounts and sql statements for adding them to the db.
*/
public static void main(String[] args) {
/* String pass = generatePassword();
String pass = generatePassword();

Map<String, String> users = new LinkedHashMap<>();

@@ -78,7 +78,7 @@ public static void main(String[] args) {

for (String username : users.keySet()) {
System.out.println(username + " : " + users.get(username));
}*/
}

String hash = BCrypt.hashpw("password", BCrypt.gensalt());
System.out.println(hash);
@@ -1,12 +1,16 @@
<td><span class="glyphicon glyphicon-log-out icon-flipped drag-handle"> </span><div class="dragging-user"><%= username %> <% if(!username) { %> <%= email %> <% } %></div></td>
<td><!-- TODO: <input type="checkbox" /> --></td>
<td><%= username %> <% if(!username) { %><i style="color: #777">N/A</i><% } %> <span class="badge" data-toggle="tooltip" title="Run Count"><%= runCount %></span></td>
<td><%= username %> <% if(!username) { %><i style="color: #777">N/A</i><% } %></td>
<td><%= firstname %> <%= lastname %></td>
<td><%= email %></td>
<td><%= affiliation %></td>
<td><%= new Date(createdOn).toLocaleString() %></td>
<td><% if (lastActive) { %><%= new Date(lastActive).toLocaleString() %><% } else { %><i style="color: #777">No activity</i><% } %></td>

<td>
<span class="badge badge-success" data-toggle="tooltip" title="Success Count"><%= runReport.successCount %></span>
<span class="badge badge-error" data-toggle="tooltip" title="Errors Count"><%= runReport.errorsCount %></span>
<span class="badge" data-toggle="tooltip" title="Running Count"><%= runReport.runningCount %></span>
</td>
<td>
<div class="btn-group">
<button type="button" class="btn btn-primary btn-xs dropdown-toggle role-btn" data-toggle="dropdown">
@@ -33,6 +33,7 @@
<th>Affiliation</th>
<th>Created On</th>
<th>Last Active</th>
<th>Run Counts</th>
<th>Role</th>
<th>Active</th>
</tr>
@@ -91,6 +91,66 @@ html, body {
animation-delay: 500ms;
}

/** Badge styles **/

.badge {
padding: 1px 9px 2px;
font-size: 12.025px;
font-weight: bold;
white-space: nowrap;
color: #ffffff;
background-color: #999999;
-webkit-border-radius: 9px;
-moz-border-radius: 9px;
border-radius: 9px;
}

.badge:hover {
color: #ffffff;
text-decoration: none;
cursor: pointer;
}

.badge-error {
background-color: #b94a48;
}

.badge-error:hover {
background-color: #953b39;
}

.badge-warning {
background-color: #f89406;
}

.badge-warning:hover {
background-color: #c67605;
}

.badge-success {
background-color: #468847;
}

.badge-success:hover {
background-color: #356635;
}

.badge-info {
background-color: #3a87ad;
}

.badge-info:hover {
background-color: #2d6987;
}

.badge-inverse {
background-color: #333333;
}

.badge-inverse:hover {
background-color: #1a1a1a;
}

/**********************/
/* Workflow list page */
/**********************/

0 comments on commit cc60432

Please sign in to comment.