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

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

Introduction

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

Prototype

public Reference(String id, String name) 

Source Link

Usage

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);
    }/*w  ww  . j av  a2 s.co  m*/
    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";
}

From source file:org.springframework.social.facebook.api.impl.SocialContextTemplate.java

private CountedList<Reference> getSocialContext(String userId, String context, int limit) {
    URIBuilder uriBuilder = URIBuilder.fromUri(GRAPH_API_URL + userId).queryParam("fields",
            "context.fields(" + context + ".limit(" + limit + "))");
    JsonNode responseNode = rest.getForObject(uriBuilder.build(), JsonNode.class);
    JsonNode contextNode = responseNode.get("context").get(context);
    ArrayNode dataNode = (ArrayNode) contextNode.get("data");
    ArrayList<Reference> results = new ArrayList<Reference>(dataNode.size());
    for (JsonNode itemNode : dataNode) {
        results.add(new Reference(itemNode.get("id").textValue(), itemNode.get("name").textValue()));
    }/* w  w  w  .j  av a 2s. com*/

    Integer totalCount = (contextNode.has("summary") && contextNode.get("summary").has("total_count"))
            ? contextNode.get("summary").get("total_count").intValue()
            : null;

    return new CountedList<Reference>(results, totalCount);
}

From source file:com.seajas.search.codex.service.social.SocialProfileServiceTest.java

@Test
public void testSearchFacebookProfileSuggestions() throws Exception {
    List<Reference> profileReferences = Lists.newArrayList(new Reference("id", "testPerson"),
            new Reference("id2", "anotherPerson"));

    when(socialFacadeMock.searchFacebookProfiles("testPerson")).thenReturn(profileReferences);

    FacebookProfile fbp1 = new FacebookProfile("id", "username", "testPerson", "first", "last", "gender",
            Locale.GERMAN);/*from ww w . ja v  a2 s  .c o m*/
    FacebookProfile fbp2 = new FacebookProfile("id2", "username", "anotherPerson", "first", "last", "gender",
            Locale.GERMAN);

    when(socialFacadeMock.getFacebookProfiles(Lists.newArrayList("id", "id2")))
            .thenReturn(Lists.newArrayList(fbp1, fbp2));

    List<SocialProfileDto> dtos = socialProfileService.searchFacebookProfiles("testPerson", true);

    List profiles = Lists.newArrayList(SocialProfileDto.translate(fbp1));
    Assert.assertEquals(profiles, dtos);
    verify(mediaServiceMock).storeUrl(anyString(), (String) isNull(), eq("image"));
}

From source file:com.seajas.search.codex.service.social.SocialProfileServiceTest.java

@Test
public void testSearchFacebookPages() throws Exception {
    List<Reference> pageReferences = Lists.newArrayList(new Reference("id3", "name3"));
    FacebookProfile fbp3 = new FacebookProfile("id", "username", "name", "first", "last", "gender",
            Locale.GERMAN);//from  w w w.  j a  v  a 2 s  .  co  m

    when(socialFacadeMock.searchFacebookPages("testPerson")).thenReturn(pageReferences);
    when(socialFacadeMock.getFacebookPages(Lists.newArrayList("id3"))).thenReturn(Lists.newArrayList(fbp3));

    List<SocialProfileDto> dtos = socialProfileService.searchFacebookPages("testPerson", false);

    verify(mediaServiceMock, times(1)).storeUrl(anyString(), (String) isNull(), eq("image"));
    List profiles = Lists.newArrayList(SocialProfileDto.translate(fbp3));
    Assert.assertEquals(profiles, dtos);
}

From source file:com.seajas.search.codex.service.social.SocialProfileServiceTest.java

@Test
public void testGetFacebookPagesSuggestions() throws Exception {
    List<Reference> pageReferences = Lists.newArrayList(new Reference("id3", "testPerson"),
            new Reference("id4", "testPerson"), new Reference("id5", "testPerson"));
    FacebookProfile fbp3 = new FacebookProfile("id", "username", "testPerson", "first", "last", "gender",
            Locale.GERMAN);/*w ww  .  j a  v  a  2 s .  c  om*/
    FacebookProfile fbp4 = new FacebookProfile("id", "username", "testPerson", "first", "last", "gender",
            Locale.GERMAN);
    FacebookProfile fbp5 = new FacebookProfile("id", "username", "testPerson", "first", "last", "gender",
            Locale.GERMAN);

    when(socialFacadeMock.searchFacebookPages("testPerson")).thenReturn(pageReferences);
    when(socialFacadeMock.getFacebookPages(Lists.newArrayList("id3", "id4", "id5")))
            .thenReturn(Lists.newArrayList(fbp3, fbp4, fbp5));

    List<SocialProfileDto> dtos = socialProfileService.searchFacebookPages("testPerson", true);

    verify(mediaServiceMock, times(2)).storeUrl(anyString(), (String) isNull(), eq("image"));
    List profiles = Lists.newArrayList(SocialProfileDto.translate(fbp3), SocialProfileDto.translate(fbp4));
    Assert.assertEquals(profiles, dtos);
}