public static String updateWorkgroup(
      String workgroupName,
      String displayName,
      String description,
      int maxSize,
      int minSize,
      long requestTimeout,
      long offerTimeout) {
    final WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
    Workgroup workgroup;
    try {
      workgroup = workgroupManager.getWorkgroup(new JID(workgroupName));
    } catch (UserNotFoundException e) {
      return getUpdateMessage(false, "The JID specified is invalid.");
    }
    workgroup.setDisplayName(displayName);
    workgroup.setDescription(description);
    if (maxSize < minSize) {
      return getUpdateMessage(false, "Max size must be greater or equal to min size.");
    }

    workgroup.setMaxChats(maxSize);
    workgroup.setMinChats(minSize);
    workgroup.setRequestTimeout(requestTimeout);
    workgroup.setOfferTimeout(offerTimeout);

    return getUpdateMessage(true, "Workgroup has been updated");
  }
  /**
   * Adds agents to a request queue.
   *
   * @param queue the <code>RequestQueue</code> to add agents to.
   * @param agents a comma-delimited list of agents.
   */
  public static void addAgents(RequestQueue queue, String agents) {
    WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
    AgentManager agentManager = workgroupManager.getAgentManager();

    // loop thru all params
    StringTokenizer tokenizer = new StringTokenizer(agents, ", \t\n\r\f");
    while (tokenizer.hasMoreTokens()) {
      String usernameToken = tokenizer.nextToken();
      if (usernameToken.indexOf('@') != -1) {
        usernameToken = JID.escapeNode(usernameToken);
      }
      try {
        // See if they are a user in the system.
        UserManager.getInstance().getUser(usernameToken);
        usernameToken += ("@" + ComponentManagerFactory.getComponentManager().getServerName());
        JID address = new JID(usernameToken.trim());
        Agent agent;

        if (agentManager.hasAgent(address)) {
          agent = agentManager.getAgent(address);
        } else {
          agent = agentManager.createAgent(address);
        }
        queue.addMember(agent);
      } catch (Exception e) {
        Log.error(e.getMessage(), e);
      }
    }
  }
  /**
   * 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;
  }
  public static void toggleStatus(String workgroupName) {
    final WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
    Workgroup workgroup;
    try {
      workgroup = workgroupManager.getWorkgroup(new JID(workgroupName));
    } catch (UserNotFoundException e) {
      return;
    }

    Workgroup.Status status = workgroup.getStatus();
    if (status == Workgroup.Status.READY) {
      workgroup.setStatus(Workgroup.Status.CLOSED);
    } else {
      workgroup.setStatus(Workgroup.Status.READY);
    }
  }
示例#5
0
  /**
   * Returns the number of chat requests that were accepted.
   *
   * @param workgroupName the name of the workgroup where the request(s) were made.
   * @param startDate the start date.
   * @param endDate the end date.
   * @return the number of chats requests accepted by the workgroup.
   */
  public static int getNumberOfChatsAccepted(String workgroupName, Date startDate, Date endDate) {
    Workgroup workgroup = null;
    try {
      workgroup = WorkgroupManager.getInstance().getWorkgroup(new JID(workgroupName));
    } catch (Exception ex) {
      Log.error(ex.getMessage(), ex);
    }
    if (workgroup == null) {
      return 0;
    }

    int count = 0;
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      con = DbConnectionManager.getConnection();
      pstmt = con.prepareStatement(ACCEPTED_CHATS_COUNT);
      pstmt.setLong(1, workgroup.getID());
      pstmt.setString(2, StringUtils.dateToMillis(startDate));
      pstmt.setString(3, StringUtils.dateToMillis(endDate));

      rs = pstmt.executeQuery();
      if (rs.next()) {
        count = rs.getInt(1);
      }
    } catch (Exception ex) {
      Log.error(ex.getMessage(), ex);
    } finally {
      DbConnectionManager.closeConnection(rs, pstmt, con);
    }

    return count;
  }
