Permalink
Browse files

Merge pull request #26 from habuma/master

SOCIALFB-51: Added commentCount to Post
  • Loading branch information...
Craig Walls
Craig Walls committed Feb 17, 2012
2 parents 7389533 + f185186 commit 9ebd068f6691347511e5b59df413fe74f43959f7
@@ -19,6 +19,7 @@
import java.util.List;
+
/**
* Model class representing a user checkin on Facebook Places.
* @author Craig Walls
@@ -36,7 +37,7 @@
private String message;
- private List<Comment> comments;
+ private Comments comments;
private List<Reference> likes;
@@ -75,7 +76,7 @@ public String getMessage() {
}
public List<Comment> getComments() {
- return comments;
+ return comments.getComments();
}
public List<Reference> getLikes() {
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2011 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.social.facebook.api;
+
+import java.util.List;
+
+/**
+ * Contains a list of comments and a count of the total number of comments for a post or checkin.
+ * This type is not intended for direct use and is not exposed by either the Post or Checkin type.
+ * Instead, the comments list and count are available through Comment.getComments(), Post.getComments(), and Post.getCommentCount().
+ * @author habuma
+ */
+public class Comments {
+
+ private final List<Comment> comments;
+
+ private final int commentCount;
+
+ public Comments(List<Comment> comments, int commentCount) {
+ this.comments = comments;
+ this.commentCount = commentCount;
+ }
+
+ public int getCommentCount() {
+ return commentCount;
+ }
+
+ public List<Comment> getComments() {
+ return comments;
+ }
+
+}
@@ -56,7 +56,9 @@
private int likeCount;
- private List<Comment> comments;
+ private Comments comments;
+
+ private int commentCount;
private int sharesCount;
@@ -135,9 +137,12 @@ public int getSharesCount() {
* The most recent comments for the post.
*/
public List<Comment> getComments() {
- return comments;
+ return comments.getComments();
}
- public static enum PostType { POST, CHECKIN, LINK, NOTE, PHOTO, STATUS, VIDEO, SWF, MUSIC }
+ public int getCommentCount() {
+ return comments.getCommentCount();
+ }
+ public static enum PostType { POST, CHECKIN, LINK, NOTE, PHOTO, STATUS, VIDEO, SWF, MUSIC }
}
@@ -116,7 +116,7 @@
/**
* Removes a question option.
* Requires "publish_stream" permission.
- * @param questionId the ID of the option to delete
+ * @param optionId the ID of the option to delete
* @throws ApiException if there is an error while communicating with Facebook.
* @throws InsufficientPermissionException if the user has not granted "publish_stream" permission.
* @throws MissingAuthorizationException if FacebookTemplate was not created with an access token.
@@ -22,7 +22,7 @@
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonDeserialize;
-import org.springframework.social.facebook.api.Comment;
+import org.springframework.social.facebook.api.Comments;
import org.springframework.social.facebook.api.Page;
import org.springframework.social.facebook.api.Reference;
@@ -46,7 +46,7 @@
@JsonProperty("comments")
@JsonDeserialize(using = CommentListDeserializer.class)
- List<Comment> comments;
+ Comments comments;
@JsonProperty("likes")
@JsonDeserialize(using = ReferenceListDeserializer.class)
@@ -16,6 +16,7 @@
package org.springframework.social.facebook.api.impl.json;
import java.io.IOException;
+import java.util.Collections;
import java.util.List;
import org.codehaus.jackson.JsonNode;
@@ -26,19 +27,25 @@
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
import org.springframework.social.facebook.api.Comment;
+import org.springframework.social.facebook.api.Comments;
+
+class CommentListDeserializer extends JsonDeserializer<Comments> {
-class CommentListDeserializer extends JsonDeserializer<List<Comment>> {
@SuppressWarnings("unchecked")
@Override
- public List<Comment> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
+ public Comments deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
mapper.setDeserializationConfig(ctxt.getConfig());
jp.setCodec(mapper);
if(jp.hasCurrentToken()) {
- JsonNode dataNode = jp.readValueAsTree().get("data");
- if(dataNode != null) {
- return (List<Comment>) mapper.readValue(dataNode, new TypeReference<List<Comment>>() {});
- }
+ JsonNode commentsNode = jp.readValueAsTree();
+ JsonNode dataNode = commentsNode.get("data");
+ List<Comment> commentsList = dataNode != null ?
+ (List<Comment>) mapper.readValue(dataNode, new TypeReference<List<Comment>>() {}) :
+ Collections.<Comment>emptyList();
+ JsonNode countNode = commentsNode.get("count");
+ int commentCount = countNode != null ? countNode.getIntValue() : 0;
+ return new Comments(commentsList, commentCount);
}
return null;
@@ -34,7 +34,7 @@
import org.codehaus.jackson.map.JsonDeserializer;
import org.codehaus.jackson.map.annotate.JsonDeserialize;
import org.springframework.social.facebook.api.CheckinPost;
-import org.springframework.social.facebook.api.Comment;
+import org.springframework.social.facebook.api.Comments;
import org.springframework.social.facebook.api.LinkPost;
import org.springframework.social.facebook.api.MusicPost;
import org.springframework.social.facebook.api.NotePost;
@@ -118,7 +118,8 @@
@JsonProperty("comments")
@JsonDeserialize(using = CommentListDeserializer.class)
- List<Comment> comments;
+ Comments comments;
+
private static class TypeDeserializer extends JsonDeserializer<PostType> {
@Override
@@ -351,6 +351,7 @@ public void getFeedEntry() {
assertEquals("Art Names", feedEntry.getFrom().getName());
assertEquals(2, feedEntry.getLikeCount());
assertEquals(2, feedEntry.getComments().size());
+ assertEquals(22, feedEntry.getCommentCount());
assertNull(feedEntry.getComments().get(1).getLikes());
assertEquals(3, feedEntry.getComments().get(1).getLikesCount());
}
@@ -55,7 +55,7 @@
"created_time":"2011-01-18T05:01:07+0000"
}
],
- "count":2
+ "count":22
}
}

0 comments on commit 9ebd068

Please sign in to comment.