Search in sources :

Example 11 with AgentNotFoundException

use of org.jivesoftware.xmpp.workgroup.AgentNotFoundException in project Openfire by igniterealtime.

the class TransferRequest 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
            offerAccepted = 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)

Example 12 with AgentNotFoundException

use of org.jivesoftware.xmpp.workgroup.AgentNotFoundException in project Openfire by igniterealtime.

the class IQChatSearchHandler method handleIQ.

public void handleIQ(IQ packet) {
    try {
        // Check that the sender of this IQ is an agent
        workgroupManager.getAgentManager().getAgent(packet.getFrom());
        Element iq = packet.getChildElement();
        IQ reply = IQ.createResultIQ(packet);
        if (iq.elements().isEmpty()) {
            reply.setChildElement(iq.createCopy());
            // Send the search form to the agent
            reply.addExtension(searchForm.createCopy());
            workgroupManager.send(reply);
        } else {
            // Send the result of the search to the agent
            Date startDate = null;
            Date endDate = null;
            Collection<Workgroup> workgroups = WorkgroupManager.getInstance().getWorkgroups();
            JID agentJID = null;
            String queryString = null;
            // Get the search parameters from the completed form
            DataForm submitedForm = (DataForm) packet.getExtension(DataForm.ELEMENT_NAME, DataForm.NAMESPACE);
            for (FormField field : submitedForm.getFields()) {
                if ("date/start".equals(field.getVariable())) {
                    try {
                        startDate = DataForm.parseDate(field.getValues().get(0));
                    } catch (ParseException e) {
                        Log.debug("Invalid startDate " + field.getValues().get(0), e);
                    }
                } else if ("date/end".equals(field.getVariable())) {
                    try {
                        endDate = DataForm.parseDate(field.getValues().get(0));
                    } catch (ParseException e) {
                        Log.debug("Invalid endDate " + field.getValues().get(0), e);
                    }
                } else if ("workgroups".equals(field.getVariable())) {
                    if (!field.getValues().isEmpty()) {
                        workgroups = new ArrayList<Workgroup>();
                        for (String value : field.getValues()) {
                            try {
                                workgroups.add(WorkgroupManager.getInstance().getWorkgroup(new JID(value)));
                            } catch (UserNotFoundException e) {
                                Log.debug("Invalid workgroup JID " + value, e);
                            }
                        }
                    } else {
                        // Search in all the workgroups since no one was specified
                        workgroups = WorkgroupManager.getInstance().getWorkgroups();
                    }
                } else if ("agent".equals(field.getVariable())) {
                    agentJID = new JID(field.getValues().get(0));
                } else if ("queryString".equals(field.getVariable())) {
                    queryString = field.getValues().get(0);
                }
            }
            // Build the response
            DataForm searchResults = resultForm.createCopy();
            // Perform the search
            for (Workgroup workgroup : workgroups) {
                ChatSearch search = new ChatSearch(workgroup, startDate, endDate, agentJID, queryString);
                for (QueryResult result : search.getResults()) {
                    Map<String, Object> fields = new LinkedHashMap<String, Object>();
                    fields.put("workgroup", result.getWorkgroup().getJID().toBareJID());
                    fields.put("sessionID", result.getSessionID());
                    fields.put("startDate", result.getStartDate());
                    fields.put("agentJIDs", result.getAgentJIDs());
                    fields.put("relevance", result.getRelevance());
                    // Add Metadata
                    Map<String, String> metadata = getMetadataMap(result.getSessionID());
                    if (metadata.containsKey("question")) {
                        fields.put("question", metadata.get("question"));
                    }
                    if (metadata.containsKey("email")) {
                        fields.put("email", metadata.get("email"));
                    }
                    if (metadata.containsKey("username")) {
                        fields.put("username", metadata.get("username"));
                    }
                    searchResults.addItemFields(fields);
                }
            }
            reply.setChildElement(iq.getName(), iq.getNamespaceURI());
            reply.addExtension(searchResults);
            workgroupManager.send(reply);
        }
    } catch (AgentNotFoundException e) {
        IQ reply = IQ.createResultIQ(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.not_authorized));
        workgroupManager.send(reply);
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) JID(org.xmpp.packet.JID) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException) PacketError(org.xmpp.packet.PacketError) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) DataForm(org.xmpp.forms.DataForm) ParseException(java.text.ParseException) FormField(org.xmpp.forms.FormField)

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