Search in sources :

Example 11 with Form

use of org.jivesoftware.smackx.Form in project ecf by eclipse.

the class Workgroup method joinQueue.

/**
 * <p>Joins the workgroup queue to wait to be routed to an agent. After joining
 * the queue, queue status events will be sent to indicate the user's position and
 * estimated time left in the queue. Once joining the queue, there are three ways
 * the user can leave the queue: <ul>
 * <p/>
 * <li>The user is routed to an agent, which triggers a GroupChat invitation.
 * <li>The user asks to leave the queue by calling the {@link #departQueue} method.
 * <li>A server error occurs, or an administrator explicitly removes the user
 * from the queue.
 * </ul>
 * <p/>
 * A user cannot request to join the queue again if already in the queue. Therefore,
 * this method will throw an IllegalStateException if the user is already in the queue.<p>
 * <p/>
 * Some servers may be configured to require certain meta-data in order to
 * join the queue.<p>
 * <p/>
 * The server tracks the conversations that a user has with agents over time. By
 * default, that tracking is done using the user's JID. However, this is not always
 * possible. For example, when the user is logged in anonymously using a web client.
 * In that case the user ID might be a randomly generated value put into a persistent
 * cookie or a username obtained via the session. When specified, that userID will
 * be used instead of the user's JID to track conversations. The server will ignore a
 * manually specified userID if the user's connection to the server is not anonymous.
 *
 * @param metadata metadata to create a dataform from.
 * @param userID   String that represents the ID of the user when using anonymous sessions
 *                 or <tt>null</tt> if a userID should not be used.
 * @throws XMPPException if an error occured joining the queue. An error may indicate
 *                       that a connection failure occured or that the server explicitly rejected the
 *                       request to join the queue.
 */
public void joinQueue(Map<String, Object> metadata, String userID) throws XMPPException {
    // If already in the queue ignore the join request.
    if (inQueue) {
        throw new IllegalStateException("Already in queue " + workgroupJID);
    }
    // Build dataform from metadata
    Form form = new Form(Form.TYPE_SUBMIT);
    Iterator<String> iter = metadata.keySet().iterator();
    while (iter.hasNext()) {
        String name = iter.next();
        String value = metadata.get(name).toString();
        String escapedName = StringUtils.escapeForXML(name);
        String escapedValue = StringUtils.escapeForXML(value);
        FormField field = new FormField(escapedName);
        field.setType(FormField.TYPE_TEXT_SINGLE);
        form.addField(field);
        form.setAnswer(escapedName, escapedValue);
    }
    joinQueue(form, userID);
}
Also used : WorkgroupForm(org.jivesoftware.smackx.workgroup.ext.forms.WorkgroupForm) DataForm(org.jivesoftware.smackx.packet.DataForm) Form(org.jivesoftware.smackx.Form) FormField(org.jivesoftware.smackx.FormField)

Aggregations

Form (org.jivesoftware.smackx.Form)11 XMPPException (org.jivesoftware.smack.XMPPException)7 FormField (org.jivesoftware.smackx.FormField)4 ArrayList (java.util.ArrayList)2 XMPPError (org.jivesoftware.smack.packet.XMPPError)2 URISyntaxException (java.net.URISyntaxException)1 Iterator (java.util.Iterator)1 List (java.util.List)1 ECFException (org.eclipse.ecf.core.util.ECFException)1 ChatRoomCreateException (org.eclipse.ecf.presence.chatroom.ChatRoomCreateException)1 IChatRoomInfo (org.eclipse.ecf.presence.chatroom.IChatRoomInfo)1 ICriterion (org.eclipse.ecf.presence.search.ICriterion)1 IResultList (org.eclipse.ecf.presence.search.IResultList)1 ResultList (org.eclipse.ecf.presence.search.ResultList)1 UserSearchException (org.eclipse.ecf.presence.search.UserSearchException)1 XMPPRoomID (org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID)1 ReportedData (org.jivesoftware.smackx.ReportedData)1 Action (org.jivesoftware.smackx.commands.AdHocCommand.Action)1 MultiUserChat (org.jivesoftware.smackx.muc.MultiUserChat)1 RoomInfo (org.jivesoftware.smackx.muc.RoomInfo)1