📄 userrequest.java
字号:
return pos;
}
public int getTimeStatus() {
int averageTime = queue == null ? 0 : queue.getAverageTime();
int timeStatus;
if (averageTime == 0) {
timeStatus = (getPosition() + 1) * 15;
}
else {
timeStatus = (getPosition() + 1) * averageTime;
}
return timeStatus;
}
public JID getUserJID() {
return userJID;
}
/**
* Returns the user unique identification. If the user joined using an anonymous connection
* then the userID will be the value of the ID attribute of the USER element. Otherwise, the
* userID will be the bare JID of the user that made the request.
*
* @return the user unique identification.
*/
public String getUserID() {
return userID;
}
/**
* Returns true if the request was made by a user that is using an anonymous session. For
* anonymous user the userJID will be something like "server.com/a9d32h" and will vary
* each time the user creates a new connection whilst the userID will represent the user
* unique identification that may be used across several sessions.
*
* @return true if the request was made by a user that is using an anonymous session.
*/
public boolean isAnonymousUser() {
return anonymousUser;
}
/**
* The request is being asked to verify if a new invitation must be sent to the user that
* didn't answer the previous invitation. The request will only retry one more time.
*
* @param roomID the id of the room where the user was invited.
*/
public void checkInvitation(String roomID) {
if (!invitationChecked && !hasJoinedRoom() &&
System.currentTimeMillis() - invitationSent > 10000) {
invitationChecked = true;
communicationMethod.checkInvitation(this);
}
}
/**
* Notification message saying that the request has been accepted by an agent and that
* invitations have been sent to the agent and the user that made the request.
*
* @param roomID the id of the room for which invitations were sent.
*/
public void invitationsSent(String roomID) {
invitationSent = System.currentTimeMillis();
invitedRoomID = roomID;
communicationMethod.invitationsSent(this);
}
/**
* Notification message saying that the user that made the request has joined the room to have
* a chat with an agent.
*
* @param roomID the id of the room where the user has joined.
*/
public void supportStarted(String roomID) {
joinedRoom = System.currentTimeMillis();
communicationMethod.supportStarted(this);
}
/**
* Notification message saying that the support session has finished. At this point all room
* occupants have left the room.
*/
public void supportEnded() {
communicationMethod.supportEnded(this);
}
public void userJoinedRoom(JID roomJID, JID user) {
// Notify related requests that new a occupant has joined the room
for (Request request : relatedRequests) {
request.userJoinedRoom(roomJID, user);
}
}
/**
* Adds a request that is somehow related to this user request. This is usually the case when
* an invitation or transfer was sent to another agent. For these cases a new Request is generated
* that is related to this request. Since all these requests will be interested in the room activitiy
* we need to propagate support events (i.e. supportStarted and supportEnded).
*
* @param request the request that is related to this request.
*/
public void addRelatedRequest(Request request) {
relatedRequests.add(request);
}
/**
* Remvoes a request that is no longer related to this user request.
*
* @param request the request that is no longer related to this request.
*/
public void removeRelatedRequest(Request request) {
relatedRequests.remove(request);
}
public void cancel(Request.CancelType type) {
super.cancel(type);
JID sender = workgroup.getJID();
if (queue != null) {
sender = queue.getWorkgroup().getJID();
queue.removeRequest(this);
}
try {
// Notify the user that he has left the queue
communicationMethod.notifyQueueDepartued(sender, userJID, this, type);
}
catch (Exception e) {
ComponentManagerFactory.getComponentManager().getLog().error(e);
}
}
void addOfferContent(Element offerElement) {
// Flag the offer as a user request
offerElement.addElement("user-request");
// Add custom extension that includes the userID if the session belongs to an
// anonymous user
if (isAnonymousUser()) {
Element element = offerElement.addElement("user", "http://jivesoftware.com/protocol/workgroup");
element.addAttribute("id", getUserID());
}
}
void addRevokeContent(Element revoke) {
// Add custom extension that includes the userID if the session belongs to an
// anonymous user
if (isAnonymousUser()) {
Element element = revoke.addElement("user", "http://jivesoftware.com/protocol/workgroup");
element.addAttribute("id", getUserID());
}
}
public Element getSessionElement() {
QName qName = DocumentHelper.createQName("session", DocumentHelper.createNamespace("", "http://jivesoftware.com/protocol/workgroup"));
Element sessionElement = DocumentHelper.createElement(qName);
sessionElement.addAttribute("id", requestID);
sessionElement.addAttribute("workgroup", getWorkgroup().getJID().toString());
return sessionElement;
}
/**
* Sends an invitation to the agent that previously accepted the offer to join a room.
* Agents need to join a room to be able to chat (and fulfil the request) with the
* user that sent the request.
*
* @param agentSession the agent that previously accepted the offer.
*/
public void offerAccepted(AgentSession agentSession) {
super.offerAccepted(agentSession);
// Ask the workgroup to send invitations to the agent and to the user that made the
// request. The Workgroup will create a MUC room and send invitations to the agent and
// the user.
getWorkgroup().sendInvitation(agentSession, this);
}
public void updateSession(int state, long offerTime) {
boolean inserted = false;
long queueWaitTime = new Date().getTime() - offerTime;
String tempDate = StringUtils.dateToMillis(new Date());
// Gather all information needed.
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
synchronized (this) {
if (!savedToDB) {
pstmt = con.prepareStatement(INSERT_SESSION);
pstmt.setString(1, requestID);
pstmt.setString(2, getUserID());
pstmt.setLong(3, getWorkgroup().getID());
pstmt.setInt(4, state);
pstmt.setLong(5, queueWaitTime);
pstmt.setString(6, tempDate);
pstmt.setString(7, tempDate);
pstmt.executeUpdate();
savedToDB = true;
inserted = true;
}
else {
pstmt = con.prepareStatement(UPDATE_SESSION);
pstmt.setInt(1, state);
pstmt.setLong(2, queueWaitTime);
pstmt.setString(3, tempDate);
pstmt.setString(4, requestID);
pstmt.executeUpdate();
}
}
}
catch (Exception ex) {
ComponentManagerFactory.getComponentManager().getLog().error(
"There was an issue handling offer update using sessionID " + requestID, ex);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
if (inserted) {
saveMetadata();
}
}
private void saveMetadata() {
final Map<String, List<String>> map = getMetaData();
Connection con = null;
try {
con = DbConnectionManager.getConnection();
PreparedStatement pstmt = con.prepareStatement(INSERT_META_DATA);
for (String key : map.keySet()) {
List<String> values = map.get(key);
pstmt.setString(1, requestID);
pstmt.setString(2, key);
pstmt.setString(3, encodeMetadataValue(values));
pstmt.executeUpdate();
}
pstmt.close();
}
catch (SQLException e) {
ComponentManagerFactory.getComponentManager().getLog().error(e);
}
finally {
DbConnectionManager.closeConnection(con);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -