Exemplo n.º 1
0
 /**
  * @param user
  * @param friend
  * @return String "OWN" if the user, "KNOWN" if he is a friend, "UNKNOWN" if he is not a friend.
  */
 @SuppressWarnings("unchecked")
 @POST
 @Path("/isfriend")
 @Produces("text/plain")
 @Consumes("application/json")
 public String isFriend(String json) {
   Gson gson = new Gson();
   Map<String, String> jsonFriend = gson.fromJson(json, HashMap.class);
   String user = jsonFriend.get("user");
   String friend = jsonFriend.get("friend");
   String isFriend = "";
   if (user.equals(friend)) {
     isFriend = "OWN";
   } else {
     isFriend = "UNKNOWN";
     List<User> friends = FriendDB.getFriends(new User(user));
     for (User fr : friends) {
       if (fr.equals(friend)) {
         isFriend = "KNOWN";
         break;
       }
     }
   }
   return isFriend;
 }
Exemplo n.º 2
0
 @SuppressWarnings("unchecked")
 @POST
 @Path("/addfriend")
 @Produces("text/plain")
 @Consumes("application/json")
 public String addFriend(String json) {
   Gson gson = new Gson();
   Map<String, String> jsonFriend = gson.fromJson(json, HashMap.class);
   return String.valueOf(
       FriendDB.addFriend(new User(jsonFriend.get("user")), new User(jsonFriend.get("friend"))));
 }
Exemplo n.º 3
0
 @GET
 @Path("/friendlist")
 @Produces("application/json")
 public String getFriends(@QueryParam("user") String userName) {
   User user = new User(userName);
   List<String> friendNames = new ArrayList<String>();
   List<User> friendList = FriendDB.getFriends(user);
   for (User friend : friendList) {
     friendNames.add(friend.getUsername());
   }
   String json = null;
   if (friendNames.size() > 0) {
     Gson gson = new Gson();
     json = gson.toJson(friendNames, ArrayList.class);
   }
   return json;
 }