Search in sources :

Example 1 with ChatSettingsManager

use of org.jivesoftware.openfire.fastpath.settings.chat.ChatSettingsManager in project Openfire by igniterealtime.

the class WorkgroupIQHandler method handleIQGet.

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));
        }
    } else if ("transcripts".equals(name)) {
        try {
            // Otherwise return a not_authorized
            if (agentManager.getAgentSession(packet.getFrom()) == null) {
                reply = IQ.createResultIQ(packet);
                reply.setChildElement(packet.getChildElement().createCopy());
                reply.setError(new PacketError(PacketError.Condition.not_authorized));
            } else {
                String userID = iq.attributeValue("userID");
                stats.getChatTranscripts(packet, userID);
            }
        } catch (AgentNotFoundException e) {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.not_authorized));
        }
    } else if ("transcript".equals(name)) {
        try {
            // Otherwise return a not_authorized
            if (agentManager.getAgentSession(packet.getFrom()) == null) {
                reply = IQ.createResultIQ(packet);
                reply.setChildElement(packet.getChildElement().createCopy());
                reply.setError(new PacketError(PacketError.Condition.not_authorized));
            } else {
                String sessionID = iq.attributeValue("sessionID");
                stats.getChatTranscript(packet, sessionID);
            }
        } catch (AgentNotFoundException e) {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.not_authorized));
        }
    } else if ("agent-status-request".equals(name)) {
        try {
            AgentSession agentSession = agentManager.getAgentSession(packet.getFrom());
            if (agentSession == null) {
                reply = IQ.createResultIQ(packet);
                reply.setChildElement(packet.getChildElement().createCopy());
                reply.setError(new PacketError(PacketError.Condition.item_not_found));
            } else {
                agentSession.sendAgentsInWorkgroup(packet, workgroup);
            }
        } catch (AgentNotFoundException e) {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.item_not_found));
        }
    } else if ("agent-info".equals(name)) {
        try {
            // Send the agent's info to the session that requested its own information
            AgentSession agentSession = agentManager.getAgentSession(packet.getFrom());
            if (agentSession == null) {
                reply = IQ.createResultIQ(packet);
                reply.setChildElement(packet.getChildElement().createCopy());
                reply.setError(new PacketError(PacketError.Condition.item_not_found));
            } else {
                agentSession.sendAgentInfo(packet);
            }
        } catch (AgentNotFoundException e) {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.item_not_found));
        }
    } else if ("occupants-info".equals(name)) {
        try {
            // Just check that the packet was sent by a logged agent to this workgroup
            AgentSession agentSession = agentManager.getAgentSession(packet.getFrom());
            if (agentSession == null) {
                reply = IQ.createResultIQ(packet);
                reply.setChildElement(packet.getChildElement().createCopy());
                reply.setError(new PacketError(PacketError.Condition.not_authorized));
            } else {
                // Send information about the occupants of the requested room
                String roomID = iq.attributeValue("roomID");
                workgroup.sendOccupantsInfo(packet, roomID);
            }
        } catch (AgentNotFoundException e) {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.not_authorized));
        }
    } else if ("chat-settings".equals(name)) {
        ChatSettingsManager chatSettingsManager = ChatSettingsManager.getInstance();
        String key = iq.attributeValue("key");
        String type = iq.attributeValue("type");
        if (ModelUtil.hasLength(key)) {
            chatSettingsManager.getChatSettingByKey(packet, workgroup, key);
        } else if (ModelUtil.hasLength(type)) {
            try {
                int typeInt = Integer.parseInt(type);
                chatSettingsManager.getChatSettingsByType(packet, workgroup, typeInt);
            } catch (NumberFormatException e) {
            // Bad type.
            }
        } else {
            chatSettingsManager.getAllChatSettings(packet, workgroup);
        }
    } else if ("jabber:iq:private".equals(namespace)) {
        // IQ private for agents global macro storage
        getIQPrivate(packet);
    } else if ("vcard-temp".equals(namespace)) {
        // Return workgroup's VCard
        getVCard(packet);
    } else {
        // none are found, send bad request error.
        for (WorkgroupProvider provider : providerManager.getWorkgroupProviders()) {
            // Will provider handle the GET
            if (provider.handleGet(packet)) {
                // Pass off packet
                provider.executeGet(packet, workgroup);
                return;
            }
        }
        dropPacket(packet);
        reply = IQ.createResultIQ(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.bad_request));
    }
    if (reply != null) {
        workgroup.send(reply);
    }
}
Also used : ChatSettingsManager(org.jivesoftware.openfire.fastpath.settings.chat.ChatSettingsManager) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) NotFoundException(org.jivesoftware.util.NotFoundException) PacketError(org.xmpp.packet.PacketError) UserRequest(org.jivesoftware.xmpp.workgroup.request.UserRequest)

Aggregations

Element (org.dom4j.Element)1 ChatSettingsManager (org.jivesoftware.openfire.fastpath.settings.chat.ChatSettingsManager)1 NotFoundException (org.jivesoftware.util.NotFoundException)1 UserRequest (org.jivesoftware.xmpp.workgroup.request.UserRequest)1 IQ (org.xmpp.packet.IQ)1 PacketError (org.xmpp.packet.PacketError)1