use of org.jivesoftware.xmpp.workgroup.AgentNotFoundException in project Openfire by igniterealtime.
the class AgentHistory method executeGet.
public void executeGet(IQ packet, Workgroup workgroup) {
IQ reply = IQ.createResultIQ(packet);
try {
if (workgroup.getAgentManager().getAgentSession(packet.getFrom()) == null) {
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.not_authorized));
workgroup.send(reply);
return;
}
} catch (AgentNotFoundException e) {
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.not_authorized));
workgroup.send(reply);
return;
}
// Create session list
List<AgentHistoryModel> sessionList = new ArrayList<AgentHistoryModel>();
Element chatSessions = reply.setChildElement("chat-sessions", "http://jivesoftware.com/protocol/workgroup");
Element iq = packet.getChildElement();
String agentJID = iq.attributeValue("agentJID");
String ms = iq.attributeValue("maxSessions");
String date = iq.attributeValue("startDate");
long startTime = 0;
if (date != null) {
startTime = Long.parseLong(date);
}
int maxSessions = Integer.parseInt(ms);
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(GET_AGENT_SESSIONS);
pstmt.setString(1, agentJID);
ResultSet result = pstmt.executeQuery();
while (result.next()) {
String sessionID = result.getString(1);
String joinTime = result.getString(2);
String leftTime = result.getString(3);
AgentHistoryModel model = new AgentHistoryModel();
if (ModelUtil.hasLength(joinTime) && ModelUtil.hasLength(leftTime)) {
try {
long start = Long.valueOf(joinTime);
long end = Long.valueOf(leftTime);
long totalTime = end - start;
model.setSessionID(sessionID);
model.setJoinTime(joinTime);
model.setDuration(Long.toString(totalTime));
if (start >= startTime) {
sessionList.add(model);
}
} catch (NumberFormatException e) {
Log.error(e.getMessage(), e);
}
}
}
result.close();
} catch (Exception ex) {
Log.error(ex.getMessage(), ex);
} finally {
DbConnectionManager.closeConnection(pstmt, con);
}
buildAndSend(sessionList, chatSessions, reply, workgroup, maxSessions);
}
use of org.jivesoftware.xmpp.workgroup.AgentNotFoundException in project Openfire by igniterealtime.
the class ChatMetadataProvider method executeGet.
public void executeGet(IQ packet, Workgroup workgroup) {
IQ reply = IQ.createResultIQ(packet);
try {
AgentSession agentSession = workgroup.getAgentManager().getAgentSession(packet.getFrom());
if (agentSession == null) {
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.not_authorized));
workgroup.send(reply);
return;
}
} catch (AgentNotFoundException e) {
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.not_authorized));
workgroup.send(reply);
return;
}
Element chatSessions = reply.setChildElement("chat-metadata", "http://jivesoftware.com/protocol/workgroup");
Element iq = packet.getChildElement();
String sessionID = iq.element("sessionID").getTextTrim();
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
Map<String, String> map = new HashMap<String, String>();
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(GET_SESSION_METADATA);
pstmt.setString(1, sessionID);
rs = pstmt.executeQuery();
while (rs.next()) {
String name = rs.getString(1);
String value = rs.getString(2);
map.put(name, value);
}
} catch (Exception ex) {
Log.error(ex.getMessage(), ex);
} finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
// Add metadata
chatSessions.add(getMetaDataElement(map));
workgroup.send(reply);
}
use of org.jivesoftware.xmpp.workgroup.AgentNotFoundException in project Openfire by igniterealtime.
the class ChatNotes method executeSet.
public void executeSet(IQ packet, Workgroup workgroup) {
IQ reply;
Element iq = packet.getChildElement();
try {
// Verify that an agent is requesting this information.
AgentSession agentSession = workgroup.getAgentManager().getAgentSession(packet.getFrom());
if (agentSession != null) {
String sessionID = iq.element("sessionID").getTextTrim();
Element notes = iq.element("notes");
String noteText = notes.getTextTrim();
appendNote(sessionID, noteText);
reply = IQ.createResultIQ(packet);
} else {
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.item_not_found));
}
} catch (AgentNotFoundException e) {
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.item_not_found));
}
workgroup.send(reply);
}
use of org.jivesoftware.xmpp.workgroup.AgentNotFoundException in project Openfire by igniterealtime.
the class SiteTracker method handleUserHistoryRequest.
private void handleUserHistoryRequest(IQ packet, Workgroup workgroup) {
IQ reply;
Element iq = packet.getChildElement();
try {
AgentSession agentSession = workgroup.getAgentManager().getAgentSession(packet.getFrom());
if (agentSession == null) {
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.not_authorized));
workgroup.send(reply);
return;
}
} catch (AgentNotFoundException e) {
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.not_authorized));
workgroup.send(reply);
return;
}
// Define default values
String sessionID = iq.attribute("sessionID").getText();
reply = IQ.createResultIQ(packet);
Element views = reply.setChildElement("site-user-history", "http://jivesoftware.com/protocol/workgroup");
views.addAttribute("sessionID", sessionID);
SiteUser siteUser = siteUsers.get(sessionID);
if (siteUser != null) {
for (PageView view : siteUser.getViews()) {
Element pageView = views.addElement("page-view");
pageView.addElement("title").setText(view.getTitle());
pageView.addElement("url").setText(view.getUrl());
pageView.addElement("time").setText(Long.toString(view.getTimeViewed()));
}
workgroup.send(reply);
}
}
use of org.jivesoftware.xmpp.workgroup.AgentNotFoundException in project Openfire by igniterealtime.
the class SearchProvider method executeGet.
public void executeGet(IQ packet, Workgroup workgroup) {
IQ reply = IQ.createResultIQ(packet);
// Retrieve the web chat setting.
String kbURL = workgroup.getProperties().getProperty("kb");
String forumURL = workgroup.getProperties().getProperty("forums");
// Check that the sender of this IQ is an agent
WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
try {
workgroupManager.getAgentManager().getAgent(packet.getFrom());
} catch (AgentNotFoundException e) {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.item_not_found));
workgroup.send(reply);
return;
}
Element searchSetting = reply.setChildElement("search-settings", "http://jivesoftware.com/protocol/workgroup");
if (forumURL != null) {
searchSetting.addElement("forums").setText(forumURL);
}
if (kbURL != null) {
searchSetting.addElement("kb").setText(kbURL);
}
workgroup.send(reply);
}
Aggregations