Search in sources :

Example 1 with AgentManager

use of org.jivesoftware.xmpp.workgroup.AgentManager 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);
        }
    }
}
Also used : Agent(org.jivesoftware.xmpp.workgroup.Agent) AgentManager(org.jivesoftware.xmpp.workgroup.AgentManager) StringTokenizer(java.util.StringTokenizer) JID(org.xmpp.packet.JID) WorkgroupManager(org.jivesoftware.xmpp.workgroup.WorkgroupManager) StringprepException(gnu.inet.encoding.StringprepException) UserAlreadyExistsException(org.jivesoftware.xmpp.workgroup.UserAlreadyExistsException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Aggregations

StringprepException (gnu.inet.encoding.StringprepException)1 StringTokenizer (java.util.StringTokenizer)1 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)1 Agent (org.jivesoftware.xmpp.workgroup.Agent)1 AgentManager (org.jivesoftware.xmpp.workgroup.AgentManager)1 UserAlreadyExistsException (org.jivesoftware.xmpp.workgroup.UserAlreadyExistsException)1 WorkgroupManager (org.jivesoftware.xmpp.workgroup.WorkgroupManager)1 JID (org.xmpp.packet.JID)1