use of org.xmpp.packet.PacketError 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.xmpp.packet.PacketError 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.xmpp.packet.PacketError in project Openfire by igniterealtime.
the class EmailProvider method executeSet.
public void executeSet(IQ packet, Workgroup workgroup) {
IQ reply = IQ.createResultIQ(packet);
Element iq = packet.getChildElement();
String from = iq.element("fromAddress").getTextTrim();
String to = iq.element("toAddress").getTextTrim();
String subject = iq.element("subject").getTextTrim();
String body = iq.element("message").getTextTrim();
// Need to replace the \\n for \n to allow for text sending.
body = body.replace("\\n", "\n");
String html = iq.element("useHTML").getTextTrim();
boolean useHTML = false;
if ("true".equals(html)) {
useHTML = true;
}
String sessionID = null;
if (iq.element("sessionID") != null) {
sessionID = iq.element("sessionID").getTextTrim();
}
// Handle missing information.
if (!ModelUtil.hasLength(from) || !ModelUtil.hasLength(to) || !ModelUtil.hasLength(subject) || (!ModelUtil.hasLength(body) && !ModelUtil.hasLength(sessionID))) {
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.not_acceptable));
workgroup.send(reply);
return;
}
if (ModelUtil.hasLength(sessionID)) {
ChatTranscriptManager.sendTranscriptByMail(sessionID, to);
} else {
EmailService emailService = EmailService.getInstance();
if (!useHTML) {
emailService.sendMessage(null, to, null, from, subject, body, null);
} else {
emailService.sendMessage(null, to, null, from, subject, null, body);
}
}
workgroup.send(reply);
}
use of org.xmpp.packet.PacketError in project Openfire by igniterealtime.
the class MonitorProvider method executeSet.
public void executeSet(IQ packet, Workgroup workgroup) {
IQ reply = null;
Element iq = packet.getChildElement();
try {
JID from = packet.getFrom();
String bareJID = from.toBareJID();
if (!isOwner(bareJID, workgroup)) {
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.forbidden));
workgroup.send(reply);
return;
}
// Verify that an agent is requesting this information.
WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
if (iq.element("makeOwner") != null) {
String sessionID = iq.element("makeOwner").attributeValue("sessionID");
final String serviceName = workgroupManager.getMUCServiceName();
final String roomName = sessionID + "@" + serviceName;
// final String roomJID = roomName + "/" + workgroup.getJID().getNode();
IQ iqPacket = new IQ(IQ.Type.set);
iqPacket.setTo(roomName);
iqPacket.setFrom(workgroup.getFullJID());
Element query = iqPacket.setChildElement("query", "http://jabber.org/protocol/muc#admin");
Element item = query.addElement("item");
item.addAttribute("affiliation", "owner");
item.addAttribute("jid", packet.getFrom().toBareJID());
workgroup.send(iqPacket);
}
reply = IQ.createResultIQ(packet);
} catch (Exception 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.xmpp.packet.PacketError 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