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 {
public final Map<String, Map<String, Date>> getSessions() {
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() {
int result = 0;
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.database.SessionEntry" %>
<%@ page import="org.jivesoftware.openfire.plugin.gojara.utils.JspColumnSortingHelper"%>
<%@ page import="java.util.Map"%>
<%@ page import="java.util.HashMap"%>
<%@ page import="java.util.Set"%>
......@@ -10,18 +11,11 @@
TransportSessionManager transportManager = TransportSessionManager.getInstance();
int current_page;
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>();
if (request.getParameter("sortby") != null && request.getParameter("sortorder") != null) {
// prfen wenn ok, nehmen wir die, ansonsten
String allowedAttr = "username transport lastActivity";
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);
}
sortParams.put("sortby", request.getParameter("sortby") );
sortParams.put("sortorder", request.getParameter("sortorder"));
} else {
sortParams.put("sortby", "username");
sortParams.put("sortorder", "ASC");
......@@ -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>
<head>
<title>Overview of existing Registrations</title>
......@@ -97,16 +71,16 @@
<c:forEach var="i" begin="1" end="20" step="1" varStatus ="status">
<c:out value="${i}" />
</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">
<div class="jive-table">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<thead>
<tr>
<th nowrap><%= sortingHelper("username",sortParams) %></th>
<th nowrap><%= sortingHelper("transport",sortParams) %></th>
<tr>
<th nowrap><%= JspColumnSortingHelper.sortingHelperRegistrations("username", sortParams) %></th>
<th nowrap><%= JspColumnSortingHelper.sortingHelperRegistrations("transport", sortParams) %></th>
<th nowrap>Resource active?</th>
<th nowrap><%= sortingHelper("lastActivity",sortParams) %></th>
<th nowrap><%= JspColumnSortingHelper.sortingHelperRegistrations("lastActivity", sortParams)%></th>
<th nowrap>Unregister?</th>
</tr>
</thead>
......
<%@ 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.HashMap"%>
<%@ page import="java.util.Set"%>
<%@ page import="java.util.Date"%>
<%
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>
<head>
......@@ -37,29 +49,24 @@
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<thead>
<tr>
<th nowrap>User Name</th>
<th nowrap>Resource</th>
<th nowrap>Login Time</th>
<th nowrap><%= JspColumnSortingHelper.sortingHelperSessions("username", sortParams) %></th>
<th nowrap><%= JspColumnSortingHelper.sortingHelperSessions("transport", sortParams) %></th>
<th nowrap><%= JspColumnSortingHelper.sortingHelperSessions("loginTime", sortParams)%></th>
</tr>
</thead>
<tbody>
<%
for (String transport : sessions.keySet()) {
%>
<%
for (String user : sessions.get(transport).keySet()) {
for (GatewaySession gwsession : transportManager.getSessionArrayList()) {
%>
<tr class="jive-odd">
<td><a href="gojara-sessionDetails.jsp?username=<%=user%>"><%=user%></a></td>
<td><%=transport%></td>
<td><%=sessions.get(transport).get(user)%></td>
<td><a href="gojara-sessionDetails.jsp?username=<%=gwsession.getUsername()%>"><%=gwsession.getUsername()%></a></td>
<td><%=gwsession.getTransport()%></td>
<td><%=gwsession.getLastActivity()%></td>
</tr>
<%
}
%>
<%
}
%>
</tbody>
</table>
</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