Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package domain;
- import exception.BioException;
- import exception.UserException;
- import javax.persistence.*;
- import java.io.Serializable;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * The type User.
- */
- @Entity
- @NamedQueries({
- @NamedQuery(name="User.getByUsername",
- query="SELECT User FROM User WHERE username LIKE :username "),
- })
- public class User implements Serializable {
- @Id
- @GeneratedValue
- private Long id;
- @Column
- private String nickname;
- @Column(unique=true)
- private String username;
- @Column
- private String password;
- @Column
- private String email;
- @Column
- private String bio;
- @Column
- private String website;
- @Column
- private String location;
- @ManyToMany
- //@JoinTable(name = "follower")
- private List<User> follower;
- @ManyToMany
- //@JoinTable(name = "following")
- private List<User> following;
- @OneToMany
- private List<Kweet> kweets;
- private int boiLimit = 160;
- /**
- * Instantiates a new User.
- *
- * @param nickname the nickname
- * @param username the username
- * @param password the password
- * @param email the email
- */
- public User(String nickname, String username, String password, String email) throws UserException {
- setNickname(nickname);
- setUsername(username);
- setPassword(password);
- setEmail(email);
- follower = new ArrayList<>();
- following = new ArrayList<>();
- kweets = new ArrayList<>();
- }
- public User() {}
- public void setId(Long id) {
- this.id = id;
- }
- /**
- * Gets id.
- *
- * @return the id
- */
- public Long getId() {
- return id;
- }
- /**
- * Gets nickname.
- *
- * @return the nickname
- */
- public String getNickname() {
- return nickname;
- }
- /**
- * Sets nickname.
- *
- * @param nickname the nickname
- */
- public void setNickname(String nickname) throws UserException {
- int len = nickname.length();
- if (nickname.length() > 1) {
- this.nickname = nickname;
- } else {
- throw new UserException("Nickname can not be a length of 0");
- }
- }
- /**
- * Gets username.
- *
- * @return the username
- */
- public String getUsername() {
- return username;
- }
- /**
- * Sets username.
- *
- * @param username the username
- */
- public void setUsername(String username) throws UserException {
- if (username.length() > 1) {
- this.username = username;
- } else {
- throw new UserException("Username can not be a length of 0");
- }
- }
- /**
- * Gets password.
- *
- * @return the password
- */
- public String getPassword() {
- return password;
- }
- /**
- * Sets password.
- *
- * @param password the password
- */
- public void setPassword(String password) throws UserException {
- if (password.length() > 1) {
- this.password = password;
- } else {
- throw new UserException("Password can not be a length of 0");
- }
- }
- /**
- * Gets email.
- *
- * @return the email
- */
- public String getEmail() {
- return email;
- }
- /**
- * Sets email.
- *
- * @param email the email
- */
- public void setEmail(String email) throws UserException {
- if (isValidEmailAddress(email)) {
- this.email = email;
- } else {
- throw new UserException("Email is not valid");
- }
- }
- /**
- * Gets bio.
- *
- * @return the bio
- */
- public String getBio() {
- return bio;
- }
- /**
- * Sets bio.
- *
- * @param bio the bio
- */
- public void setBio(String bio) throws BioException {
- if (bio.length() > this.boiLimit) {
- throw new BioException("Biography is to long, it can not be longer than: " + this.boiLimit);
- } else {
- this.bio = bio;
- }
- }
- /**
- * Gets website.
- *
- * @return the website
- */
- public String getWebsite() {
- return website;
- }
- /**
- * Sets website.
- *
- * @param website the website
- */
- public void setWebsite(String website) {
- this.website = website;
- }
- /**
- * Gets location.
- *
- * @return the location
- */
- public String getLocation() {
- return location;
- }
- /**
- * Sets location.
- *
- * @param location the location
- */
- public void setLocation(String location) {
- this.location = location;
- }
- /**
- * Gets follower.
- *
- * @return the follower
- */
- public List<User> getFollower() {
- return follower;
- }
- /**
- * Add follower.
- *
- * @param user the user
- */
- public void addFollower(User user) {
- this.follower.add(user);
- }
- /**
- * Remove follower.
- *
- * @param user the user
- */
- public void removeFollower(User user) {
- this.follower.remove(user);
- }
- /**
- * Gets following.
- *
- * @return the following
- */
- public List<User> getFollowing() {
- return following;
- }
- /**
- * Add following.
- *
- * @param user the user
- */
- public void addFollowing(User user) {
- this.following.add(user);
- }
- /**
- * Remove following.
- *
- * @param user the user
- */
- public void removeFollowing(User user) {
- this.following.remove(user);
- }
- /**
- * Add kweet.
- *
- * @param kweet the kweet
- */
- public void addKweet(Kweet kweet) {
- this.kweets.add(kweet);
- }
- /**
- * Add kweet.
- *
- * @param kweet the kweet
- */
- public boolean removeKweet(Kweet kweet) {
- return this.kweets.remove(kweet);
- }
- /**
- * Gets kweets.
- *
- * @return the kweets
- */
- public List<Kweet> getKweets() {
- return kweets;
- }
- public boolean isValidEmailAddress(String email) {
- String ePattern = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1," +
- "3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$";
- java.util.regex.Pattern p = java.util.regex.Pattern.compile(ePattern);
- java.util.regex.Matcher m = p.matcher(email);
- return m.matches();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement