use of org.jivesoftware.xmpp.workgroup.Agent in project Openfire by igniterealtime.
the class WorkgroupUtils method addAgents.
/**
* Adds agents to a request queue.
*
* @param queue the <code>RequestQueue</code> to add agents to.
* @param agents a comma-delimited list of agents.
*/
public static void addAgents(RequestQueue queue, String agents) {
WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
AgentManager agentManager = workgroupManager.getAgentManager();
// loop thru all params
StringTokenizer tokenizer = new StringTokenizer(agents, ", \t\n\r\f");
while (tokenizer.hasMoreTokens()) {
String usernameToken = tokenizer.nextToken();
if (usernameToken.indexOf('@') != -1) {
usernameToken = JID.escapeNode(usernameToken);
}
try {
// See if they are a user in the system.
UserManager.getInstance().getUser(usernameToken);
usernameToken += ("@" + ComponentManagerFactory.getComponentManager().getServerName());
JID address = new JID(usernameToken.trim());
Agent agent;
if (agentManager.hasAgent(address)) {
agent = agentManager.getAgent(address);
} else {
agent = agentManager.createAgent(address);
}
queue.addMember(agent);
} catch (Exception e) {
Log.error(e.getMessage(), e);
}
}
}
use of org.jivesoftware.xmpp.workgroup.Agent 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.Agent 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);
}
Aggregations