Search in sources :

Example 1 with AgentNotFoundException

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

the class AgentHistory method executeGet.

public void executeGet(IQ packet, Workgroup workgroup) {
    IQ reply = IQ.createResultIQ(packet);
    try {
        if (workgroup.getAgentManager().getAgentSession(packet.getFrom()) == null) {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.not_authorized));
            workgroup.send(reply);
            return;
        }
    } catch (AgentNotFoundException e) {
        reply = IQ.createResultIQ(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.not_authorized));
        workgroup.send(reply);
        return;
    }
    // Create session list
    List<AgentHistoryModel> sessionList = new ArrayList<AgentHistoryModel>();
    Element chatSessions = reply.setChildElement("chat-sessions", "http://jivesoftware.com/protocol/workgroup");
    Element iq = packet.getChildElement();
    String agentJID = iq.attributeValue("agentJID");
    String ms = iq.attributeValue("maxSessions");
    String date = iq.attributeValue("startDate");
    long startTime = 0;
    if (date != null) {
        startTime = Long.parseLong(date);
    }
    int maxSessions = Integer.parseInt(ms);
    Connection con = null;
    PreparedStatement pstmt = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(GET_AGENT_SESSIONS);
        pstmt.setString(1, agentJID);
        ResultSet result = pstmt.executeQuery();
        while (result.next()) {
            String sessionID = result.getString(1);
            String joinTime = result.getString(2);
            String leftTime = result.getString(3);
            AgentHistoryModel model = new AgentHistoryModel();
            if (ModelUtil.hasLength(joinTime) && ModelUtil.hasLength(leftTime)) {
                try {
                    long start = Long.valueOf(joinTime);
                    long end = Long.valueOf(leftTime);
                    long totalTime = end - start;
                    model.setSessionID(sessionID);
                    model.setJoinTime(joinTime);
                    model.setDuration(Long.toString(totalTime));
                    if (start >= startTime) {
                        sessionList.add(model);
                    }
                } catch (NumberFormatException e) {
                    Log.error(e.getMessage(), e);
                }
            }
        }
        result.close();
    } catch (Exception ex) {
        Log.error(ex.getMessage(), ex);
    } finally {
        DbConnectionManager.closeConnection(pstmt, con);
    }
    buildAndSend(sessionList, chatSessions, reply, workgroup, maxSessions);
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) PacketError(org.xmpp.packet.PacketError) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException) PreparedStatement(java.sql.PreparedStatement) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException) ResultSet(java.sql.ResultSet)

Example 2 with AgentNotFoundException

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

the class ChatMetadataProvider method executeGet.

public void executeGet(IQ packet, Workgroup workgroup) {
    IQ reply = IQ.createResultIQ(packet);
    try {
        AgentSession agentSession = workgroup.getAgentManager().getAgentSession(packet.getFrom());
        if (agentSession == null) {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.not_authorized));
            workgroup.send(reply);
            return;
        }
    } catch (AgentNotFoundException e) {
        reply = IQ.createResultIQ(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.not_authorized));
        workgroup.send(reply);
        return;
    }
    Element chatSessions = reply.setChildElement("chat-metadata", "http://jivesoftware.com/protocol/workgroup");
    Element iq = packet.getChildElement();
    String sessionID = iq.element("sessionID").getTextTrim();
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    Map<String, String> map = new HashMap<String, String>();
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(GET_SESSION_METADATA);
        pstmt.setString(1, sessionID);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            String name = rs.getString(1);
            String value = rs.getString(2);
            map.put(name, value);
        }
    } catch (Exception ex) {
        Log.error(ex.getMessage(), ex);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
    // Add metadata
    chatSessions.add(getMetaDataElement(map));
    workgroup.send(reply);
}
Also used : AgentSession(org.jivesoftware.xmpp.workgroup.AgentSession) HashMap(java.util.HashMap) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PacketError(org.xmpp.packet.PacketError) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException) PreparedStatement(java.sql.PreparedStatement) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException)

Example 3 with AgentNotFoundException

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

the class ChatNotes method executeSet.

public void executeSet(IQ packet, Workgroup workgroup) {
    IQ reply;
    Element iq = packet.getChildElement();
    try {
        // Verify that an agent is requesting this information.
        AgentSession agentSession = workgroup.getAgentManager().getAgentSession(packet.getFrom());
        if (agentSession != null) {
            String sessionID = iq.element("sessionID").getTextTrim();
            Element notes = iq.element("notes");
            String noteText = notes.getTextTrim();
            appendNote(sessionID, noteText);
            reply = IQ.createResultIQ(packet);
        } else {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.item_not_found));
        }
    } 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 4 with AgentNotFoundException

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

the class SiteTracker method handleUserHistoryRequest.

private void handleUserHistoryRequest(IQ packet, Workgroup workgroup) {
    IQ reply;
    Element iq = packet.getChildElement();
    try {
        AgentSession agentSession = workgroup.getAgentManager().getAgentSession(packet.getFrom());
        if (agentSession == null) {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.not_authorized));
            workgroup.send(reply);
            return;
        }
    } catch (AgentNotFoundException e) {
        reply = IQ.createResultIQ(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.not_authorized));
        workgroup.send(reply);
        return;
    }
    // Define default values
    String sessionID = iq.attribute("sessionID").getText();
    reply = IQ.createResultIQ(packet);
    Element views = reply.setChildElement("site-user-history", "http://jivesoftware.com/protocol/workgroup");
    views.addAttribute("sessionID", sessionID);
    SiteUser siteUser = siteUsers.get(sessionID);
    if (siteUser != null) {
        for (PageView view : siteUser.getViews()) {
            Element pageView = views.addElement("page-view");
            pageView.addElement("title").setText(view.getTitle());
            pageView.addElement("url").setText(view.getUrl());
            pageView.addElement("time").setText(Long.toString(view.getTimeViewed()));
        }
        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 5 with AgentNotFoundException

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

the class SearchProvider method executeGet.

public void executeGet(IQ packet, Workgroup workgroup) {
    IQ reply = IQ.createResultIQ(packet);
    // Retrieve the web chat setting.
    String kbURL = workgroup.getProperties().getProperty("kb");
    String forumURL = workgroup.getProperties().getProperty("forums");
    // Check that the sender of this IQ is an agent
    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;
    }
    Element searchSetting = reply.setChildElement("search-settings", "http://jivesoftware.com/protocol/workgroup");
    if (forumURL != null) {
        searchSetting.addElement("forums").setText(forumURL);
    }
    if (kbURL != null) {
        searchSetting.addElement("kb").setText(kbURL);
    }
    workgroup.send(reply);
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException) PacketError(org.xmpp.packet.PacketError) WorkgroupManager(org.jivesoftware.xmpp.workgroup.WorkgroupManager)

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