Search in sources :

Example 1 with UserAlreadyExistsException

use of org.jivesoftware.xmpp.workgroup.UserAlreadyExistsException in project Openfire by igniterealtime.

the class WorkgroupUtils method createWorkgroup.

/**
     * Create a new Workgroup.
     *
     * @param workgroupName the name of the workgroup.
     * @param description the description of the workgroup.
     * @param agents the agents, in a comma delimited string.
     * @return a map of errors (if any)
     */
public static Map<String, String> createWorkgroup(String workgroupName, String description, String agents) {
    Map<String, String> errors = new HashMap<String, String>();
    // Get a workgroup manager
    WorkgroupManager wgManager = WorkgroupManager.getInstance();
    if (wgManager == null) {
        errors.put("general_error", "The server is down");
        return errors;
    }
    String defaultQueueName = "Default Queue";
    // Validate
    if (workgroupName == null) {
        errors.put("wgName", "");
    } else {
        try {
            workgroupName = workgroupName.trim().toLowerCase();
            workgroupName = Stringprep.nodeprep(workgroupName);
        } catch (StringprepException se) {
            errors.put("wgName", "");
        }
    }
    // do a create if there were no errors
    RequestQueue queue = null;
    if (errors.size() == 0) {
        try {
            // Create new workgroup
            Workgroup workgroup = wgManager.createWorkgroup(workgroupName);
            workgroup.setDescription(description);
            // Create a default workgroup queue
            queue = workgroup.createRequestQueue(defaultQueueName);
            //workgroup.setMaxChats(maxChats);
            //workgroup.setMinChats(minChats);
            // Make the workgroup ready by default:
            workgroup.setStatus(Workgroup.Status.READY);
            // Create default messages and images for the new workgroup
            ChatSettingsCreator.getInstance().createDefaultSettings(workgroup.getJID());
            // Add generic web form
            FormManager formManager = FormManager.getInstance();
            formManager.createGenericForm(workgroup);
        } catch (UserAlreadyExistsException uaee) {
            errors.put("exists", "");
        } catch (Exception e) {
            Log.error(e.getMessage(), e);
            errors.put("general", "");
        }
    }
    if (ModelUtil.hasLength(agents)) {
        addAgents(queue, agents);
    }
    return errors;
}
Also used : StringprepException(gnu.inet.encoding.StringprepException) HashMap(java.util.HashMap) FormManager(org.jivesoftware.openfire.fastpath.dataforms.FormManager) RequestQueue(org.jivesoftware.xmpp.workgroup.RequestQueue) UserAlreadyExistsException(org.jivesoftware.xmpp.workgroup.UserAlreadyExistsException) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) WorkgroupManager(org.jivesoftware.xmpp.workgroup.WorkgroupManager) StringprepException(gnu.inet.encoding.StringprepException) UserAlreadyExistsException(org.jivesoftware.xmpp.workgroup.UserAlreadyExistsException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Aggregations

StringprepException (gnu.inet.encoding.StringprepException)1 HashMap (java.util.HashMap)1 FormManager (org.jivesoftware.openfire.fastpath.dataforms.FormManager)1 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)1 RequestQueue (org.jivesoftware.xmpp.workgroup.RequestQueue)1 UserAlreadyExistsException (org.jivesoftware.xmpp.workgroup.UserAlreadyExistsException)1 Workgroup (org.jivesoftware.xmpp.workgroup.Workgroup)1 WorkgroupManager (org.jivesoftware.xmpp.workgroup.WorkgroupManager)1