| Code with Finding: |
class SocialNetworkAdmin {
public static String friendRequests(Connection conn, String username) {
String command = "";
List<String> pendingFriends = DatabaseAdmin.getFriendRequestList(conn, username);
if (pendingFriends == null) {
command = "print Database error. Please contact System Admin.;";
} else if (pendingFriends.size() == 0) {
command = "print No pending friend requests at the moment.;";
} else {
command = "print Pending Friend Requests (" + pendingFriends.size() + "):;";
for (String f: pendingFriends) {
command = command + "print " + f + ";";
}
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 {
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;
}
}
|