示例#6
0
 /**
  * Returns a <code>Workgroup</code> based on it's full jid.
  *
  * @param workgroupJID the full jid of the workgroup (ex. [email protected])
  * @return the Workgroup
  */
 public static Workgroup getWorkgroup(String workgroupJID) {
   Workgroup workgroup = null;
   try {
     workgroup = WorkgroupManager.getInstance().getWorkgroup(new JID(workgroupJID));
   } catch (UserNotFoundException e) {
     Log.error("Error retrieving Workgroup", e);
   }
   return workgroup;
 }
示例#7
0
  public void executeSet(IQ packet, Workgroup workgroup) {
    IQ reply = null;
    Element iq = packet.getChildElement();

    try {
      JID from = packet.getFrom();
      String bareJID = from.toBareJID();
      if (!isOwner(bareJID, workgroup)) {
        reply = IQ.createResultIQ(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.forbidden));
        workgroup.send(reply);
        return;
      }

      // Verify that an agent is requesting this information.
      WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
      if (iq.element("makeOwner") != null) {
        String sessionID = iq.element("makeOwner").attributeValue("sessionID");
        final String serviceName = workgroupManager.getMUCServiceName();
        final String roomName = sessionID + "@" + serviceName;
        // final String roomJID = roomName + "/" + workgroup.getJID().getNode();

        IQ iqPacket = new IQ(IQ.Type.set);
        iqPacket.setTo(roomName);
        iqPacket.setFrom(workgroup.getFullJID());

        Element query = iqPacket.setChildElement("query", "http://jabber.org/protocol/muc#admin");
        Element item = query.addElement("item");
        item.addAttribute("affiliation", "owner");
        item.addAttribute("jid", packet.getFrom().toBareJID());
        workgroup.send(iqPacket);
      }

      reply = IQ.createResultIQ(packet);
    } catch (Exception e) {
      reply = IQ.createResultIQ(packet);
      reply.setChildElement(packet.getChildElement().createCopy());
      reply.setError(new PacketError(PacketError.Condition.item_not_found));
    }
    workgroup.send(reply);
  }
示例#8
0
  /**
   * Returns the total number of chats that have occured within a workgroup.
   *
   * @param workgroupName the jid of the workgroup.
   * @return the total number of chats that have occured within a workgroup.
   */
  public static int getNumberOfChatsForWorkgroup(String workgroupName) {
    Workgroup workgroup = null;

    try {
      workgroup = WorkgroupManager.getInstance().getWorkgroup(new JID(workgroupName));
    } catch (Exception ex) {
      Log.error(ex.getMessage(), ex);
    }

    int count = 0;
    for (RequestQueue requestQueue : workgroup.getRequestQueues()) {
      count += requestQueue.getTotalChatCount();
    }

    return count;
  }
示例#9
0
  /**
   * Returns the total chat length of an individual workgroup.
   *
   * @param workgroupName the name of the workgroup.
   * @return the total length of all chats in the specified workgroup.
   */
  public static long getTotalChatTimeForWorkgroup(String workgroupName) {
    Workgroup workgroup = null;

    try {
      workgroup = WorkgroupManager.getInstance().getWorkgroup(new JID(workgroupName));
    } catch (Exception ex) {
      Log.error(ex.getMessage(), ex);
    }

    int totalWorkgroupChatTime = 0;
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      con = DbConnectionManager.getConnection();
      pstmt = con.prepareStatement(CHAT_TIMES_FOR_WORKGROUPS);
      pstmt.setLong(1, workgroup.getID());
      rs = pstmt.executeQuery();

      while (rs.next()) {
        String startTimeString = rs.getString(1);
        String endTimeString = rs.getString(2);

        if ((startTimeString != null)
            && (startTimeString.trim().length() > 0)
            && (endTimeString != null)
            && (endTimeString.trim().length() > 0)) {
          long startLong = Long.parseLong(startTimeString);
          long endLong = Long.parseLong(endTimeString);

          totalWorkgroupChatTime += endLong - startLong;
        }
      }
    } catch (Exception ex) {
      Log.error(ex.getMessage(), ex);
    } finally {
      DbConnectionManager.closeConnection(rs, pstmt, con);
    }

    return totalWorkgroupChatTime;
  }
