User.java

// license-header java merge-point
//
// Attention: Generated code! Do not modify by hand!
// Generated by EntityEmbeddable.vsl in andromda-ejb3-cartridge on 09/18/2014 12:09:10.
//
package org.andromda.timetracker.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

/**
 * <p>
 * TODO: Model Documentation for org.andromda.timetracker.domain.User
 * </p>
 *
 * Autogenerated POJO EJB class for User containing the
 * bulk of the entity implementation.
 *
 * This is autogenerated by AndroMDA using the EJB3
 * cartridge.
 *
 * DO NOT MODIFY this class.
 */
@Entity
@Table(name="USERS")
@NamedQueries
({
    @NamedQuery(name="User.findAll", query="SELECT u FROM User AS u"),
    @NamedQuery(name="User.findByUsername", query="SELECT u from User as u WHERE u.username = :username")
})
public class User
    implements Serializable, Comparable<User>{
    private static final long serialVersionUID = 8028448959302332055L;

    // ----------- 9 Attribute Definitions ------------
    protected String username;
    protected String firstName;
    protected String lastName;
    protected String password;
    protected String email;
    protected boolean isActive;
    protected Date creationDate;
    protected String comment;
    protected Long userId;

    // --------- 1 Relationship Definitions -----------
    protected Set<UserRole> roles = new HashSet<UserRole>();

    // ---- Manageable Display Attributes (Transient) -----

    // -------- 9 Attribute Accessors ----------
    /**
     * <p>
     * TODO: Model Documentation for username
     * </p>
     * Get the username property.
     * @return String The value of username
     */
    @Column(name="USERNAME", unique=true, nullable=false, insertable=true, updatable=true)
    @NotNull(message="username is required")
    public String getUsername()
    {
        return this.username;
    }

    /**
     * <p>
     * TODO: Model Documentation for username
     * </p>
     * Set the username property.
     * @param value the new value
     */
    public void setUsername(String value)
    {
        this.username = value;
    }

    /**
     * <p>
     * TODO: Model Documentation for firstName
     * </p>
     * Get the firstName property.
     * @return String The value of firstName
     */
    @Column(name="FIRST_NAME", nullable=false, insertable=true, updatable=true)
    @NotNull(message="firstName is required")
    public String getFirstName()
    {
        return this.firstName;
    }

    /**
     * <p>
     * TODO: Model Documentation for firstName
     * </p>
     * Set the firstName property.
     * @param value the new value
     */
    public void setFirstName(String value)
    {
        this.firstName = value;
    }

    /**
     * <p>
     * TODO: Model Documentation for lastName
     * </p>
     * Get the lastName property.
     * @return String The value of lastName
     */
    @Column(name="LAST_NAME", nullable=false, insertable=true, updatable=true)
    @NotNull(message="lastName is required")
    public String getLastName()
    {
        return this.lastName;
    }

    /**
     * <p>
     * TODO: Model Documentation for lastName
     * </p>
     * Set the lastName property.
     * @param value the new value
     */
    public void setLastName(String value)
    {
        this.lastName = value;
    }

    /**
     * <p>
     * TODO: Model Documentation for password
     * </p>
     * Get the password property.
     * @return String The value of password
     */
    @Column(name="PASSWORD", nullable=false, insertable=true, updatable=true)
    @NotNull(message="password is required")
    public String getPassword()
    {
        return this.password;
    }

    /**
     * <p>
     * TODO: Model Documentation for password
     * </p>
     * Set the password property.
     * @param value the new value
     */
    public void setPassword(String value)
    {
        this.password = value;
    }

    /**
     * <p>
     * TODO: Model Documentation for email
     * </p>
     * Get the email property.
     * @return String The value of email
     */
    @Column(name="EMAIL", nullable=false, insertable=true, updatable=true)
    @NotNull(message="email is required")
    public String getEmail()
    {
        return this.email;
    }

    /**
     * <p>
     * TODO: Model Documentation for email
     * </p>
     * Set the email property.
     * @param value the new value
     */
    public void setEmail(String value)
    {
        this.email = value;
    }

    /**
     * <p>
     * TODO: Model Documentation for isActive
     * </p>
     * Get the isActive property.
     * @return boolean The value of isActive
     */
    @Column(name="IS_ACTIVE", nullable=false, insertable=true, updatable=true)
    @NotNull(message="isActive is required")
    public boolean isIsActive()
    {
        return this.isActive;
    }

    /**
     * <p>
     * TODO: Model Documentation for isActive
     * </p>
     * Set the isActive property.
     * @param value the new value
     */
    public void setIsActive(boolean value)
    {
        this.isActive = value;
    }

    /**
     * <p>
     * TODO: Model Documentation for creationDate
     * </p>
     * Get the creationDate property.
     * @return Date The value of creationDate
     */
    @Column(name="CREATION_DATE", nullable=false, insertable=true, updatable=true)
    @Temporal(TemporalType.TIMESTAMP)
    @NotNull(message="creationDate is required")
    public Date getCreationDate()
    {
        return this.creationDate;
    }

    /**
     * <p>
     * TODO: Model Documentation for creationDate
     * </p>
     * Set the creationDate property.
     * @param value the new value
     */
    public void setCreationDate(Date value)
    {
        this.creationDate = value;
    }

    /**
     * <p>
     * TODO: Model Documentation for comment
     * </p>
     * Get the comment property.
     * @return String The value of comment
     */
    @Column(name="COMMENT", insertable=true, updatable=true)
    public String getComment()
    {
        return this.comment;
    }

    /**
     * <p>
     * TODO: Model Documentation for comment
     * </p>
     * Set the comment property.
     * @param value the new value
     */
    public void setComment(String value)
    {
        this.comment = value;
    }

    /**
     * <p>
     * TODO: Model Documentation for userId
     * </p>
     * Get the userId property.
     * @return Long The value of userId
     */
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="USER_ID", nullable=false, insertable=true, updatable=true)
    public Long getUserId()
    {
        return this.userId;
    }

    /**
     * <p>
     * TODO: Model Documentation for userId
     * </p>
     * Set the userId property.
     * @param value the new value
     */
    public void setUserId(Long value)
    {
        this.userId = value;
    }


    // ------------- 1 Relations ------------------
    /**
     * <p>
     * TODO: Model Documentation for roles
     * </p>
     * Get the roles Collection
     * @return Set<UserRole>
     */
    @OneToMany(cascade={CascadeType.ALL})
    @JoinTable
    (
        name="USER_ROLES",
        joinColumns={@JoinColumn(name="USER_USER_ID_FK", referencedColumnName="USER_ID")},
        inverseJoinColumns={@JoinColumn(name="ROLES_USER_ROLE_ID_FK", referencedColumnName="USER_ROLE_ID")}
    )
    public Set<UserRole> getRoles()
    {
        return this.roles;
    }

    /**
     * <p>
     * TODO: Model Documentation for roles
     * </p>
     * Set the roles
     * @param rolesIn
     */
    public void setRoles (Set<UserRole> rolesIn)
    {
        this.roles = rolesIn;
    }

    // --------------- Constructors -----------------

    /**
     * Default empty no-arg constructor
     */
    public User()
    {
        // Default empty constructor
    }

    /**
     * Constructor with all updatable Entity attributes except auto incremented identifiers.
     *
     * @param username String value for the username property required=true lower=1
     * @param firstName String value for the firstName property required=true lower=1
     * @param lastName String value for the lastName property required=true lower=1
     * @param password String value for the password property required=true lower=1
     * @param email String value for the email property required=true lower=1
     * @param isActive boolean value for the isActive property required=true lower=1
     * @param creationDate Date value for the creationDate property required=true lower=1
     * @param comment String value for the comment property required=false lower=0
     */
    public User(String username, String firstName, String lastName, String password, String email, boolean isActive, Date creationDate, String comment)
    {
        this.username = username;
        this.firstName = firstName;
        this.lastName = lastName;
        this.password = password;
        this.email = email;
        this.isActive = isActive;
        this.creationDate = creationDate;
        this.comment = comment;
    }

    /**
     * Constructor with required Entity attributes except auto incremented identifiers.
     *
     * @param username Value for the username property
     * @param firstName Value for the firstName property
     * @param lastName Value for the lastName property
     * @param password Value for the password property
     * @param email Value for the email property
     * @param isActive Value for the isActive property
     * @param creationDate Value for the creationDate property
     */
    public User(String username, String firstName, String lastName, String password, String email, boolean isActive, Date creationDate)
    {
        this.username = username;
        this.firstName = firstName;
        this.lastName = lastName;
        this.password = password;
        this.email = email;
        this.isActive = isActive;
        this.creationDate = creationDate;
    }

    /**
     * Constructor with all Entity attribute values and CMR relations.
     *
     * @param username String value for the username property
     * @param firstName String value for the firstName property
     * @param lastName String value for the lastName property
     * @param password String value for the password property
     * @param email String value for the email property
     * @param isActive boolean value for the isActive property
     * @param creationDate Date value for the creationDate property
     * @param comment String value for the comment property
     * @param roles Set<UserRole> value for the roles relation
     */
    public User(String username, String firstName, String lastName, String password, String email, boolean isActive, Date creationDate, String comment, Set<UserRole> roles)
    {
        // 8 updatableAttributes
        setUsername(username);
        setFirstName(firstName);
        setLastName(lastName);
        setPassword(password);
        setEmail(email);
        setIsActive(isActive);
        setCreationDate(creationDate);
        setComment(comment);

        // 1 relations
        setRoles(roles);
    }

    // -------- Common Methods -----------
    /**
     * Indicates if the argument is of the same type and all values are equal.
     * @param object The target object to compare with
     * @return boolean True if both objects a 'equal'
     * @see Object#equals(Object)
     */
    @Override
    public boolean equals(Object object)
    {
        if (null == object)
        {
            return false;
        }
        if (this == object)
        {
            return true;
        }
        if (!(object instanceof User))
        {
            return false;
        }
        final User that = (User)object;
        if (this.getUserId() == null || that.getUserId() == null || !this.getUserId().equals(that.getUserId()))
        {
            return false;
        }
        return true;
    }

    /**
     * Returns a hash code value for the object
     * @return int The hash code value
     * @see Object#hashCode
     */
    @Override
    public int hashCode()
    {
        int hashCode = 0;
        hashCode = 29 * hashCode + (getUserId() == null ? 0 : getUserId().hashCode());

        return hashCode;
    }

    /**
     * Returns a String representation of the object
     * @return String Textual representation of the object displaying name/value pairs for all attributes
     * @see Object#toString
     */
    @Override
    public String toString()
    {
        StringBuilder sb = new StringBuilder();
        sb.append("User(");
        sb.append(" username=").append(getUsername());
        sb.append(" firstName=").append(getFirstName());
        sb.append(" lastName=").append(getLastName());
        sb.append(" password=").append(getPassword());
        sb.append(" email=").append(getEmail());
        sb.append(" isActive=").append(isIsActive());
        sb.append(" creationDate=").append(getCreationDate());
        sb.append(" comment=").append(getComment());
        sb.append(" userId=").append(getUserId());
        sb.append(" roles=").append(getRoles());
        sb.append(")");
        return sb.toString();
    }

    /**
     * @see Comparable#compareTo
     */
    @Override
    public int compareTo(User o)
    {
        int cmp = 0;
        if (this.getUserId() != null)
        {
            cmp = this.getUserId().compareTo(o.getUserId());
        }
        else
        {
            if (this.getUsername() != null)
            {
                cmp = (cmp != 0 ? cmp : this.getUsername().compareTo(o.getUsername()));
            }
            if (this.getFirstName() != null)
            {
                cmp = (cmp != 0 ? cmp : this.getFirstName().compareTo(o.getFirstName()));
            }
            if (this.getLastName() != null)
            {
                cmp = (cmp != 0 ? cmp : this.getLastName().compareTo(o.getLastName()));
            }
            if (this.getPassword() != null)
            {
                cmp = (cmp != 0 ? cmp : this.getPassword().compareTo(o.getPassword()));
            }
            if (this.getEmail() != null)
            {
                cmp = (cmp != 0 ? cmp : this.getEmail().compareTo(o.getEmail()));
            }
            if (this.getCreationDate() != null)
            {
                cmp = (cmp != 0 ? cmp : this.getCreationDate().compareTo(o.getCreationDate()));
            }
            if (this.getComment() != null)
            {
                cmp = (cmp != 0 ? cmp : this.getComment().compareTo(o.getComment()));
            }
        }
        return cmp;
    }


}