Commit 63e58d01 authored by Axel Brand's avatar Axel Brand Committed by daeva

GoJara

Implemented Comparator to sort active Gatewaysessions on overview page.
Some refactoring of jsps and TransportSession manager as well as some docs.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13678 b35dd754-fafc-0310-a699-88a17e54d16e
parent ea772f79
...@@ -14,7 +14,6 @@ import org.jivesoftware.openfire.container.Plugin; ...@@ -14,7 +14,6 @@ import org.jivesoftware.openfire.container.Plugin;
import org.jivesoftware.openfire.container.PluginManager; import org.jivesoftware.openfire.container.PluginManager;
import org.jivesoftware.openfire.interceptor.InterceptorManager; import org.jivesoftware.openfire.interceptor.InterceptorManager;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.MainInterceptor; import org.jivesoftware.openfire.plugin.gojara.messagefilter.MainInterceptor;
import org.jivesoftware.openfire.plugin.gojara.permissions.TransportSessionManager;
import org.jivesoftware.openfire.plugin.gojara.utils.XpathHelper; import org.jivesoftware.openfire.plugin.gojara.utils.XpathHelper;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.PropertyEventDispatcher; import org.jivesoftware.util.PropertyEventDispatcher;
......
...@@ -3,14 +3,12 @@ package org.jivesoftware.openfire.plugin.gojara.messagefilter; ...@@ -3,14 +3,12 @@ package org.jivesoftware.openfire.plugin.gojara.messagefilter;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Iterator;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.Node;
import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.interceptor.PacketInterceptor; import org.jivesoftware.openfire.interceptor.PacketInterceptor;
import org.jivesoftware.openfire.interceptor.PacketRejectedException; import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.processors.*; import org.jivesoftware.openfire.plugin.gojara.messagefilter.processors.*;
import org.jivesoftware.openfire.plugin.gojara.permissions.TransportSessionManager; import org.jivesoftware.openfire.plugin.gojara.sessions.TransportSessionManager;
import org.jivesoftware.openfire.roster.RosterManager; import org.jivesoftware.openfire.roster.RosterManager;
import org.jivesoftware.openfire.session.Session; import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.ConcurrentHashSet; import org.jivesoftware.util.ConcurrentHashSet;
......
package org.jivesoftware.openfire.plugin.gojara.permissions; package org.jivesoftware.openfire.plugin.gojara.sessions;
import java.util.Date; import java.util.Date;
...@@ -28,6 +28,11 @@ public class GatewaySession { ...@@ -28,6 +28,11 @@ public class GatewaySession {
public Date getLastActivity() { public Date getLastActivity() {
return lastActivity; return lastActivity;
} }
@Override
public String toString() {
return "GatewaySession [username=" + username + ", transport=" + transport + ", lastActivity=" + lastActivity + "]";
}
} }
package org.jivesoftware.openfire.plugin.gojara.sessions;
import java.util.Comparator;
public class SortLastActivity implements Comparator<GatewaySession>{
public int compare(GatewaySession gws1, GatewaySession gws2) {
return gws1.getLastActivity().compareTo(gws2.getLastActivity());
}
}
package org.jivesoftware.openfire.plugin.gojara.sessions;
import java.util.Comparator;
public class SortTransport implements Comparator<GatewaySession>{
public int compare(GatewaySession gws1, GatewaySession gws2) {
return gws1.getTransport().compareTo(gws2.getTransport());
}
}
package org.jivesoftware.openfire.plugin.gojara.sessions;
import java.util.Comparator;
public class SortUserName implements Comparator<GatewaySession>{
public int compare(GatewaySession gw1, GatewaySession gw2) {
return gw1.getUsername().compareTo(gw2.getUsername());
}
}
package org.jivesoftware.openfire.plugin.gojara.permissions; package org.jivesoftware.openfire.plugin.gojara.sessions;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
...@@ -12,6 +12,10 @@ import org.slf4j.Logger; ...@@ -12,6 +12,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
/**
* @author axel.frederik.brand
* This is the central point for doing anything Gojara GatewaySession Related
*/
public class TransportSessionManager { public class TransportSessionManager {
private static TransportSessionManager myself; private static TransportSessionManager myself;
private DatabaseManager db; private DatabaseManager db;
...@@ -93,16 +97,38 @@ public class TransportSessionManager { ...@@ -93,16 +97,38 @@ public class TransportSessionManager {
return transportSessions; return transportSessions;
} }
public ArrayList<GatewaySession> getSessionArrayList(){
/**
* Puts all Sessions into an ArrayList of GatewaySession Objects, and sorts it according to specified sorting attributes.
* @param sortby username, transport or LoginTime
* @param sortorder ASC or DESC
* @return Sorted/Unsorted ArrayList of GatewaySession Objects
*/
public ArrayList<GatewaySession> getSessionsSorted(String sortby, String sortorder){
ArrayList<GatewaySession> result = new ArrayList<GatewaySession>(); ArrayList<GatewaySession> result = new ArrayList<GatewaySession>();
for (String key : transportSessions.keySet()) { for (String key : transportSessions.keySet()) {
for (String user : transportSessions.get(key).keySet()) { for (String user : transportSessions.get(key).keySet()) {
result.add(new GatewaySession(user, key, transportSessions.get(key).get(user))); result.add(new GatewaySession(user, key, transportSessions.get(key).get(user)));
} }
} }
if (sortby.equals("username")) {
Collections.sort(result, new SortUserName());
} else if (sortby.equals("transport")) {
Collections.sort(result, new SortTransport());
} else if (sortby.equals("loginTime")) {
Collections.sort(result, new SortLastActivity());
}
if (sortorder.equals("DESC")){
Collections.reverse(result);
}
return result; return result;
} }
/**
* @return count of recognized active Sessions
*/
public int getNumberOfActiveSessions() { public int getNumberOfActiveSessions() {
int result = 0; int result = 0;
for (String key : transportSessions.keySet()) { for (String key : transportSessions.keySet()) {
...@@ -110,20 +136,28 @@ public class TransportSessionManager { ...@@ -110,20 +136,28 @@ public class TransportSessionManager {
} }
return result; return result;
} }
public final Map<String, Date> getConnectionsFor(String username) { /**
// Maybe i do too much with hashes * Searches for Sessions with given Username and returns them as ArrList
Map<String, Date> userconnections = null; * @param username
* @return
*/
public ArrayList<GatewaySession> getConnectionsFor(String username) {
ArrayList<GatewaySession> userconnections = null;
for (String transport : transportSessions.keySet()) { for (String transport : transportSessions.keySet()) {
if (transportSessions.get(transport).containsKey(username)) { if (transportSessions.get(transport).containsKey(username)) {
if (userconnections == null) if (userconnections == null)
userconnections = new HashMap<String, Date>(); userconnections = new ArrayList<GatewaySession>();
userconnections.put(transport, transportSessions.get(transport).get(username)); userconnections.add(new GatewaySession(username, transport, transportSessions.get(transport).get(username)));
} }
} }
return userconnections; return userconnections;
} }
/**
* Returns Registrations associated with Username
* @param username
* @return ArrayList of SessionEntries
*/
public ArrayList<SessionEntry> getRegistrationsFor(String username) { public ArrayList<SessionEntry> getRegistrationsFor(String username) {
return db.getSessionEntriesFor(username); return db.getSessionEntriesFor(username);
} }
......
<%@ page <%@ page
import="org.jivesoftware.openfire.plugin.gojara.permissions.TransportSessionManager"%> import="org.jivesoftware.openfire.plugin.gojara.sessions.TransportSessionManager"%>
<%@ page <%@ page
import="org.jivesoftware.openfire.plugin.gojara.database.SessionEntry"%> import="org.jivesoftware.openfire.plugin.gojara.database.SessionEntry"%>
<%@ page <%@ page
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
<% <%
TransportSessionManager transportManager = TransportSessionManager.getInstance(); TransportSessionManager transportManager = TransportSessionManager.getInstance();
//Helper object for generation of sorting links, column restriction is done in DatabaseManager //Helper object for generation of sorting links, column restriction is done in DatabaseManager
Map<String, String> sortParams = new HashMap<String, String>(); Map<String, String> sortParams = new HashMap<String, String>();
if (request.getParameter("sortby") != null && request.getParameter("sortorder") != null) { if (request.getParameter("sortby") != null && request.getParameter("sortorder") != null) {
...@@ -22,6 +23,7 @@ ...@@ -22,6 +23,7 @@
sortParams.put("sortby", "username"); sortParams.put("sortby", "username");
sortParams.put("sortorder", "ASC"); sortParams.put("sortorder", "ASC");
} }
//pagination
int current_page = 1; int current_page = 1;
%> %>
...@@ -46,7 +48,7 @@ ...@@ -46,7 +48,7 @@
<%=transportManager.removeRegistrationOfUser(transport, key.toString())%> <%=transportManager.removeRegistrationOfUser(transport, key.toString())%>
</ul> </ul>
<% <%
} }
} }
} }
%> %>
...@@ -79,6 +81,7 @@ ...@@ -79,6 +81,7 @@
if (next_items > numOfSessions) if (next_items > numOfSessions)
next_items = numOfSessions; next_items = numOfSessions;
%> %>
<p> <p>
Pages: [ Pages: [
<% <%
...@@ -138,7 +141,7 @@ ...@@ -138,7 +141,7 @@
<% <%
for (int i = 1; i <= numOfPages; i++) { for (int i = 1; i <= numOfPages; i++) {
%> %>
<%="<a href=\"gojara-activeSessions.jsp?page=" + i + "&sortby=" + sortParams.get("sortby") + "&sortorder=" <%="<a href=\"gojara-RegistrationsOverview?page=" + i + "&sortby=" + sortParams.get("sortby") + "&sortorder="
+ sortParams.get("sortorder") + "\" class=\"" + ((current_page + 1) == i ? "jive-current" : "") + "\">" + i + sortParams.get("sortorder") + "\" class=\"" + ((current_page + 1) == i ? "jive-current" : "") + "\">" + i
+ "</a>"%> + "</a>"%>
<% <%
......
<%@ page <%@ page
import="org.jivesoftware.openfire.plugin.gojara.permissions.TransportSessionManager"%> import="org.jivesoftware.openfire.plugin.gojara.sessions.TransportSessionManager"%>
<%@ page <%@ page
import="org.jivesoftware.openfire.plugin.gojara.permissions.GatewaySession"%> import="org.jivesoftware.openfire.plugin.gojara.sessions.GatewaySession"%>
<%@ page <%@ page
import="org.jivesoftware.openfire.plugin.gojara.utils.JspColumnSortingHelper"%> import="org.jivesoftware.openfire.plugin.gojara.utils.JspColumnSortingHelper"%>
<%@ page import="java.util.Map"%> <%@ page import="java.util.Map"%>
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
<% <%
TransportSessionManager transportManager = TransportSessionManager.getInstance(); TransportSessionManager transportManager = TransportSessionManager.getInstance();
//Helper object for generation of sorting links, column restriction is done in DatabaseManager //Helper object for generation of sorting links, column restriction is done in DatabaseManager
Map<String, String> sortParams = new HashMap<String, String>(); Map<String, String> sortParams = new HashMap<String, String>();
if (request.getParameter("sortby") != null && request.getParameter("sortorder") != null) { if (request.getParameter("sortby") != null && request.getParameter("sortorder") != null) {
...@@ -22,6 +23,7 @@ ...@@ -22,6 +23,7 @@
sortParams.put("sortorder", "ASC"); sortParams.put("sortorder", "ASC");
} }
//pagination
int current_page = 1; int current_page = 1;
%> %>
<html> <html>
...@@ -34,15 +36,14 @@ ...@@ -34,15 +36,14 @@
<center>Please be aware that currently only users that connect <center>Please be aware that currently only users that connect
AFTER GoJara has been started are considered for these Sessions. This AFTER GoJara has been started are considered for these Sessions. This
affects Plugin-restarts.</center> affects Plugin-restarts.</center>
<% <br>
Map<String, Map<String, Date>> sessions = transportManager.getSessions();
%><br>
<h4> <h4>
Current number of active Gateway Sessions: &emsp; Current number of active Gateway Sessions: &emsp;
<%=transportManager.getNumberOfActiveSessions()%> <%=transportManager.getNumberOfActiveSessions()%>
</h4> </h4>
<br> <br>
<% <%
Map<String, Map<String, Date>> sessions = transportManager.getSessions();
for (String transport : sessions.keySet()) { for (String transport : sessions.keySet()) {
%> %>
<%=transport.substring(0, 10)%>... : <%=transport.substring(0, 10)%>... :
...@@ -53,7 +54,7 @@ ...@@ -53,7 +54,7 @@
<br> <br>
<br> <br>
<% <%
ArrayList<GatewaySession> gwSessions = transportManager.getSessionArrayList(); ArrayList<GatewaySession> gwSessions = transportManager.getSessionsSorted(sortParams.get("sortby"), sortParams.get("sortorder"));
int numOfSessions = gwSessions.size(); int numOfSessions = gwSessions.size();
int numOfPages = numOfSessions / 100; int numOfPages = numOfSessions / 100;
if (request.getParameter("page") != null) { if (request.getParameter("page") != null) {
...@@ -76,7 +77,7 @@ ...@@ -76,7 +77,7 @@
Pages: [ Pages: [
<% <%
for (int i = 1; i <= numOfPages; i++) { for (int i = 1; i <= numOfPages; i++) {
%> %>
<%="<a href=\"gojara-activeSessions.jsp?page=" + i + "&sortby=" + sortParams.get("sortby") + "&sortorder=" <%="<a href=\"gojara-activeSessions.jsp?page=" + i + "&sortby=" + sortParams.get("sortby") + "&sortorder="
+ sortParams.get("sortorder") + "\" class=\"" + ((current_page + 1) == i ? "jive-current" : "") + "\">" + i + sortParams.get("sortorder") + "\" class=\"" + ((current_page + 1) == i ? "jive-current" : "") + "\">" + i
+ "</a>"%> + "</a>"%>
...@@ -115,7 +116,7 @@ ...@@ -115,7 +116,7 @@
Pages: [ Pages: [
<% <%
for (int i = 1; i <= numOfPages; i++) { for (int i = 1; i <= numOfPages; i++) {
%> %>
<%="<a href=\"gojara-activeSessions.jsp?page=" + i + "&sortby=" + sortParams.get("sortby") + "&sortorder=" <%="<a href=\"gojara-activeSessions.jsp?page=" + i + "&sortby=" + sortParams.get("sortby") + "&sortorder="
+ sortParams.get("sortorder") + "\" class=\"" + ((current_page + 1) == i ? "jive-current" : "") + "\">" + i + sortParams.get("sortorder") + "\" class=\"" + ((current_page + 1) == i ? "jive-current" : "") + "\">" + i
+ "</a>"%> + "</a>"%>
......
<%@ page import="org.jivesoftware.openfire.plugin.gojara.permissions.TransportSessionManager"%> <%@page
<%@ page import="org.jivesoftware.openfire.plugin.gojara.database.SessionEntry" %> import="org.jivesoftware.openfire.plugin.gojara.sessions.GatewaySession"%>
<%@ page
import="org.jivesoftware.openfire.plugin.gojara.sessions.TransportSessionManager"%>
<%@ page
import="org.jivesoftware.openfire.plugin.gojara.database.SessionEntry"%>
<%@ page import="java.util.Map"%> <%@ page import="java.util.Map"%>
<%@ page import="java.util.Set"%> <%@ page import="java.util.Set"%>
<%@ page import="java.util.Date"%> <%@ page import="java.util.Date"%>
<%@ page import="java.util.ArrayList" %> <%@ page import="java.util.ArrayList"%>
<% <%
TransportSessionManager transportManager = TransportSessionManager.getInstance(); TransportSessionManager transportManager = TransportSessionManager.getInstance();
String username = request.getParameter("username"); String username = request.getParameter("username");
%> %>
<html> <html>
<head> <head>
<title>GatewaySession Details for: &emsp; <%=username%></title> <title>GatewaySession Details for: &emsp; <%=username%></title>
...@@ -23,28 +27,37 @@ ...@@ -23,28 +27,37 @@
</script> </script>
</head> </head>
<body> <body>
<% <%
if (request.getParameter(username) != null) { if (request.getParameter(username) != null) {
String[] unregister = request.getParameterValues(username); String[] unregister = request.getParameterValues(username);
%>
<br>
<br>
<%
for (String key : unregister) {
%> %>
<br><br>
<%=transportManager.removeRegistrationOfUser(key, username)%><br>
<% <%
for (String key : unregister) { }
%> %>
<br>
<%=transportManager.removeRegistrationOfUser(key, username) %><br> <br>
<% } %>
<br> <br>
<% <%
} }
Map<String, Date> userconnections = transportManager.getConnectionsFor(username); ArrayList<GatewaySession> userconnections = transportManager.getConnectionsFor(username);
if (userconnections == null) { if (userconnections == null) {
%> %>
<h2><center>User has no active sessions</center></h2> <h2>
<center>User has no active sessions</center>
</h2>
<% <%
} else { } else {
%> %>
<center><h1>Active Sessions:</h1></center><br> <center>
<h1>Active Sessions:</h1>
</center>
<br>
<div class="jive-table"> <div class="jive-table">
<table cellpadding="0" cellspacing="0" border="0" width="100%"> <table cellpadding="0" cellspacing="0" border="0" width="100%">
<thead> <thead>
...@@ -54,12 +67,16 @@ ...@@ -54,12 +67,16 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<% for (String transport : userconnections.keySet()) { %> <%
for (GatewaySession gws : userconnections) {
%>
<tr class="jive-odd"> <tr class="jive-odd">
<td><%= transport%></td> <td><%=gws.getTransport()%></td>
<td><%=userconnections.get(transport)%></td> <td><%=gws.getLastActivity()%></td>
</tr> </tr>
<% } %> <%
}
%>
</tbody> </tbody>
</table> </table>
</div> </div>
...@@ -68,42 +85,67 @@ ...@@ -68,42 +85,67 @@
} }
%> %>
<br><hr>
<center><h1>Associated Registrations:</h1></center><br>
<form name="unregister-form" id="gojara-sessDetailsUnregister"method="POST">
<div class="jive-table">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<thead>
<tr>
<th nowrap>User Name:</th>
<th nowrap>Resource:</th>
<th nowrap>Resource active?</th>
<th nowrap>Last login was at:</th>
<th nowrap>Unregister?</th>
</tr>
</thead>
<tbody>
<% ArrayList<SessionEntry> registrations = transportManager.getRegistrationsFor(username); %>
<% for (SessionEntry registration : registrations) { %>
<tr class="jive-odd">
<td><a href="/user-properties.jsp?username=<%=registration.getUsername()%>"><%= registration.getUsername()%></a></td>
<td><%= registration.getTransport()%></td>
<td><% if (transportManager.isTransportActive(registration.getTransport())) { %>
<img alt="Yes" src="/images/success-16x16.gif">
<% } else { %>
<img alt="No" src="/images/error-16x16.gif">
<% } %></td>
<td><%= registration.getLast_activityAsDate()%></td>
<td><input type="checkbox" name="<%= registration.getUsername() %>" value="<%= registration.getTransport() %>"></td>
</tr>
<% } %>
</tbody>
</table>
</div>
<br> <br>
<center><input type="button" value="check/uncheck all" onclick='checkedAll();'></center> <hr>
<center>
<h1>Associated Registrations:</h1>
</center>
<br> <br>
<center><input type="submit" value="Unregister"></center> <form name="unregister-form" id="gojara-sessDetailsUnregister"
method="POST">
<div class="jive-table">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<thead>
<tr>
<th nowrap>User Name:</th>
<th nowrap>Resource:</th>
<th nowrap>Resource active?</th>
<th nowrap>Last login was at:</th>
<th nowrap>Unregister?</th>
</tr>
</thead>
<tbody>
<%
ArrayList<SessionEntry> registrations = transportManager.getRegistrationsFor(username);
%>
<%
for (SessionEntry registration : registrations) {
%>
<tr class="jive-odd">
<td><a
href="/user-properties.jsp?username=<%=registration.getUsername()%>"><%=registration.getUsername()%></a></td>
<td><%=registration.getTransport()%></td>
<td>
<%
if (transportManager.isTransportActive(registration.getTransport())) {
%>
<img alt="Yes" src="/images/success-16x16.gif"> <%
} else {
%>
<img alt="No" src="/images/error-16x16.gif"> <%
}
%>
</td>
<td><%=registration.getLast_activityAsDate()%></td>
<td><input type="checkbox"
name="<%=registration.getUsername()%>"
value="<%=registration.getTransport()%>"></td>
</tr>
<%
}
%>
</tbody>
</table>
</div>
<br>
<center>
<input type="button" value="check/uncheck all"
onclick='checkedAll();'>
</center>
<br>
<center>
<input type="submit" value="Unregister">
</center>
</form> </form>
</body> </body>
</html> </html>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment