Commit 33b5e8c0 authored by Leon Roy's avatar Leon Roy Committed by leonroy

OF-651 - Monitoring plugin should have an option to purge and restrict

Restriction implemented, purging left

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13650 b35dd754-fafc-0310-a699-88a17e54d16e
parent 1a4803a6
...@@ -76,6 +76,10 @@ archive.settings.idle.time = Idle Time ...@@ -76,6 +76,10 @@ archive.settings.idle.time = Idle Time
archive.settings.idle.time.description = The number of minutes a conversation can be idle before it's ended. archive.settings.idle.time.description = The number of minutes a conversation can be idle before it's ended.
archive.settings.max.time = Max Time archive.settings.max.time = Max Time
archive.settings.max.time.description = The maximum number of minutes a conversation can last before it's ended. archive.settings.max.time.description = The maximum number of minutes a conversation can last before it's ended.
archive.settings.max.age = Max Message Age
archive.settings.max.age.description = The maximum number of days to keep messages before purging them from the database.
archive.settings.max.retrievable = Retrievable Messages
archive.settings.max.retrievable.description = The number of days worth of messages a user is allowed to retrieve.
archive.settings.index.settings = Index Settings archive.settings.index.settings = Index Settings
archive.settings.index.settings.description = View and/or rebuild the current Search Index. archive.settings.index.settings.description = View and/or rebuild the current Search Index.
archive.settings.current.index = Current Search Index archive.settings.current.index = Current Search Index
......
...@@ -50,6 +50,10 @@ archive.settings.idle.time = Doba ne\u010dinnosti ...@@ -50,6 +50,10 @@ archive.settings.idle.time = Doba ne\u010dinnosti
archive.settings.idle.time.description = Po\u010det minut b\u011bhem kter\u00fdch m\u016f\u017ee b\u00fdt konverzace ne\u010dinn\u00e1 ne\u017e bude ukon\u010dena. archive.settings.idle.time.description = Po\u010det minut b\u011bhem kter\u00fdch m\u016f\u017ee b\u00fdt konverzace ne\u010dinn\u00e1 ne\u017e bude ukon\u010dena.
archive.settings.max.time = Maxim\u00e1ln\u00ed \u010das archive.settings.max.time = Maxim\u00e1ln\u00ed \u010das
archive.settings.max.time.description = Maxim\u00e1ln\u00ed po\u010det minut trv\u00e1n\u00ed konverzace ne\u017e bude ukon\u010dena. archive.settings.max.time.description = Maxim\u00e1ln\u00ed po\u010det minut trv\u00e1n\u00ed konverzace ne\u017e bude ukon\u010dena.
archive.settings.max.age = Max Message Age
archive.settings.max.age.description = The maximum number of days to keep messages before purging them from the database.
archive.settings.max.retrievable = Retrievable Messages
archive.settings.max.retrievable.description = The number of days worth of messages a user is allowed to retrieve.
archive.settings.index.settings = Nastaven\u00ed index\u016f archive.settings.index.settings = Nastaven\u00ed index\u016f
archive.settings.index.settings.description = Prohl\u00ed\u017een\u00ed a/nebo obnova aktu\u00e1ln\u00edho vyhled\u00e1vac\u00edho indexu. archive.settings.index.settings.description = Prohl\u00ed\u017een\u00ed a/nebo obnova aktu\u00e1ln\u00edho vyhled\u00e1vac\u00edho indexu.
archive.settings.current.index = Aktu\u00e1ln\u00ed vyhled\u00e1vac\u00ed index archive.settings.current.index = Aktu\u00e1ln\u00ed vyhled\u00e1vac\u00ed index
......
...@@ -50,6 +50,10 @@ archive.settings.idle.time = Tiempo Ocioso ...@@ -50,6 +50,10 @@ archive.settings.idle.time = Tiempo Ocioso
archive.settings.idle.time.description = El n\u00famero de minutos una conversaci\u00f3n puede estar libre antes de ser finalizada. archive.settings.idle.time.description = El n\u00famero de minutos una conversaci\u00f3n puede estar libre antes de ser finalizada.
archive.settings.max.time = Tiempo M\u00e1ximo archive.settings.max.time = Tiempo M\u00e1ximo
archive.settings.max.time.description = El m\u00e1ximo n\u00famero de minutos una conversacion puede durar antes de ser finalizada. archive.settings.max.time.description = El m\u00e1ximo n\u00famero de minutos una conversacion puede durar antes de ser finalizada.
archive.settings.max.age = Max Message Age
archive.settings.max.age.description = The maximum number of days to keep messages before purging them from the database.
archive.settings.max.retrievable = Max Retrievable Messages
archive.settings.max.retrievable.description = The number of days worth of messages a user is allowed to retrieve.
archive.settings.index.settings = Seteos de Indices archive.settings.index.settings = Seteos de Indices
archive.settings.index.settings.description = Ver y/o reconstruir el \u00edndice de b\u00fasqueda actual. archive.settings.index.settings.description = Ver y/o reconstruir el \u00edndice de b\u00fasqueda actual.
archive.settings.current.index = Indice de B\u00fasqueda Actual archive.settings.current.index = Indice de B\u00fasqueda Actual
......
...@@ -110,6 +110,10 @@ archive.settings.index.settings=Param\u00e8tres d'Indexage ...@@ -110,6 +110,10 @@ archive.settings.index.settings=Param\u00e8tres d'Indexage
archive.settings.index.settings.description=Voir et/ou reconstruire les indexes de recherche. archive.settings.index.settings.description=Voir et/ou reconstruire les indexes de recherche.
archive.settings.max.time=Temps Max archive.settings.max.time=Temps Max
archive.settings.max.time.description=Le nombre de minutes maximum d'une conversation avant qu'elle ne soit coup\u00e9e automatiquement. archive.settings.max.time.description=Le nombre de minutes maximum d'une conversation avant qu'elle ne soit coup\u00e9e automatiquement.
archive.settings.max.age = Max Message Age
archive.settings.max.age.description = The maximum number of days to keep messages before purging them from the database.
archive.settings.max.retrievable = Retrievable Messages
archive.settings.max.retrievable.description = The number of days worth of messages a user is allowed to retrieve.
archive.settings.message.count=Nombre de messages archiv\u00e9s archive.settings.message.count=Nombre de messages archiv\u00e9s
archive.settings.message.count.description=Le nombre total de messages archiv\u00e9s. archive.settings.message.count.description=Le nombre total de messages archiv\u00e9s.
archive.settings.message.metadata.description=Activer ou D\u00e9sactiver l'archivage des messages et/ou metadata. archive.settings.message.metadata.description=Activer ou D\u00e9sactiver l'archivage des messages et/ou metadata.
......
...@@ -74,6 +74,10 @@ archive.settings.idle.time = Tempo Ocioso ...@@ -74,6 +74,10 @@ archive.settings.idle.time = Tempo Ocioso
archive.settings.idle.time.description = N\u00famero de minutos que a conversa pode estar ociosa antes de ser encerrada. archive.settings.idle.time.description = N\u00famero de minutos que a conversa pode estar ociosa antes de ser encerrada.
archive.settings.max.time = Tempo M\u00e1ximo archive.settings.max.time = Tempo M\u00e1ximo
archive.settings.max.time.description = N\u00famero m\u00e1ximo de minutos que a conversa pode durar antes de ser encerrada. archive.settings.max.time.description = N\u00famero m\u00e1ximo de minutos que a conversa pode durar antes de ser encerrada.
archive.settings.max.age = Max Message Age
archive.settings.max.age.description = The maximum number of days to keep messages before purging them from the database.
archive.settings.max.retrievable = Retrievable Messages
archive.settings.max.retrievable.description = The number of days worth of messages a user is allowed to retrieve.
archive.settings.index.settings = Ajustes de \u00edndice archive.settings.index.settings = Ajustes de \u00edndice
archive.settings.index.settings.description = Ver e/ou refazer o \u00edndice de Buscas atual. archive.settings.index.settings.description = Ver e/ou refazer o \u00edndice de Buscas atual.
archive.settings.current.index = \u00edndice de Buscas Atual archive.settings.current.index = \u00edndice de Buscas Atual
......
...@@ -71,6 +71,10 @@ archive.settings.idle.time = \u7a7a\u95f2\u65f6\u95f4 ...@@ -71,6 +71,10 @@ archive.settings.idle.time = \u7a7a\u95f2\u65f6\u95f4
archive.settings.idle.time.description = \u4f1a\u8bdd\u7ed3\u675f\u540e\u7a7a\u95f2\u7684\u65f6\u95f4 archive.settings.idle.time.description = \u4f1a\u8bdd\u7ed3\u675f\u540e\u7a7a\u95f2\u7684\u65f6\u95f4
archive.settings.max.time = \u6700\u5927\u65f6\u95f4 archive.settings.max.time = \u6700\u5927\u65f6\u95f4
archive.settings.max.time.description = \u4f1a\u8bdd\u7ed3\u675f\u524d\u53ef\u6301\u7eed\u7684\u6700\u5927\u65f6\u95f4 archive.settings.max.time.description = \u4f1a\u8bdd\u7ed3\u675f\u524d\u53ef\u6301\u7eed\u7684\u6700\u5927\u65f6\u95f4
archive.settings.max.age = Max Message Age
archive.settings.max.age.description = The maximum number of days to keep messages before purging them from the database.
archive.settings.max.retrievable = Retrievable Messages
archive.settings.max.retrievable.description = The number of days worth of messages a user is allowed to retrieve.
archive.settings.index.settings = \u7d22\u5f15\u8bbe\u7f6e archive.settings.index.settings = \u7d22\u5f15\u8bbe\u7f6e
archive.settings.index.settings.description = \u67e5\u770b\u6216\u91cd\u5efa\u5f53\u524d\u7684\u641c\u7d22\u7d22\u5f15 archive.settings.index.settings.description = \u67e5\u770b\u6216\u91cd\u5efa\u5f53\u524d\u7684\u641c\u7d22\u7d22\u5f15
archive.settings.current.index = \u5f53\u524d\u7684\u641c\u7d22\u7d22\u5f15 archive.settings.current.index = \u5f53\u524d\u7684\u641c\u7d22\u7d22\u5f15
......
...@@ -4,6 +4,7 @@ import java.sql.Connection; ...@@ -4,6 +4,7 @@ import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.text.DateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
...@@ -13,6 +14,9 @@ import java.util.HashSet; ...@@ -13,6 +14,9 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import org.jivesoftware.database.DbConnectionManager; import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.openfire.archive.ConversationManager;
import org.jivesoftware.util.JiveConstants;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
...@@ -30,23 +34,11 @@ import com.reucon.openfire.plugin.archive.xep0059.XmppResultSet; ...@@ -30,23 +34,11 @@ import com.reucon.openfire.plugin.archive.xep0059.XmppResultSet;
public class JdbcPersistenceManager implements PersistenceManager { public class JdbcPersistenceManager implements PersistenceManager {
public static final int DEFAULT_MAX = 1000; public static final int DEFAULT_MAX = 1000;
public static final String SELECT_MESSAGES_BY_CONVERSATION = "SELECT DISTINCT " public static final String SELECT_MESSAGES_BY_CONVERSATION = "SELECT DISTINCT " + "ofConversation.conversationID, " + "ofConversation.room, "
+ "ofConversation.conversationID, " + "ofConversation.isExternal, " + "ofConversation.startDate, " + "ofConversation.lastActivity, " + "ofConversation.messageCount, "
+ "ofConversation.room, " + "ofConParticipant.joinedDate, " + "ofConParticipant.leftDate, " + "ofConParticipant.bareJID, " + "ofConParticipant.jidResource, "
+ "ofConversation.isExternal, " + "ofConParticipant.nickname, " + "ofMessageArchive.fromJID, " + "ofMessageArchive.toJID, " + "ofMessageArchive.sentDate, "
+ "ofConversation.startDate, " + "ofMessageArchive.body " + "FROM ofConversation "
+ "ofConversation.lastActivity, "
+ "ofConversation.messageCount, "
+ "ofConParticipant.joinedDate, "
+ "ofConParticipant.leftDate, "
+ "ofConParticipant.bareJID, "
+ "ofConParticipant.jidResource, "
+ "ofConParticipant.nickname, "
+ "ofMessageArchive.fromJID, "
+ "ofMessageArchive.toJID, "
+ "ofMessageArchive.sentDate, "
+ "ofMessageArchive.body "
+ "FROM ofConversation "
+ "INNER JOIN ofConParticipant ON ofConversation.conversationID = ofConParticipant.conversationID " + "INNER JOIN ofConParticipant ON ofConversation.conversationID = ofConParticipant.conversationID "
+ "INNER JOIN ofMessageArchive ON ofConParticipant.conversationID = ofMessageArchive.conversationID " + "INNER JOIN ofMessageArchive ON ofConParticipant.conversationID = ofMessageArchive.conversationID "
+ "WHERE ofConversation.conversationID = ? AND ofConParticipant.bareJID = ? ORDER BY ofMessageArchive.sentDate"; + "WHERE ofConversation.conversationID = ? AND ofConParticipant.bareJID = ? ORDER BY ofMessageArchive.sentDate";
...@@ -55,23 +47,11 @@ public class JdbcPersistenceManager implements PersistenceManager { ...@@ -55,23 +47,11 @@ public class JdbcPersistenceManager implements PersistenceManager {
// "SELECT messageId,time,direction,type,subject,body " // "SELECT messageId,time,direction,type,subject,body "
// + "FROM archiveMessages WHERE conversationId = ? ORDER BY time"; // + "FROM archiveMessages WHERE conversationId = ? ORDER BY time";
public static final String SELECT_CONVERSATIONS = "SELECT DISTINCT " public static final String SELECT_CONVERSATIONS = "SELECT DISTINCT " + "ofConversation.conversationID, " + "ofConversation.room, "
+ "ofConversation.conversationID, " + "ofConversation.isExternal, " + "ofConversation.startDate, " + "ofConversation.lastActivity, " + "ofConversation.messageCount, "
+ "ofConversation.room, " + "ofConParticipant.joinedDate, " + "ofConParticipant.leftDate, " + "ofConParticipant.bareJID, " + "ofConParticipant.jidResource, "
+ "ofConversation.isExternal, " + "ofConParticipant.nickname, " + "ofMessageArchive.fromJID, " + "ofMessageArchive.toJID, " + "ofMessageArchive.sentDate, "
+ "ofConversation.startDate, " + "ofMessageArchive.body " + "FROM ofConversation "
+ "ofConversation.lastActivity, "
+ "ofConversation.messageCount, "
+ "ofConParticipant.joinedDate, "
+ "ofConParticipant.leftDate, "
+ "ofConParticipant.bareJID, "
+ "ofConParticipant.jidResource, "
+ "ofConParticipant.nickname, "
+ "ofMessageArchive.fromJID, "
+ "ofMessageArchive.toJID, "
+ "ofMessageArchive.sentDate, "
+ "ofMessageArchive.body "
+ "FROM ofConversation "
+ "INNER JOIN ofConParticipant ON ofConversation.conversationID = ofConParticipant.conversationID " + "INNER JOIN ofConParticipant ON ofConversation.conversationID = ofConParticipant.conversationID "
+ "INNER JOIN ofMessageArchive ON ofConParticipant.conversationID = ofMessageArchive.conversationID"; + "INNER JOIN ofMessageArchive ON ofConParticipant.conversationID = ofMessageArchive.conversationID";
...@@ -101,23 +81,11 @@ public class JdbcPersistenceManager implements PersistenceManager { ...@@ -101,23 +81,11 @@ public class JdbcPersistenceManager implements PersistenceManager {
public static final String CONVERSATION_WITH_JID = "(ofMessageArchive.toJID = ? OR ofMessageArchive.fromJID = ?)"; public static final String CONVERSATION_WITH_JID = "(ofMessageArchive.toJID = ? OR ofMessageArchive.fromJID = ?)";
// public static final String CONVERSATION_WITH_JID = "c.withJid"; // public static final String CONVERSATION_WITH_JID = "c.withJid";
public static final String SELECT_ACTIVE_CONVERSATIONS = "SELECT DISTINCT " public static final String SELECT_ACTIVE_CONVERSATIONS = "SELECT DISTINCT " + "ofConversation.conversationID, " + "ofConversation.room, "
+ "ofConversation.conversationID, " + "ofConversation.isExternal, " + "ofConversation.startDate, " + "ofConversation.lastActivity, " + "ofConversation.messageCount, "
+ "ofConversation.room, " + "ofConParticipant.joinedDate, " + "ofConParticipant.leftDate, " + "ofConParticipant.bareJID, " + "ofConParticipant.jidResource, "
+ "ofConversation.isExternal, " + "ofConParticipant.nickname, " + "ofMessageArchive.fromJID, " + "ofMessageArchive.toJID, " + "ofMessageArchive.sentDate, "
+ "ofConversation.startDate, " + "ofMessageArchive.body " + "FROM ofConversation "
+ "ofConversation.lastActivity, "
+ "ofConversation.messageCount, "
+ "ofConParticipant.joinedDate, "
+ "ofConParticipant.leftDate, "
+ "ofConParticipant.bareJID, "
+ "ofConParticipant.jidResource, "
+ "ofConParticipant.nickname, "
+ "ofMessageArchive.fromJID, "
+ "ofMessageArchive.toJID, "
+ "ofMessageArchive.sentDate, "
+ "ofMessageArchive.body "
+ "FROM ofConversation "
+ "INNER JOIN ofConParticipant ON ofConversation.conversationID = ofConParticipant.conversationID " + "INNER JOIN ofConParticipant ON ofConversation.conversationID = ofConParticipant.conversationID "
+ "INNER JOIN ofMessageArchive ON ofConParticipant.conversationID = ofMessageArchive.conversationID " + "INNER JOIN ofMessageArchive ON ofConParticipant.conversationID = ofMessageArchive.conversationID "
+ "WHERE ofConversation.lastActivity > ?"; + "WHERE ofConversation.lastActivity > ?";
...@@ -127,12 +95,8 @@ public class JdbcPersistenceManager implements PersistenceManager { ...@@ -127,12 +95,8 @@ public class JdbcPersistenceManager implements PersistenceManager {
// + " c.subject,c.thread " // + " c.subject,c.thread "
// + "FROM archiveConversations AS c WHERE c.endTime > ?"; // + "FROM archiveConversations AS c WHERE c.endTime > ?";
public static final String SELECT_PARTICIPANTS_BY_CONVERSATION = "SELECT DISTINCT " public static final String SELECT_PARTICIPANTS_BY_CONVERSATION = "SELECT DISTINCT " + "ofConversation.conversationID, "
+ "ofConversation.conversationID, " + "ofConversation.startDate, " + "ofConversation.lastActivity, " + "ofConParticipant.bareJID " + "FROM ofConversation "
+ "ofConversation.startDate, "
+ "ofConversation.lastActivity, "
+ "ofConParticipant.bareJID "
+ "FROM ofConversation "
+ "INNER JOIN ofConParticipant ON ofConversation.conversationID = ofConParticipant.conversationID " + "INNER JOIN ofConParticipant ON ofConversation.conversationID = ofConParticipant.conversationID "
+ "INNER JOIN ofMessageArchive ON ofConParticipant.conversationID = ofMessageArchive.conversationID " + "INNER JOIN ofMessageArchive ON ofConParticipant.conversationID = ofMessageArchive.conversationID "
+ "WHERE ofConversation.conversationID = ? ORDER BY ofConversation.startDate"; + "WHERE ofConversation.conversationID = ? ORDER BY ofConversation.startDate";
...@@ -159,20 +123,32 @@ public class JdbcPersistenceManager implements PersistenceManager { ...@@ -159,20 +123,32 @@ public class JdbcPersistenceManager implements PersistenceManager {
return false; return false;
} }
public boolean createParticipant(Participant participant, public boolean createParticipant(Participant participant, Long conversationId) {
Long conversationId) {
return false; return false;
} }
public List<Conversation> findConversations(String[] participants, public List<Conversation> findConversations(String[] participants, Date startDate, Date endDate) {
Date startDate, Date endDate) {
final List<Conversation> conversations = new ArrayList<Conversation>(); final List<Conversation> conversations = new ArrayList<Conversation>();
return conversations; return conversations;
} }
public Collection<Conversation> findConversations(Date startDate, public Date getAuditedStartDate(Date startDate) {
Date endDate, String ownerJid, String withJid, long maxRetrievable = JiveGlobals.getIntProperty("conversation.maxRetrievable", ConversationManager.DEFAULT_MAX_RETRIEVABLE)
XmppResultSet xmppResultSet) { * JiveConstants.DAY;
Date result = null;
if (maxRetrievable > 0) {
Date now = new Date();
Date maxRetrievableDate = new Date(now.getTime() - maxRetrievable);
if (startDate == null) {
result = maxRetrievableDate;
} else if (startDate.before(maxRetrievableDate)) {
result = maxRetrievableDate;
}
}
return result;
}
public Collection<Conversation> findConversations(Date startDate, Date endDate, String ownerJid, String withJid, XmppResultSet xmppResultSet) {
final HashMap<Long, Conversation> conversations; final HashMap<Long, Conversation> conversations;
final StringBuilder querySB; final StringBuilder querySB;
final StringBuilder whereSB; final StringBuilder whereSB;
...@@ -184,6 +160,7 @@ public class JdbcPersistenceManager implements PersistenceManager { ...@@ -184,6 +160,7 @@ public class JdbcPersistenceManager implements PersistenceManager {
whereSB = new StringBuilder(); whereSB = new StringBuilder();
limitSB = new StringBuilder(); limitSB = new StringBuilder();
startDate = getAuditedStartDate(startDate);
if (startDate != null) { if (startDate != null) {
appendWhere(whereSB, CONVERSATION_START_TIME, " >= ?"); appendWhere(whereSB, CONVERSATION_START_TIME, " >= ?");
} }
...@@ -199,22 +176,16 @@ public class JdbcPersistenceManager implements PersistenceManager { ...@@ -199,22 +176,16 @@ public class JdbcPersistenceManager implements PersistenceManager {
if (xmppResultSet != null) { if (xmppResultSet != null) {
Integer firstIndex = null; Integer firstIndex = null;
int max = xmppResultSet.getMax() != null ? xmppResultSet.getMax() int max = xmppResultSet.getMax() != null ? xmppResultSet.getMax() : DEFAULT_MAX;
: DEFAULT_MAX;
xmppResultSet.setCount(countConversations(startDate, endDate, xmppResultSet.setCount(countConversations(startDate, endDate, ownerJid, withJid, whereSB.toString()));
ownerJid, withJid, whereSB.toString()));
if (xmppResultSet.getIndex() != null) { if (xmppResultSet.getIndex() != null) {
firstIndex = xmppResultSet.getIndex(); firstIndex = xmppResultSet.getIndex();
} else if (xmppResultSet.getAfter() != null) { } else if (xmppResultSet.getAfter() != null) {
firstIndex = countConversationsBefore(startDate, endDate, firstIndex = countConversationsBefore(startDate, endDate, ownerJid, withJid, xmppResultSet.getAfter(), whereSB.toString());
ownerJid, withJid, xmppResultSet.getAfter(),
whereSB.toString());
firstIndex += 1; firstIndex += 1;
} else if (xmppResultSet.getBefore() != null) { } else if (xmppResultSet.getBefore() != null) {
firstIndex = countConversationsBefore(startDate, endDate, firstIndex = countConversationsBefore(startDate, endDate, ownerJid, withJid, xmppResultSet.getBefore(), whereSB.toString());
ownerJid, withJid, xmppResultSet.getBefore(),
whereSB.toString());
firstIndex -= max; firstIndex -= max;
if (firstIndex < 0) { if (firstIndex < 0) {
firstIndex = 0; firstIndex = 0;
...@@ -239,11 +210,9 @@ public class JdbcPersistenceManager implements PersistenceManager { ...@@ -239,11 +210,9 @@ public class JdbcPersistenceManager implements PersistenceManager {
try { try {
con = DbConnectionManager.getConnection(); con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(querySB.toString()); pstmt = con.prepareStatement(querySB.toString());
bindConversationParameters(startDate, endDate, ownerJid, withJid, bindConversationParameters(startDate, endDate, ownerJid, withJid, pstmt);
pstmt);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
Log.debug("findConversations: SELECT_CONVERSATIONS: " Log.debug("findConversations: SELECT_CONVERSATIONS: " + pstmt.toString());
+ pstmt.toString());
while (rs.next()) { while (rs.next()) {
Conversation conv = extractConversation(rs); Conversation conv = extractConversation(rs);
conversations.put(conv.getId(), conv); conversations.put(conv.getId(), conv);
...@@ -255,12 +224,10 @@ public class JdbcPersistenceManager implements PersistenceManager { ...@@ -255,12 +224,10 @@ public class JdbcPersistenceManager implements PersistenceManager {
} }
if (xmppResultSet != null && conversations.size() > 0) { if (xmppResultSet != null && conversations.size() > 0) {
ArrayList<Long> sortedConvKeys = new ArrayList<Long>( ArrayList<Long> sortedConvKeys = new ArrayList<Long>(conversations.keySet());
conversations.keySet());
Collections.sort(sortedConvKeys); Collections.sort(sortedConvKeys);
xmppResultSet.setFirst(sortedConvKeys.get(0)); xmppResultSet.setFirst(sortedConvKeys.get(0));
xmppResultSet xmppResultSet.setLast(sortedConvKeys.get(sortedConvKeys.size() - 1));
.setLast(sortedConvKeys.get(sortedConvKeys.size() - 1));
} }
return conversations.values(); return conversations.values();
} }
...@@ -275,8 +242,7 @@ public class JdbcPersistenceManager implements PersistenceManager { ...@@ -275,8 +242,7 @@ public class JdbcPersistenceManager implements PersistenceManager {
} }
} }
private int countConversations(Date startDate, Date endDate, private int countConversations(Date startDate, Date endDate, String ownerJid, String withJid, String whereClause) {
String ownerJid, String withJid, String whereClause) {
StringBuilder querySB; StringBuilder querySB;
querySB = new StringBuilder(COUNT_CONVERSATIONS); querySB = new StringBuilder(COUNT_CONVERSATIONS);
...@@ -290,8 +256,7 @@ public class JdbcPersistenceManager implements PersistenceManager { ...@@ -290,8 +256,7 @@ public class JdbcPersistenceManager implements PersistenceManager {
try { try {
con = DbConnectionManager.getConnection(); con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(querySB.toString()); pstmt = con.prepareStatement(querySB.toString());
bindConversationParameters(startDate, endDate, ownerJid, withJid, bindConversationParameters(startDate, endDate, ownerJid, withJid, pstmt);
pstmt);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) { if (rs.next()) {
return rs.getInt(1); return rs.getInt(1);
...@@ -306,8 +271,7 @@ public class JdbcPersistenceManager implements PersistenceManager { ...@@ -306,8 +271,7 @@ public class JdbcPersistenceManager implements PersistenceManager {
} }
} }
private int countConversationsBefore(Date startDate, Date endDate, private int countConversationsBefore(Date startDate, Date endDate, String ownerJid, String withJid, Long before, String whereClause) {
String ownerJid, String withJid, Long before, String whereClause) {
StringBuilder querySB; StringBuilder querySB;
querySB = new StringBuilder(COUNT_CONVERSATIONS); querySB = new StringBuilder(COUNT_CONVERSATIONS);
...@@ -325,8 +289,7 @@ public class JdbcPersistenceManager implements PersistenceManager { ...@@ -325,8 +289,7 @@ public class JdbcPersistenceManager implements PersistenceManager {
int parameterIndex; int parameterIndex;
con = DbConnectionManager.getConnection(); con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(querySB.toString()); pstmt = con.prepareStatement(querySB.toString());
parameterIndex = bindConversationParameters(startDate, endDate, parameterIndex = bindConversationParameters(startDate, endDate, ownerJid, withJid, pstmt);
ownerJid, withJid, pstmt);
pstmt.setLong(parameterIndex, before); pstmt.setLong(parameterIndex, before);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) { if (rs.next()) {
...@@ -342,8 +305,7 @@ public class JdbcPersistenceManager implements PersistenceManager { ...@@ -342,8 +305,7 @@ public class JdbcPersistenceManager implements PersistenceManager {
} }
} }
private int bindConversationParameters(Date startDate, Date endDate, private int bindConversationParameters(Date startDate, Date endDate, String ownerJid, String withJid, PreparedStatement pstmt)
String ownerJid, String withJid, PreparedStatement pstmt)
throws SQLException { throws SQLException {
int parameterIndex = 1; int parameterIndex = 1;
...@@ -363,8 +325,7 @@ public class JdbcPersistenceManager implements PersistenceManager { ...@@ -363,8 +325,7 @@ public class JdbcPersistenceManager implements PersistenceManager {
return parameterIndex; return parameterIndex;
} }
public Collection<Conversation> getActiveConversations( public Collection<Conversation> getActiveConversations(int conversationTimeout) {
int conversationTimeout) {
final Collection<Conversation> conversations; final Collection<Conversation> conversations;
final long now = System.currentTimeMillis(); final long now = System.currentTimeMillis();
...@@ -438,8 +399,7 @@ public class JdbcPersistenceManager implements PersistenceManager { ...@@ -438,8 +399,7 @@ public class JdbcPersistenceManager implements PersistenceManager {
return conversations; return conversations;
} }
public Conversation getConversation(String ownerJid, String withJid, public Conversation getConversation(String ownerJid, String withJid, Date start) {
Date start) {
return getConversation(null, ownerJid, withJid, start); return getConversation(null, ownerJid, withJid, start);
} }
...@@ -447,8 +407,7 @@ public class JdbcPersistenceManager implements PersistenceManager { ...@@ -447,8 +407,7 @@ public class JdbcPersistenceManager implements PersistenceManager {
return getConversation(conversationId, null, null, null); return getConversation(conversationId, null, null, null);
} }
private Conversation getConversation(Long conversationId, String ownerJid, private Conversation getConversation(Long conversationId, String ownerJid, String withJid, Date start) {
String withJid, Date start) {
Conversation conversation = null; Conversation conversation = null;
StringBuilder querySB; StringBuilder querySB;
...@@ -490,8 +449,7 @@ public class JdbcPersistenceManager implements PersistenceManager { ...@@ -490,8 +449,7 @@ public class JdbcPersistenceManager implements PersistenceManager {
} }
} }
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
Log.debug("getConversation: SELECT_CONVERSATIONS: " Log.debug("getConversation: SELECT_CONVERSATIONS: " + pstmt.toString());
+ pstmt.toString());
if (rs.next()) { if (rs.next()) {
conversation = extractConversation(rs); conversation = extractConversation(rs);
} else { } else {
...@@ -505,8 +463,7 @@ public class JdbcPersistenceManager implements PersistenceManager { ...@@ -505,8 +463,7 @@ public class JdbcPersistenceManager implements PersistenceManager {
pstmt.setLong(1, conversation.getId()); pstmt.setLong(1, conversation.getId());
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
Log.debug("getConversation: SELECT_PARTICIPANTS_BY_CONVERSATION: " Log.debug("getConversation: SELECT_PARTICIPANTS_BY_CONVERSATION: " + pstmt.toString());
+ pstmt.toString());
while (rs.next()) { while (rs.next()) {
for (Participant participant : extractParticipant(rs)) { for (Participant participant : extractParticipant(rs)) {
...@@ -522,8 +479,7 @@ public class JdbcPersistenceManager implements PersistenceManager { ...@@ -522,8 +479,7 @@ public class JdbcPersistenceManager implements PersistenceManager {
pstmt.setString(2, conversation.getOwnerJid()); pstmt.setString(2, conversation.getOwnerJid());
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
Log.debug("getConversation: SELECT_MESSAGES_BY_CONVERSATION: " Log.debug("getConversation: SELECT_MESSAGES_BY_CONVERSATION: " + pstmt.toString());
+ pstmt.toString());
while (rs.next()) { while (rs.next()) {
ArchivedMessage message; ArchivedMessage message;
...@@ -567,14 +523,12 @@ public class JdbcPersistenceManager implements PersistenceManager { ...@@ -567,14 +523,12 @@ public class JdbcPersistenceManager implements PersistenceManager {
if (bareJid != null && fromJid != null && toJid != null) { if (bareJid != null && fromJid != null && toJid != null) {
if (bareJid.equals(fromJid)) { if (bareJid.equals(fromJid)) {
/* /*
* if message from me to withJid then it is to the withJid * if message from me to withJid then it is to the withJid participant
* participant
*/ */
direction = Direction.to; direction = Direction.to;
} else { } else {
/* /*
* if message to me from withJid then it is from the withJid * if message to me from withJid then it is from the withJid participant
* participant
*/ */
direction = Direction.from; direction = Direction.from;
} }
...@@ -594,14 +548,12 @@ public class JdbcPersistenceManager implements PersistenceManager { ...@@ -594,14 +548,12 @@ public class JdbcPersistenceManager implements PersistenceManager {
String subject = null; String subject = null;
String thread = String.valueOf(id); String thread = String.valueOf(id);
conversation = new Conversation(startDate, ownerJid, ownerResource, conversation = new Conversation(startDate, ownerJid, ownerResource, withJid, withResource, subject, thread);
withJid, withResource, subject, thread);
conversation.setId(id); conversation.setId(id);
return conversation; return conversation;
} }
private Collection<Participant> extractParticipant(ResultSet rs) private Collection<Participant> extractParticipant(ResultSet rs) throws SQLException {
throws SQLException {
Collection<Participant> participants = new HashSet<Participant>(); Collection<Participant> participants = new HashSet<Participant>();
Date startDate = millisToDate(rs.getLong("startDate")); Date startDate = millisToDate(rs.getLong("startDate"));
......
...@@ -67,17 +67,14 @@ import org.xmpp.packet.JID; ...@@ -67,17 +67,14 @@ import org.xmpp.packet.JID;
import org.xmpp.packet.Message; import org.xmpp.packet.Message;
/** /**
* Manages all conversations in the system. Optionally, conversations (messages plus * Manages all conversations in the system. Optionally, conversations (messages plus meta-data) can be archived to the database. Archiving of
* meta-data) can be archived to the database. Archiving of conversation data is * conversation data is enabled by default, but can be disabled by setting "conversation.metadataArchiving" to <tt>false</tt>. Archiving of messages
* enabled by default, but can be disabled by setting "conversation.metadataArchiving" to * in a conversation is disabled by default, but can be enabled by setting "conversation.messageArchiving" to <tt>true</tt>.
* <tt>false</tt>. Archiving of messages in a conversation is disabled by default, but * <p>
* can be enabled by setting "conversation.messageArchiving" to <tt>true</tt>.<p>
* *
* When running in a cluster only the senior cluster member will keep track of the active * When running in a cluster only the senior cluster member will keep track of the active conversations. Other cluster nodes will forward conversation
* conversations. Other cluster nodes will forward conversation events that occurred in the * events that occurred in the local node to the senior cluster member. If the senior cluster member goes down then current conversations will be
* local node to the senior cluster member. If the senior cluster member goes down then * terminated and if users keep sending messages between them then new conversations will be created.
* current conversations will be terminated and if users keep sending messages between them
* then new conversations will be created.
* *
* @author Matt Tucker * @author Matt Tucker
*/ */
...@@ -85,21 +82,19 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -85,21 +82,19 @@ public class ConversationManager implements Startable, ComponentEventListener {
private static final Logger Log = LoggerFactory.getLogger(ConversationManager.class); private static final Logger Log = LoggerFactory.getLogger(ConversationManager.class);
private static final String UPDATE_CONVERSATION = private static final String UPDATE_CONVERSATION = "UPDATE ofConversation SET lastActivity=?, messageCount=? WHERE conversationID=?";
"UPDATE ofConversation SET lastActivity=?, messageCount=? WHERE conversationID=?"; private static final String UPDATE_PARTICIPANT = "UPDATE ofConParticipant SET leftDate=? WHERE conversationID=? AND bareJID=? AND jidResource=? AND joinedDate=?";
private static final String UPDATE_PARTICIPANT = private static final String INSERT_MESSAGE = "INSERT INTO ofMessageArchive(conversationID, fromJID, fromJIDResource, toJID, toJIDResource, sentDate, body) "
"UPDATE ofConParticipant SET leftDate=? WHERE conversationID=? AND bareJID=? AND jidResource=? AND joinedDate=?"; + "VALUES (?,?,?,?,?,?,?)";
private static final String INSERT_MESSAGE = private static final String CONVERSATION_COUNT = "SELECT COUNT(*) FROM ofConversation";
"INSERT INTO ofMessageArchive(conversationID, fromJID, fromJIDResource, toJID, toJIDResource, sentDate, body) " + private static final String MESSAGE_COUNT = "SELECT COUNT(*) FROM ofMessageArchive";
"VALUES (?,?,?,?,?,?,?)";
private static final String CONVERSATION_COUNT =
"SELECT COUNT(*) FROM ofConversation";
private static final String MESSAGE_COUNT =
"SELECT COUNT(*) FROM ofMessageArchive";
private static final int DEFAULT_IDLE_TIME = 10; private static final int DEFAULT_IDLE_TIME = 10;
private static final int DEFAULT_MAX_TIME = 60; private static final int DEFAULT_MAX_TIME = 60;
public static final int DEFAULT_MAX_RETRIEVABLE = 0;
private static final int DEFAULT_MAX_AGE = 0;
public static final String CONVERSATIONS_KEY = "conversations"; public static final String CONVERSATIONS_KEY = "conversations";
private ConversationEventsQueue conversationEventsQueue; private ConversationEventsQueue conversationEventsQueue;
...@@ -116,19 +111,19 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -116,19 +111,19 @@ public class ConversationManager implements Startable, ComponentEventListener {
*/ */
private boolean roomArchivingEnabled; private boolean roomArchivingEnabled;
/** /**
* List of room names to archive. When list is empty then all rooms are archived (if * List of room names to archive. When list is empty then all rooms are archived (if roomArchivingEnabled is enabled).
* roomArchivingEnabled is enabled).
*/ */
private Collection<String> roomsArchived; private Collection<String> roomsArchived;
private long idleTime; private long idleTime;
private long maxTime; private long maxTime;
private long maxAge;
private long maxRetrievable;
private PropertyEventListener propertyListener; private PropertyEventListener propertyListener;
private Queue<Conversation> conversationQueue; private Queue<Conversation> conversationQueue;
private Queue<ArchivedMessage> messageQueue; private Queue<ArchivedMessage> messageQueue;
/** /**
* Queue of participants that joined or left a conversation. This queue is processed by the * Queue of participants that joined or left a conversation. This queue is processed by the ArchivingTask.
* ArchivingTask.
*/ */
private Queue<RoomParticipant> participantQueue; private Queue<RoomParticipant> participantQueue;
...@@ -137,6 +132,8 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -137,6 +132,8 @@ public class ConversationManager implements Startable, ComponentEventListener {
private TimerTask archiveTask; private TimerTask archiveTask;
private TimerTask cleanupTask; private TimerTask cleanupTask;
private TimerTask maxAgeTask;
private Collection<ConversationListener> conversationListeners; private Collection<ConversationListener> conversationListeners;
/** /**
...@@ -165,10 +162,12 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -165,10 +162,12 @@ public class ConversationManager implements Startable, ComponentEventListener {
Log.warn("Metadata archiving must be enabled when room archiving is enabled. Overriding setting."); Log.warn("Metadata archiving must be enabled when room archiving is enabled. Overriding setting.");
metadataArchivingEnabled = true; metadataArchivingEnabled = true;
} }
idleTime = JiveGlobals.getIntProperty("conversation.idleTime", DEFAULT_IDLE_TIME) * idleTime = JiveGlobals.getIntProperty("conversation.idleTime", DEFAULT_IDLE_TIME) * JiveConstants.MINUTE;
JiveConstants.MINUTE; maxTime = JiveGlobals.getIntProperty("conversation.maxTime", DEFAULT_MAX_TIME) * JiveConstants.MINUTE;
maxTime = JiveGlobals.getIntProperty("conversation.maxTime",
DEFAULT_MAX_TIME) * JiveConstants.MINUTE; maxAge = JiveGlobals.getIntProperty("conversation.maxAge", DEFAULT_MAX_AGE) * JiveConstants.DAY;
maxRetrievable = JiveGlobals.getIntProperty("conversation.maxRetrievable", DEFAULT_MAX_RETRIEVABLE) * JiveConstants.DAY;
// Listen for any changes to the conversation properties. // Listen for any changes to the conversation properties.
propertyListener = new ConversationPropertyListener(); propertyListener = new ConversationPropertyListener();
PropertyEventDispatcher.addListener(propertyListener); PropertyEventDispatcher.addListener(propertyListener);
...@@ -195,8 +194,7 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -195,8 +194,7 @@ public class ConversationManager implements Startable, ComponentEventListener {
for (String key : conversations.keySet()) { for (String key : conversations.keySet()) {
Conversation conversation = conversations.get(key); Conversation conversation = conversations.get(key);
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
if ((now - conversation.getLastActivity().getTime() > idleTime) || if ((now - conversation.getLastActivity().getTime() > idleTime) || (now - conversation.getStartDate().getTime() > maxTime)) {
(now - conversation.getStartDate().getTime() > maxTime)) {
removeConversation(key, conversation, new Date(now)); removeConversation(key, conversation, new Date(now));
} }
} }
...@@ -204,6 +202,16 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -204,6 +202,16 @@ public class ConversationManager implements Startable, ComponentEventListener {
}; };
taskEngine.scheduleAtFixedRate(cleanupTask, JiveConstants.MINUTE * 5, JiveConstants.MINUTE * 5); taskEngine.scheduleAtFixedRate(cleanupTask, JiveConstants.MINUTE * 5, JiveConstants.MINUTE * 5);
// Schedule a task to do conversation purging.
maxAgeTask = new TimerTask() {
@Override
public void run() {
// Delete conversations older than maxAge days
// TODO
}
};
taskEngine.scheduleAtFixedRate(maxAgeTask, JiveConstants.MINUTE, JiveConstants.DAY);
// Register a statistic. // Register a statistic.
Statistic conversationStat = new Statistic() { Statistic conversationStat = new Statistic() {
...@@ -266,9 +274,8 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -266,9 +274,8 @@ public class ConversationManager implements Startable, ComponentEventListener {
} }
/** /**
* Returns true if metadata archiving is enabled. Conversation meta-data includes * Returns true if metadata archiving is enabled. Conversation meta-data includes the participants, start date, last activity, and the count of
* the participants, start date, last activity, and the count of messages sent. * messages sent. When archiving is enabled, all meta-data is written to the database.
* When archiving is enabled, all meta-data is written to the database.
* *
* @return true if metadata archiving is enabled. * @return true if metadata archiving is enabled.
*/ */
...@@ -277,11 +284,11 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -277,11 +284,11 @@ public class ConversationManager implements Startable, ComponentEventListener {
} }
/** /**
* Sets whether metadata archiving is enabled. Conversation meta-data includes * Sets whether metadata archiving is enabled. Conversation meta-data includes the participants, start date, last activity, and the count of
* the participants, start date, last activity, and the count of messages sent. * messages sent. When archiving is enabled, all meta-data is written to the database.
* When archiving is enabled, all meta-data is written to the database.
* *
* @param enabled true if archiving should be enabled. * @param enabled
* true if archiving should be enabled.
*/ */
public void setMetadataArchivingEnabled(boolean enabled) { public void setMetadataArchivingEnabled(boolean enabled) {
this.metadataArchivingEnabled = enabled; this.metadataArchivingEnabled = enabled;
...@@ -298,10 +305,9 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -298,10 +305,9 @@ public class ConversationManager implements Startable, ComponentEventListener {
} }
/** /**
* Returns true if message archiving is enabled for one-to-one chats. When enabled, all messages * Returns true if message archiving is enabled for one-to-one chats. When enabled, all messages in one-to-one conversations are stored in the
* in one-to-one conversations are stored in the database. Note: it's not possible for * database. Note: it's not possible for meta-data archiving to be disabled when message archiving is enabled; enabling message archiving
* meta-data archiving to be disabled when message archiving is enabled; enabling * automatically enables meta-data archiving.
* message archiving automatically enables meta-data archiving.
* *
* @return true if message archiving is enabled. * @return true if message archiving is enabled.
*/ */
...@@ -310,12 +316,11 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -310,12 +316,11 @@ public class ConversationManager implements Startable, ComponentEventListener {
} }
/** /**
* Sets whether message archiving is enabled. When enabled, all messages * Sets whether message archiving is enabled. When enabled, all messages in conversations are stored in the database. Note: it's not possible for
* in conversations are stored in the database. Note: it's not possible for * meta-data archiving to be disabled when message archiving is enabled; enabling message archiving automatically enables meta-data archiving.
* meta-data archiving to be disabled when message archiving is enabled; enabling
* message archiving automatically enables meta-data archiving.
* *
* @param enabled true if message should be enabled. * @param enabled
* true if message should be enabled.
*/ */
public void setMessageArchivingEnabled(boolean enabled) { public void setMessageArchivingEnabled(boolean enabled) {
this.messageArchivingEnabled = enabled; this.messageArchivingEnabled = enabled;
...@@ -327,11 +332,9 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -327,11 +332,9 @@ public class ConversationManager implements Startable, ComponentEventListener {
} }
/** /**
* Returns true if message archiving is enabled for group chats. When enabled, all messages * Returns true if message archiving is enabled for group chats. When enabled, all messages in group conversations are stored in the database
* in group conversations are stored in the database unless a list of rooms was specified * unless a list of rooms was specified in {@link #getRoomsArchived()} . Note: it's not possible for meta-data archiving to be disabled when room
* in {@link #getRoomsArchived()} . Note: it's not possible for meta-data archiving to be * archiving is enabled; enabling room archiving automatically enables meta-data archiving.
* disabled when room archiving is enabled; enabling room archiving automatically
* enables meta-data archiving.
* *
* @return true if room archiving is enabled. * @return true if room archiving is enabled.
*/ */
...@@ -340,13 +343,12 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -340,13 +343,12 @@ public class ConversationManager implements Startable, ComponentEventListener {
} }
/** /**
* Sets whether message archiving is enabled for group chats. When enabled, all messages * Sets whether message archiving is enabled for group chats. When enabled, all messages in group conversations are stored in the database unless
* in group conversations are stored in the database unless a list of rooms was specified * a list of rooms was specified in {@link #getRoomsArchived()} . Note: it's not possible for meta-data archiving to be disabled when room
* in {@link #getRoomsArchived()} . Note: it's not possible for meta-data archiving to be * archiving is enabled; enabling room archiving automatically enables meta-data archiving.
* disabled when room archiving is enabled; enabling room archiving automatically
* enables meta-data archiving.
* *
* @param enabled if room archiving is enabled. * @param enabled
* if room archiving is enabled.
*/ */
public void setRoomArchivingEnabled(boolean enabled) { public void setRoomArchivingEnabled(boolean enabled) {
this.roomArchivingEnabled = enabled; this.roomArchivingEnabled = enabled;
...@@ -358,9 +360,8 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -358,9 +360,8 @@ public class ConversationManager implements Startable, ComponentEventListener {
} }
/** /**
* Returns list of room names whose messages will be archived. When room archiving is enabled and * Returns list of room names whose messages will be archived. When room archiving is enabled and this list is empty then messages of all local
* this list is empty then messages of all local rooms will be archived. However, when name of * rooms will be archived. However, when name of rooms are defined in this list then only messages of those rooms will be archived.
* rooms are defined in this list then only messages of those rooms will be archived.
* *
* @return list of local room names whose messages will be archived. * @return list of local room names whose messages will be archived.
*/ */
...@@ -369,11 +370,11 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -369,11 +370,11 @@ public class ConversationManager implements Startable, ComponentEventListener {
} }
/** /**
* Sets list of room names whose messages will be archived. When room archiving is enabled and * Sets list of room names whose messages will be archived. When room archiving is enabled and this list is empty then messages of all local rooms
* this list is empty then messages of all local rooms will be archived. However, when name of * will be archived. However, when name of rooms are defined in this list then only messages of those rooms will be archived.
* rooms are defined in this list then only messages of those rooms will be archived.
* *
* @param roomsArchived list of local room names whose messages will be archived. * @param roomsArchived
* list of local room names whose messages will be archived.
*/ */
public void setRoomsArchived(Collection<String> roomsArchived) { public void setRoomsArchived(Collection<String> roomsArchived) {
this.roomsArchived = roomsArchived; this.roomsArchived = roomsArchived;
...@@ -386,14 +387,16 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -386,14 +387,16 @@ public class ConversationManager implements Startable, ComponentEventListener {
* @return the conversation idle time. * @return the conversation idle time.
*/ */
public int getIdleTime() { public int getIdleTime() {
return (int)(idleTime / JiveConstants.MINUTE); return (int) (idleTime / JiveConstants.MINUTE);
} }
/** /**
* Sets the number of minutes a conversation can be idle before it's ended. * Sets the number of minutes a conversation can be idle before it's ended.
* *
* @param idleTime the max number of minutes a conversation can be idle before it's ended. * @param idleTime
* @throws IllegalArgumentException if idleTime is less than 1. * the max number of minutes a conversation can be idle before it's ended.
* @throws IllegalArgumentException
* if idleTime is less than 1.
*/ */
public void setIdleTime(int idleTime) { public void setIdleTime(int idleTime) {
if (idleTime < 1) { if (idleTime < 1) {
...@@ -404,23 +407,23 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -404,23 +407,23 @@ public class ConversationManager implements Startable, ComponentEventListener {
} }
/** /**
* Returns the maximum number of minutes a conversation can last before it's ended. * Returns the maximum number of minutes a conversation can last before it's ended. Any additional messages between the participants in the chat
* Any additional messages between the participants in the chat will be associated * will be associated with a new conversation.
* with a new conversation.
* *
* @return the maximum number of minutes a conversation can last. * @return the maximum number of minutes a conversation can last.
*/ */
public int getMaxTime() { public int getMaxTime() {
return (int)(maxTime / JiveConstants.MINUTE); return (int) (maxTime / JiveConstants.MINUTE);
} }
/** /**
* Sets the maximum number of minutes a conversation can last before it's ended. * Sets the maximum number of minutes a conversation can last before it's ended. Any additional messages between the participants in the chat will
* Any additional messages between the participants in the chat will be associated * be associated with a new conversation.
* with a new conversation.
* *
* @param maxTime the maximum number of minutes a conversation can last. * @param maxTime
* @throws IllegalArgumentException if maxTime is less than 1. * the maximum number of minutes a conversation can last.
* @throws IllegalArgumentException
* if maxTime is less than 1.
*/ */
public void setMaxTime(int maxTime) { public void setMaxTime(int maxTime) {
if (maxTime < 1) { if (maxTime < 1) {
...@@ -430,6 +433,30 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -430,6 +433,30 @@ public class ConversationManager implements Startable, ComponentEventListener {
this.maxTime = maxTime * JiveConstants.MINUTE; this.maxTime = maxTime * JiveConstants.MINUTE;
} }
public int getMaxAge() {
return (int) (maxAge / JiveConstants.DAY);
}
public void setMaxAge(int maxAge) {
if (maxAge < 0) {
throw new IllegalArgumentException("Max age less than 0 is not valid: " + maxAge);
}
JiveGlobals.setProperty("conversation.maxAge", Integer.toString(maxAge));
this.maxAge = maxAge * JiveConstants.DAY;
}
public int getMaxRetrievable() {
return (int) (maxRetrievable / JiveConstants.DAY);
}
public void setMaxRetrievable(int maxRetrievable) {
if (maxRetrievable < 0) {
throw new IllegalArgumentException("Max retrievable less than 0 is not valid: " + maxRetrievable);
}
JiveGlobals.setProperty("conversation.maxRetrievable", Integer.toString(maxRetrievable));
this.maxRetrievable = maxRetrievable * JiveConstants.DAY;
}
public ConversationEventsQueue getConversationEventsQueue() { public ConversationEventsQueue getConversationEventsQueue() {
return conversationEventsQueue; return conversationEventsQueue;
} }
...@@ -443,16 +470,17 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -443,16 +470,17 @@ public class ConversationManager implements Startable, ComponentEventListener {
if (ClusterManager.isSeniorClusterMember()) { if (ClusterManager.isSeniorClusterMember()) {
return conversations.size(); return conversations.size();
} }
return (Integer) CacheFactory.doSynchronousClusterTask(new GetConversationCountTask(), return (Integer) CacheFactory.doSynchronousClusterTask(new GetConversationCountTask(), ClusterManager.getSeniorClusterMember().toByteArray());
ClusterManager.getSeniorClusterMember().toByteArray());
} }
/** /**
* Returns a conversation by ID. * Returns a conversation by ID.
* *
* @param conversationID the ID of the conversation. * @param conversationID
* the ID of the conversation.
* @return the conversation. * @return the conversation.
* @throws NotFoundException if the conversation could not be found. * @throws NotFoundException
* if the conversation could not be found.
*/ */
public Conversation getConversation(long conversationID) throws NotFoundException { public Conversation getConversation(long conversationID) throws NotFoundException {
if (ClusterManager.isSeniorClusterMember()) { if (ClusterManager.isSeniorClusterMember()) {
...@@ -464,11 +492,10 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -464,11 +492,10 @@ public class ConversationManager implements Startable, ComponentEventListener {
} }
// Otherwise, it might be an archived conversation, so attempt to load it. // Otherwise, it might be an archived conversation, so attempt to load it.
return new Conversation(this, conversationID); return new Conversation(this, conversationID);
} } else {
else {
// Get this info from the senior cluster member when running in a cluster // Get this info from the senior cluster member when running in a cluster
Conversation conversation = (Conversation) CacheFactory.doSynchronousClusterTask( Conversation conversation = (Conversation) CacheFactory.doSynchronousClusterTask(new GetConversationTask(conversationID), ClusterManager
new GetConversationTask(conversationID), ClusterManager.getSeniorClusterMember().toByteArray()); .getSeniorClusterMember().toByteArray());
if (conversation == null) { if (conversation == null) {
throw new NotFoundException("Conversation not found: " + conversationID); throw new NotFoundException("Conversation not found: " + conversationID);
} }
...@@ -491,18 +518,16 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -491,18 +518,16 @@ public class ConversationManager implements Startable, ComponentEventListener {
} }
}); });
return conversationList; return conversationList;
} } else {
else {
// Get this info from the senior cluster member when running in a cluster // Get this info from the senior cluster member when running in a cluster
return (Collection<Conversation>) CacheFactory.doSynchronousClusterTask(new GetConversationsTask(), return (Collection<Conversation>) CacheFactory.doSynchronousClusterTask(new GetConversationsTask(), ClusterManager
ClusterManager.getSeniorClusterMember().toByteArray()); .getSeniorClusterMember().toByteArray());
} }
} }
/** /**
* Returns the total number of conversations that have been archived to the database. * Returns the total number of conversations that have been archived to the database. The archived conversation may only be the meta-data, or it
* The archived conversation may only be the meta-data, or it might include messages * might include messages as well if message archiving is turned on.
* as well if message archiving is turned on.
* *
* @return the total number of archived conversations. * @return the total number of archived conversations.
*/ */
...@@ -518,11 +543,9 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -518,11 +543,9 @@ public class ConversationManager implements Startable, ComponentEventListener {
if (rs.next()) { if (rs.next()) {
conversationCount = rs.getInt(1); conversationCount = rs.getInt(1);
} }
} } catch (SQLException sqle) {
catch (SQLException sqle) {
Log.error(sqle.getMessage(), sqle); Log.error(sqle.getMessage(), sqle);
} } finally {
finally {
DbConnectionManager.closeConnection(rs, pstmt, con); DbConnectionManager.closeConnection(rs, pstmt, con);
} }
return conversationCount; return conversationCount;
...@@ -545,21 +568,19 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -545,21 +568,19 @@ public class ConversationManager implements Startable, ComponentEventListener {
if (rs.next()) { if (rs.next()) {
messageCount = rs.getInt(1); messageCount = rs.getInt(1);
} }
} } catch (SQLException sqle) {
catch (SQLException sqle) {
Log.error(sqle.getMessage(), sqle); Log.error(sqle.getMessage(), sqle);
} } finally {
finally {
DbConnectionManager.closeConnection(rs, pstmt, con); DbConnectionManager.closeConnection(rs, pstmt, con);
} }
return messageCount; return messageCount;
} }
/** /**
* Adds a conversation listener, which will be notified of newly created conversations, * Adds a conversation listener, which will be notified of newly created conversations, conversations ending, and updates to conversations.
* conversations ending, and updates to conversations.
* *
* @param listener the conversation listener. * @param listener
* the conversation listener.
*/ */
public void addConversationListener(ConversationListener listener) { public void addConversationListener(ConversationListener listener) {
conversationListeners.add(listener); conversationListeners.add(listener);
...@@ -568,20 +589,25 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -568,20 +589,25 @@ public class ConversationManager implements Startable, ComponentEventListener {
/** /**
* Removes a conversation listener. * Removes a conversation listener.
* *
* @param listener the conversation listener. * @param listener
* the conversation listener.
*/ */
public void removeConversationListener(ConversationListener listener) { public void removeConversationListener(ConversationListener listener) {
conversationListeners.remove(listener); conversationListeners.remove(listener);
} }
/** /**
* Processes an incoming message of a one-to-one chat. The message will mapped to a * Processes an incoming message of a one-to-one chat. The message will mapped to a conversation and then queued for storage if archiving is
* conversation and then queued for storage if archiving is turned on. * turned on.
* *
* @param sender sender of the message. * @param sender
* @param receiver receiver of the message. * sender of the message.
* @param body body of the message. * @param receiver
* @param date date when the message was sent. * receiver of the message.
* @param body
* body of the message.
* @param date
* date when the message was sent.
*/ */
void processMessage(JID sender, JID receiver, String body, Date date) { void processMessage(JID sender, JID receiver, String body, Date date) {
String conversationKey = getConversationKey(sender, receiver); String conversationKey = getConversationKey(sender, receiver);
...@@ -608,8 +634,8 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -608,8 +634,8 @@ public class ConversationManager implements Startable, ComponentEventListener {
} }
// Check to see if the current conversation exceeds either the max idle time // Check to see if the current conversation exceeds either the max idle time
// or max conversation time. // or max conversation time.
else if ((date.getTime() - conversation.getLastActivity().getTime() > idleTime) || else if ((date.getTime() - conversation.getLastActivity().getTime() > idleTime)
(date.getTime() - conversation.getStartDate().getTime() > maxTime)) { || (date.getTime() - conversation.getStartDate().getTime() > maxTime)) {
removeConversation(conversationKey, conversation, conversation.getLastActivity()); removeConversation(conversationKey, conversation, conversation.getLastActivity());
Collection<JID> participants = new ArrayList<JID>(2); Collection<JID> participants = new ArrayList<JID>(2);
...@@ -635,8 +661,7 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -635,8 +661,7 @@ public class ConversationManager implements Startable, ComponentEventListener {
conversationQueue.add(conversation); conversationQueue.add(conversation);
} }
if (messageArchivingEnabled) { if (messageArchivingEnabled) {
messageQueue messageQueue.add(new ArchivedMessage(conversation.getConversationID(), sender, receiver, date, body, false));
.add(new ArchivedMessage(conversation.getConversationID(), sender, receiver, date, body, false));
} }
// Notify listeners of the conversation update. // Notify listeners of the conversation update.
for (ConversationListener listener : conversationListeners) { for (ConversationListener listener : conversationListeners) {
...@@ -646,14 +671,18 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -646,14 +671,18 @@ public class ConversationManager implements Startable, ComponentEventListener {
} }
/** /**
* Processes an incoming message sent to a room. The message will mapped to a conversation and then * Processes an incoming message sent to a room. The message will mapped to a conversation and then queued for storage if archiving is turned on.
* queued for storage if archiving is turned on.
* *
* @param roomJID the JID of the room where the group conversation is taking place. * @param roomJID
* @param sender the JID of the entity that sent the message. * the JID of the room where the group conversation is taking place.
* @param nickname nickname of the user in the room when the message was sent. * @param sender
* @param body the message sent to the room. * the JID of the entity that sent the message.
* @param date date when the message was sent. * @param nickname
* nickname of the user in the room when the message was sent.
* @param body
* the message sent to the room.
* @param date
* date when the message was sent.
*/ */
void processRoomMessage(JID roomJID, JID sender, String nickname, String body, Date date) { void processRoomMessage(JID roomJID, JID sender, String nickname, String body, Date date) {
String conversationKey = getRoomConversationKey(roomJID); String conversationKey = getRoomConversationKey(roomJID);
...@@ -672,8 +701,8 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -672,8 +701,8 @@ public class ConversationManager implements Startable, ComponentEventListener {
} }
// Check to see if the current conversation exceeds either the max idle time // Check to see if the current conversation exceeds either the max idle time
// or max conversation time. // or max conversation time.
else if ((date.getTime() - conversation.getLastActivity().getTime() > idleTime) || else if ((date.getTime() - conversation.getLastActivity().getTime() > idleTime)
(date.getTime() - conversation.getStartDate().getTime() > maxTime)) { || (date.getTime() - conversation.getStartDate().getTime() > maxTime)) {
removeConversation(conversationKey, conversation, conversation.getLastActivity()); removeConversation(conversationKey, conversation, conversation.getLastActivity());
// Make sure that the user joined the conversation before a message was received // Make sure that the user joined the conversation before a message was received
Date start = new Date(date.getTime() - 1); Date start = new Date(date.getTime() - 1);
...@@ -701,18 +730,21 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -701,18 +730,21 @@ public class ConversationManager implements Startable, ComponentEventListener {
} }
/** /**
* Notification message indicating that a user joined a groupchat conversation. If * Notification message indicating that a user joined a groupchat conversation. If no groupchat conversation was taking place in the specified
* no groupchat conversation was taking place in the specified room then ignore this * room then ignore this event.
* event.<p> * <p>
* <p/> * <p/>
* Eventually, when a new conversation will start in the room and if this user is * Eventually, when a new conversation will start in the room and if this user is still in the room then the new conversation will detect this
* still in the room then the new conversation will detect this user and mark like * user and mark like if the user joined the converstion from the beginning.
* if the user joined the converstion from the beginning.
* *
* @param room the room where the user joined. * @param room
* @param user the user that joined the room. * the room where the user joined.
* @param nickname nickname of the user in the room. * @param user
* @param date date when the user joined the group coversation. * the user that joined the room.
* @param nickname
* nickname of the user in the room.
* @param date
* date when the user joined the group coversation.
*/ */
void joinedGroupConversation(JID room, JID user, String nickname, Date date) { void joinedGroupConversation(JID room, JID user, String nickname, Date date) {
Conversation conversation = getRoomConversation(room); Conversation conversation = getRoomConversation(room);
...@@ -722,13 +754,15 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -722,13 +754,15 @@ public class ConversationManager implements Startable, ComponentEventListener {
} }
/** /**
* Notification message indicating that a user left a groupchat conversation. If * Notification message indicating that a user left a groupchat conversation. If no groupchat conversation was taking place in the specified room
* no groupchat conversation was taking place in the specified room then ignore this * then ignore this event.
* event.
* *
* @param room the room where the user left. * @param room
* @param user the user that left the room. * the room where the user left.
* @param date date when the user left the group coversation. * @param user
* the user that left the room.
* @param date
* date when the user left the group coversation.
*/ */
void leftGroupConversation(JID room, JID user, Date date) { void leftGroupConversation(JID room, JID user, Date date) {
Conversation conversation = getRoomConversation(room); Conversation conversation = getRoomConversation(room);
...@@ -757,7 +791,8 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -757,7 +791,8 @@ public class ConversationManager implements Startable, ComponentEventListener {
/** /**
* Returns the group conversation taking place in the specified room or <tt>null</tt> if none. * Returns the group conversation taking place in the specified room or <tt>null</tt> if none.
* *
* @param room JID of the room. * @param room
* JID of the room.
* @return the group conversation taking place in the specified room or null if none. * @return the group conversation taking place in the specified room or null if none.
*/ */
private Conversation getRoomConversation(JID room) { private Conversation getRoomConversation(JID room) {
...@@ -770,10 +805,11 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -770,10 +805,11 @@ public class ConversationManager implements Startable, ComponentEventListener {
} }
/** /**
* Returns true if the specified message should be processed by the conversation manager. * Returns true if the specified message should be processed by the conversation manager. Only messages between two users, group chats, or
* Only messages between two users, group chats, or gateways are processed. * gateways are processed.
* *
* @param message the message to analyze. * @param message
* the message to analyze.
* @return true if the specified message should be processed by the conversation manager. * @return true if the specified message should be processed by the conversation manager.
*/ */
boolean isConversation(Message message) { boolean isConversation(Message message) {
...@@ -787,7 +823,8 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -787,7 +823,8 @@ public class ConversationManager implements Startable, ComponentEventListener {
/** /**
* Returns true if the specified JID should be recorded in a conversation. * Returns true if the specified JID should be recorded in a conversation.
* *
* @param jid the JID. * @param jid
* the JID.
* @return true if the JID should be recorded in a conversation. * @return true if the JID should be recorded in a conversation.
*/ */
private boolean isConversationJID(JID jid) { private boolean isConversationJID(JID jid) {
...@@ -816,19 +853,19 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -816,19 +853,19 @@ public class ConversationManager implements Startable, ComponentEventListener {
} }
/** /**
* Returns a unique key for a coversation between two JID's. The order of two JID parameters * Returns a unique key for a coversation between two JID's. The order of two JID parameters is irrelevant; the same key will be returned.
* is irrelevant; the same key will be returned.
* *
* @param jid1 the first JID. * @param jid1
* @param jid2 the second JID. * the first JID.
* @param jid2
* the second JID.
* @return a unique key. * @return a unique key.
*/ */
String getConversationKey(JID jid1, JID jid2) { String getConversationKey(JID jid1, JID jid2) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
if (jid1.compareTo(jid2) < 0) { if (jid1.compareTo(jid2) < 0) {
builder.append(jid1.toBareJID()).append("_").append(jid2.toBareJID()); builder.append(jid1.toBareJID()).append("_").append(jid2.toBareJID());
} } else {
else {
builder.append(jid2.toBareJID()).append("_").append(jid1.toBareJID()); builder.append(jid2.toBareJID()).append("_").append(jid1.toBareJID());
} }
return builder.toString(); return builder.toString();
...@@ -839,7 +876,7 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -839,7 +876,7 @@ public class ConversationManager implements Startable, ComponentEventListener {
} }
public void componentInfoReceived(IQ iq) { public void componentInfoReceived(IQ iq) {
//Check if the component is a gateway // Check if the component is a gateway
boolean gatewayFound = false; boolean gatewayFound = false;
Element childElement = iq.getChildElement(); Element childElement = iq.getChildElement();
for (Iterator<Element> it = childElement.elementIterator("identity"); it.hasNext();) { for (Iterator<Element> it = childElement.elementIterator("identity"); it.hasNext();) {
...@@ -855,7 +892,7 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -855,7 +892,7 @@ public class ConversationManager implements Startable, ComponentEventListener {
} }
public void componentRegistered(JID componentJID) { public void componentRegistered(JID componentJID) {
//Do nothing // Do nothing
} }
public void componentUnregistered(JID componentJID) { public void componentUnregistered(JID componentJID) {
...@@ -903,8 +940,7 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -903,8 +940,7 @@ public class ConversationManager implements Startable, ComponentEventListener {
DbConnectionManager.setLargeTextField(pstmt, 7, message.getBody()); DbConnectionManager.setLargeTextField(pstmt, 7, message.getBody());
if (DbConnectionManager.isBatchUpdatesSupported()) { if (DbConnectionManager.isBatchUpdatesSupported()) {
pstmt.addBatch(); pstmt.addBatch();
} } else {
else {
pstmt.execute(); pstmt.execute();
} }
// Only batch up to 500 items at a time. // Only batch up to 500 items at a time.
...@@ -926,8 +962,7 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -926,8 +962,7 @@ public class ConversationManager implements Startable, ComponentEventListener {
pstmt.setLong(3, conversation.getConversationID()); pstmt.setLong(3, conversation.getConversationID());
if (DbConnectionManager.isBatchUpdatesSupported()) { if (DbConnectionManager.isBatchUpdatesSupported()) {
pstmt.addBatch(); pstmt.addBatch();
} } else {
else {
pstmt.execute(); pstmt.execute();
} }
// Only batch up to 500 items at a time. // Only batch up to 500 items at a time.
...@@ -951,8 +986,7 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -951,8 +986,7 @@ public class ConversationManager implements Startable, ComponentEventListener {
pstmt.setLong(5, particpiant.joined.getTime()); pstmt.setLong(5, particpiant.joined.getTime());
if (DbConnectionManager.isBatchUpdatesSupported()) { if (DbConnectionManager.isBatchUpdatesSupported()) {
pstmt.addBatch(); pstmt.addBatch();
} } else {
else {
pstmt.execute(); pstmt.execute();
} }
// Only batch up to 500 items at a time. // Only batch up to 500 items at a time.
...@@ -964,11 +998,9 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -964,11 +998,9 @@ public class ConversationManager implements Startable, ComponentEventListener {
if (DbConnectionManager.isBatchUpdatesSupported()) { if (DbConnectionManager.isBatchUpdatesSupported()) {
pstmt.executeBatch(); pstmt.executeBatch();
} }
} } catch (Exception e) {
catch (Exception e) {
Log.error(e.getMessage(), e); Log.error(e.getMessage(), e);
} } finally {
finally {
DbConnectionManager.closeConnection(pstmt, con); DbConnectionManager.closeConnection(pstmt, con);
} }
} }
...@@ -978,77 +1010,86 @@ public class ConversationManager implements Startable, ComponentEventListener { ...@@ -978,77 +1010,86 @@ public class ConversationManager implements Startable, ComponentEventListener {
} }
/** /**
* A PropertyEventListener that tracks updates to Jive properties that are related * A PropertyEventListener that tracks updates to Jive properties that are related to conversation tracking and archiving.
* to conversation tracking and archiving.
*/ */
private class ConversationPropertyListener implements PropertyEventListener { private class ConversationPropertyListener implements PropertyEventListener {
public void propertySet(String property, Map<String, Object> params) { public void propertySet(String property, Map<String, Object> params) {
if (property.equals("conversation.metadataArchiving")) { if (property.equals("conversation.metadataArchiving")) {
String value = (String)params.get("value"); String value = (String) params.get("value");
metadataArchivingEnabled = Boolean.valueOf(value); metadataArchivingEnabled = Boolean.valueOf(value);
} } else if (property.equals("conversation.messageArchiving")) {
else if (property.equals("conversation.messageArchiving")) { String value = (String) params.get("value");
String value = (String)params.get("value");
messageArchivingEnabled = Boolean.valueOf(value); messageArchivingEnabled = Boolean.valueOf(value);
// Force metadata archiving enabled on if message archiving on. // Force metadata archiving enabled on if message archiving on.
if (messageArchivingEnabled) { if (messageArchivingEnabled) {
metadataArchivingEnabled = true; metadataArchivingEnabled = true;
} }
} } else if (property.equals("conversation.roomArchiving")) {
else if (property.equals("conversation.roomArchiving")) { String value = (String) params.get("value");
String value = (String)params.get("value");
roomArchivingEnabled = Boolean.valueOf(value); roomArchivingEnabled = Boolean.valueOf(value);
// Force metadata archiving enabled on if message archiving on. // Force metadata archiving enabled on if message archiving on.
if (roomArchivingEnabled) { if (roomArchivingEnabled) {
metadataArchivingEnabled = true; metadataArchivingEnabled = true;
} }
} } else if (property.equals("conversation.roomsArchived")) {
else if (property.equals("conversation.roomsArchived")) { String value = (String) params.get("value");
String value = (String)params.get("value");
roomsArchived = StringUtils.stringToCollection(value); roomsArchived = StringUtils.stringToCollection(value);
} } else if (property.equals("conversation.idleTime")) {
else if (property.equals("conversation.idleTime")) { String value = (String) params.get("value");
String value = (String)params.get("value");
try { try {
idleTime = Integer.parseInt(value) * JiveConstants.MINUTE; idleTime = Integer.parseInt(value) * JiveConstants.MINUTE;
} } catch (Exception e) {
catch (Exception e) {
Log.error(e.getMessage(), e); Log.error(e.getMessage(), e);
idleTime = DEFAULT_IDLE_TIME * JiveConstants.MINUTE; idleTime = DEFAULT_IDLE_TIME * JiveConstants.MINUTE;
} }
} } else if (property.equals("conversation.maxTime")) {
else if (property.equals("conversation.maxTime")) { String value = (String) params.get("value");
String value = (String)params.get("value");
try { try {
maxTime = Integer.parseInt(value) * JiveConstants.MINUTE; maxTime = Integer.parseInt(value) * JiveConstants.MINUTE;
} } catch (Exception e) {
catch (Exception e) {
Log.error(e.getMessage(), e); Log.error(e.getMessage(), e);
maxTime = DEFAULT_MAX_TIME * JiveConstants.MINUTE; maxTime = DEFAULT_MAX_TIME * JiveConstants.MINUTE;
} }
} else if (property.equals("conversation.maxRetrievable")) {
String value = (String) params.get("value");
try {
maxRetrievable = Integer.parseInt(value) * JiveConstants.DAY;
} catch (Exception e) {
Log.error(e.getMessage(), e);
maxRetrievable = DEFAULT_MAX_RETRIEVABLE * JiveConstants.DAY;
}
} else if (property.equals("conversation.maxAge")) {
String value = (String) params.get("value");
try {
maxAge = Integer.parseInt(value) * JiveConstants.DAY;
} catch (Exception e) {
Log.error(e.getMessage(), e);
maxAge = DEFAULT_MAX_AGE * JiveConstants.DAY;
}
} }
} }
public void propertyDeleted(String property, Map<String, Object> params) { public void propertyDeleted(String property, Map<String, Object> params) {
if (property.equals("conversation.metadataArchiving")) { if (property.equals("conversation.metadataArchiving")) {
metadataArchivingEnabled = true; metadataArchivingEnabled = true;
} } else if (property.equals("conversation.messageArchiving")) {
else if (property.equals("conversation.messageArchiving")) {
messageArchivingEnabled = false; messageArchivingEnabled = false;
} } else if (property.equals("conversation.roomArchiving")) {
else if (property.equals("conversation.roomArchiving")) {
roomArchivingEnabled = false; roomArchivingEnabled = false;
} } else if (property.equals("conversation.roomsArchived")) {
else if (property.equals("conversation.roomsArchived")) {
roomsArchived = Collections.emptyList(); roomsArchived = Collections.emptyList();
} } else if (property.equals("conversation.idleTime")) {
else if (property.equals("conversation.idleTime")) {
idleTime = DEFAULT_IDLE_TIME * JiveConstants.MINUTE; idleTime = DEFAULT_IDLE_TIME * JiveConstants.MINUTE;
} } else if (property.equals("conversation.maxTime")) {
else if (property.equals("conversation.maxTime")) {
maxTime = DEFAULT_MAX_TIME * JiveConstants.MINUTE; maxTime = DEFAULT_MAX_TIME * JiveConstants.MINUTE;
} else if (property.equals("conversation.maxAge")) {
maxAge = DEFAULT_MAX_AGE * JiveConstants.DAY;
} else if (property.equals("conversation.maxRetrievable")) {
maxRetrievable = DEFAULT_MAX_RETRIEVABLE * JiveConstants.DAY;
} }
} }
public void xmlPropertySet(String property, Map<String, Object> params) { public void xmlPropertySet(String property, Map<String, Object> params) {
......
...@@ -163,6 +163,10 @@ ...@@ -163,6 +163,10 @@
boolean roomArchiving = conversationManager.isRoomArchivingEnabled(); boolean roomArchiving = conversationManager.isRoomArchivingEnabled();
int idleTime = ParamUtils.getIntParameter(request, "idleTime", conversationManager.getIdleTime()); int idleTime = ParamUtils.getIntParameter(request, "idleTime", conversationManager.getIdleTime());
int maxTime = ParamUtils.getIntParameter(request, "maxTime", conversationManager.getMaxTime()); int maxTime = ParamUtils.getIntParameter(request, "maxTime", conversationManager.getMaxTime());
int maxAge = ParamUtils.getIntParameter(request, "maxAge", conversationManager.getMaxAge());
int maxRetrievable = ParamUtils.getIntParameter(request, "maxRetrievable", conversationManager.getMaxRetrievable());
boolean rebuildIndex = request.getParameter("rebuild") != null; boolean rebuildIndex = request.getParameter("rebuild") != null;
if (request.getParameter("cancel") != null) { if (request.getParameter("cancel") != null) {
...@@ -197,6 +201,14 @@ ...@@ -197,6 +201,14 @@
errors.put("roomsArchived", ""); errors.put("roomsArchived", "");
errorMessage = "Only name of local rooms should be specified."; errorMessage = "Only name of local rooms should be specified.";
} }
if (maxAge < 0) {
errors.put("maxAge", "");
errorMessage = "Max Age must be greater than or equal to 0.";
}
if (maxRetrievable < 1) {
errors.put("maxRetrievable", "");
errorMessage = "Max Retrievable must be greater than or equal to 0.";
}
// If no errors, continue: // If no errors, continue:
if (errors.size() == 0) { if (errors.size() == 0) {
conversationManager.setMetadataArchivingEnabled(metadataArchiving); conversationManager.setMetadataArchivingEnabled(metadataArchiving);
...@@ -206,6 +218,9 @@ ...@@ -206,6 +218,9 @@
conversationManager.setIdleTime(idleTime); conversationManager.setIdleTime(idleTime);
conversationManager.setMaxTime(maxTime); conversationManager.setMaxTime(maxTime);
conversationManager.setMaxAge(maxAge);
conversationManager.setMaxRetrievable(maxRetrievable);
%> %>
<div class="success"> <div class="success">
<fmt:message key="archive.settings.success"/> <fmt:message key="archive.settings.success"/>
...@@ -285,6 +300,21 @@ ...@@ -285,6 +300,21 @@
<td><input type="text" name="maxTime" size="10" maxlength="10" value="<%= conversationManager.getMaxTime()%>" /></td> <td><input type="text" name="maxTime" size="10" maxlength="10" value="<%= conversationManager.getMaxTime()%>" /></td>
<td></td> <td></td>
</tr> </tr>
<tr>
<td><label class="jive-label"><fmt:message key="archive.settings.max.age"/>:</label><br>
<fmt:message key="archive.settings.max.age.description"/><br><br></td>
<td><input type="text" name="maxAge" size="10" maxlength="10" value="<%= conversationManager.getMaxAge()%>" /></td>
<td></td>
</tr>
<tr>
<td><label class="jive-label"><fmt:message key="archive.settings.max.retrievable"/>:</label><br>
<fmt:message key="archive.settings.max.retrievable.description"/><br><br></td>
<td><input type="text" name="maxRetrievable" size="10" maxlength="10" value="<%= conversationManager.getMaxRetrievable()%>" /></td>
<td></td>
</tr>
</tbody> </tbody>
</table> </table>
......
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