User

public class User implements Serializable

Represents a CultureMesh user’s public profile. Methods that require non-public data (e.g. email or password) take that information in as parameters and do not store it after the method completes.

Fields

CM_LOGO_URL

public static final String CM_LOGO_URL

DEFAULT_BIO

public static final String DEFAULT_BIO

DEFAULT_GENDER

public static final String DEFAULT_GENDER

IMG_URL_PREFIX

public static final String IMG_URL_PREFIX

aboutMe

public String aboutMe

Bio user has written about themselves. Editable by user.

firstName

public String firstName

User’s first name. Editable by user, and may be pseudonymous.

gender

public String gender

User’s gender. Editable by user.

id

public long id

The user’s unique identifier, which identifies them across all of CultureMesh and is constant. Not editable by user.

imgURL

public String imgURL

URL for the user’s profile picture. Editable by user.

lastName

public String lastName

User’s last name. Editable by user, and may be pseudonymous.

role

public int role

TODO: What does a user’s role represent? This value seems to be 0 for all users. Editable by user.

username

public String username

User’s display name that is publicly used to identify their posts, events, etc. Editable by user. Must be unique across all of CultureMesh’s users.

Constructors

User

public User(long id, String firstName, String lastName, String username, String imgURL, String aboutMe, String gender)

Create a new object, storing the provided parameters into the related instance fields.

Parameters:
  • id – Uniquely identifies user across all of CultureMesh.
  • firstName – User’s first name (may be pseudonymous)
  • lastName – User’s last name (may be pseudonymous)
  • username – The user’s “display name” that will serve as their main public identifier. Must be unique across all of CultureMesh’s users.
  • imgURL – URL suffix (after User.IMG_URL_PREFIX to the user’s profile picture
  • aboutMe – Short bio describing the user
  • gender – User’s self-identified gender

User

public User(long id, String firstName, String lastName, String username)

Create a new object, storing the provided parameters into the related instance fields. Intended to be used when creating accounts, as img_url, about_me, and gender are initialized to defaults as described in the constants for User.

Parameters:
  • id – Uniquely identifies user across all of CultureMesh.
  • firstName – User’s first name (may be pseudonymous)
  • lastName – User’s last name (may be pseudonymous)
  • username – The user’s “display name” that will serve as their main public identifier. Must be unique across all of CultureMesh’s users.

User

public User(JSONObject res)

Create a new user from a JSON that conforms to the following format:

{
          "id": 0,
          "username": "string",
          "first_name": "string",
          "last_name": "string",
          "role": 0,
          "gender": "string",
          "about_me": "string",
          "img_link": "string",
         }

Other key-value pairs are acceptable, but will be ignored. Note that img_link does not include the base User.IMG_URL_PREFIX. A missing, null, or empty img_link is interpreted as an unset link, which User.CM_LOGO_URL is used for.

Parameters:
  • res – JSON describing the user to create
Throws:
  • JSONException – May be thrown in the case of an improperly structured JSON

User

public User()

Empty constructor that does no initialization. For database use only.

Methods

getBio

public String getBio()

Get the user’s self-written bio (i.e. “about me” text)

Returns:User’s description of themselves (i.e. their bio)

getFirstName

public String getFirstName()

Get the user’s first name. May be pseudonymous.

Returns:User’s potentially pseudonymous first name.

getImgURL

public String getImgURL()

Get the URL to the user’s profile photo

Returns:URL that links to the user’s profile photo

getLastName

public String getLastName()

Get the user’s last name. May be pseudonymous.

Returns:User’s potentially pseudonymous last name.

getPostJson

public JSONObject getPostJson(String email, String password)

Create a JSON representation of the object that conforms to the following format:

{
           "username": "string",
           "password": "string",
           "first_name": "string",
           "last_name": "string",
           "email": "string",
           "role": 0,
           "img_link": "string",
           "about_me": "string",
           "gender": "string"
        }

This is intended to be the format used by the /user/users POST endpoint. Note that img_link does not include the base User.IMG_URL_PREFIX. A missing, null, or empty img_link is interpreted as an unset link, which User.CM_LOGO_URL is used for.

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

JSON representation of the object

getPutJson

public JSONObject getPutJson(String email)

Create a JSON representation of the object that conforms to the following format:

{
          "id": 0,
          "username": "string",
          "first_name": "string",
          "last_name": "string",
          "email": "string",
          "role": 0,
          "gender": "string",
          "about_me": "string",
          "img_link": "string"
        }

This is intended to be the format used by the /user/users PUT endpoint. Note that img_link does not include the base User.IMG_URL_PREFIX. A missing, null, or empty img_link is interpreted as an unset link, which User.CM_LOGO_URL is used for.

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

JSON representation of the object

getUsername

public String getUsername()

Get the user’s chosen display name, which should be used as their unique public identifier.

Returns:User’s display name, which must be unique across all of CultureMesh’s users.

setBio

public void setBio(String bio)

Set the text of the user’s bio

Parameters:
  • bio – New bio the user has chosen for themselves

setFirstName

public void setFirstName(String firstName)

Set the user’s first name

Parameters:
  • firstName – New name to save as the user’s first name

setImgURL

public void setImgURL(String imgURL)

Set the URL for the user’s profile photo

Parameters:
  • imgURL – URL to the user’s new profile photo

setLastName

public void setLastName(String lastName)

Set the user’s last name

Parameters:
  • lastName – New name to save as the user’s last name

setUsername

public void setUsername(String username)

Set the user’s display name, which must be unique across CultureMesh

Parameters:
  • username – New display name to use for the user. Must be unique across all of CultureMesh’s users.