示例#10
0
  /**
   * Returns the number of canceled requests.
   *
   * @param workgroupName the workgroup to search
   * @param startDate the time to begin the search from.
   * @param endDate the time to end the search.
   * @return the total number of requests
   */
  public static int getNumberOfRequestsNeverPickedUp(
      String workgroupName, Date startDate, Date endDate) {
    Workgroup workgroup = null;
    try {
      workgroup = WorkgroupManager.getInstance().getWorkgroup(new JID(workgroupName));
    } catch (Exception ex) {
      Log.error(ex.getMessage(), ex);
    }
    if (workgroup == null) {
      return 0;
    }

    int count = 0;
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      con = DbConnectionManager.getConnection();
      pstmt = con.prepareStatement(WORKGROUP_STATE_REQUEST_COUNT);
      pstmt.setLong(1, workgroup.getID());
      // Set the state the ignored requests.
      pstmt.setInt(2, 1);
      pstmt.setString(3, StringUtils.dateToMillis(startDate));
      pstmt.setString(4, StringUtils.dateToMillis(endDate));

      rs = pstmt.executeQuery();
      if (rs.next()) {
        count = rs.getInt(1);
      }
    } catch (Exception ex) {
      Log.error(ex.getMessage(), ex);
    } finally {
      DbConnectionManager.closeConnection(rs, pstmt, con);
    }

    return count;
  }
