/** * 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; }
/** * 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; }
/** * 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; }