/**
   * 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;
  }
Example #2
0
  public void setState(Workgroup workgroup, WorkgroupSettings workgroupSettings, QName namespace) {
    this.workgroupSettings = workgroupSettings;
    this.workgroup = workgroup;
    this.namespace = namespace;

    try {
      final Element element =
          workgroupSettings.get(
              workgroup.getJID().toBareJID(), DocumentHelper.createElement(namespace));
      final List list = element.elements();

      final Iterator iter = list.iterator();
      while (iter.hasNext()) {
        Element el = (Element) iter.next();
        addToSettings(el);
      }
    } catch (Exception ex) {
      Log.error(ex.getMessage(), ex);
    }
  }
Example #3
0
  public void setMap(Map map) {
    Element element = DocumentHelper.createElement(namespace);
    final Iterator i = element.elementIterator();
    while (i.hasNext()) {
      element.remove((Element) i.next());
    }
    final Iterator iter = map.keySet().iterator();
    while (iter.hasNext()) {
      String key = (String) iter.next();
      String value = (String) map.get(key);

      Element elem = DocumentHelper.createElement("entry");
      elem.addElement(key).setText(value);
      element.add(elem);
    }

    try {
      workgroupSettings.add(workgroup.getJID().toBareJID(), element);
    } catch (Exception ex) {
      Log.error(ex.getMessage(), ex);
    }
  }