示例#11
0
  /**
   * Returns the number of canceled requests.
   *
   * @param workgroupName the workgroup to search
   * @param startDate the time to begin the search from.
   * @param endDate the time to end the search.
   * @return the total number of requests
   */
  public static long getTotalWaitTimeForWorkgroup(
      String workgroupName, Date startDate, Date endDate) {
    Workgroup workgroup = null;
    try {
      workgroup = WorkgroupManager.getInstance().getWorkgroup(new JID(workgroupName));
    } catch (Exception ex) {
      Log.error(ex.getMessage(), ex);
    }
    if (workgroup == null) {
      return 0;
    }

    int waitTime = 0;
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      con = DbConnectionManager.getConnection();
      pstmt = con.prepareStatement(WORKGROUP_WAIT_TIME);
      pstmt.setLong(1, workgroup.getID());
      // Set the state the ignored requests.
      pstmt.setInt(2, 1);
      pstmt.setString(2, StringUtils.dateToMillis(startDate));
      pstmt.setString(3, StringUtils.dateToMillis(endDate));

      rs = pstmt.executeQuery();
      rs.next();
      waitTime = rs.getInt(1);
    } catch (Exception ex) {
      Log.error(ex.getMessage(), ex);
    } finally {
      DbConnectionManager.closeConnection(rs, pstmt, con);
    }

    return waitTime;
  }
  public void _jspService(HttpServletRequest request, HttpServletResponse response)
      throws java.io.IOException, ServletException {

    JspFactory _jspxFactory = null;
    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;

    try {
      _jspxFactory = JspFactory.getDefaultFactory();
      response.setContentType("text/html");
      pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write('\r');
      out.write('\n');
      try {
        out.write("\r\n\r\n ");

        String wgID = request.getParameter("wgID");
        final WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
        Workgroup workgroup = workgroupManager.getWorkgroup(new JID(wgID));

        OfflineSettingsManager offlineManager = new OfflineSettingsManager();
        String redirectValue = request.getParameter("redirectToPage");
        String statusMessage = "";

        OfflineSettings offlineSettings = null;

        boolean emailConfigured = false;

        String property = JiveGlobals.getProperty("mail.configured");
        if (ModelUtil.hasLength(property)) {
          emailConfigured = true;
        }

        boolean delete = request.getParameter("delete") != null;
        boolean save = request.getParameter("save") != null && !delete;

        if (save) {
          String emailAddress = request.getParameter("email");
          String subject = request.getParameter("subject");
          String header = request.getParameter("headerField");
          offlineSettings =
              offlineManager.saveOfflineSettings(
                  workgroup, redirectValue, emailAddress, subject, header);
          if (offlineSettings != null) {
            statusMessage = "Offline settings have been saved.";
          }
        } else if (delete) {
          statusMessage = "Offline settings have been deleted.";
          offlineSettings =
              offlineManager.saveOfflineSettings(workgroup, redirectValue, "", "", "");
        } else {
          try {
            offlineSettings = offlineManager.getOfflineSettings(workgroup);
          } catch (OfflineSettingsNotFound offlineSettingsNotFound) {
            offlineSettings = new OfflineSettings();
          }
        }

        out.write("\r\n<html>\r\n    <head>\r\n        <title>");
        out.print("Offline Settings for " + wgID);
        out.write(
            "</title>\r\n        <meta name=\"subPageID\" content=\"workgroup-offline\"/>\r\n        <meta name=\"extraParams\" content=\"");
        out.print("wgID=" + wgID);
        out.write(
            "\"/>\r\n        <!--<meta name=\"helpPage\" content=\"set_an_offline_policy_for_a_workgroup.html\"/>-->\r\n\r\n        <script>\r\n        function saveOfflineSettings(){\r\n             var todo = document.offline.todo;\r\n             if(todo[0].checked){\r\n                 var url = document.offline.redirectToPage.value;\r\n                 if(!Jtrim(url)){\r\n                   alert(\"Please specify the URL to forward to.\");\r\n                   document.offline.redirectToPage.focus();\r\n                   return;\r\n                 }\r\n                 document.offline.email.value = \"\";\r\n                 document.offline.subject.value = \"\";\r\n                 document.offline.headerField.value = \"\";\r\n\r\n                 document.offline.submit();\r\n             }\r\n             else if(todo[1].checked){\r\n               var email = document.offline.email.value;\r\n               var subject = document.offline.subject.value;\r\n               var message = document.offline.headerField.value;\r\n               document.offline.redirectToPage.value = '';\r\n");
        out.write(
            "\r\n               if(!Jtrim(email) || !Jtrim(subject) || !Jtrim(message)){\r\n                 alert(\"All fields are required.\");\r\n                 return;\r\n               }\r\n                document.offline.submit();\r\n             }\r\n        }\r\n\r\n\r\n\r\n         function Jtrim(st) {\r\n             var len = st.length;\r\n             var begin = 0, end = len - 1;\r\n             while (st.charAt(begin) == \" \" && begin < len) {\r\n                 begin++;\r\n             }\r\n             while (st.charAt(end) == \" \" && end > begin) {\r\n                 end--;\r\n             }\r\n             return st.substring(begin, end + 1);\r\n         }\r\n        </script>\r\n    </head>\r\n    <body>\r\n    Specify action to take when this workgroup has no available agents to take incoming chat requests.\r\n    ");
        if (statusMessage != null && !statusMessage.equals("")) {
          out.write("\r\n    <div class=\"success\">\r\n        ");
          out.print(statusMessage);
          out.write("\r\n    </div>\r\n    ");
        }
        out.write("\r\n\r\n      ");
        if (!emailConfigured) {
          out.write(
              "\r\n            <div class=\"error\">\r\n                Email form will not be displayed until you configure your <a href=\"../../system-email.jsp\">email settings</a>.\r\n            </div>\r\n    ");
        }
        out.write("\r\n\r\n    <div id=\"offline_message\">");
        out.print(statusMessage);
        out.write(
            "</div>\r\n    <p/>\r\n    <form action=\"workgroup-offline.jsp\" method=\"get\" name=\"offline\">\r\n    <input type=\"hidden\" name=\"wgID\" value=\"");
        out.print(wgID);
        out.write(
            "\" />\r\n    <div>\r\n        <div class=\"jive-contentBoxHeader\">\r\n        Offline Workgroup Action\r\n        </div>\r\n        <table width=\"100%\" cellpadding=\"3\" cellspacing=\"0\" border=\"0\" class=\"jive-contentBox\">\r\n                <tr valign=\"top\">\r\n                ");
        String checked = offlineSettings.redirects() ? "checked" : "";
        out.write(
            "\r\n                            <td width=\"1%\">\r\n                                <input type=\"radio\" name=\"todo\" value=\"redirectToPage\" ");
        out.print(checked);
        out.write(
            " />\r\n                            </td>\r\n                            <td nowrap><b>Redirect To Web Page</b>\r\n                               </td>\r\n                            <td class=\"c2\">\r\n                                <input type=\"text\" name=\"redirectToPage\" size=\"40\" value=\"");
        out.print(offlineSettings.getRedirectURL());
        out.write(
            "\" /><br/>\r\n                                 <span class=\"jive-description\">e.g. http://www.jivesoftware.com/contact.html</span>\r\n                            </td>\r\n                </tr>\r\n                <tr>\r\n                    <td nowrap width=\"1%\">\r\n                         <input type=\"radio\" name=\"todo\" value=\"showEmailPage\" ");
        out.print(!offlineSettings.redirects() ? "checked" : "");
        out.write(
            "/>\r\n                         <td><b>Display Email Form</b></td>\r\n                     </td>\r\n                     <td>&nbsp;</td>\r\n                </tr>\r\n                <!-- Email Address -->\r\n                <tr valign=\"top\">\r\n                    <td>&nbsp;</td>\r\n                    <td>Email Address:</td>\r\n                    <td>\r\n                        <input type=\"text\" size=\"40\" name=\"email\" value=\"");
        out.print(offlineSettings.getEmailAddress());
        out.write(
            "\" /><br/>\r\n                        <span class=\"jive-description\">Email address to send all offline messages to.</span>\r\n                    </td>\r\n                </tr>\r\n                <!-- End of Email Address -->\r\n                <!-- Subject Line -->\r\n                 <tr valign=\"top\">\r\n                    <td>&nbsp;</td>\r\n                    <td>Subject:</td>\r\n                    <td>\r\n                        <input type=\"text\" size=\"40\" name=\"subject\" value=\"");
        out.print(offlineSettings.getSubject());
        out.write(
            "\"/><br/>\r\n                        <span class=\"jive-description\">The subject of all offline email messages.</span>\r\n                    </td>\r\n                </tr>\r\n                <!--  End Of Subject Line -->\r\n                <tr valign=\"top\">\r\n                     <td>&nbsp;</td>\r\n                    <td>Offline Text:</td>\r\n                    <td>\r\n                        <textarea name=\"headerField\" cols=\"40\" rows=\"5\">");
        out.print(offlineSettings.getOfflineText());
        out.write(
            "</textarea><br/>\r\n                        <span class=\"jive-description\">Text to display to the user in the email form.</span>\r\n                    </td>\r\n                </tr>\r\n                    <input type=\"hidden\" name=\"save\" value=\"save\">\r\n                 <tr>\r\n                </tr>\r\n            ");
        out.write(
            "\r\n            </table>\r\n            <table><tr>\r\n                 <td colspan=\"1\"> <input type=\"button\" name=\"save\" value=\"Save Changes\" onclick=\"return saveOfflineSettings();\" /></td>\r\n                <td colspan=\"1\"> <input type=\"submit\" name=\"delete\" value=\"Delete Changes\" /></td>\r\n            </tr></table>\r\n       </div>\r\n    </form>\r\n\r\n</body>\r\n</html>\r\n\r\n");
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)) {
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0) out.clearBuffer();
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }