⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 workgroup.java

📁 openfire 服务器源码下载
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * session.
     *
     * @return a collection with all the agent session that are available for chat in the workgroup.
     */
    public Collection<AgentSession> getAgentAvailableSessions() {
        Collection<AgentSession> answer = new HashSet<AgentSession>();
        for (RequestQueue queue : queues.values()) {
            for (AgentSession session : queue.getAgentSessionList().getAgentSessions()) {
                if (session.isAvailableToChat()) {
                    answer.add(session);
                }
            }
        }
        return Collections.unmodifiableCollection(answer);
    }

    /**
     * Returns a collection with all the agents that belong to the workgroup. If the same agent
     * is present in more than one queue then the answer will only include one instance
     * of the agent.
     *
     * @return a collection with all the agents that are belong to the workgroup.
     */
    public Collection<Agent> getAgents() {
        Collection<Agent> answer = new HashSet<Agent>();
        for (RequestQueue queue : queues.values()) {
            answer.addAll(queue.getMembers());

            for (Group group : queue.getGroups()) {
                for (Agent agent : agentManager.getAgents(group)) {
                    answer.add(agent);
                }
            }
        }
        return Collections.unmodifiableCollection(answer);
    }

    // #############################################################################
    // Field access methods
    // #############################################################################
    public void setDescription(String description) {
        if (description == null) {
            description = "";
        }

        if (description.equals(this.description)) {
            // Do nothing
            return;
        }
        this.description = description;
        updateWorkgroup();
    }

    public String getDescription() {
        return description;
    }

    /**
     * Returns the chatbot that will respond to messages sent to this workgroup. Workgroups may
     * have a chatbot but it's not mandatory to have one.
     *
     * @return the chatbot that will respond to messages sent to this workgroup.
     */
    public Chatbot getChatBot() {
        if (!isChatbotEnabled()) {
            return null;
        }
        if (chatbot == null) {
            synchronized (this) {
                if (chatbot == null) {
                    chatbot = new Chatbot(this);
                }
            }
        }
        return chatbot;
    }

    /**
     * Sets if the workgroup should use a chatbot for answering the messages sent to the workgroup.
     *
     * @param enabled true if a chatbot will respond to the messages sent to the workgroup.
     * @throws UnauthorizedException if not allowed to change the workgroup property
     */
    public void chatbotEnabled(boolean enabled) throws UnauthorizedException {
        getProperties().setProperty("chatbot.enabled", enabled ? "true" : "false");
    }

    /**
     * Returns true if the chatbot is enabled. When the chatbot is enabled it will answer
     * messages sent to the workgroup.
     *
     * @return true if the chatbot is enabled.
     */
    public boolean isChatbotEnabled() {
        return "true".equals(getProperties().getProperty("chatbot.enabled"));
    }

    public Status getStatus() {
        // TODO: The logic in this method appears too complex. May need refactor after
        // TODO: removing schedule feature. 
        boolean actualOpenStatus = open;

        // Workgroup can only be open if there are agents in the workgroup.
        if (actualOpenStatus) {
            actualOpenStatus = isOpen();
            if (open) {
                if (actualOpenStatus) {
                    return Status.OPEN;
                }
                else {
                    return Status.READY;
                }
            }
            else {
                return Status.CLOSED;
            }
        }
        return Status.CLOSED;
    }

    private boolean isOpen() {
        boolean opened = false;
        for (RequestQueue requestQueue : getRequestQueues()) {
            opened = requestQueue.getAgentSessionList().containsAvailableAgents();
            if (opened) {
                break;
            }
        }
        return opened;
    }

    public void setStatus(Status status) {
        if (status == Status.OPEN || status == Status.READY) {
            if (open) {
                // Do nothing if the value is not going to change
                return;
            }
            this.open = true;
        }
        else {
            if (!open) {
                // Do nothing if the value is not going to change
                return;
            }
            this.open = false;
        }
        // Seems that this method is being used as an initialization resort so we are resetting
        // the schedule of the workgroup (if there was one)
        disableSchedule();
        if (updateWorkgroup()) {
            broadcastPresence();
        }
    }

    /**
     * Notification message that the some images of the workgroup has changed.
     */
    public void imagesChanged() {
        // Note: The update to the DB is useless except for updating the last modified date though
        // the actual modification took place in another table. But we could say that images are
        // an internal component of this object. :) The last modified date will be sent in the
        // broadcasted presence
        if (updateWorkgroup()) {
            broadcastPresence();
        }
    }

    public boolean isFollowingSchedule() {
        return false;
    }

    /**
     * Disables the schedule that this workgroup might be following. To enable the schedule a new
     * schedule must be assigned to the workgroup.
     */
    public void disableSchedule() {
        followSchedule = false;
        if (schedule != null) {
            schedule.clear();
        }
        if (updateWorkgroup()) {
            broadcastPresence();
        }
    }

    public Schedule getSchedule() {
        return schedule;
    }

    /**
     * Sets a new schedule for this workgroup thus enabling the scheduling feature.
     *
     * @param schedule the new schedule to follow for this workgroup.
     */
    public void setSchedule(Schedule schedule) {
        if (schedule == null || schedule.getID() != id) {
            throw new IllegalArgumentException();
        }
        followSchedule = true;
        if (updateWorkgroup()) {
            broadcastPresence();
        }
    }


    public int getMaxChats() {
        if (isDefaultMaxChats()) {
            return WorkgroupManager.getInstance().getDefaultMaxChats();
        }
        return maxChats;
    }

    public void setMaxChats(int max) {
        if (max == maxChats) {
            // Do nothing
            return;
        }
        maxChats = max;
        updateWorkgroup();
    }

    public int getMinChats() {
        if (isDefaultMinChats()) {
            return WorkgroupManager.getInstance().getDefaultMinChats();
        }
        return minChats;
    }

    public void setMinChats(int min) {
        if (min == minChats) {
            // Do nothing
            return;
        }
        minChats = min;
        updateWorkgroup();
    }

    public void setRequestTimeout(long timeout) {
        if (timeout == requestTimeout) {
            // Do nothing
            return;
        }
        requestTimeout = timeout;
        updateWorkgroup();
    }

    public long getRequestTimeout() {
        if (isDefaultRequestTimeout()) {
            return WorkgroupManager.getInstance().getDefaultRequestTimeout();
        }
        return requestTimeout;
    }

    public void setOfferTimeout(long timeout) {
        if (timeout == offerTimeout) {
            // Do nothing
            return;
        }
        offerTimeout = timeout;
        updateWorkgroup();
    }

    public long getOfferTimeout() {
        if (isDefaultOfferTimeout()) {
            return WorkgroupManager.getInstance().getDefaultOfferTimeout();
        }
        return offerTimeout;
    }

    public boolean isDefaultMaxChats() {
        return maxChats == -1;
    }

    public boolean isDefaultMinChats() {
        return minChats == -1;
    }

    public boolean isDefaultRequestTimeout() {
        return requestTimeout == -1;
    }

    public boolean isDefaultOfferTimeout() {
        return offerTimeout == -1;
    }

    public DbProperties getProperties() {
        if (properties == null) {
            properties = new JiveLiveProperties("fpWorkgroupProp", id);
        }
        return properties;
    }

    public void shutdown() {
        for (RequestQueue requestQueue : getRequestQueues()) {
            requestQueue.shutdown();
        }
        // Release the chatbot
        chatbot = null;
        queueComparator = null;
    }

    private void loadWorkgroup() {
        Connection con = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(LOAD_WORKGROUP);

            pstmt.setLong(1, id);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -