📄 workgroup.java
字号:
rs = pstmt.executeQuery();
if (rs.next()) {
workgroupName = rs.getString(1);
if (rs.getString(2) != null && rs.getString(2).length() > 0) {
displayName = rs.getString(2);
}
else {
displayName = workgroupName;
}
description = rs.getString(3);
open = rs.getInt(4) == 1;
followSchedule = rs.getInt(5) == 1;
creationDate = new Date(Long.parseLong(rs.getString(6).trim()));
modDate = new Date(Long.parseLong(rs.getString(7).trim()));
maxChats = rs.getInt(8);
minChats = rs.getInt(9);
offerTimeout = rs.getInt(10);
requestTimeout = rs.getInt(11);
schedule = new Schedule(id, rs.getString(12));
}
}
catch (SQLException ex) {
ComponentManagerFactory.getComponentManager().getLog().error(ex);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
}
private void loadQueues() {
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(LOAD_QUEUES);
pstmt.setLong(1, id);
rs = pstmt.executeQuery();
while (rs.next()) {
loadRequestQueue(rs.getLong(1));
}
}
catch (SQLException ex) {
ComponentManagerFactory.getComponentManager().getLog().error(ex);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
}
private boolean createQueue(long handbackid, Object data) {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(CREATE_QUEUE);
pstmt.setLong(1, handbackid);
pstmt.setLong(2, id);
pstmt.setString(3, (String)data);
pstmt.setInt(4, 0);
pstmt.setInt(5, -1);
pstmt.setInt(6, -1);
pstmt.executeUpdate();
return true;
}
catch (SQLException ex) {
ComponentManagerFactory.getComponentManager().getLog().error(ex);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
return false;
}
private boolean deleteQueue(long handbackid) {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(DELETE_QUEUE);
pstmt.setLong(1, handbackid);
pstmt.executeUpdate();
pstmt.close();
// Delete dispatcher properties
pstmt = con.prepareStatement(DELETE_QUEUE_PROPS);
pstmt.setLong(1, handbackid);
pstmt.executeUpdate();
return true;
}
catch (SQLException ex) {
ComponentManagerFactory.getComponentManager().getLog().error(ex);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
return false;
}
private boolean updateWorkgroup() {
// Update the last modification date
modDate = new Date(System.currentTimeMillis());
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(UPDATE_WORKGRUP);
pstmt.setString(1, displayName);
pstmt.setString(2, description);
pstmt.setInt(3, open ? 1 : 0);
pstmt.setInt(4, followSchedule ? 1 : 0);
pstmt.setString(5, StringUtils.dateToMillis(creationDate));
pstmt.setString(6, StringUtils.dateToMillis(modDate));
pstmt.setInt(7, maxChats);
pstmt.setInt(8, minChats);
pstmt.setLong(9, offerTimeout);
pstmt.setLong(10, requestTimeout);
pstmt.setString(11, schedule.toString());
pstmt.setLong(12, id);
pstmt.executeUpdate();
return true;
}
catch (SQLException ex) {
ComponentManagerFactory.getComponentManager().getLog().error(ex);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
return false;
}
/**
* Returns the JID of the workgroup. The node of the JID will be the workgroup name and
* the domain will have a "workgroup." prefix before the hostname of the server. No
* resource is included in the returned JID.
*
* @return the JID of the workgroup.
*/
public JID getJID() {
return new JID(workgroupName + "@workgroup." +
ComponentManagerFactory.getComponentManager().getServerName());
}
/**
* Returns a full JID of the workgroup composed by the workgroup JID and a resource that
* will match the workgroup name. The only place where a full JID may be required is when
* sending packets to the conference service. Somce servers require that a full JID might
* be used to route packets between components.
*
* @return a full JID of the workgroup composed by the workgroup JID and a resource that
* will match the workgroup name.
*/
public JID getFullJID() {
return new JID(workgroupName,
"workgroup." + ComponentManagerFactory.getComponentManager().getServerName(),
workgroupName);
}
public long getID() {
return id;
}
/**
* Returns the name to use when displaying the workgroup. This information can be used
* when showing the workgroup as a roster item.
*
* @return the name to use when displaying the workgroup.
*/
public String getDisplayName() {
return displayName;
}
/**
* Sets the name to use when displaying the workgroup. This information can be used
* when showing the workgroup as a roster item.
*
* @param displayName the name to use when displaying the workgroup.
*/
public void setDisplayName(String displayName) {
if (displayName.equals(this.displayName)) {
// Do nothing
return;
}
this.displayName = displayName;
updateWorkgroup();
}
/**
* Returns the last date when the workgroup properties were modified.
*
* @return the last date when the workgroup properties were modified.
*/
public Date getModificationDate() {
return modDate;
}
/**
* Notification message that a new AgentSession has been started. This method is useful
* for triggering events (in the future).
*
* @param agentSession the session that has just been started.
*/
public void agentJoined(AgentSession agentSession) {
// Since the session has received the queues status details we need to update the status
// in the manager so that the thread that is polling for changes in the status does not
// send the queues status details again to this session
WorkgroupManager.getInstance().updateWorkgroupStatus(this);
// Trigger the event that an agent has joined the workgroup
WorkgroupEventDispatcher.agentJoined(this, agentSession);
}
/**
* Notification message that an AgentSession has ended. This method is useful
* for triggering events (in the future).
*
* @param agentSession the session that has ended.
*/
public void agentDeparted(AgentSession agentSession) {
// Trigger the event that an agent has left the workgroup
WorkgroupEventDispatcher.agentDeparted(this, agentSession);
// Update the status in the manager so that the thread that is polling for changes in
// the status does not send the queues status details again to this session
WorkgroupManager.getInstance().updateWorkgroupStatus(this);
}
/**
* Notification method saying that the workgroup has been opened.
*/
public void notifyOpened() {
// Notify the prensence handler of this workgroup that the workgroup is now opened. The
// presence handler will notify the availability of the workgroup to the users that are
// tracking the workgroup's presence
workgroupPresenceHandler.broadcastWorkgroupPresence();
// Trigger the event that the workgroup has been opened
WorkgroupEventDispatcher.workgroupOpened(this);
}
/**
* Notification method saying that the workgroup has been closed.
*/
public void notifyClosed() {
// Notify the prensence handler of this workgroup that the workgroup is now closed. The
// presence handler will notify the availability of the workgroup to the users that are
// tracking the workgroup's presence
workgroupPresenceHandler.broadcastWorkgroupPresence();
// Trigger the event that the workgroup has been closed
WorkgroupEventDispatcher.workgroupClosed(this);
}
public void cleanup() {
// TODO Clean up dangling requests
// TODO Destroy rooms that never got occupants except the workgroup
// Clean up the chatbot sessions
if (chatbot != null) {
chatbot.cleanup();
}
}
/**
* Sends information to the agent that requested it about the occupants in the specified
* room. If the room does no longer exist then no information will be returned. This means
* that the chat should be happening at the moment of the query.
*
* @param packet the request sent by the agent.
* @param roomID the id of the room that the agent is requesting information
*/
public void sendOccupantsInfo(IQ packet, String roomID) {
IQ statusPacket = IQ.createResultIQ(packet);
Element occupantsInfo = statusPacket.setChildElement("occupants-info",
"http://jivesoftware.com/protocol/workgroup");
occupantsInfo.addAttribute("roomID", roomID);
Map<Packet, java.util.Date> packets = transcripts.get(roomID);
if (packets != null) {
Collection<String> processed = new ArrayList<String>();
for (Packet p : packets.keySet()) {
if (p instanceof Presence) {
Presence presence = (Presence)p;
// Get the JID of the presence's user
String userJID = presence.getChildElement("x",
"http://jabber.org/protocol/muc#user")
.element("item")
.attributeValue("jid");
// Only add information about the first presence so we know the time when the
// occupant joined the room
if (!processed.contains(userJID)) {
processed.add(userJID);
Element occupantInfo = occupantsInfo.addElement("occupant");
occupantInfo.addElement("jid").setText(userJID);
occupantInfo.addElement("nickname").setText(presence.getFrom().getResource());
occupantInfo.addElement("joined").setText(UTC_FORMAT.format(packets.get(p)));
}
}
}
}
// Send the response
send(statusPacket);
}
public void processInvitation(InvitationRequest invitation, IQ packet) {
IQ reply = IQ.createResultIQ(packet);
reply.setFrom(getJID());
// Verify that requester is a valid agent
AgentSession agentSession = null;
try {
agentSession = agentManager.getAgentSession(packet.getFrom());
} catch (AgentNotFoundException e) {
// Ig
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -