Package org.jivesoftware.xmpp.workgroup.request

Examples of org.jivesoftware.xmpp.workgroup.request.UserRequest


                JID presenceFullJID = new JID(item.attributeValue("jid"));
                String presenceJID = presenceFullJID.toBareJID();
                // Invoke the room interceptor before processing the presence
                interceptorManager.invokeInterceptors(getJID().toBareJID(), packet, false, false);
                // Get the userID associated to this sessionID
                UserRequest initialRequest = requests.get(sessionID);
                // Add the new presence to the list of sent packets
                Map<Packet, java.util.Date> messageList = transcripts.get(roomID);
                if (messageList == null) {
                    messageList = new LinkedHashMap<Packet, java.util.Date>();
                    transcripts.put(roomID, messageList);
                    // Trigger the event that a chat support has started
                    WorkgroupEventDispatcher.chatSupportStarted(this, sessionID);
                }
                messageList.put(packet.createCopy(), new java.util.Date());

                // Update the number of occupants in the room.
                boolean occupantAdded = false;
                Set<String> set = occupantsCounter.get(roomID);
                if (set == null) {
                    set = new HashSet<String>();
                    occupantsCounter.put(roomID, set);
                }
                if (presence.isAvailable()) {
                    occupantAdded = set.add(presenceJID);
                }
                else {
                    String xpath = "/presence/*[name()='x']/*[name()='status']";
                    Element status = (Element)presence.getElement().selectSingleNode(xpath);
                    if (status == null || !"303".equals(status.attributeValue("code"))) {
                        // Remove the occupant unless the occupant is changing his nickname
                        set.remove(presenceJID);
                    }
                }
                // If the presence belongs to an Agent then create/update a track
                // Look for an agent whose JID matches the presence's JID
                String agentJID = null;
                for (Agent agent : getAgents()) {
                    if (agent.getAgentJID().toBareJID().equals(presenceJID)) {
                        agentJID = agent.getAgentJID().toBareJID();
                    }
                }
                if (agentJID != null) {
                    AgentSession agentSession;
                    // Update the current chats that the agent is having
                    try {
                        agentSession = agentManager.getAgentSession(presenceFullJID);
                        if (agentSession != null) {
                            if (presence.isAvailable()) {
                                if (occupantAdded) {
                                    agentSession.addChatInfo(this, sessionID, initialRequest, new java.util.Date());
                                    // Trigger the event that an agent has joined a chat session
                                    WorkgroupEventDispatcher.agentJoinedChatSupport(this, sessionID, agentSession);
                                }
                            }
                            else {
                                agentSession.removeChatInfo(this, sessionID);
                                // Trigger the event that an agent has left a chat session
                                WorkgroupEventDispatcher.agentLeftChatSupport(this, sessionID, agentSession);
                            }
                        }
                    }
                    catch (AgentNotFoundException e) {
                        // Do nothing since the AgentSession was not found
                    }
                    if (presence.isAvailable()) {
                        if (occupantAdded) {
                            // Store in the DB that an agent has joined a room
                            DbWorkgroup.updateJoinedSession(sessionID, agentJID, true);
                        }
                    }
                    else {
                        // Store in the DB that an agent has left a room
                        DbWorkgroup.updateJoinedSession(sessionID, agentJID, false);
                    }
                }
                else {
                    if (occupantAdded) {
                        // Notify the request that the user has joined a support session
                        initialRequest.supportStarted(roomID);
                    }
                }
                if (occupantAdded) {
                    initialRequest.userJoinedRoom(new JID(packet.getFrom().toBareJID()), presenceFullJID);
                }

                // If just the user has left the room, just persist the transcript
                boolean isAgent = false;
                try {
                    isAgent = agentManager.getAgentSession(presenceFullJID) != null;
                }
                catch (AgentNotFoundException e) {
                    // Ignore.
                }

                if (!((Presence)packet).isAvailable() && !isAgent) {
                    // Build the XML for the transcript
                    Map<Packet, java.util.Date> map = transcripts.get(roomID);
                    StringBuilder buf = new StringBuilder();
                    buf.append("<transcript>");
                    for (Packet p : map.keySet()) {
                        java.util.Date date = map.get(p);
                        // Add the delay information
                        if (p instanceof Message) {
                            Message storedMessage = (Message)p;
                            Element delay = storedMessage.addChildElement("x", "jabber:x:delay");
                            delay.addAttribute("stamp", UTC_FORMAT.format(date));
                            if (ModelUtil.hasLength(storedMessage.getBody())) {
                                buf.append(p.toXML());
                            }
                        }
                        else {
                            Presence storedPresence = (Presence)p;
                            Element delay = storedPresence.addChildElement("x", "jabber:x:delay");
                            delay.addAttribute("stamp", UTC_FORMAT.format(date));
                            buf.append(p.toXML());
                        }
                        // Append an XML representation of the packet to the string buffer
                    }
                    buf.append("</transcript>");
                    // Save the transcript (in XML) to the DB
                    DbWorkgroup.updateTranscript(sessionID, buf.toString(), new java.util.Date());
                }

                // If the agent and the user left the room then proceed to dump the transcript to
                // the DB and destroy the room
                if (!((Presence)packet).isAvailable() && set.isEmpty()) {
                    // Delete the counter of occupants for this room
                    occupantsCounter.remove(roomID);
                    initialRequest = requests.remove(sessionID);
                    if (initialRequest != null && initialRequest.hasJoinedRoom()) {
                        // Notify the request that the support session has finished
                        initialRequest.supportEnded();
                    }
                    // Build the XML for the transcript
                    Map<Packet, java.util.Date> map = transcripts.get(roomID);
                    StringBuilder buf = new StringBuilder();
                    buf.append("<transcript>");
View Full Code Here


     * join the workgroup then instead of receiving another invitation he may be asked if he wants
     * to receive another invitation.
     */
    public void checkRequests() {
        for (String roomID : requests.keySet()) {
            UserRequest request = requests.get(roomID);
            // Check invitations if an invitation was sent and the user hasn't joined the room yet
            if (request != null) {
                request.checkRequest(roomID);
            }
        }
    }
View Full Code Here

    public Collection<UserRequest> getRequests() {
        return new ArrayList<UserRequest>(requests);
    }

    public UserRequest getRequest(JID requestAddress) {
        UserRequest returnRequest = null;

        for (UserRequest request : getRequests()) {
            if (requestAddress.equals(request.getUserJID())) {
                returnRequest = request;
                break;
View Full Code Here

            InterceptorManager interceptorManager = QueueInterceptorManager.getInstance();
            try {
                interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true,
                        false);
                // Received a Join Queue request from a visitor, create a new request.
                UserRequest request = new UserRequest(packet, workgroup);
                // Let the workgroup process the new request
                if (!workgroup.queueRequest(request)) {
                    // It was not possible to add the request to a queue so answer that the
                    // workgroup is not accepting new join-queue requests
                    reply.setChildElement(packet.getChildElement().createCopy());
                    reply.setError(new PacketError(PacketError.Condition.service_unavailable));
                }
                interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true,
                        true);
            }
            catch (PacketRejectedException e) {
                workgroup.rejectPacket(packet, e);
                reply = null;
            }
        }
        else if ("depart-queue".equals(queryName)) {
            // Visitor is departing queue
            try {
                Request request = UserRequest.getRequest(workgroup, sender);
                InterceptorManager interceptorManager = QueueInterceptorManager.getInstance();
                try {
                    interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet,
                            true, false);
                    request.cancel(Request.CancelType.DEPART);
                    iq.add(request.getSessionElement());
                    interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet,
                            true, true);
                }
                catch (PacketRejectedException e) {
                    workgroup.rejectPacket(packet, e);
                    reply = null;
                }
            }
            catch (NotFoundException e) {
                reply.setChildElement(packet.getChildElement().createCopy());
                reply.setError(new PacketError(PacketError.Condition.item_not_found));
                Log.debug("Request not found" +
                        " while departing queue:", e);
            }
        }
        else if ("offer-accept".equals(queryName)) {
            try {
                InterceptorManager interceptorManager = OfferInterceptorManager.getInstance();
                String id = iq.attributeValue("id");
                String jid = iq.attributeValue("jid");
                if (id != null || jid  != null) {
                    Request request;
                    if (id != null) {
                        // Search request by its unique ID
                        request = Request.getRequest(id);
                    }
                    else  {
                        // Old version of FP refers to requests by the user's jid. This old version
                        // implements transfers and invitations on the client and not the server side.
                        // Therefore, for each user's jid there is always a unique Request
                        request = UserRequest.getRequest(workgroup, new JID(jid));
                    }
                    Offer offer = request.getOffer();
                    if (offer != null && offer.isOutstanding()) {
                        AgentSession agentSession = agentManager.getAgentSession(packet.getFrom());
                        if (agentSession == null) {
                            reply.setChildElement(packet.getChildElement().createCopy());
                            reply.setError(new PacketError(PacketError.Condition.item_not_found));
                            Log
                                    .debug("Agent not found while accepting offer");
                        }
                        else {
                            try {
                                interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(),
                                        packet, true, false);
                                offer.accept(agentSession);
                                interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(),
                                        packet, true, true);
                            }
                            catch (PacketRejectedException e) {
                                workgroup.rejectPacket(packet, e);
                                reply = null;
                            }
                        }
                    }
                    else {
                        reply.setChildElement(packet.getChildElement().createCopy());
                        reply.setError(new PacketError(PacketError.Condition.not_acceptable));
                    }
                }
            }
            catch (NotFoundException e) {
                reply.setChildElement(packet.getChildElement().createCopy());
                reply.setError(new PacketError(PacketError.Condition.item_not_found));
                Log.debug("Request not found " +
                        "while accepting offer: ", e);
            }
            catch (AgentNotFoundException e) {
                reply.setChildElement(packet.getChildElement().createCopy());
                reply.setError(new PacketError(PacketError.Condition.item_not_found));
                Log.debug("Agent not found " +
                        "while accepting offer: ", e);
            }
        }
        else if ("offer-reject".equals(queryName)) {
            try {
                InterceptorManager interceptorManager = OfferInterceptorManager.getInstance();
                String id = iq.attributeValue("id");
                String jid = iq.attributeValue("jid");
                if (id != null || jid  != null) {
                    Request request;
                    if (id != null) {
                        // Search request by its unique ID
                        request = Request.getRequest(id);
                    }
                    else  {
                        // Old version of FP refers to requests by the user's jid. This old version
                        // implements transfers and invitations on the client and not the server side.
                        // Therefore, for each user's jid there is always a unique Request
                        request = UserRequest.getRequest(workgroup, new JID(jid));
                    }
                    Offer offer = request.getOffer();
                    if (offer != null) {
                        AgentSession agentSession = agentManager.getAgentSession(packet.getFrom());
                        if (agentSession == null) {
                            reply.setChildElement(packet.getChildElement().createCopy());
                            reply.setError(new PacketError(PacketError.Condition.item_not_found));
View Full Code Here

    private void handleIQGet(IQ packet) {
        IQ reply = null;
        // TODO: verify namespace and send error if wrong
        Element iq = packet.getChildElement();
        UserRequest request;

        final WorkgroupStats stats = new WorkgroupStats(workgroup);

        String name = iq.getName();
        String namespace = iq.getNamespaceURI();
        if ("queue-status".equals(name)) {
            try {
                request = UserRequest.getRequest(workgroup, packet.getFrom());
                request.updateQueueStatus(true);
            }
            catch (NotFoundException e) {
                reply = IQ.createResultIQ(packet);
                reply.setChildElement(packet.getChildElement().createCopy());
                reply.setError(new PacketError(PacketError.Condition.item_not_found));
View Full Code Here

            }
            // Set that we are currently joining a waiting queue
            session.setCurrentStep(3);

            // Received a Join Queue request from a visitor, create a new request.
            UserRequest request = new UserRequest(session, workgroup);
            // Let the workgroup process the new request
            if (!workgroup.queueRequest(request)) {
                // It was not possible to add the request to a queue so send message saying that
                // the workgroup is not accepting new join requests
                sendReply(message, getCannotJoinMessage());
View Full Code Here

        session.setCurrentStep(6);
        sendMessage(receiver, session.getMessageThread(), getSendEmailQuestion());
    }

    private void sendRoomInvitation(Message message, ChatbotSession session) {
        UserRequest request = session.getRequest();
        // Send again the room invitation to the user
        workgroup.sendUserInvitiation(request, request.getInvitedRoomID());
        // Send a confirmation to the user notifying that the invitation was sent
        sendMessage(message.getFrom(), session.getMessageThread(), getInvitationResentMessage());
    }
View Full Code Here

            }
        }
        else if (session.getCurrentStep() == 3) {
            if (getPositionCommand().equalsIgnoreCase(command)) {
                try {
                    UserRequest request = UserRequest.getRequest(workgroup, message.getFrom());
                    request.updateQueueStatus(true);
                }
                catch (NotFoundException e) {
                    // Tell the user that he is not waiting in the queue
                    sendReply(message, getNotInQueueMessage());
                }
View Full Code Here

        }
        // If a backup queue was found then cancel this offer, remove the request from the queue
        // and add the request in the backup queue
        if (backup != null) {
            offer.cancel();
            UserRequest request = (UserRequest) offer.getRequest();
            // Remove the request from the queue since it is going to be added to another
            // queue
            queue.removeRequest(request);
            // Log debug trace
            Log.debug("RR - Overflowing request: " + request + " to queue: " +
View Full Code Here

TOP

Related Classes of org.jivesoftware.xmpp.workgroup.request.UserRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.