Commit 9d5d7c27 authored by Axel Brand's avatar Axel Brand Committed by daeva

Gojara Doc

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13680 b35dd754-fafc-0310-a699-88a17e54d16e
parent 804b8573
...@@ -16,16 +16,15 @@ import org.jivesoftware.database.DbConnectionManager; ...@@ -16,16 +16,15 @@ import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
/** /**
* @author Holger Bergunde, Axel-Frederik Brand * @author Holger Bergunde, Axel-Frederik Brand This class is used to store logs in the database. A log entry is
* This class is used to store logs in the database. A * representated by {@link LogEntry}
* log entry is representated by {@link LogEntry}
*/ */
public class DatabaseManager { public class DatabaseManager {
private static Logger Log = Logger.getLogger(DatabaseManager.class); private static Logger Log = Logger.getLogger(DatabaseManager.class);
private static volatile DatabaseManager _myself; private static volatile DatabaseManager _myself;
//Logging // Logging
private static final String COUNT_LOG_ENTRIES = "SELECT count(*) FROM ofGojaraStatistics"; private static final String COUNT_LOG_ENTRIES = "SELECT count(*) FROM ofGojaraStatistics";
private static final String COUNT_PACKAGES_ODLER = "SELECT count(*) FROM ofGojaraStatistics WHERE messageType like ? AND component = ? AND messageDate > ?"; private static final String COUNT_PACKAGES_ODLER = "SELECT count(*) FROM ofGojaraStatistics WHERE messageType like ? AND component = ? AND messageDate > ?";
private static final String GET_ALL_LOGS = "SELECT * FROM ofGojaraStatistics ORDER BY logID desc LIMIT 100"; private static final String GET_ALL_LOGS = "SELECT * FROM ofGojaraStatistics ORDER BY logID desc LIMIT 100";
...@@ -35,17 +34,18 @@ public class DatabaseManager { ...@@ -35,17 +34,18 @@ public class DatabaseManager {
private static final String CLEAN_OLD_DATA = "DELETE FROM ofGojaraStatistics WHERE messageDate < ?"; private static final String CLEAN_OLD_DATA = "DELETE FROM ofGojaraStatistics WHERE messageDate < ?";
private static final String GET_LOGS_DATE_LIMIT_COMPONENT = "SELECT * FROM ofGojaraStatistics WHERE messageDate > ? AND component = ? ORDER BY messageDate DESC LIMIT ?"; private static final String GET_LOGS_DATE_LIMIT_COMPONENT = "SELECT * FROM ofGojaraStatistics WHERE messageDate > ? AND component = ? ORDER BY messageDate DESC LIMIT ?";
private final int _dbCleanMinutes; private final int _dbCleanMinutes;
//Session // Session
private static final String ADD_SESSION_ENTRY = "INSERT INTO ofGojaraSessions(username, transport, lastActivity) VALUES (?,?,?)"; private static final String ADD_SESSION_ENTRY = "INSERT INTO ofGojaraSessions(username, transport, lastActivity) VALUES (?,?,?)";
private static final String UPDATE_SESSION_ENTRY = "UPDATE ofGojaraSessions SET lastActivity = ? WHERE username = ? AND transport = ?"; private static final String UPDATE_SESSION_ENTRY = "UPDATE ofGojaraSessions SET lastActivity = ? WHERE username = ? AND transport = ?";
private static final String GET_SESSION_ENTRIES_FOR_USERNAME = "SELECT * FROM ofGojaraSessions WHERE username = ? ORDER BY lastActivity DESC"; private static final String GET_SESSION_ENTRIES_FOR_USERNAME = "SELECT * FROM ofGojaraSessions WHERE username = ? ORDER BY lastActivity DESC";
private static final String DELETE_SESSION_ENTRY = "DELETE FROM ofGojaraSessions WHERE username = ? AND transport = ?"; private static final String DELETE_SESSION_ENTRY = "DELETE FROM ofGojaraSessions WHERE username = ? AND transport = ?";
private static final String GET_SESSION_COUNT = "SELECT count(*) FROM ofGojaraSessions"; private static final String GET_SESSION_COUNT = "SELECT count(*) FROM ofGojaraSessions";
private DatabaseManager() { private DatabaseManager() {
/* /*
* Load time from globals if it is set. It represents the minutes the * Load time from globals if it is set. It represents the minutes the log entries stay in database until they
* log entries stay in database until they will get deleted * will get deleted
*/ */
// TODO: Use PropertyEventListener to check if cleaner.minutes have // TODO: Use PropertyEventListener to check if cleaner.minutes have
// changed // changed
...@@ -125,8 +125,7 @@ public class DatabaseManager { ...@@ -125,8 +125,7 @@ public class DatabaseManager {
} }
/* /*
* Cleans log entries older than 60 minutes if * Cleans log entries older than 60 minutes if plugin.remoteroster.log.cleaner.minutes is not set
* plugin.remoteroster.log.cleaner.minutes is not set
*/ */
private void cleanOldLogEntries() { private void cleanOldLogEntries() {
Connection con = null; Connection con = null;
...@@ -149,16 +148,13 @@ public class DatabaseManager { ...@@ -149,16 +148,13 @@ public class DatabaseManager {
* Adds new log entry for specified component. * Adds new log entry for specified component.
* *
* @param component * @param component
* subdomain of the external component. e.g. * subdomain of the external component. e.g. icq.myjabberserver.com
* icq.myjabberserver.com
* @param type * @param type
* string representation of the class. normaly it is like * string representation of the class. normaly it is like {@link org.xmpp.packet}
* {@link org.xmpp.packet}
* @param from * @param from
* full qualified JID of user or component this packet was from * full qualified JID of user or component this packet was from
* @param to * @param to
* full qualified JID of user or component this packet was * full qualified JID of user or component this packet was adressed to
* adressed to
*/ */
public void addNewLogEntry(String component, String type, String from, String to) { public void addNewLogEntry(String component, String type, String from, String to) {
Connection con = null; Connection con = null;
...@@ -182,8 +178,7 @@ public class DatabaseManager { ...@@ -182,8 +178,7 @@ public class DatabaseManager {
} }
/** /**
* This method return the last 100 log entries. Every entry is one string * This method return the last 100 log entries. Every entry is one string and added to a ArrayList
* and added to a ArrayList
* *
* @return each log as string in a list * @return each log as string in a list
* */ * */
...@@ -203,8 +198,8 @@ public class DatabaseManager { ...@@ -203,8 +198,8 @@ public class DatabaseManager {
String type = rs.getString(3); String type = rs.getString(3);
String component = rs.getString(6); String component = rs.getString(6);
Timestamp date = rs.getTimestamp(2); Timestamp date = rs.getTimestamp(2);
String res = "From: " + from + " To: " + to + " Type: " + type + " Timestamp: " + date.toString() String res = "From: " + from + " To: " + to + " Type: " + type + " Timestamp: " + date.toString() + "Component: "
+ "Component: " + component; + component;
_result.add(res); _result.add(res);
} }
} }
...@@ -254,16 +249,14 @@ public class DatabaseManager { ...@@ -254,16 +249,14 @@ public class DatabaseManager {
} }
/** /**
* Counts the number of log entries in the databse that are older than * Counts the number of log entries in the databse that are older than specified value
* specified value
* *
* @param component * @param component
* subdomain of the component the packages were flown by * subdomain of the component the packages were flown by
* @param packetClass * @param packetClass
* the class the packet was instance of * the class the packet was instance of
* @param minutes * @param minutes
* the log entry should not be older than (timestamp should be * the log entry should not be older than (timestamp should be smaller than currentTime - minutes)
* smaller than currentTime - minutes)
* @return number of rows found in database or -1 if there was an error * @return number of rows found in database or -1 if there was an error
*/ */
public int getPacketCountOlderThan(String component, @SuppressWarnings("rawtypes") Class packetClass, int minutes) { public int getPacketCountOlderThan(String component, @SuppressWarnings("rawtypes") Class packetClass, int minutes) {
...@@ -287,10 +280,10 @@ public class DatabaseManager { ...@@ -287,10 +280,10 @@ public class DatabaseManager {
} }
return -1; return -1;
} }
/** /**
* Trys to update SessionEntry for given user/transport combination. If update does not * Trys to update SessionEntry for given user/transport combination. If update does not work due to no record being
* work due to no record being there, it inserts record. * there, it inserts record.
*/ */
public void insertOrUpdateSession(String transport, String user, long time) { public void insertOrUpdateSession(String transport, String user, long time) {
Connection con = null; Connection con = null;
...@@ -318,13 +311,13 @@ public class DatabaseManager { ...@@ -318,13 +311,13 @@ public class DatabaseManager {
DbConnectionManager.closeConnection(pstmt, con); DbConnectionManager.closeConnection(pstmt, con);
} }
} }
public int removeSessionEntry(String transport, String user) { public int removeSessionEntry(String transport, String user) {
int result = 0; int result = 0;
Log.info("I would now hit the DB and remove " + transport + " " + user); Log.info("I would now hit the DB and remove " + transport + " " + user);
Connection con = null; Connection con = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
try { try {
con = DbConnectionManager.getConnection(); con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(DELETE_SESSION_ENTRY); pstmt = con.prepareStatement(DELETE_SESSION_ENTRY);
...@@ -338,7 +331,7 @@ public class DatabaseManager { ...@@ -338,7 +331,7 @@ public class DatabaseManager {
} }
return result; return result;
} }
public ArrayList<SessionEntry> getSessionEntriesFor(String username) { public ArrayList<SessionEntry> getSessionEntriesFor(String username) {
ArrayList<SessionEntry> result = new ArrayList<SessionEntry>(); ArrayList<SessionEntry> result = new ArrayList<SessionEntry>();
Connection con = null; Connection con = null;
...@@ -353,7 +346,7 @@ public class DatabaseManager { ...@@ -353,7 +346,7 @@ public class DatabaseManager {
String user = rs.getString(1); String user = rs.getString(1);
String transport = rs.getString(2); String transport = rs.getString(2);
long lastActivity = rs.getLong(3); long lastActivity = rs.getLong(3);
SessionEntry res = new SessionEntry(user,transport,lastActivity); SessionEntry res = new SessionEntry(user, transport, lastActivity);
result.add(res); result.add(res);
} }
...@@ -365,16 +358,15 @@ public class DatabaseManager { ...@@ -365,16 +358,15 @@ public class DatabaseManager {
} }
return result; return result;
} }
public ArrayList<SessionEntry> getAllSessionEntries(String orderAttr, String order) { public ArrayList<SessionEntry> getAllSessionEntries(String orderAttr, String order) {
String allowedAttr = "username transport lastActivity"; String allowedAttr = "username transport lastActivity";
String allowedOrder = "ASC DESC"; String allowedOrder = "ASC DESC";
if ((orderAttr == null || order == null) if ((orderAttr == null || order == null) || (!allowedAttr.contains(orderAttr) || !allowedOrder.contains(order))) {
|| (!allowedAttr.contains(orderAttr) || !allowedOrder.contains(order))) { // Use default case if sorting attributes are not correct.
//Use default case if sorting attributes are not correct.
orderAttr = "username"; orderAttr = "username";
order = "DESC"; order = "DESC";
} }
ArrayList<SessionEntry> result = new ArrayList<SessionEntry>(); ArrayList<SessionEntry> result = new ArrayList<SessionEntry>();
Connection con = null; Connection con = null;
...@@ -388,7 +380,7 @@ public class DatabaseManager { ...@@ -388,7 +380,7 @@ public class DatabaseManager {
String user = rs.getString(1); String user = rs.getString(1);
String transport = rs.getString(2); String transport = rs.getString(2);
long lastActivity = rs.getLong(3); long lastActivity = rs.getLong(3);
SessionEntry res = new SessionEntry(user,transport,lastActivity); SessionEntry res = new SessionEntry(user, transport, lastActivity);
result.add(res); result.add(res);
} }
pstmt.close(); pstmt.close();
...@@ -399,7 +391,7 @@ public class DatabaseManager { ...@@ -399,7 +391,7 @@ public class DatabaseManager {
} }
return result; return result;
} }
public int getNumberOfRegistrations() { public int getNumberOfRegistrations() {
int result = 0; int result = 0;
Connection con = null; Connection con = null;
......
...@@ -3,14 +3,15 @@ package org.jivesoftware.openfire.plugin.gojara.sessions; ...@@ -3,14 +3,15 @@ package org.jivesoftware.openfire.plugin.gojara.sessions;
import java.util.Date; import java.util.Date;
/** /**
* @author axel.frederik.brand
* Class for storing Gateway Session Objects for Iteration for JSP * Class for storing Gateway Session Objects for Iteration for JSP
*
* @author axel.frederik.brand
*/ */
public class GatewaySession { public class GatewaySession {
private String username; private String username;
private String transport; private String transport;
private Date lastActivity; private Date lastActivity;
public GatewaySession(String username, String transport, Date lastActivity) { public GatewaySession(String username, String transport, Date lastActivity) {
this.username = username; this.username = username;
this.transport = transport; this.transport = transport;
...@@ -33,6 +34,5 @@ public class GatewaySession { ...@@ -33,6 +34,5 @@ public class GatewaySession {
public String toString() { public String toString() {
return "GatewaySession [username=" + username + ", transport=" + transport + ", lastActivity=" + lastActivity + "]"; return "GatewaySession [username=" + username + ", transport=" + transport + ", lastActivity=" + lastActivity + "]";
} }
} }
...@@ -2,7 +2,13 @@ package org.jivesoftware.openfire.plugin.gojara.sessions; ...@@ -2,7 +2,13 @@ package org.jivesoftware.openfire.plugin.gojara.sessions;
import java.util.Comparator; import java.util.Comparator;
public class SortLastActivity implements Comparator<GatewaySession>{ /**
* Comparator to sort GatewaySessions
*
* @author axel.frederik.brand
*
*/
public class SortLastActivity implements Comparator<GatewaySession> {
public int compare(GatewaySession gws1, GatewaySession gws2) { public int compare(GatewaySession gws1, GatewaySession gws2) {
return gws1.getLastActivity().compareTo(gws2.getLastActivity()); return gws1.getLastActivity().compareTo(gws2.getLastActivity());
......
...@@ -2,7 +2,13 @@ package org.jivesoftware.openfire.plugin.gojara.sessions; ...@@ -2,7 +2,13 @@ package org.jivesoftware.openfire.plugin.gojara.sessions;
import java.util.Comparator; import java.util.Comparator;
public class SortTransport implements Comparator<GatewaySession>{ /**
* Comparator to sort GatewaySessions
*
* @author axel.frederik.brand
*
*/
public class SortTransport implements Comparator<GatewaySession> {
public int compare(GatewaySession gws1, GatewaySession gws2) { public int compare(GatewaySession gws1, GatewaySession gws2) {
return gws1.getTransport().compareTo(gws2.getTransport()); return gws1.getTransport().compareTo(gws2.getTransport());
......
...@@ -2,8 +2,14 @@ package org.jivesoftware.openfire.plugin.gojara.sessions; ...@@ -2,8 +2,14 @@ package org.jivesoftware.openfire.plugin.gojara.sessions;
import java.util.Comparator; import java.util.Comparator;
public class SortUserName implements Comparator<GatewaySession>{ /**
* Comparator to sort GatewaySessions
*
* @author axel.frederik.brand
*
*/
public class SortUserName implements Comparator<GatewaySession> {
public int compare(GatewaySession gw1, GatewaySession gw2) { public int compare(GatewaySession gw1, GatewaySession gw2) {
return gw1.getUsername().compareTo(gw2.getUsername()); return gw1.getUsername().compareTo(gw2.getUsername());
} }
......
...@@ -13,8 +13,10 @@ import org.slf4j.LoggerFactory; ...@@ -13,8 +13,10 @@ import org.slf4j.LoggerFactory;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
/** /**
* This is the central point for doing anything Gojara GatewaySession related, we can add component session, add
* gatewaysession etc
*
* @author axel.frederik.brand * @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;
...@@ -38,11 +40,21 @@ public class TransportSessionManager { ...@@ -38,11 +40,21 @@ public class TransportSessionManager {
return myself; return myself;
} }
/**
* adds a subdomain to watched transports
*
* @param subdomain
*/
public void addTransport(String subdomain) { public void addTransport(String subdomain) {
transportSessions.put(subdomain, new ConcurrentHashMap<String, Date>()); transportSessions.put(subdomain, new ConcurrentHashMap<String, Date>());
Log.info("Added key to transportSessionMap: " + subdomain); Log.info("Added key to transportSessionMap: " + subdomain);
} }
/**
* removes subdomain from watched transports
*
* @param subdomain
*/
public void removeTransport(String subdomain) { public void removeTransport(String subdomain) {
Map<String, Date> disconnectedUsers = transportSessions.remove(subdomain); Map<String, Date> disconnectedUsers = transportSessions.remove(subdomain);
Log.info("Removed " + subdomain + "from TransportSessionMap " + disconnectedUsers.toString()); Log.info("Removed " + subdomain + "from TransportSessionMap " + disconnectedUsers.toString());
...@@ -52,11 +64,25 @@ public class TransportSessionManager { ...@@ -52,11 +64,25 @@ public class TransportSessionManager {
public boolean isTransportActive(String subdomain) { public boolean isTransportActive(String subdomain) {
return transportSessions.containsKey(subdomain) ? true : false; return transportSessions.containsKey(subdomain) ? true : false;
} }
/**
* register is seperate because a user may register to transport but not connect to it, e.g. with wrong credentials.
* we still want to keep track of those registrations so we know they happened and we can reset them
*
* @param transport
* @param user
*/
public void registerUserTo(String transport, String user) { public void registerUserTo(String transport, String user) {
//This ofc is not a session yet, so we just keep the registration in db to track eventual unsuccessful registers
db.insertOrUpdateSession(transport, user, 0); db.insertOrUpdateSession(transport, user, 0);
} }
/**
* Add the session of user that connected to gateway and update or create timestamp for session
*
* @param transport
* @param user
* @return
*/
public boolean connectUserTo(String transport, String user) { public boolean connectUserTo(String transport, String user) {
if (transportSessions.get(transport) != null) { if (transportSessions.get(transport) != null) {
long millis = System.currentTimeMillis(); long millis = System.currentTimeMillis();
...@@ -82,6 +108,14 @@ public class TransportSessionManager { ...@@ -82,6 +108,14 @@ public class TransportSessionManager {
return transportSessions.get(transport).containsKey(user); return transportSessions.get(transport).containsKey(user);
} }
/**
* Removing a registration will cause a unregister msg being sent to Spectrum2 for this specific User/Gateway
* combination Also it will be removed from our db.
*
* @param transport
* @param user
* @return
*/
public String removeRegistrationOfUser(String transport, String user) { public String removeRegistrationOfUser(String transport, String user) {
int result = db.removeSessionEntry(transport, user); int result = db.removeSessionEntry(transport, user);
if (result == 0) { if (result == 0) {
...@@ -96,22 +130,25 @@ public class TransportSessionManager { ...@@ -96,22 +130,25 @@ public class TransportSessionManager {
public final Map<String, Map<String, Date>> getSessions() { public final Map<String, Map<String, Date>> getSessions() {
return transportSessions; return transportSessions;
} }
/** /**
* Puts all Sessions into an ArrayList of GatewaySession Objects, and sorts it according to specified sorting attributes. * Puts all Sessions into an ArrayList of GatewaySession Objects, and sorts it according to specified sorting
* @param sortby username, transport or LoginTime * attributes.
* @param sortorder ASC or DESC *
* @param sortby
* username, transport or LoginTime
* @param sortorder
* ASC or DESC
* @return Sorted/Unsorted ArrayList of GatewaySession Objects * @return Sorted/Unsorted ArrayList of GatewaySession Objects
*/ */
public ArrayList<GatewaySession> getSessionsSorted(String sortby, String sortorder){ 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")) { if (sortby.equals("username")) {
Collections.sort(result, new SortUserName()); Collections.sort(result, new SortUserName());
} else if (sortby.equals("transport")) { } else if (sortby.equals("transport")) {
...@@ -119,15 +156,14 @@ public class TransportSessionManager { ...@@ -119,15 +156,14 @@ public class TransportSessionManager {
} else if (sortby.equals("loginTime")) { } else if (sortby.equals("loginTime")) {
Collections.sort(result, new SortLastActivity()); Collections.sort(result, new SortLastActivity());
} }
if (sortorder.equals("DESC")){ if (sortorder.equals("DESC")) {
Collections.reverse(result); Collections.reverse(result);
} }
return result; return result;
} }
/** /**
* @return count of recognized active Sessions * @return count of recognized active Sessions
*/ */
public int getNumberOfActiveSessions() { public int getNumberOfActiveSessions() {
int result = 0; int result = 0;
...@@ -136,9 +172,10 @@ public class TransportSessionManager { ...@@ -136,9 +172,10 @@ public class TransportSessionManager {
} }
return result; return result;
} }
/** /**
* Searches for Sessions with given Username and returns them as ArrList * Searches for Sessions with given Username and returns them as ArrList
*
* @param username * @param username
* @return * @return
*/ */
...@@ -153,8 +190,10 @@ public class TransportSessionManager { ...@@ -153,8 +190,10 @@ public class TransportSessionManager {
} }
return userconnections; return userconnections;
} }
/** /**
* Returns Registrations associated with Username * Returns Registrations associated with Username
*
* @param username * @param username
* @return ArrayList of SessionEntries * @return ArrayList of SessionEntries
*/ */
...@@ -163,13 +202,13 @@ public class TransportSessionManager { ...@@ -163,13 +202,13 @@ public class TransportSessionManager {
} }
/** /**
* Validation for correctness of attributes is done in DB Manager, returns default sorting: username ASC when not * Get all registrations sorted by attribute and order. Validation for correctness of attributes is done in DB
* correct * Manager, returns default sorting: username ASC when not valid
*/ */
public ArrayList<SessionEntry> getAllRegistrations(String orderAttr, String order) { public ArrayList<SessionEntry> getAllRegistrations(String orderAttr, String order) {
return db.getAllSessionEntries(orderAttr, order); return db.getAllSessionEntries(orderAttr, order);
} }
public int getNumberOfRegistrations() { public int getNumberOfRegistrations() {
return db.getNumberOfRegistrations(); return db.getNumberOfRegistrations();
} }
......
...@@ -5,12 +5,14 @@ import java.util.Date; ...@@ -5,12 +5,14 @@ import java.util.Date;
import java.util.Map; import java.util.Map;
/** /**
* @author axel.frederik.brand * @author axel.frederik.brand Helper for some functions we call from gojara registration / session jsps
* Helper for generating specificly linked helper columns.
*/ */
public class JspHelper { public class JspHelper {
/** /**
* Create a link that leads to the same page, sorted by the attribute clicked on. The sorting Order depends on the
* current sorting order. If element is not the one currently sorted by, its always ASC, else DESC
*
* @param column * @param column
* @param sortParams * @param sortParams
* @return String with html in it * @return String with html in it
...@@ -18,17 +20,17 @@ public class JspHelper { ...@@ -18,17 +20,17 @@ public class JspHelper {
public static String sortingHelperRegistrations(String column, Map<String, String> sortParams) { public static String sortingHelperRegistrations(String column, Map<String, String> sortParams) {
String link_beginning = "<a href=\"gojara-RegistrationsOverview.jsp?sortby="; String link_beginning = "<a href=\"gojara-RegistrationsOverview.jsp?sortby=";
return helpMe(column, sortParams, link_beginning); return helpMe(column, sortParams, link_beginning);
} }
public static String sortingHelperSessions(String column, Map<String, String> sortParams) { public static String sortingHelperSessions(String column, Map<String, String> sortParams) {
String link_beginning = "<a href=\"gojara-activeSessions.jsp?sortby="; String link_beginning = "<a href=\"gojara-activeSessions.jsp?sortby=";
return helpMe(column, sortParams, link_beginning); return helpMe(column, sortParams, link_beginning);
} }
private static String helpMe(String column, Map<String, String> sortParams, String 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_asc = "<img alt=\"sorted ASC\" src=\"/images/sort_ascending.gif\">";
String image_desc = "<img alt=\"sorted DESC\" src=\"/images/sort_descending.gif\">"; String image_desc = "<img alt=\"sorted DESC\" src=\"/images/sort_descending.gif\">";
String ending = ""; String ending = "";
if (column.equals("username")) if (column.equals("username"))
ending = "User Name:"; ending = "User Name:";
...@@ -38,10 +40,10 @@ public class JspHelper { ...@@ -38,10 +40,10 @@ public class JspHelper {
ending = "Last Login was at:"; ending = "Last Login was at:";
else if (column.equals("loginTime")) else if (column.equals("loginTime"))
ending = "Login Time:"; ending = "Login Time:";
else else
ending = "i dont want to be here"; ending = "i dont want to be here";
ending += "</a>"; ending += "</a>";
String sortinglink = ""; String sortinglink = "";
if (sortParams.containsValue(column)) { if (sortParams.containsValue(column)) {
if (sortParams.containsValue("ASC")) { if (sortParams.containsValue("ASC")) {
...@@ -55,9 +57,11 @@ public class JspHelper { ...@@ -55,9 +57,11 @@ public class JspHelper {
} }
return sortinglink; return sortinglink;
} }
/** /**
* Compares specified date to current date and returns String explaining how much Minutes / Hours / Days has passed since then * Compares specified date to current date and returns String explaining how much Minutes / Hours / Days has passed
* since then
*
* @param oldDate * @param oldDate
* @return * @return
*/ */
...@@ -65,12 +69,12 @@ public class JspHelper { ...@@ -65,12 +69,12 @@ public class JspHelper {
Timestamp stamp = new Timestamp(System.currentTimeMillis()); Timestamp stamp = new Timestamp(System.currentTimeMillis());
Date currentDate = new Date(stamp.getTime()); Date currentDate = new Date(stamp.getTime());
long diff = currentDate.getTime() - oldDate.getTime(); long diff = currentDate.getTime() - oldDate.getTime();
long diffSeconds = diff / 1000 % 60; long diffSeconds = diff / 1000 % 60;
long diffMinutes = diff / (60 * 1000) % 60; long diffMinutes = diff / (60 * 1000) % 60;
long diffHours = diff / (60 * 60 * 1000) % 24; long diffHours = diff / (60 * 60 * 1000) % 24;
long diffDays = diff / (24 * 60 * 60 * 1000); long diffDays = diff / (24 * 60 * 60 * 1000);
return "" + diffSeconds + " Seconds " + diffMinutes + " Minutes " + diffHours + " Hours " + diffDays + " Days ago"; return "" + diffSeconds + " Seconds " + diffMinutes + " Minutes " + diffHours + " Hours " + diffDays + " Days ago";
} }
} }
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