Code with Finding: |
class SocialNetworkAdmin {
public static String regRequests(Connection conn, String username) {
String command = "";
List<String> pendingUsers = DatabaseAdmin.getRegRequestList(conn, username);
if (pendingUsers == null) {
command = "print Database error. Please contact System Admin.;";
} else if (pendingUsers.size() == 0) {
command = "print No pending registration requests at the moment.;";
} else {
command = "print Pending User Registration Requests ("
+ pendingUsers.size() + "):;";
for (String u: pendingUsers) {
command = command + "print " + u + ";";
}
command += "print ;print [To approve: approve "
+ "<username1>, <username2>];print [To remove: "
+ "remove <username1>, <username2>];askForInput;";
}
return command;
}
}
class SocialNetworkAdmin {
public static String transferSA(Connection conn, String from, String to) {
String success = "print SA role has been transferred to " + to + ";";
String error = "print Database error occurred while transferring SA role to " +
to + ". Please try again or contact the System Admin.;";
try {
conn.setAutoCommit(false);
} catch (SQLException e) {
if (DEBUG) System.err.println("transferSA: turning off auto commit failed.");
return error;
}
int demoteStatus = DatabaseAdmin.changeRole(conn, from, "admin");
int promoteStatus = DatabaseAdmin.changeRole(conn, to, "sa");
if (demoteStatus != 1 || promoteStatus != 1) {
DBManager.rollback(conn);
DBManager.trueAutoCommit(conn);
if (DEBUG) System.err.printf("transferSA: DB operations failed. " +
"demoteStatus: %d, promoteStatus: %d\n", demoteStatus, promoteStatus);
return error;
} else {
try {
conn.commit();
DBManager.trueAutoCommit(conn);
return success;
} catch (SQLException e) {
DBManager.trueAutoCommit(conn);
if (DEBUG) e.printStackTrace();
return error;
}
}
}
}
class SocialNetworkAdmin {
/**
* Precond: if board is freeforall, region is post, if not, board and regions are valid
* @param conn
* @param board
* @param region
* @return
*/
public static String displayParticipAndAdmins(Connection conn, String board, String region) {
String command = "print Displaying participants in "+board+"/"+region+":;";
List<String> admins = DatabaseAdmin.getAdminsOfBoard(conn, board);
List<String[]> part = DatabaseAdmin.getParticipants(conn, board, region);
if ((admins == null || admins.size() == 0) && (part == null || part.size() == 0)) {
command += EMPTY_LIST;
} else {
for (String a: admins) {
command += "print " + a + " (Admin);";
}
for (String[] p: part) {
command += "print " + p[0];
if (p[1].equals("view")) {
command += " (view only)";
}
command += ";";
}
}
//command += "print ;print Other Commands: addParticipants, removeParticipants, editParticipants;";
return command;
}
}
class SocialNetworkAdmin {
public static List<String> getAddableParticip(Connection conn, String username, String board, String region) {
List<String> addables = new ArrayList<String>();
// friends that are not already participants of the region and not admins
List<String> friends = DatabaseAdmin.getFriends(conn, username);
List<String[]> participants = DatabaseAdmin.getParticipants(conn, board, region);
if (friends == null || participants == null) {
return null;
}
for (String f: friends) {
if (board == "freeforall" || !DatabaseAdmin.isAdmin(conn, f)) {
boolean isPart = false;
for (String[] p: participants) {
if (f.equals(p[0])) {
isPart = true;
break;
}
}
if (!isPart) {
addables.add(f);
}
}
}
return addables;
}
}
|