2014-02-17 23:58:40 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Copyright 2003-2007 Jive Software.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.jivesoftware.smackx.workgroup.agent;
|
|
|
|
|
2017-06-14 17:12:43 +02:00
|
|
|
import java.util.Collection;
|
|
|
|
|
2014-03-12 11:50:05 +01:00
|
|
|
import org.jivesoftware.smack.SmackException.NoResponseException;
|
2014-03-19 14:22:20 +01:00
|
|
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
2014-03-10 09:45:50 +01:00
|
|
|
import org.jivesoftware.smack.XMPPConnection;
|
2014-03-12 11:50:05 +01:00
|
|
|
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
2014-02-17 23:58:40 +01:00
|
|
|
import org.jivesoftware.smack.packet.IQ;
|
|
|
|
|
2017-06-14 17:12:43 +02:00
|
|
|
import org.jivesoftware.smackx.workgroup.packet.AgentInfo;
|
|
|
|
import org.jivesoftware.smackx.workgroup.packet.AgentWorkgroups;
|
|
|
|
|
2018-04-18 08:48:52 +02:00
|
|
|
import org.jxmpp.jid.EntityBareJid;
|
2017-06-14 17:12:43 +02:00
|
|
|
import org.jxmpp.jid.Jid;
|
2014-02-17 23:58:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The <code>Agent</code> class is used to represent one agent in a Workgroup Queue.
|
|
|
|
*
|
|
|
|
* @author Derek DeMoro
|
|
|
|
*/
|
|
|
|
public class Agent {
|
2014-03-10 09:45:50 +01:00
|
|
|
private XMPPConnection connection;
|
2018-04-18 08:48:52 +02:00
|
|
|
private final EntityBareJid workgroupJID;
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2015-02-14 17:15:02 +01:00
|
|
|
public static Collection<String> getWorkgroups(Jid serviceJID, Jid agentJID, XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2014-02-17 23:58:40 +01:00
|
|
|
AgentWorkgroups request = new AgentWorkgroups(agentJID);
|
|
|
|
request.setTo(serviceJID);
|
2021-05-11 22:03:24 +02:00
|
|
|
AgentWorkgroups response = connection.sendIqRequestAndWaitForResponse(request);
|
2014-02-17 23:58:40 +01:00
|
|
|
return response.getWorkgroups();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs an Agent.
|
|
|
|
*/
|
2018-04-18 08:48:52 +02:00
|
|
|
Agent(XMPPConnection connection, EntityBareJid workgroupJID) {
|
2014-02-17 23:58:40 +01:00
|
|
|
this.connection = connection;
|
|
|
|
this.workgroupJID = workgroupJID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-03-29 12:15:32 +02:00
|
|
|
* Return the agents JID.
|
2014-02-17 23:58:40 +01:00
|
|
|
*
|
|
|
|
* @return - the agents JID.
|
|
|
|
*/
|
2015-02-14 17:15:02 +01:00
|
|
|
public Jid getUser() {
|
2014-02-17 23:58:40 +01:00
|
|
|
return connection.getUser();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the agents name.
|
|
|
|
*
|
|
|
|
* @return - the agents name.
|
2019-08-30 12:08:30 +02:00
|
|
|
* @throws XMPPErrorException if there was an XMPP error returned.
|
|
|
|
* @throws NoResponseException if there was no response from the remote entity.
|
|
|
|
* @throws NotConnectedException if the XMPP connection is not connected.
|
|
|
|
* @throws InterruptedException if the calling thread was interrupted.
|
2014-02-17 23:58:40 +01:00
|
|
|
*/
|
2015-02-14 09:43:44 +01:00
|
|
|
public String getName() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2014-02-17 23:58:40 +01:00
|
|
|
AgentInfo agentInfo = new AgentInfo();
|
2014-06-06 02:20:45 +02:00
|
|
|
agentInfo.setType(IQ.Type.get);
|
2014-02-17 23:58:40 +01:00
|
|
|
agentInfo.setTo(workgroupJID);
|
|
|
|
agentInfo.setFrom(getUser());
|
2021-05-11 22:03:24 +02:00
|
|
|
AgentInfo response = connection.sendIqRequestAndWaitForResponse(agentInfo);
|
2014-02-17 23:58:40 +01:00
|
|
|
return response.getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes the name of the agent in the server. The server may have this functionality
|
|
|
|
* disabled for all the agents or for this agent in particular. If the agent is not
|
|
|
|
* allowed to change his name then an exception will be thrown with a service_unavailable
|
|
|
|
* error code.
|
|
|
|
*
|
|
|
|
* @param newName the new name of the agent.
|
2019-08-30 12:08:30 +02:00
|
|
|
* @throws XMPPErrorException if there was an XMPP error returned.
|
|
|
|
* @throws NoResponseException if there was no response from the remote entity.
|
|
|
|
* @throws NotConnectedException if the XMPP connection is not connected.
|
|
|
|
* @throws InterruptedException if the calling thread was interrupted.
|
2014-02-17 23:58:40 +01:00
|
|
|
*/
|
2015-02-14 09:43:44 +01:00
|
|
|
public void setName(String newName) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2014-02-17 23:58:40 +01:00
|
|
|
AgentInfo agentInfo = new AgentInfo();
|
2014-06-06 02:20:45 +02:00
|
|
|
agentInfo.setType(IQ.Type.set);
|
2014-02-17 23:58:40 +01:00
|
|
|
agentInfo.setTo(workgroupJID);
|
|
|
|
agentInfo.setFrom(getUser());
|
|
|
|
agentInfo.setName(newName);
|
2021-05-11 22:03:24 +02:00
|
|
|
connection.sendIqRequestAndWaitForResponse(agentInfo);
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|
|
|
|
}
|