/** * Returns all NEW projects submitted to this YRC member's group(s) * * @param researcherID The researcher ID of the YRC member * @return A list of new projects (within the last 30 days) for this member's groups, null if this * is not a YRC member */ public static List<Project> getNewProjectsForYRCMember(Researcher r) throws SQLException { int researcherID = r.getID(); Groups gm = Groups.getInstance(); // return null if they're not in a YRC group if (!gm.isInAGroup(researcherID)) return null; ProjectsSearcher ps = new ProjectsSearcher(); // ps.setResearcher(r); // Set the start date of the search to 1 month ago Calendar cal = GregorianCalendar.getInstance(); cal.add(Calendar.MONTH, -1); ps.setStartDate(cal.getTime()); // Set the groups to search List groups = gm.getGroups(); Iterator iter = groups.iterator(); while (iter.hasNext()) { String group = (String) (iter.next()); if (gm.isMember(researcherID, group)) { ps.addGroup(group); } } List<Project> projects = ps.search(); return projects; }
/** * Simply return an ArrayList of all the researchers in the database (as Researcher objects) * * @return A list of all the Researchers in the database */ public static ArrayList getAllResearchers() throws SQLException, InvalidIDException { ArrayList retList = new ArrayList(); // Get our connection to the database. Connection conn = DBConnectionManager.getConnection("yrc"); Statement stmt = null; ResultSet rs = null; try { stmt = conn.createStatement(); // Our SQL statement String sqlStr = "SELECT researcherID, researcherFirstName, researcherLastName, researcherEmail, researcherOrganization FROM tblResearchers ORDER BY researcherLastName"; // Our results rs = stmt.executeQuery(sqlStr); // Iterate over list and populate our return list while (rs.next()) { Researcher researcher = new Researcher(); researcher.setID(rs.getInt("researcherID")); researcher.setFirstName(rs.getString("researcherFirstName")); researcher.setLastName(rs.getString("researcherLastName")); researcher.setEmail(rs.getString("researcherEmail")); researcher.setOrganization(rs.getString("researcherOrganization")); retList.add(researcher); } rs.close(); rs = null; stmt.close(); stmt = null; conn.close(); conn = null; } finally { // Always make sure result sets and statements are closed, // and the connection is returned to the pool if (rs != null) { try { rs.close(); } catch (SQLException e) {; } rs = null; } if (stmt != null) { try { stmt.close(); } catch (SQLException e) {; } stmt = null; } if (conn != null) { try { conn.close(); } catch (SQLException e) {; } conn = null; } } return retList; }