Example usage for org.springframework.social.facebook.api Reference getId

List of usage examples for org.springframework.social.facebook.api Reference getId

Introduction

In this page you can find the example usage for org.springframework.social.facebook.api Reference getId.

Prototype

public String getId() 

Source Link

Usage

From source file:com.springsource.greenhouse.invite.FacebookInviteController.java

private List<Long> friendAccountIds(Long accountId, Facebook facebook) {
    List<Reference> friends = facebook.friendOperations().getFriends();
    if (friends.isEmpty()) {
        return Collections.emptyList();
    }//w  w  w  .jav a 2s . co  m
    Set<String> providerUserIds = new HashSet<String>(friends.size());
    for (Reference friend : friends) {
        providerUserIds.add(friend.getId());
    }
    Set<String> userIds = connectionRepository.findUserIdsConnectedTo("facebook", providerUserIds);
    List<Long> friendAccountIds = new ArrayList<Long>(userIds.size());
    for (String localUserId : userIds) {
        friendAccountIds.add(Long.valueOf(localUserId));
    }
    return friendAccountIds;
}

From source file:org.easit.core.controllers.facebook.FacebookFriendsController.java

@RequestMapping(value = "/facebook/manageLists/{friendId}", method = RequestMethod.POST)
public String manageLists(@PathVariable("friendId") String friendId, String fListId[],
        HttpServletRequest request) {//  w  w  w  .ja  v a2 s. c  o m
    String[] listids = request.getParameterValues("fListId[]");
    List<Reference> currentLists = new ArrayList<Reference>();
    List<String> newListIds = new ArrayList<String>();
    newListIds = Arrays.asList(listids);
    currentLists = friendListsPerUser(facebook.friendOperations().getFriendLists(), friendId);
    for (Reference current : currentLists) {
        if (!(newListIds.contains(current.getId())))
            facebook.friendOperations().removeFromFriendList(current.getId(), friendId);
    }
    for (String listId : newListIds) {
        if (!(currentLists.contains(listId)))
            facebook.friendOperations().addToFriendList(listId, friendId);
    }

    return "redirect:/facebook/friends";
}

From source file:org.easit.core.controllers.facebook.FacebookFriendsController.java

@RequestMapping(value = "/facebook/addFriend/{userId}", method = RequestMethod.POST)
public String addFriend(@PathVariable("userId") String userId, HttpSession session) {
    String web_name = session.getAttribute("web_name").toString();
    String listId = null;//from w  ww . jav  a2  s.c om
    List<Reference> fl = facebook.friendOperations().getFriendLists();
    for (Reference fl_exists : fl) {
        if (fl_exists.getName().equals(web_name)) {
            listId = fl_exists.getId();
            break;
        }
    }
    if (listId == null) {
        listId = facebook.friendOperations().createFriendList(web_name);
    }
    facebook.friendOperations().addToFriendList(listId, userId);
    return "redirect:/facebook/friends";
}

From source file:org.easit.core.controllers.facebook.FacebookFriendsController.java

private List<Reference> friendListsPerUser(List<Reference> friendLists, String friend) {
    // Copy friendLists values into other List and remove "All" friendList:
    List<Reference> fl = new ArrayList<Reference>();
    fl.addAll(friendLists);/* ww  w .  j a va 2  s.  com*/
    fl.remove(fl.size() - 1);

    List<Reference> lists = new ArrayList<Reference>();
    for (Reference friendList : fl) {
        List<Reference> members = facebook.friendOperations().getFriendListMembers(friendList.getId());
        for (Reference member : members) {
            if (member.getId().equals(friend))
                lists.add(friendList);
        }
    }
    return lists;
}

From source file:org.easit.core.controllers.facebook.FacebookFriendsController.java

@RequestMapping(value = "/facebook/friends", method = RequestMethod.GET)
public String showFriends(Model model, String friendListId, String offset, String size, HttpSession session) {
    int resultLimit = 0;
    int resultOffset = 0;
    int listSize = 0;
    int int_offset = 0;
    List<Reference> friendList = new ArrayList<Reference>();
    if (offset != null) {
        int_offset = Integer.valueOf(offset);
    }//ww w. j a  v  a2 s  .  com
    String currentListName = null;
    String currentListId = null;
    List<Reference> friends = null;
    List<Reference> friendLists = facebook.friendOperations().getFriendLists();
    Reference allList = new Reference("1", "All");
    friendLists.add(allList);
    if (friendListId == null || friendListId.equals("1") || friendListId.equals("All")) {
        currentListName = "All";
        currentListId = "1";

        if (size != null) {
            listSize = Integer.valueOf(size);
        } else {
            listSize = facebook.friendOperations().getFriends().size();
        }
        if (listSize <= int_offset + PSMetadata.FACEBOOK_LIMIT_RESULT) {
            resultLimit = listSize;
        } else {
            resultLimit = int_offset + PSMetadata.FACEBOOK_LIMIT_RESULT;
        }
        if (listSize <= int_offset) {
            resultOffset = listSize;
        } else {
            resultOffset = int_offset;
        }
        friends = facebook.friendOperations().getFriends().subList(resultOffset, resultLimit);

    } else {

        currentListName = facebook.friendOperations().getFriendList(friendListId).getName();
        currentListId = facebook.friendOperations().getFriendList(friendListId).getId();

        if (size != null) {
            listSize = Integer.valueOf(size);
        } else {
            listSize = facebook.friendOperations().getFriendListMembers(friendListId).size();
        }
        if (listSize <= int_offset + PSMetadata.FACEBOOK_LIMIT_RESULT) {
            resultLimit = listSize;
        } else {
            resultLimit = int_offset + PSMetadata.FACEBOOK_LIMIT_RESULT;
        }
        if (listSize <= int_offset) {
            resultOffset = listSize;
        } else {
            resultOffset = int_offset;
        }
        friends = facebook.friendOperations().getFriendListMembers(friendListId).subList(resultOffset,
                resultLimit);
    }
    // only show it if the user has very high technological skills
    if (session.getAttribute("techSkills").equals(3)) {
        List<List> listsPerUser = new ArrayList<List>();
        for (Reference friend : friends) {
            listsPerUser.add(friendListsPerUser(friendLists, friend.getId()));
        }
        model.addAttribute("listsPerUser", listsPerUser);
    }
    model.addAttribute("currentListName", currentListName);
    model.addAttribute("currentListId", currentListId);
    model.addAttribute("friendLists", friendLists);
    model.addAttribute("friends", friends);
    model.addAttribute("offset", int_offset);
    model.addAttribute("pageSize", listSize);
    return "facebook/friends";
}