Issue #2937 Moved presence/site determination from feed log to feed listener.
Use MUCRoom to get presence and role because UserManager is not able to understand nicnames. Change-Id: Ie27d804cfea37a27df7e3c0d4445b16f3f2c12a7 Former-commit-id:10a8b59e4e
[formerly45264a2cde
] [formerly189282166d
] [formerly535611f556
[formerly189282166d
[formerly e975a825046c8d0505223093e5765d5283425b2f]]] Former-commit-id:535611f556
Former-commit-id: 31d35028c1bb41e7e74a7a5b46e8631cb1b8dfcd [formerly7384a458eb
] Former-commit-id:b18cefb6bd
This commit is contained in:
parent
886d42182e
commit
c67332f5c8
2 changed files with 45 additions and 63 deletions
|
@ -35,15 +35,11 @@ import java.util.Queue;
|
|||
import java.util.TimerTask;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import org.dom4j.Element;
|
||||
import org.jivesoftware.openfire.MessageRouter;
|
||||
import org.jivesoftware.openfire.XMPPServer;
|
||||
import org.jivesoftware.openfire.container.Plugin;
|
||||
import org.jivesoftware.openfire.container.PluginManager;
|
||||
import org.jivesoftware.openfire.muc.MUCEventDispatcher;
|
||||
import org.jivesoftware.openfire.user.User;
|
||||
import org.jivesoftware.openfire.user.UserManager;
|
||||
import org.jivesoftware.openfire.user.UserNotFoundException;
|
||||
import org.jivesoftware.util.JiveGlobals;
|
||||
import org.jivesoftware.util.Log;
|
||||
import org.jivesoftware.util.PropertyEventDispatcher;
|
||||
|
@ -51,13 +47,15 @@ import org.jivesoftware.util.PropertyEventListener;
|
|||
import org.jivesoftware.util.TaskEngine;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.xmpp.packet.Message;
|
||||
import org.xmpp.packet.Presence;
|
||||
|
||||
import com.raytheon.openfire.plugin.detailedfeedlog.listener.DetailedFeedLogEventListener;
|
||||
|
||||
/**
|
||||
* Plugin that logs and purges qualifying packets in Openfire
|
||||
* Plugin that logs and purges qualifying packets in Openfire.
|
||||
*
|
||||
* This plugin handles logging history so to prevent conflicting messages, the
|
||||
* group chat history settings need to be turned off on the Openfire server.
|
||||
* Group Chat > Group Chat Setting > History Settings > Don't Show History
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
|
@ -73,6 +71,7 @@ import com.raytheon.openfire.plugin.detailedfeedlog.listener.DetailedFeedLogEven
|
|||
* Apr 07, 2014 2937 bgonzale Use new LogEntry toString and fromString methods
|
||||
* and changed error handling to log each bad line.
|
||||
* Create new DateFormatter for the purge thread.
|
||||
* Moved presence/site determination out of log method.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -116,8 +115,6 @@ public class DetailedFeedLogPlugin implements Plugin, PropertyEventListener {
|
|||
|
||||
private DetailedFeedLogEventListener feedListener;
|
||||
|
||||
public static final String SITE_INFO = "Site";
|
||||
|
||||
private static final String ROOM_DIR = "Rooms";
|
||||
|
||||
private static final String DATE_FORMAT_STR = "MM/dd/yyyy h:mm a";
|
||||
|
@ -227,27 +224,6 @@ public class DetailedFeedLogPlugin implements Plugin, PropertyEventListener {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
public static void log(Message message, String room) {
|
||||
User user = null;
|
||||
try {
|
||||
user = UserManager.getInstance().getUser(
|
||||
message.getFrom().getResource());
|
||||
} catch (UserNotFoundException e) {
|
||||
logger.error("Unable to get user for Room: " + room
|
||||
+ " and Message: " + message.toXML(), e);
|
||||
}
|
||||
|
||||
String site = getSiteFromPresence(user);
|
||||
|
||||
// format it with the site so the site can be sent with the packet later
|
||||
log(user.getUsername(), site, message.getBody(), room);
|
||||
}
|
||||
|
||||
/**
|
||||
* To log in openfire
|
||||
*
|
||||
|
@ -255,7 +231,7 @@ public class DetailedFeedLogPlugin implements Plugin, PropertyEventListener {
|
|||
* - fqname
|
||||
* @param message
|
||||
*/
|
||||
private static void log(String user, String site, String message,
|
||||
public static void log(String user, String site, String message,
|
||||
String room) {
|
||||
logger.info("Logging : " + user + " \"" + message + "\"");
|
||||
Date date = new Date();
|
||||
|
@ -290,27 +266,6 @@ public class DetailedFeedLogPlugin implements Plugin, PropertyEventListener {
|
|||
entries.remove(room);
|
||||
}
|
||||
|
||||
private static String getSiteFromPresence(User user) {
|
||||
Presence presence = XMPPServer.getInstance().getPresenceManager()
|
||||
.getPresence(user);
|
||||
|
||||
// need to get the site from the presence, add that to the text that we
|
||||
// log, and use that for filtering on the client side
|
||||
Element props = presence.getChildElement("properties",
|
||||
"http://www.jivesoftware.com/xmlns/xmpp/properties");
|
||||
String site = null;
|
||||
for (Object propObj : props.elements("property")) {
|
||||
Element prop = (Element) propObj;
|
||||
String name = prop.elementText("name");
|
||||
String value = prop.elementText("value");
|
||||
if (SITE_INFO.equals(name)) {
|
||||
site = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return site;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write out the current in memory log to a file
|
||||
*/
|
||||
|
|
|
@ -22,19 +22,19 @@ package com.raytheon.openfire.plugin.detailedfeedlog.listener;
|
|||
import java.util.Queue;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import org.dom4j.Element;
|
||||
import org.jivesoftware.openfire.MessageRouter;
|
||||
import org.jivesoftware.openfire.XMPPServer;
|
||||
import org.jivesoftware.openfire.muc.MUCEventListener;
|
||||
import org.jivesoftware.openfire.muc.MUCRole;
|
||||
import org.jivesoftware.openfire.muc.MUCRoom;
|
||||
import org.jivesoftware.openfire.user.User;
|
||||
import org.jivesoftware.openfire.user.UserManager;
|
||||
import org.jivesoftware.openfire.user.UserNotFoundException;
|
||||
import org.jivesoftware.util.TaskEngine;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.xmpp.packet.JID;
|
||||
import org.xmpp.packet.Message;
|
||||
import org.xmpp.packet.Message.Type;
|
||||
import org.xmpp.packet.Presence;
|
||||
|
||||
import com.raytheon.openfire.plugin.detailedfeedlog.DetailedFeedLogPlugin;
|
||||
import com.raytheon.openfire.plugin.detailedfeedlog.LogEntry;
|
||||
|
@ -53,7 +53,10 @@ import com.raytheon.openfire.plugin.detailedfeedlog.LogEntry;
|
|||
* Jul 25, 2012 mnash Initial creation
|
||||
* Apr 07, 2014 2937 bgonzale Handle errors processing room events.
|
||||
* Fixed message from user.
|
||||
*
|
||||
* Added getSiteFromPresence. Use
|
||||
* MUCRoom to get presence and role
|
||||
* because UserManager is not able to
|
||||
* understand nicknames.
|
||||
* </pre>
|
||||
*
|
||||
* @author mnash
|
||||
|
@ -73,6 +76,8 @@ public class DetailedFeedLogEventListener implements MUCEventListener {
|
|||
// this tag will tell CAVE that this is a history message
|
||||
private static final String HISTORY_START = "[[HISTORY]]";
|
||||
|
||||
private static final String SITE_INFO = "Site";
|
||||
|
||||
/**
|
||||
* When the occupant joins, we want to send out the history to them. This
|
||||
* only happens in the permanent feed room.
|
||||
|
@ -85,17 +90,14 @@ public class DetailedFeedLogEventListener implements MUCEventListener {
|
|||
TimerTask messageTask = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
UserManager userManager = UserManager.getInstance();
|
||||
Queue<LogEntry> log = DetailedFeedLogPlugin.getLog(roomJID
|
||||
.getNode());
|
||||
|
||||
for (LogEntry entry : log) {
|
||||
Message message = new Message();
|
||||
message.setTo(roomJID + "/" + nickname);
|
||||
String usr = entry.getUsername();
|
||||
String sendUser = entry.getUsername();
|
||||
try {
|
||||
User sendUser = userManager
|
||||
.getUser(entry.getUser());
|
||||
// set all the necessary values in the message to be
|
||||
// sent out
|
||||
message.setTo(user);
|
||||
|
@ -110,8 +112,6 @@ public class DetailedFeedLogEventListener implements MUCEventListener {
|
|||
router.route(message);
|
||||
logger.info("Routed message : " + message.getBody()
|
||||
+ " from " + sendUser + " to " + user);
|
||||
} catch (UserNotFoundException e) {
|
||||
logger.error(usr + " not found", e);
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
logger.error(
|
||||
"Failed to parse log history for Routing. Bad Entry was date: "
|
||||
|
@ -135,11 +135,38 @@ public class DetailedFeedLogEventListener implements MUCEventListener {
|
|||
Message message) {
|
||||
if (isLoggedRoom(roomJID)) {
|
||||
if (message.getBody().startsWith(COMMAND_START) == false) {
|
||||
DetailedFeedLogPlugin.log(message, roomJID.getNode());
|
||||
MUCRoom mucRoom = XMPPServer.getInstance()
|
||||
.getMultiUserChatManager()
|
||||
.getMultiUserChatService(roomJID)
|
||||
.getChatRoom(roomJID.getNode());
|
||||
MUCRole role = mucRoom.getOccupantByFullJID(user);
|
||||
DetailedFeedLogPlugin.log(role.getNickname(),
|
||||
getSiteFromPresence(role.getPresence()),
|
||||
message.getBody(),
|
||||
roomJID.getNode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getSiteFromPresence(Presence presence) {
|
||||
// need to get the site from the presence, add that to the text that we
|
||||
// log, and use that for filtering on the client side
|
||||
Element props = presence.getChildElement("properties",
|
||||
"http://www.jivesoftware.com/xmlns/xmpp/properties");
|
||||
String site = null;
|
||||
for (Object propObj : props.elements("property")) {
|
||||
Element prop = (Element) propObj;
|
||||
String name = prop.elementText("name");
|
||||
String value = prop.elementText("value");
|
||||
if (SITE_INFO.equals(name)) {
|
||||
site = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return site;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine if this is the room that we want to log for here
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue