Esempio n. 1
0
  public void executeGet(IQ packet, Workgroup workgroup) {
    IQ reply = IQ.createResultIQ(packet);

    JID from = packet.getFrom();
    String bareJID = from.toBareJID();

    boolean isMonitor = false;

    // Retrieve the sound settings.
    String monitors = workgroup.getProperties().getProperty("monitors");
    if (monitors != null) {
      StringTokenizer tkn = new StringTokenizer(monitors, ",");
      while (tkn.hasMoreTokens()) {
        String agent = tkn.nextToken();
        if (agent.equalsIgnoreCase(bareJID)) {
          isMonitor = true;
        }
      }
    }

    Element monitorElement =
        reply.setChildElement("monitor", "http://jivesoftware.com/protocol/workgroup");

    if (!isMonitor) {
      monitorElement.addElement("isMonitor").setText("false");
    } else {
      monitorElement.addElement("isMonitor").setText("true");
    }

    workgroup.send(reply);
  }
Esempio n. 2
0
  /**
   * Returns the number of request made to a workgroup between specified dates.
   *
   * @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 getNumberOfRequestsForWorkgroup(
      String workgroupName, Date startDate, Date endDate) {
    Workgroup workgroup = getWorkgroup(workgroupName);
    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_REQUEST_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;
  }
Esempio n. 3
0
  /**
   * 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;
  }
Esempio n. 4
0
  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);
    }
  }
Esempio n. 5
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;
  }
Esempio n. 6
0
  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");
  }
Esempio n. 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);
  }
Esempio n. 8
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;
  }
Esempio n. 9
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;
  }
Esempio n. 10
0
 private boolean isOwner(String jid, Workgroup workgroup) {
   DbProperties props = workgroup.getProperties();
   // Add monitors if you wish :)
   String monitors = props.getProperty("monitors");
   if (monitors != null) {
     StringTokenizer tkn = new StringTokenizer(monitors, ",");
     while (tkn.hasMoreTokens()) {
       String monitor = tkn.nextToken();
       if (monitor.equalsIgnoreCase(jid)) {
         return true;
       }
     }
   }
   return false;
 }
Esempio n. 11
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);
    }
  }
Esempio n. 12
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);
    }
  }