Search in sources :

Example 6 with Workgroup

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

the class ChatHistoryUtils method getTotalChatTimeForWorkgroup.

/**
     * Returns the total chat length of an individual workgroup.
     *
     * @param workgroupName the name of the workgroup.
     * @return the total length of all chats in the specified workgroup.
     */
public static long getTotalChatTimeForWorkgroup(String workgroupName) {
    Workgroup workgroup = null;
    try {
        workgroup = WorkgroupManager.getInstance().getWorkgroup(new JID(workgroupName));
    } catch (Exception ex) {
        Log.error(ex.getMessage(), ex);
    }
    int totalWorkgroupChatTime = 0;
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(CHAT_TIMES_FOR_WORKGROUPS);
        pstmt.setLong(1, workgroup.getID());
        rs = pstmt.executeQuery();
        while (rs.next()) {
            String startTimeString = rs.getString(1);
            String endTimeString = rs.getString(2);
            if ((startTimeString != null) && (startTimeString.trim().length() > 0) && (endTimeString != null) && (endTimeString.trim().length() > 0)) {
                long startLong = Long.parseLong(startTimeString);
                long endLong = Long.parseLong(endTimeString);
                totalWorkgroupChatTime += endLong - startLong;
            }
        }
    } catch (Exception ex) {
        Log.error(ex.getMessage(), ex);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
    return totalWorkgroupChatTime;
}
Also used : JID(org.xmpp.packet.JID) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) SQLException(java.sql.SQLException)

Example 7 with Workgroup

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

the class ChatHistoryUtils method getNumberOfChatsForWorkgroup.

/**
     * Returns the total number of chats that have occured within a workgroup.
     *
     * @param workgroupName the jid of the workgroup.
     * @return the total number of chats that have occured within a workgroup.
     */
public static int getNumberOfChatsForWorkgroup(String workgroupName) {
    Workgroup workgroup = null;
    try {
        workgroup = WorkgroupManager.getInstance().getWorkgroup(new JID(workgroupName));
    } catch (Exception ex) {
        Log.error(ex.getMessage(), ex);
    }
    int count = 0;
    for (RequestQueue requestQueue : workgroup.getRequestQueues()) {
        count += requestQueue.getTotalChatCount();
    }
    return count;
}
Also used : JID(org.xmpp.packet.JID) RequestQueue(org.jivesoftware.xmpp.workgroup.RequestQueue) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) SQLException(java.sql.SQLException)

Example 8 with Workgroup

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

the class ImageServlet method getImage.

/**
     * Returns the image bytes of the encoded image.
     *
     * @param imageName the name of the image.
     * @param workgroupName the name of the workgroup.
     * @return the image bytes found, otherwise null.
     */
public byte[] getImage(String imageName, String workgroupName) {
    WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
    JID workgroupJID = new JID(workgroupName);
    Workgroup workgroup;
    try {
        workgroup = workgroupManager.getWorkgroup(workgroupJID);
    } catch (UserNotFoundException e) {
        Log.error(e.getMessage(), e);
        return null;
    }
    ChatSettings chatSettings = chatSettingsManager.getChatSettings(workgroup);
    ChatSetting setting = chatSettings.getChatSetting(imageName);
    String encodedValue = setting.getValue();
    if (encodedValue == null) {
        return null;
    }
    return StringUtils.decodeBase64(encodedValue);
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) ChatSettings(org.jivesoftware.openfire.fastpath.settings.chat.ChatSettings) JID(org.xmpp.packet.JID) ChatSetting(org.jivesoftware.openfire.fastpath.settings.chat.ChatSetting) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) WorkgroupManager(org.jivesoftware.xmpp.workgroup.WorkgroupManager)

Example 9 with Workgroup

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

the class DeleteWorkgroup method execute.

@Override
public void execute(SessionData data, Element command) {
    Element note = command.addElement("note");
    // Get requested group
    WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
    // Load the workgroup
    try {
        Workgroup workgroup = workgroupManager.getWorkgroup(new JID(data.getData().get("workgroup").get(0)));
        workgroupManager.deleteWorkgroup(workgroup);
    } catch (UserNotFoundException e) {
        // Group not found
        note.addAttribute("type", "error");
        note.setText("Workgroup not found");
        return;
    } catch (Exception e) {
        // Group not found
        note.addAttribute("type", "error");
        note.setText("Error executing the command");
        return;
    }
    note.addAttribute("type", "info");
    note.setText("Operation finished successfully");
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) JID(org.xmpp.packet.JID) Element(org.dom4j.Element) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) WorkgroupManager(org.jivesoftware.xmpp.workgroup.WorkgroupManager) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 10 with Workgroup

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

the class WorkgroupUtils method updateWorkgroup.

public static String updateWorkgroup(String workgroupName, String displayName, String description, int maxSize, int minSize, long requestTimeout, long offerTimeout) {
    final WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
    Workgroup workgroup;
    try {
        workgroup = workgroupManager.getWorkgroup(new JID(workgroupName));
    } catch (UserNotFoundException e) {
        return getUpdateMessage(false, "The JID specified is invalid.");
    }
    workgroup.setDisplayName(displayName);
    workgroup.setDescription(description);
    if (maxSize < minSize) {
        return getUpdateMessage(false, "Max size must be greater or equal to min size.");
    }
    workgroup.setMaxChats(maxSize);
    workgroup.setMinChats(minSize);
    workgroup.setRequestTimeout(requestTimeout);
    workgroup.setOfferTimeout(offerTimeout);
    return getUpdateMessage(true, "Workgroup has been updated");
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) JID(org.xmpp.packet.JID) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) WorkgroupManager(org.jivesoftware.xmpp.workgroup.WorkgroupManager)

Aggregations

Workgroup (org.jivesoftware.xmpp.workgroup.Workgroup)25 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)19 JID (org.xmpp.packet.JID)15 SQLException (java.sql.SQLException)7 Connection (java.sql.Connection)6 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 WorkgroupManager (org.jivesoftware.xmpp.workgroup.WorkgroupManager)6 Element (org.dom4j.Element)4 AgentSession (org.jivesoftware.xmpp.workgroup.AgentSession)4 RequestQueue (org.jivesoftware.xmpp.workgroup.RequestQueue)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 NotFoundException (org.jivesoftware.util.NotFoundException)3 AgentNotFoundException (org.jivesoftware.xmpp.workgroup.AgentNotFoundException)3 UnauthorizedException (org.jivesoftware.xmpp.workgroup.UnauthorizedException)3 IQ (org.xmpp.packet.IQ)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 AdHocCommand (org.jivesoftware.openfire.commands.AdHocCommand)2 AgentSessionList (org.jivesoftware.xmpp.workgroup.AgentSessionList)2