Commit f6f097aa authored by Axel Brand's avatar Axel Brand Committed by daeva

Sorting helper refactored so i can use it to generate links for active...

Sorting helper refactored so i can use it to generate links for active GatewaySessions too. Storing Sessions in Objects for jsps now. Actual sorting & pagination of active Sessions & gateway Registrations up next.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13671 b35dd754-fafc-0310-a699-88a17e54d16e
parent 4945c72d
package org.jivesoftware.openfire.plugin.gojara.permissions;
import java.util.Date;
/**
* @author axel.frederik.brand
* Class for storing Gateway Session Objects for Iteration for JSP
*/
public class GatewaySession {
private String username;
private String transport;
private Date lastActivity;
public GatewaySession(String username, String transport, Date lastActivity) {
this.username = username;
this.transport = transport;
this.lastActivity = lastActivity;
}
public String getUsername() {
return username;
}
public String getTransport() {
return transport;
}
public Date getLastActivity() {
return lastActivity;
}
}
...@@ -92,7 +92,17 @@ public class TransportSessionManager { ...@@ -92,7 +92,17 @@ public class TransportSessionManager {
public final Map<String, Map<String, Date>> getSessions() { public final Map<String, Map<String, Date>> getSessions() {
return transportSessions; return transportSessions;
} }
public ArrayList<GatewaySession> getSessionArrayList(){
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)));
}
}
return result;
}
public int getNumberOfActiveSessions() { public int getNumberOfActiveSessions() {
int result = 0; int result = 0;
for (String key : transportSessions.keySet()) { for (String key : transportSessions.keySet()) {
......
package org.jivesoftware.openfire.plugin.gojara.utils;
import java.util.Map;
/**
* @author axel.frederik.brand
* Helper for generating specificly linked helper columns.
*/
public class JspColumnSortingHelper {
/**
* @param column
* @param sortParams
* @return String with html in it
*/
public static String sortingHelperRegistrations(String column, Map<String, String> sortParams) {
String link_beginning = "<a href=\"gojara-RegistrationsOverview.jsp?sortby=";
return helpMe(column, sortParams, link_beginning);
}
public static String sortingHelperSessions(String column, Map<String, String> sortParams) {
String link_beginning = "<a href=\"gojara-activeSessions.jsp?sortby=";
return helpMe(column, sortParams, link_beginning);
}
private static String helpMe(String column, Map<String, String> sortParams, String link_beginning) {
String image_asc = "<img alt=\"sorted ASC\" src=\"/images/sort_ascending.gif\">";
String image_desc = "<img alt=\"sorted DESC\" src=\"/images/sort_descending.gif\">";
String ending = "";
if (column.equals("username"))
ending = "User Name:";
else if (column.equals("transport"))
ending = "Resource:";
else if (column.equals("lastActivity"))
ending = "Last Login was at:";
else if (column.equals("loginTime"))
ending = "Login Time:";
else
ending = "i dont want to be here";
ending += "</a>";
String sortinglink = "";
if (sortParams.containsValue(column)) {
if (sortParams.containsValue("ASC")) {
sortinglink = image_asc + link_beginning + column + "&sortorder=DESC\">" + ending;
} else if (sortParams.containsValue("DESC")) {
sortinglink = image_desc + link_beginning + column + "&sortorder=ASC\">" + ending;
}
} else {
// This is not the currently sorted colum so we want to sort with it, Ascending.
sortinglink = link_beginning + column + "&sortorder=ASC\">" + ending;
}
return sortinglink;
}
}
<%@ page import="org.jivesoftware.openfire.plugin.gojara.permissions.TransportSessionManager"%> <%@ 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.database.SessionEntry" %>
<%@ page import="org.jivesoftware.openfire.plugin.gojara.utils.JspColumnSortingHelper"%>
<%@ page import="java.util.Map"%> <%@ page import="java.util.Map"%>
<%@ page import="java.util.HashMap"%> <%@ page import="java.util.HashMap"%>
<%@ page import="java.util.Set"%> <%@ page import="java.util.Set"%>
...@@ -10,18 +11,11 @@ ...@@ -10,18 +11,11 @@
TransportSessionManager transportManager = TransportSessionManager.getInstance(); TransportSessionManager transportManager = TransportSessionManager.getInstance();
int current_page; int current_page;
int current_limit; int current_limit;
//Helper object for restraining sorting to existing colums and nice generation of sorting links //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) {
// prfen wenn ok, nehmen wir die, ansonsten sortParams.put("sortby", request.getParameter("sortby") );
String allowedAttr = "username transport lastActivity"; sortParams.put("sortorder", request.getParameter("sortorder"));
String allowedOrder = "ASC DESC";
String sortAttr = request.getParameter("sortby");
String sortOrder = request.getParameter("sortorder");
if (allowedAttr.contains(sortAttr) && allowedOrder.contains(sortOrder)) {
sortParams.put("sortby", sortAttr);
sortParams.put("sortorder", sortOrder);
}
} else { } else {
sortParams.put("sortby", "username"); sortParams.put("sortby", "username");
sortParams.put("sortorder", "ASC"); sortParams.put("sortorder", "ASC");
...@@ -48,27 +42,7 @@ ...@@ -48,27 +42,7 @@
} }
} }
%> %>
<%!
public String sortingHelper(String column, Map<String, String> sortParams) {
String image_asc = "<img alt=\"sorted ASC\" src=\"/images/sort_ascending.gif\">";
String image_desc = "<img alt=\"sorted DESC\" src=\"/images/sort_descending.gif\">";
String link_beginning = "<a href=\"gojara-RegistrationsOverview.jsp?sortby=";
String ending = (column.equals("username") ? "User Name:" : column.equals("transport") ? "Resource:" : "Last Login was at:") + "</a>";
String sortinglink = "";
if (sortParams.containsValue(column)) {
if (sortParams.containsValue("ASC")) {
sortinglink = image_asc + link_beginning + column + "&sortorder=DESC\">" + ending;
} else if (sortParams.containsValue("DESC")) {
sortinglink = image_desc + link_beginning + column + "&sortorder=ASC\">" + ending;
}
} else {
// This is not the currently sorted colum so we want to sort with it, Ascending.
sortinglink = link_beginning + column + "&sortorder=ASC\">" + ending;
}
return sortinglink;
}
%>
<html> <html>
<head> <head>
<title>Overview of existing Registrations</title> <title>Overview of existing Registrations</title>
...@@ -97,16 +71,16 @@ ...@@ -97,16 +71,16 @@
<c:forEach var="i" begin="1" end="20" step="1" varStatus ="status"> <c:forEach var="i" begin="1" end="20" step="1" varStatus ="status">
<c:out value="${i}" /> <c:out value="${i}" />
</c:forEach> </c:forEach>
<h6>Logintime 1970 means User did only register but never logged in, propably because of invalid credentials.</h6> <h5>Logintime 1970 means User did only register but never logged in, propably because of invalid credentials.</h5><br>
<form name="unregister-form" id="gojara-RegOverviewUnregister"method="POST"> <form name="unregister-form" id="gojara-RegOverviewUnregister"method="POST">
<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>
<tr> <tr>
<th nowrap><%= sortingHelper("username",sortParams) %></th> <th nowrap><%= JspColumnSortingHelper.sortingHelperRegistrations("username", sortParams) %></th>
<th nowrap><%= sortingHelper("transport",sortParams) %></th> <th nowrap><%= JspColumnSortingHelper.sortingHelperRegistrations("transport", sortParams) %></th>
<th nowrap>Resource active?</th> <th nowrap>Resource active?</th>
<th nowrap><%= sortingHelper("lastActivity",sortParams) %></th> <th nowrap><%= JspColumnSortingHelper.sortingHelperRegistrations("lastActivity", sortParams)%></th>
<th nowrap>Unregister?</th> <th nowrap>Unregister?</th>
</tr> </tr>
</thead> </thead>
......
<%@ page import="org.jivesoftware.openfire.plugin.gojara.permissions.TransportSessionManager"%> <%@ page import="org.jivesoftware.openfire.plugin.gojara.permissions.TransportSessionManager"%>
<%@ page import="org.jivesoftware.openfire.plugin.gojara.permissions.GatewaySession"%>
<%@ page import="org.jivesoftware.openfire.plugin.gojara.utils.JspColumnSortingHelper"%>
<%@ page import="java.util.Map"%> <%@ page import="java.util.Map"%>
<%@ page import="java.util.HashMap"%>
<%@ page import="java.util.Set"%> <%@ page import="java.util.Set"%>
<%@ page import="java.util.Date"%> <%@ page import="java.util.Date"%>
<% <%
TransportSessionManager transportManager = TransportSessionManager.getInstance(); 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) {
sortParams.put("sortby", request.getParameter("sortby") );
sortParams.put("sortorder", request.getParameter("sortorder"));
} else {
sortParams.put("sortby", "transport");
sortParams.put("sortorder", "ASC");
}
%> %>
<html> <html>
<head> <head>
...@@ -37,29 +49,24 @@ ...@@ -37,29 +49,24 @@
<table cellpadding="0" cellspacing="0" border="0" width="100%"> <table cellpadding="0" cellspacing="0" border="0" width="100%">
<thead> <thead>
<tr> <tr>
<th nowrap>User Name</th> <th nowrap><%= JspColumnSortingHelper.sortingHelperSessions("username", sortParams) %></th>
<th nowrap>Resource</th> <th nowrap><%= JspColumnSortingHelper.sortingHelperSessions("transport", sortParams) %></th>
<th nowrap>Login Time</th> <th nowrap><%= JspColumnSortingHelper.sortingHelperSessions("loginTime", sortParams)%></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<% <%
for (String transport : sessions.keySet()) { for (GatewaySession gwsession : transportManager.getSessionArrayList()) {
%>
<%
for (String user : sessions.get(transport).keySet()) {
%> %>
<tr class="jive-odd"> <tr class="jive-odd">
<td><a href="gojara-sessionDetails.jsp?username=<%=user%>"><%=user%></a></td> <td><a href="gojara-sessionDetails.jsp?username=<%=gwsession.getUsername()%>"><%=gwsession.getUsername()%></a></td>
<td><%=transport%></td> <td><%=gwsession.getTransport()%></td>
<td><%=sessions.get(transport).get(user)%></td> <td><%=gwsession.getLastActivity()%></td>
</tr> </tr>
<% <%
} }
%> %>
<%
}
%>
</tbody> </tbody>
</table> </table>
</div> </div>
......
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