Post

public class Post extends FeedItem implements Serializable, Postable, Putable

Represents a post made by a user in a network. A post is arbitrary, formatted text of the user’s choosing.

Fields

author

public User author

The User who created the post. This may not be present and have to be instantiated from Post.userId. Currently, this is handled by org.codethechange.culturemesh.API

content

public String content

The body of the post. May be formatted.

See also: org.codethechange.culturemesh.FormatManager

datePosted

public String datePosted

Timestamp for when the post was created. Should conform to EEE, dd MMM yyyy kk:mm:ss z

id

public long id

Uniquely identifies the post across all of CultureMesh

network

public Network network

The Network who created the post. This may not be present and have to be instantiated from Post.networkId. Currently, this is handled by org.codethechange.culturemesh.API

networkId

public long networkId

Unique identifier for the network the post was made in. This is used when only a reference to the full Network object is needed, e.g. when getting a post from the API. The rest of the information associated with the network can be fetched later.

userId

public long userId

Unique identifier for the user who created the post. This is used when only a reference to the full User object is needed, e.g. when getting a post from the API. The rest of the information associated with the user can be fetched later.

Constructors

Post

public Post(long id, long author, long networkId, String content, String imgLink, String vidLink, String datePosted)

Create a new post object from the provided parameters. The resulting object will not be fully instantiated (e.g. Post.author and Post.network will be null.

Parameters:
  • id – Uniquely identifies the post across all of CultureMesh
  • author – ID of User who created the post
  • networkId – ID of the Network in which the post was made
  • content – Formatted text that composes the body of the post.
  • imgLink – Link to an image associated with the post. null if none associated.
  • vidLink – Link to a video associated with the post. null if none associated
  • datePosted – When the post was created. Must conform to EEE, dd MMM yyyy kk:mm:ss z

See also: org.codethechange.culturemesh.FormatManager

Post

public Post()

Empty constructor for database

Post

public Post(JSONObject json)

Creates a bare (uninstantiated) Post from a JSON that conforms to the below format:

{
        "id": 0,
        "id_user": 0,
        "id_network": 0,
        "post_date": "string",
        "post_text": "string",
        "post_class": 0,
        "post_original": "string",
        "vid_link": "string",
        "img_link": "string"
       }
Parameters:
  • json – JSON representation of the Post to construct
Throws:
  • JSONException – May be thrown in response to an improperly formatted JSON

Methods

getAuthor

public User getAuthor()

Get the author of the post. Object must be fully instantiated, not just populated with IDs

Returns:Author of the post

getContent

public String getContent()

Get the formatted text that makes up the body of the post.

Returns:Body of the post, which may be formatted.

See also: org.codethechange.culturemesh.FormatManager

getDatePosted

public String getDatePosted()

Get when the post was created.

Returns:Timestamp of when post was created. Conforms to EEE, dd MMM yyyy kk:mm:ss z

getNetwork

public Network getNetwork()

Get the network of the post. Object must be fully instantiated, not just populated with IDs

Returns:Network of the post

getPostJson

public JSONObject getPostJson()

Wrapper for Post.toJSON()

getPostedTime

public Date getPostedTime()

Sometimes, we will want to get the time not just as a string but as a Date object (i.e. for comparing time for sorting)

Returns:Date object based on datePosted string.

getPutJson

public JSONObject getPutJson()

Wrapper for Post.toJSON()

setContent

public void setContent(String content)

Set the body of the post to the parameter provided.

Parameters:
  • content – Formatted body of the post.

See also: org.codethechange.culturemesh.FormatManager

setDatePosted

public void setDatePosted(String datePosted)

Get the timestamp for when the post was created.

Parameters:
  • datePosted – When post was created. Conforms to EEE, dd MMM yyyy kk:mm:ss z

toJSON

public JSONObject toJSON()

Generate a JSON describing the object. The JSON will conform to the following format:

{
               "id_user": 0,
               "id_network": 0,
               "post_text": "string",
               "vid_link": "string",
               "img_link": "string"
           }

The resulting object is suitable for use with the /post/new endpoint (PUT and POST).

Throws:
  • JSONException – Unclear when this would be thrown
Returns:

JSON representation of the object