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;
import org.jivesoftware.openfire.container.PluginManager;
import org.jivesoftware.openfire.interceptor.InterceptorManager;
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.util.JiveGlobals;
import org.jivesoftware.util.PropertyEventDispatcher;
......
......@@ -3,14 +3,12 @@ package org.jivesoftware.openfire.plugin.gojara.messagefilter;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.Iterator;
import org.dom4j.Element;
import org.dom4j.Node;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.interceptor.PacketInterceptor;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
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.session.Session;
import org.jivesoftware.util.ConcurrentHashSet;
......
package org.jivesoftware.openfire.plugin.gojara.permissions;
package org.jivesoftware.openfire.plugin.gojara.sessions;
import java.util.Date;
......@@ -29,5 +29,10 @@ public class GatewaySession {
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.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
......@@ -12,6 +12,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.packet.JID;
/**
* @author axel.frederik.brand
* This is the central point for doing anything Gojara GatewaySession Related
*/
public class TransportSessionManager {
private static TransportSessionManager myself;
private DatabaseManager db;
......@@ -93,16 +97,38 @@ public class TransportSessionManager {
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>();
for (String key : transportSessions.keySet()) {
for (String user : transportSessions.get(key).keySet()) {
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 count of recognized active Sessions
*/
public int getNumberOfActiveSessions() {
int result = 0;
for (String key : transportSessions.keySet()) {
......@@ -111,19 +137,27 @@ public class TransportSessionManager {
return result;
}
public final Map<String, Date> getConnectionsFor(String username) {
// Maybe i do too much with hashes
Map<String, Date> userconnections = null;
/**
* Searches for Sessions with given Username and returns them as ArrList
* @param username
* @return
*/
public ArrayList<GatewaySession> getConnectionsFor(String username) {
ArrayList<GatewaySession> userconnections = null;
for (String transport : transportSessions.keySet()) {
if (transportSessions.get(transport).containsKey(username)) {
if (userconnections == null)
userconnections = new HashMap<String, Date>();
userconnections.put(transport, transportSessions.get(transport).get(username));
userconnections = new ArrayList<GatewaySession>();
userconnections.add(new GatewaySession(username, transport, transportSessions.get(transport).get(username)));
}
}
return userconnections;
}
/**
* Returns Registrations associated with Username
* @param username
* @return ArrayList of SessionEntries
*/
public ArrayList<SessionEntry> getRegistrationsFor(String username) {
return db.getSessionEntriesFor(username);
}
......
<%@ page
import="org.jivesoftware.openfire.plugin.gojara.permissions.TransportSessionManager"%>
import="org.jivesoftware.openfire.plugin.gojara.sessions.TransportSessionManager"%>
<%@ page
import="org.jivesoftware.openfire.plugin.gojara.database.SessionEntry"%>
<%@ page
......@@ -13,6 +13,7 @@
<%
TransportSessionManager transportManager = TransportSessionManager.getInstance();
//Helper object for generation of sorting links, column restriction is done in DatabaseManager
Map<String, String> sortParams = new HashMap<String, String>();
if (request.getParameter("sortby") != null && request.getParameter("sortorder") != null) {
......@@ -22,6 +23,7 @@
sortParams.put("sortby", "username");
sortParams.put("sortorder", "ASC");
}
//pagination
int current_page = 1;
%>
......@@ -79,6 +81,7 @@
if (next_items > numOfSessions)
next_items = numOfSessions;
%>
<p>
Pages: [
<%
......@@ -138,7 +141,7 @@
<%
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
+ "</a>"%>
<%
......
<%@ page
import="org.jivesoftware.openfire.plugin.gojara.permissions.TransportSessionManager"%>
import="org.jivesoftware.openfire.plugin.gojara.sessions.TransportSessionManager"%>
<%@ page
import="org.jivesoftware.openfire.plugin.gojara.permissions.GatewaySession"%>
import="org.jivesoftware.openfire.plugin.gojara.sessions.GatewaySession"%>
<%@ page
import="org.jivesoftware.openfire.plugin.gojara.utils.JspColumnSortingHelper"%>
<%@ page import="java.util.Map"%>
......@@ -12,6 +12,7 @@
<%
TransportSessionManager transportManager = TransportSessionManager.getInstance();
//Helper object for generation of sorting links, column restriction is done in DatabaseManager
Map<String, String> sortParams = new HashMap<String, String>();
if (request.getParameter("sortby") != null && request.getParameter("sortorder") != null) {
......@@ -22,6 +23,7 @@
sortParams.put("sortorder", "ASC");
}
//pagination
int current_page = 1;
%>
<html>
......@@ -34,15 +36,14 @@
<center>Please be aware that currently only users that connect
AFTER GoJara has been started are considered for these Sessions. This
affects Plugin-restarts.</center>
<%
Map<String, Map<String, Date>> sessions = transportManager.getSessions();
%><br>
<br>
<h4>
Current number of active Gateway Sessions: &emsp;
<%=transportManager.getNumberOfActiveSessions()%>
</h4>
<br>
<%
Map<String, Map<String, Date>> sessions = transportManager.getSessions();
for (String transport : sessions.keySet()) {
%>
<%=transport.substring(0, 10)%>... :
......@@ -53,7 +54,7 @@
<br>
<br>
<%
ArrayList<GatewaySession> gwSessions = transportManager.getSessionArrayList();
ArrayList<GatewaySession> gwSessions = transportManager.getSessionsSorted(sortParams.get("sortby"), sortParams.get("sortorder"));
int numOfSessions = gwSessions.size();
int numOfPages = numOfSessions / 100;
if (request.getParameter("page") != null) {
......
<%@ page import="org.jivesoftware.openfire.plugin.gojara.permissions.TransportSessionManager"%>
<%@ page import="org.jivesoftware.openfire.plugin.gojara.database.SessionEntry" %>
<%@page
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.Set"%>
<%@ page import="java.util.Date"%>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.ArrayList"%>
<%
TransportSessionManager transportManager = TransportSessionManager.getInstance();
String username = request.getParameter("username");
%>
%>
<html>
<head>
<title>GatewaySession Details for: &emsp; <%=username%></title>
......@@ -27,24 +31,33 @@
if (request.getParameter(username) != null) {
String[] unregister = request.getParameterValues(username);
%>
<br><br>
<br>
<br>
<%
for (String key : unregister) {
%>
<%=transportManager.removeRegistrationOfUser(key, username) %><br>
<% } %>
<br> <br>
<%=transportManager.removeRegistrationOfUser(key, username)%><br>
<%
}
%>
<br>
<br>
<%
}
Map<String, Date> userconnections = transportManager.getConnectionsFor(username);
ArrayList<GatewaySession> userconnections = transportManager.getConnectionsFor(username);
if (userconnections == null) {
%>
<h2><center>User has no active sessions</center></h2>
<h2>
<center>User has no active sessions</center>
</h2>
<%
} else {
%>
<center><h1>Active Sessions:</h1></center><br>
<center>
<h1>Active Sessions:</h1>
</center>
<br>
<div class="jive-table">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<thead>
......@@ -54,12 +67,16 @@
</tr>
</thead>
<tbody>
<% for (String transport : userconnections.keySet()) { %>
<%
for (GatewaySession gws : userconnections) {
%>
<tr class="jive-odd">
<td><%= transport%></td>
<td><%=userconnections.get(transport)%></td>
<td><%=gws.getTransport()%></td>
<td><%=gws.getLastActivity()%></td>
</tr>
<% } %>
<%
}
%>
</tbody>
</table>
</div>
......@@ -68,9 +85,14 @@
}
%>
<br><hr>
<center><h1>Associated Registrations:</h1></center><br>
<form name="unregister-form" id="gojara-sessDetailsUnregister"method="POST">
<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>
......@@ -83,27 +105,47 @@
</tr>
</thead>
<tbody>
<% ArrayList<SessionEntry> registrations = transportManager.getRegistrationsFor(username); %>
<% for (SessionEntry registration : registrations) { %>
<%
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>
<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>
<center>
<input type="button" value="check/uncheck all"
onclick='checkedAll();'>
</center>
<br>
<center><input type="submit" value="Unregister"></center>
<center>
<input type="submit" value="Unregister">
</center>
</form>
</body>
</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