Search in sources :

Example 1 with Agent

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);
        }
    }
}
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)

Example 2 with Agent

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);
}
Also used : Agent(org.jivesoftware.xmpp.workgroup.Agent) XStream(com.thoughtworks.xstream.XStream) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) UnauthorizedException(org.jivesoftware.xmpp.workgroup.UnauthorizedException) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException) PacketError(org.xmpp.packet.PacketError) DbProperties(org.jivesoftware.xmpp.workgroup.DbProperties)

Example 3 with Agent

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);
}
Also used : Agent(org.jivesoftware.xmpp.workgroup.Agent) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException) PacketError(org.xmpp.packet.PacketError) DbProperties(org.jivesoftware.xmpp.workgroup.DbProperties)

Aggregations

Agent (org.jivesoftware.xmpp.workgroup.Agent)3 Element (org.dom4j.Element)2 AgentNotFoundException (org.jivesoftware.xmpp.workgroup.AgentNotFoundException)2 DbProperties (org.jivesoftware.xmpp.workgroup.DbProperties)2 IQ (org.xmpp.packet.IQ)2 PacketError (org.xmpp.packet.PacketError)2 XStream (com.thoughtworks.xstream.XStream)1 StringprepException (gnu.inet.encoding.StringprepException)1 StringTokenizer (java.util.StringTokenizer)1 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)1 AgentManager (org.jivesoftware.xmpp.workgroup.AgentManager)1 UnauthorizedException (org.jivesoftware.xmpp.workgroup.UnauthorizedException)1 UserAlreadyExistsException (org.jivesoftware.xmpp.workgroup.UserAlreadyExistsException)1 WorkgroupManager (org.jivesoftware.xmpp.workgroup.WorkgroupManager)1 JID (org.xmpp.packet.JID)1