// Path: akanke-common/src/main/java/eu/kielczewski/akanke/common/domain/FacebookStats.java
// @SuppressWarnings("UnusedDeclaration")
// @Entity
// @Table(name = "facebook_stats")
// public class FacebookStats {
// 
//     @NotNull
//     @Id
//     @GeneratedValue(strategy = GenerationType.IDENTITY)
//     @Column(name = "id", nullable = false, updatable = false)
//     private int id;
// 
//     @NotNull
//     @JsonProperty("comment_count")
//     @Column(name = "comment_count")
//     private int commentCount = 0;
// 
//     @NotNull
//     @JsonProperty("share_count")
//     @Column(name = "share_count")
//     private int shareCount = 0;
// 
//     public FacebookStats() {
//     }
// 
//     public FacebookStats(int commentCount, int shareCount) {
//         this.commentCount = commentCount;
//         this.shareCount = shareCount;
//     }
// 
//     public int getId() {
//         return id;
//     }
// 
//     public int getCommentCount() {
//         return commentCount;
//     }
// 
//     public void setCommentCount(int commentCount) {
//         this.commentCount = commentCount;
//     }
// 
//     public int getShareCount() {
//         return shareCount;
//     }
// 
//     public void setShareCount(int shareCount) {
//         this.shareCount = shareCount;
//     }
// 
//     @Override
//     public String toString() {
//         return MoreObjects.toStringHelper(this)
//                 .add("id", id)
//                 .add("commentCount", commentCount)
//                 .add("shareCount", shareCount)
//                 .toString();
//     }
// 
// }


import com.fasterxml.jackson.databind.JsonNode;
import eu.kielczewski.akanke.common.domain.FacebookStats;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.social.SocialException;
import org.springframework.social.facebook.api.impl.FacebookTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.ResourceAccessException;
import javax.inject.Inject;
import java.net.ConnectException;
import java.util.Collections;
import static com.google.common.base.Preconditions.checkArgument;
package eu.kielczewski.akanke.common.service.facebook;




@Service
class FacebookStatsServiceImpl implements FacebookStatsService {

    private static final Logger LOGGER = LoggerFactory.getLogger(FacebookStatsServiceImpl.class);
    private static final String COMMENT_COUNT = "comment_count";
    private static final String SHARE_COUNT = "share_count";
    private final FacebookTemplate facebookTemplate;

    @Value("${akanke.base-url}")
    private String baseUrl;

    @Autowired
    public FacebookStatsServiceImpl(FacebookTemplate facebookTemplate) {
        this.facebookTemplate = facebookTemplate;
    }

    @Override
    @Cacheable("facebook-stats")
    public FacebookStats get(String documentId) {
        LOGGER.debug("Getting facebook stats for document id={}", documentId);
        checkArgument(documentId != null, "Document id cannot be null");
        try {
            MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
            params.put("fields", Collections.singletonList("share"));
            params.put("id", Collections.singletonList(baseUrl + documentId));
            JsonNode ogObjectNode = facebookTemplate.fetchObject("/", JsonNode.class, params);
            JsonNode shareNode = ogObjectNode.get("share");
            if (shareNode == null) {
// Path: akanke-common/src/main/java/eu/kielczewski/akanke/common/domain/FacebookStats.java
// @SuppressWarnings("UnusedDeclaration")
// @Entity
// @Table(name = "facebook_stats")
// public class FacebookStats {
// 
//     @NotNull
//     @Id
//     @GeneratedValue(strategy = GenerationType.IDENTITY)
//     @Column(name = "id", nullable = false, updatable = false)
//     private int id;
// 
//     @NotNull
//     @JsonProperty("comment_count")
//     @Column(name = "comment_count")
//     private int commentCount = 0;
// 
//     @NotNull
//     @JsonProperty("share_count")
//     @Column(name = "share_count")
//     private int shareCount = 0;
// 
//     public FacebookStats() {
//     }
// 
//     public FacebookStats(int commentCount, int shareCount) {
//         this.commentCount = commentCount;
//         this.shareCount = shareCount;
//     }
// 
//     public int getId() {
//         return id;
//     }
// 
//     public int getCommentCount() {
//         return commentCount;
//     }
// 
//     public void setCommentCount(int commentCount) {
//         this.commentCount = commentCount;
//     }
// 
//     public int getShareCount() {
//         return shareCount;
//     }
// 
//     public void setShareCount(int shareCount) {
//         this.shareCount = shareCount;
//     }
// 
//     @Override
//     public String toString() {
//         return MoreObjects.toStringHelper(this)
//                 .add("id", id)
//                 .add("commentCount", commentCount)
//                 .add("shareCount", shareCount)
//                 .toString();
//     }
// 
// }


// Path: akanke-common/src/main/java/eu/kielczewski/akanke/common/service/facebook/FacebookStatsServiceImpl.java
import com.fasterxml.jackson.databind.JsonNode;
import eu.kielczewski.akanke.common.domain.FacebookStats;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.social.SocialException;
import org.springframework.social.facebook.api.impl.FacebookTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.ResourceAccessException;
import javax.inject.Inject;
import java.net.ConnectException;
import java.util.Collections;
import static com.google.common.base.Preconditions.checkArgument;

package eu.kielczewski.akanke.common.service.facebook;




@Service
class FacebookStatsServiceImpl implements FacebookStatsService {

    private static final Logger LOGGER = LoggerFactory.getLogger(FacebookStatsServiceImpl.class);
    private static final String COMMENT_COUNT = "comment_count";
    private static final String SHARE_COUNT = "share_count";
    private final FacebookTemplate facebookTemplate;

    @Value("${akanke.base-url}")
    private String baseUrl;

    @Autowired
    public FacebookStatsServiceImpl(FacebookTemplate facebookTemplate) {
        this.facebookTemplate = facebookTemplate;
    }

    @Override
    @Cacheable("facebook-stats")
    public FacebookStats get(String documentId) {
        LOGGER.debug("Getting facebook stats for document id={}", documentId);
        checkArgument(documentId != null, "Document id cannot be null");
        try {
            MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
            params.put("fields", Collections.singletonList("share"));
            params.put("id", Collections.singletonList(baseUrl + documentId));
            JsonNode ogObjectNode = facebookTemplate.fetchObject("/", JsonNode.class, params);
            JsonNode shareNode = ogObjectNode.get("share");
            if (shareNode == null) {
                return new FacebookStats();