use of org.jivesoftware.openfire.archive.Conversation in project Openfire by igniterealtime.
the class GetGroupConversationTranscript method execute.
@Override
public void execute(SessionData data, Element command) {
Element note = command.addElement("note");
// Get handle on the Monitoring plugin
MonitoringPlugin plugin = (MonitoringPlugin) XMPPServer.getInstance().getPluginManager().getPlugin(MonitoringConstants.NAME);
ConversationManager conversationManager = (ConversationManager) plugin.getModule(ConversationManager.class);
if (!conversationManager.isArchivingEnabled()) {
note.addAttribute("type", "error");
note.setText("Message archiving is not enabled.");
DataForm form = new DataForm(DataForm.Type.result);
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setLabel("Conversation Found?");
field.setVariable("found");
field.addValue(false);
// Add form to reply
command.add(form.getElement());
return;
}
try {
JID participant = new JID(data.getData().get("participant").get(0));
JID room = new JID(data.getData().get("room").get(0));
Date time = DataForm.parseDate(data.getData().get("time").get(0));
boolean includePDF = DataForm.parseBoolean(data.getData().get("includePDF").get(0));
// Get archive searcher module
ArchiveSearcher archiveSearcher = (ArchiveSearcher) plugin.getModule(ArchiveSearcher.class);
ArchiveSearch search = new ArchiveSearch();
search.setParticipants(participant);
search.setIncludeTimestamp(time);
search.setRoom(room);
Collection<Conversation> conversations = archiveSearcher.search(search);
DataForm form = new DataForm(DataForm.Type.result);
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setLabel("Conversation Found?");
field.setVariable("found");
field.addValue(!conversations.isEmpty());
if (includePDF) {
ByteArrayOutputStream stream = null;
if (!conversations.isEmpty()) {
stream = new ConversationUtils().getConversationPDF(conversations.iterator().next());
}
if (stream != null) {
field = form.addField();
field.setLabel("PDF");
field.setVariable("pdf");
field.addValue(StringUtils.encodeBase64(stream.toByteArray()));
}
}
// Add form to reply
command.add(form.getElement());
} catch (Exception e) {
Log.error("Error occurred while running the command", e);
note.addAttribute("type", "error");
note.setText("Error while processing the command.");
}
}
use of org.jivesoftware.openfire.archive.Conversation 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;
}
Aggregations