Search in sources :

Example 6 with ConversationManager

use of org.jivesoftware.openfire.archive.ConversationManager in project Openfire by igniterealtime.

the class StatsAction method getNLatestConversations.

/**
     * Retrieves the last n conversations from the system that were created after
     * the given conversationID.
     *
     * @param count the count of conversations to return.
     * @param mostRecentConversationID the last conversationID that has been retrieved.
     * @return a List of Map objects.
     */
public List<Map<String, Long>> getNLatestConversations(int count, long mostRecentConversationID) {
    // TODO Fix plugin name 2 lines below and missing classes
    List<Map<String, Long>> cons = new ArrayList<Map<String, Long>>();
    MonitoringPlugin plugin = (MonitoringPlugin) XMPPServer.getInstance().getPluginManager().getPlugin(MonitoringConstants.NAME);
    ConversationManager conversationManager = (ConversationManager) plugin.getModule(ConversationManager.class);
    Collection<Conversation> conversations = conversationManager.getConversations();
    List<Conversation> lConversations = Arrays.asList(conversations.toArray(new Conversation[conversations.size()]));
    Collections.sort(lConversations, conversationComparator);
    int counter = 0;
    for (Iterator<Conversation> i = lConversations.iterator(); i.hasNext() && counter < count; ) {
        Conversation con = i.next();
        if (mostRecentConversationID == con.getConversationID()) {
            break;
        } else {
            Map mCon = new HashMap();
            mCon.put("conversationid", con.getConversationID());
            String[] users;
            int usersIdx = 0;
            if (con.getRoom() == null) {
                users = new String[con.getParticipants().size()];
                for (JID jid : con.getParticipants()) {
                    String identifier = jid.toBareJID();
                    try {
                        identifier = UserNameManager.getUserName(jid, jid.toBareJID());
                    } catch (UserNotFoundException e) {
                    // Ignore
                    }
                    users[usersIdx++] = StringUtils.abbreviate(identifier, 20);
                }
            } else {
                users = new String[2];
                users[0] = LocaleUtils.getLocalizedString("dashboard.group_conversation", MonitoringConstants.NAME);
                try {
                    users[1] = "(<i>" + LocaleUtils.getLocalizedString("muc.room.summary.room") + ": <a href='../../muc-room-occupants.jsp?roomName=" + URLEncoder.encode(con.getRoom().getNode(), "UTF-8") + "'>" + con.getRoom().getNode() + "</a></i>)";
                } catch (UnsupportedEncodingException e) {
                    Log.error(e.getMessage(), e);
                }
            }
            mCon.put("users", users);
            mCon.put("lastactivity", formatTimeLong(con.getLastActivity()));
            mCon.put("messages", con.getMessageCount());
            cons.add(0, mCon);
            counter++;
        }
    }
    return cons;
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) JID(org.xmpp.packet.JID) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConversationManager(org.jivesoftware.openfire.archive.ConversationManager) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Conversation(org.jivesoftware.openfire.archive.Conversation) MonitoringPlugin(org.jivesoftware.openfire.plugin.MonitoringPlugin) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ConversationManager (org.jivesoftware.openfire.archive.ConversationManager)6 MonitoringPlugin (org.jivesoftware.openfire.plugin.MonitoringPlugin)6 Conversation (org.jivesoftware.openfire.archive.Conversation)2 JID (org.xmpp.packet.JID)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Element (org.dom4j.Element)1 ArchiveSearch (org.jivesoftware.openfire.archive.ArchiveSearch)1 ArchiveSearcher (org.jivesoftware.openfire.archive.ArchiveSearcher)1 ConversationEvent (org.jivesoftware.openfire.archive.ConversationEvent)1 ConversationUtils (org.jivesoftware.openfire.archive.ConversationUtils)1 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)1 NotFoundException (org.jivesoftware.util.NotFoundException)1 DataForm (org.xmpp.forms.DataForm)1 FormField (org.xmpp.forms.FormField)1