package awesomefb.facebook;

import awesomefb.facebook.User;
import com.mongodb.BasicDBObject;
import org.json.JSONObject;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by earl on 5/25/2015.
 */
public class Comment extends Entity {
    private String mMessage;
    private User mCreator;
    private Date mCreatedTime;

    public String getMessage() {
        return mMessage;
    }

    public User getCreator() {
        return mCreator;
    }

    public Comment(JSONObject comment) {
        super(comment);
        mMessage = comment.getString("message");
        mCreator = new User(comment.getJSONObject("from"));
        mCreatedTime = parseTime(comment.getString("created_time"));
    }

    private Date parseTime(String dateString) {
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        try {
            Date time = format.parse(dateString);
            return time;
        } catch (ParseException e) {
            System.out.println(e.toString());
        }
        return null;
    }

    public BasicDBObject toDBObject() {
        BasicDBObject doc = new BasicDBObject("fb_id", getFacebookId())
                .append("message", mMessage)
                .append("creator", mCreator.toDBObject())
                .append("time_created", mCreatedTime);

        return doc;
    }

}

@@ -403,16 +403,836 @@
 tedTime;
+%0A    private String mTopic;%0A    private boolean mIsSpam;%0A    private ExternalLink mLink;%0A%0A    private class ExternalLink %7B%0A        private String mName;%0A        private String mUrl;%0A        private String mCaption;%0A        private String mDescription;%0A%0A        public ExternalLink(JSONObject obj) %7B%0A            mName = obj.getString(%22name%22);%0A            mUrl = obj.getString(%22link%22);%0A            mCaption = obj.getString(%22caption%22);%0A            mDescription = obj.getString(%22description%22);%0A        %7D%0A%0A        public BasicDBObject toDBObject() %7B%0A            BasicDBObject doc = new BasicDBObject(%22name%22, mName)%0A                    .append(%22link%22, mUrl)%0A                    .append(%22caption%22, mCaption)%0A                    .append(%22description%22, mDescription)%0A                    ;%0A%0A            return doc;%0A        %7D%0A    %7D
 %0A%0A    pu
@@ -1591,24 +1591,164 @@
 ted_time%22));
+%0A%0A        if (comment.has(%22link%22)) %7B%0A            mLink = new ExternalLink(comment);%0A        %7D%0A%0A        mTopic = %22%22;%0A        mIsSpam = false;
 %0A    %7D%0A%0A    
@@ -2345,18 +2345,210 @@
 tedTime)
-;
 %0A
+                .append(%22topic%22, mTopic)%0A                .append(%22is_spam%22, mIsSpam)%0A                ;%0A        if (mLink != null) %7B%0A            doc.append(%22link%22, mLink.toDBObject());%0A        %7D
 %0A       

Save link data in comment object