private void mapComment(JSONObject jsonComment, Comment comment) throws JSONException {

    comment.setId(jsonComment.getInt("id"));
    comment.setUsername(
        jsonComment.getJSONObject("links").getJSONObject("user").getString("title"));
    comment.setText(jsonComment.getString("text"));
    comment.setTimestamp(ReviewboardUtil.marshallDate(jsonComment.getString("timestamp")));
  }
  @Override
  public int parseJson(JSONObject json) {
    // TODO Auto-generated method stub
    try {
      id = json.getString("id");

      JSONObject fromObject = json.getJSONObject("from");
      from = new From(fromObject.getString("id"), fromObject.getString("name"));

      createdTime = json.getString("created_time");

      JSONObject applicationObject = json.getJSONObject("application");
      application =
          new From(applicationObject.getString("id"), applicationObject.getString("name"));

      achievement = new Achievement();
      JSONObject achiveObject = json.getJSONObject("achivement");
      achievement.setId(achiveObject.getString("id"));
      achievement.setUrl(achiveObject.getString("url"));
      achievement.setType(achiveObject.getString("type"));
      achievement.setTitle(achiveObject.getString("title"));

      likes = new Like();
      JSONObject likeObject = json.getJSONObject("likes");
      JSONArray likeArray = likeObject.getJSONArray("data");
      ArrayList<From> likeList = new ArrayList<From>(likeObject.getInt("count"));
      for (int i = 0; i < likeObject.getInt("count"); i++) {
        likeList.add(
            new From(
                likeArray.getJSONObject(i).getString("id"),
                likeArray.getJSONObject(i).getString("name")));
      }
      likes = new Like(likeList, likeObject.getInt("count"));

      comments = new ArrayList<Comment>();
      JSONObject commentObject = json.getJSONObject("comments");
      JSONArray commentArray = commentObject.getJSONArray("data");
      for (int i = 0; i < commentObject.getInt("count"); i++) {
        Comment tmp = new Comment();
        tmp.setId(commentArray.getJSONObject(i).getString("id"));
        tmp.setFrom(
            new From(
                commentArray.getJSONObject(i).getJSONObject("from").getString("id"),
                commentArray.getJSONObject(i).getJSONObject("from").getString("name")));
        tmp.setMessage(commentArray.getJSONObject(i).getString("message"));
        tmp.setCreateTime(commentArray.getJSONObject(i).getString("created_time"));
        comments.add(tmp);
      }

    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return 0;
  }
 public static Comment getFromJson(JSONObject commentJson) throws JSONException {
   Comment comment = new Comment();
   comment.setId(commentJson.getLong(ID));
   comment.setSpotId(commentJson.getLong(SPOT_ID));
   comment.setUserId(commentJson.getLong(USER_ID));
   comment.setComment(commentJson.getString(COMMENT));
   comment.setCreatedAt(commentJson.getLong(CREATED_AT));
   comment.setUserName(commentJson.getString(USER_NAME));
   comment.setUserDp(commentJson.getString(USER_DP));
   return comment;
 }
  public void testDeleteComment() throws Exception {
    Comment c = new Comment();
    c.setAuthor("lolcat");
    c.setContent("Can I haz ID?");
    c.setTargetId(UUID.randomUUID());
    c.setId(UUID.randomUUID());

    boolean result = es.putComment(c);
    assertTrue(es.getErrorMessage(), result);

    System.out.println("Comment ID: " + c.getId());

    result = es.deleteComment(c.getId());
    assertTrue(es.getErrorMessage(), result);
  }
  private static void insertComments(SessionWrapper sessionWrapper, Post post, int numComments) {
    for (int i = 0; i < numComments; i++) {
      Comment com = new Comment();
      com.setCommenter(getCommenter());
      com.setContent(getString(1, 10));
      com.setId(getTimeUUID());
      com.setPostedOn(System.currentTimeMillis());
      com.setPostId(post.getId());
      com.setTitle(getString(1, 3));
      com.save(sessionWrapper);

      CommentVotes votes = new CommentVotes();
      votes.setCommentId(com.getId());
      votes.setDownvotes(getInt(0, 10));
      votes.setUpvotes(getInt(0, 10));
      votes.save(sessionWrapper);
    }
  }
  private List<Comment> readComments(Content websiteNode) throws RepositoryException {

    List<Comment> list = new ArrayList<Comment>();

    if (websiteNode.hasContent("comments")) {
      Content commentsNode = websiteNode.getContent("comments");
      Collection<Content> children = commentsNode.getChildren();
      for (Content commentNode : children) {
        Comment comment = new Comment();
        comment.setName(commentNode.getNodeData("name").getString());
        comment.setEmail(commentNode.getNodeData("email").getString());
        comment.setText(commentNode.getNodeData("text").getString());
        comment.setCreated(commentNode.getNodeData("created").getDate().getTime());
        comment.setId(commentNode.getName());
        list.add(comment);
      }
    }

    return list;
  }
 private Comment cursorToComment(Cursor cursor) {
   Comment comment = new Comment();
   comment.setId(cursor.getLong(0));
   comment.setComment(cursor.getString(1));
   return comment;
 }