use of org.jivesoftware.xmpp.workgroup.AgentNotFoundException in project Openfire by igniterealtime.
the class MacroProvider method executeSet.
public void executeSet(IQ packet, Workgroup workgroup) {
IQ reply;
Element iq = packet.getChildElement();
String personalMacro = iq.element("personalMacro").getTextTrim();
try {
// Verify that an agent is requesting this information.
Agent agent = workgroup.getAgentManager().getAgent(packet.getFrom());
DbProperties props = agent.getProperties();
XStream xstream = new XStream();
xstream.alias("macro", Macro.class);
xstream.alias("macrogroup", MacroGroup.class);
MacroGroup group = (MacroGroup) xstream.fromXML(personalMacro);
String saveString = xstream.toXML(group);
try {
props.deleteProperty("personal.macro");
props.setProperty("personal.macro", saveString);
} catch (UnauthorizedException e) {
Log.error(e.getMessage(), e);
}
reply = IQ.createResultIQ(packet);
} 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 MacroProvider method executeGet.
public void executeGet(IQ packet, Workgroup workgroup) {
IQ reply = IQ.createResultIQ(packet);
Element iq = packet.getChildElement();
String name = iq.getName();
boolean isPersonal = iq.element("personal") != null;
Agent agent;
try {
agent = workgroup.getAgentManager().getAgent(packet.getFrom());
} catch (AgentNotFoundException e) {
sendItemNotFound(packet, workgroup);
return;
}
if ("macros".equals(name) && !isPersonal) {
Element globalMacros = reply.setChildElement("macros", "http://jivesoftware.com/protocol/workgroup");
DbProperties props = workgroup.getProperties();
String macroModel = props.getProperty("jive.macro" + workgroup.getID());
if (ModelUtil.hasLength(macroModel)) {
globalMacros.addElement("model").setText(macroModel);
} else {
sendItemNotFound(packet, workgroup);
return;
}
} else if (isPersonal) {
Element personalMacros = reply.setChildElement("macros", "http://jivesoftware.com/protocol/workgroup");
DbProperties props = agent.getProperties();
String macroModel = props.getProperty("personal.macro");
if (ModelUtil.hasLength(macroModel)) {
personalMacros.addElement("model").setText(macroModel);
} else {
sendItemNotFound(packet, workgroup);
return;
}
} else {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.item_not_found));
workgroup.send(reply);
return;
}
workgroup.send(reply);
}
use of org.jivesoftware.xmpp.workgroup.AgentNotFoundException in project Openfire by igniterealtime.
the class ChatNotes method executeGet.
public void executeGet(IQ packet, Workgroup workgroup) {
IQ reply;
Element iq = packet.getChildElement();
// Verify that an agent is requesting this information.
try {
AgentSession agentSession = workgroup.getAgentManager().getAgentSession(packet.getFrom());
if (agentSession != null) {
String sessionID = iq.element("sessionID").getTextTrim();
sendNotesPacket(packet, workgroup, sessionID);
} else {
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.item_not_found));
workgroup.send(reply);
}
} 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 MetadataProvider method executeGet.
/**
* Executed if #handleGet returned true. This is responsible for sending
* information back to the client.
*
* @param packet the IQ GET packet sent to the server.
* @param workgroup the Workgroup the packet was sent to.
*/
public void executeGet(IQ packet, Workgroup workgroup) {
// Create the generic reply packet.
IQ reply = IQ.createResultIQ(packet);
// Check that the sender of this IQ is an agent. If so
// we throw an item not found exception.
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;
}
// If the sender of the packet is an agent, send back name-value pairs
// of all properties files specified.
final Map<String, String> map = new HashMap<String, String>();
final List<String> configFiles = JiveGlobals.getProperties("config");
for (String fileName : configFiles) {
File file = new File(fileName);
if (file.exists()) {
// load properties file.
Properties props = new Properties();
try {
props.load(new FileInputStream(file));
Enumeration<?> properties = props.propertyNames();
while (properties.hasMoreElements()) {
String key = (String) properties.nextElement();
String value = props.getProperty(key);
map.put(key, value);
}
} catch (IOException e) {
Log.error(e.getMessage(), e);
}
}
}
// It is VERY IMPORTANT that you use the same name and namespace as the sending packet. Otherwise,
// it would never be mapped correctly.
final Element genericSetting = reply.setChildElement("generic-metadata", "http://jivesoftware.com/protocol/workgroup");
for (Map.Entry<String, String> entry : map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
// Create a name-value element
Element element = genericSetting.addElement("entry");
element.addElement("name").setText(key);
element.addElement("value").setText(value);
}
// Send back new packet with requested information.
workgroup.send(reply);
}
use of org.jivesoftware.xmpp.workgroup.AgentNotFoundException in project Openfire by igniterealtime.
the class InvitationRequest method execute.
public void execute() {
if (Type.user == type) {
AgentSession agentSession = null;
// Verify if the invitee user is an agent that is currently logged
try {
agentSession = WorkgroupManager.getInstance().getAgentManager().getAgent(invitee).getAgentSession();
} catch (AgentNotFoundException e) {
// Ignore
}
// Only Send muc invites to a particular user.
if (true) {
// Invitee is not an agent so send a standard MUC room invitation
sendMUCInvitiation();
// Keep track when the invitation was sent to the user
offerAccpeted = System.currentTimeMillis();
} else {
// Invite the agent to the room by sending an offer
Workgroup workgroup = agentSession.getWorkgroups().iterator().next();
RequestQueue requestQueue = workgroup.getRequestQueues().iterator().next();
// Add the requested agent as the initial target agent to get the offer
getMetaData().put("agent", Arrays.asList(invitee.toString()));
getMetaData().put("ignore", Arrays.asList(inviter.toBareJID()));
// Dispatch the request
requestQueue.getDispatcher().injectRequest(this);
}
} else if (Type.queue == type) {
// Send offer to the best again available in the requested queue
Workgroup targetWorkgroup = WorkgroupManager.getInstance().getWorkgroup(invitee.getNode());
if (targetWorkgroup == null) {
// No workgroup was found for the specified invitee. Send a Message with the error
sendErrorMessage("Specified workgroup was not found.");
return;
}
try {
RequestQueue requestQueue = targetWorkgroup.getRequestQueue(invitee.getResource());
getMetaData().put("ignore", Arrays.asList(inviter.toBareJID()));
// Dispatch the request
requestQueue.getDispatcher().injectRequest(this);
} catch (NotFoundException e) {
// No queue was found for the specified invitee. Send a Message with the error
sendErrorMessage("Specified queue was not found.");
}
} else if (Type.workgroup == type) {
// Select the best queue based on the original request
Workgroup targetWorkgroup = WorkgroupManager.getInstance().getWorkgroup(invitee.getNode());
if (targetWorkgroup != null) {
RequestQueue requestQueue = RoutingManager.getInstance().getBestQueue(targetWorkgroup, userRequest);
getMetaData().put("ignore", Arrays.asList(inviter.toBareJID()));
// Send offer to the best again available in the requested queue
requestQueue.getDispatcher().injectRequest(this);
} else {
// No workgroup was found for the specified invitee. Send a Message with the error
sendErrorMessage("Specified workgroup was not found.");
}
}
}
Aggregations