Search in sources :

Example 1 with Participant

use of com.reucon.openfire.plugin.archive.model.Participant in project Openfire by igniterealtime.

the class ArchiveManagerImpl method determineConversation.

private Conversation determineConversation(JID ownerJid, JID withJid, String subject, String thread, ArchivedMessage archivedMessage) {
    Conversation conversation = null;
    Collection<Conversation> staleConversations;
    staleConversations = new ArrayList<Conversation>();
    synchronized (activeConversations) {
        for (Conversation c : activeConversations) {
            if (c.isStale(conversationTimeout)) {
                staleConversations.add(c);
                continue;
            }
            if (matches(ownerJid, withJid, thread, c)) {
                conversation = c;
                break;
            }
        }
        activeConversations.removeAll(staleConversations);
        if (conversation == null) {
            final Participant p1;
            final Participant p2;
            conversation = new Conversation(archivedMessage.getTime(), ownerJid.toBareJID(), ownerJid.getResource(), withJid.toBareJID(), withJid.getResource(), subject, thread);
            persistenceManager.createConversation(conversation);
            p1 = new Participant(archivedMessage.getTime(), ownerJid.toBareJID());
            conversation.addParticipant(p1);
            persistenceManager.createParticipant(p1, conversation.getId());
            p2 = new Participant(archivedMessage.getTime(), withJid.toBareJID());
            conversation.addParticipant(p2);
            persistenceManager.createParticipant(p2, conversation.getId());
            activeConversations.add(conversation);
        } else {
            conversation.setEnd(archivedMessage.getTime());
            persistenceManager.updateConversationEnd(conversation);
        }
    }
    return conversation;
}
Also used : Participant(com.reucon.openfire.plugin.archive.model.Participant) Conversation(com.reucon.openfire.plugin.archive.model.Conversation)

Example 2 with Participant

use of com.reucon.openfire.plugin.archive.model.Participant in project Openfire by igniterealtime.

the class JdbcPersistenceManager method getConversation.

private Conversation getConversation(Long conversationId, String ownerJid, String withJid, Date start) {
    Conversation conversation = null;
    StringBuilder querySB;
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    querySB = new StringBuilder(SELECT_CONVERSATIONS);
    querySB.append(" WHERE ");
    if (conversationId != null) {
        querySB.append(CONVERSATION_ID).append(" = ? ");
    } else {
        querySB.append(CONVERSATION_OWNER_JID).append(" = ?");
        if (withJid != null) {
            querySB.append(" AND ");
            querySB.append(CONVERSATION_WITH_JID).append(" = ? ");
        }
        if (start != null) {
            querySB.append(" AND ");
            querySB.append(CONVERSATION_START_TIME).append(" = ? ");
        }
    }
    querySB.append(SELECT_CONVERSATIONS_GROUP_BY);
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(querySB.toString());
        int i = 1;
        if (conversationId != null) {
            pstmt.setLong(1, conversationId);
        } else {
            pstmt.setString(i++, ownerJid);
            if (withJid != null) {
                pstmt.setString(i++, withJid);
            }
            if (start != null) {
                pstmt.setLong(i++, dateToMillis(start));
            }
        }
        rs = pstmt.executeQuery();
        Log.debug("getConversation: SELECT_CONVERSATIONS: " + pstmt.toString());
        if (rs.next()) {
            conversation = extractConversation(rs);
        } else {
            return null;
        }
        rs.close();
        pstmt.close();
        pstmt = con.prepareStatement(SELECT_PARTICIPANTS_BY_CONVERSATION);
        pstmt.setLong(1, conversation.getId());
        rs = pstmt.executeQuery();
        Log.debug("getConversation: SELECT_PARTICIPANTS_BY_CONVERSATION: " + pstmt.toString());
        while (rs.next()) {
            for (Participant participant : extractParticipant(rs)) {
                conversation.addParticipant(participant);
            }
        }
        rs.close();
        pstmt.close();
        pstmt = con.prepareStatement(SELECT_MESSAGES_BY_CONVERSATION);
        pstmt.setLong(1, conversation.getId());
        pstmt.setString(2, conversation.getOwnerJid());
        rs = pstmt.executeQuery();
        Log.debug("getConversation: SELECT_MESSAGES_BY_CONVERSATION: " + pstmt.toString());
        while (rs.next()) {
            ArchivedMessage message;
            message = extractMessage(rs);
            message.setConversation(conversation);
            conversation.addMessage(message);
        }
    } catch (SQLException sqle) {
        Log.error("Error selecting conversation", sqle);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
    return conversation;
}
Also used : Participant(com.reucon.openfire.plugin.archive.model.Participant) ArchivedMessage(com.reucon.openfire.plugin.archive.model.ArchivedMessage) SQLException(java.sql.SQLException) Connection(java.sql.Connection) XmppResultSet(com.reucon.openfire.plugin.archive.xep0059.XmppResultSet) ResultSet(java.sql.ResultSet) Conversation(com.reucon.openfire.plugin.archive.model.Conversation) PreparedStatement(java.sql.PreparedStatement)

Example 3 with Participant

use of com.reucon.openfire.plugin.archive.model.Participant in project Openfire by igniterealtime.

the class JdbcPersistenceManager method extractParticipant.

private Collection<Participant> extractParticipant(ResultSet rs) throws SQLException {
    Collection<Participant> participants = new HashSet<Participant>();
    Date startDate = millisToDate(rs.getLong("startDate"));
    String participantJid = rs.getString("bareJID");
    Date endDate = millisToDate(rs.getLong("lastActivity"));
    if (participantJid != null) {
        Participant participant = new Participant(startDate, participantJid);
        participant.setEnd(endDate);
        participants.add(participant);
    }
    return participants;
}
Also used : Participant(com.reucon.openfire.plugin.archive.model.Participant) Date(java.util.Date) HashSet(java.util.HashSet)

Aggregations

Participant (com.reucon.openfire.plugin.archive.model.Participant)3 Conversation (com.reucon.openfire.plugin.archive.model.Conversation)2 ArchivedMessage (com.reucon.openfire.plugin.archive.model.ArchivedMessage)1 XmppResultSet (com.reucon.openfire.plugin.archive.xep0059.XmppResultSet)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1