class ServerInputProcessor {
private void processAddFriend(String input) throws ConnectionException {
Connection conn = DBManager.getConnection();
// Stores a list of users that is not the current user, who is not a
// friend of the
// current user, and has not requested current user as friend
// Users[0]: username. Users[1]: group name
List<String[]> friendableUsers = DatabaseAdmin.getFriendableUsers(conn, user);
// input of format "addFriend" or "addFriend b"
boolean userExist = false;
String toFriend = "";
String command = "";
while (!userExist) {
String prefix = "";
if (!input.equals("addFriend")) {
prefix = Utils.getValue(input);
}
command += SocialNetworkAdmin.displayFriendableUsers(
conn, prefix, friendableUsers);
sendWithNonce(command);
toFriend = recvWithNonce().toLowerCase();
if (toFriend.equals("cancel")) {
sendWithNonce(CANCEL);
return;
}
for (String[] userInfo : friendableUsers) {
if (userInfo[0].equals(toFriend)) {
userExist = true;
break;
}
}
if (!userExist) {
command = "print Cannot friend " + toFriend + ";";
}
}
// Gets back name of person to add as friend
addFriend(conn, toFriend);
DBManager.closeConnection(conn);
}
}