mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUAC-624: Fix isActive() logic. Approximate activity calculations based on known open connections. Update rendering of active connection vs connection without end date.
This commit is contained in:
@@ -48,6 +48,11 @@ public class MySQLConnectionRecord implements ConnectionRecord {
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* Whether this connection is currently active.
|
||||
*/
|
||||
private boolean active;
|
||||
|
||||
/**
|
||||
* Initialize this MySQLConnectionRecord with the start/end dates,
|
||||
* and the name of the user it represents.
|
||||
@@ -55,12 +60,14 @@ public class MySQLConnectionRecord implements ConnectionRecord {
|
||||
* @param startDate The start date of the connection history.
|
||||
* @param endDate The end date of the connection history.
|
||||
* @param username The name of the user that used the connection.
|
||||
* @param active Whether the connection is currently active.
|
||||
*/
|
||||
public MySQLConnectionRecord(Date startDate, Date endDate,
|
||||
String username) {
|
||||
String username, boolean active) {
|
||||
if (startDate != null) this.startDate = new Date(startDate.getTime());
|
||||
if (endDate != null) this.endDate = new Date(endDate.getTime());
|
||||
this.username = username;
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,8 +89,7 @@ public class MySQLConnectionRecord implements ConnectionRecord {
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
// If the end date hasn't been stored yet, the connection is still open.
|
||||
return endDate == null;
|
||||
return active;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -288,16 +288,34 @@ public class ConnectionService {
|
||||
userIDSet.add(history.getUser_id());
|
||||
}
|
||||
|
||||
// Determine whether connection is currently active
|
||||
int user_count = activeConnectionMap.getCurrentUserCount(connectionID);
|
||||
|
||||
// Get all the usernames for the users who are in the history
|
||||
Map<Integer, String> usernameMap = userService.retrieveUsernames(userIDSet);
|
||||
|
||||
// Create the new ConnectionRecords
|
||||
for(ConnectionHistory history : connectionHistories) {
|
||||
|
||||
Date startDate = history.getStart_date();
|
||||
Date endDate = history.getEnd_date();
|
||||
String username = usernameMap.get(history.getUser_id());
|
||||
MySQLConnectionRecord connectionRecord = new MySQLConnectionRecord(startDate, endDate, username);
|
||||
|
||||
// If there are active users, list the top N not-ended connections
|
||||
// as active (best guess)
|
||||
MySQLConnectionRecord connectionRecord;
|
||||
if (user_count > 0 && endDate == null) {
|
||||
connectionRecord = new MySQLConnectionRecord(startDate, endDate, username, true);
|
||||
user_count--;
|
||||
}
|
||||
|
||||
// If no active users, or end date is recorded, connection is not
|
||||
// active.
|
||||
else
|
||||
connectionRecord = new MySQLConnectionRecord(startDate, endDate, username, false);
|
||||
|
||||
connectionRecords.add(connectionRecord);
|
||||
|
||||
}
|
||||
|
||||
return connectionRecords;
|
||||
|
Reference in New Issue
Block a user