Search in sources :

Example 6 with AgentNotFoundException

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

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

Example 8 with AgentNotFoundException

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

Example 9 with AgentNotFoundException

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);
}
Also used : HashMap(java.util.HashMap) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException) PacketError(org.xmpp.packet.PacketError) IOException(java.io.IOException) Properties(java.util.Properties) WorkgroupManager(org.jivesoftware.xmpp.workgroup.WorkgroupManager) FileInputStream(java.io.FileInputStream) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with AgentNotFoundException

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.");
        }
    }
}
Also used : AgentSession(org.jivesoftware.xmpp.workgroup.AgentSession) RequestQueue(org.jivesoftware.xmpp.workgroup.RequestQueue) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException) NotFoundException(org.jivesoftware.util.NotFoundException) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup)

Aggregations

AgentNotFoundException (org.jivesoftware.xmpp.workgroup.AgentNotFoundException)12 Element (org.dom4j.Element)10 IQ (org.xmpp.packet.IQ)10 PacketError (org.xmpp.packet.PacketError)10 AgentSession (org.jivesoftware.xmpp.workgroup.AgentSession)6 Workgroup (org.jivesoftware.xmpp.workgroup.Workgroup)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 HashMap (java.util.HashMap)2 NotFoundException (org.jivesoftware.util.NotFoundException)2 Agent (org.jivesoftware.xmpp.workgroup.Agent)2 DbProperties (org.jivesoftware.xmpp.workgroup.DbProperties)2 RequestQueue (org.jivesoftware.xmpp.workgroup.RequestQueue)2 WorkgroupManager (org.jivesoftware.xmpp.workgroup.WorkgroupManager)2 XStream (com.thoughtworks.xstream.XStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1