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

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

Introduction

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

Prototype

public CountedList(List<T> unpagedList, Integer totalCount) 

Source Link

Usage

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 ww  .j  a  v a  2  s  .  co  m

    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);
}